Skip to content

CLI: Review onboarding trigger logic on first dev run#34552

Merged
yannbf merged 8 commits into
project/sb-agentic-setupfrom
sidnioulz/fix-onboarding-ux-trigger
Apr 16, 2026
Merged

CLI: Review onboarding trigger logic on first dev run#34552
yannbf merged 8 commits into
project/sb-agentic-setupfrom
sidnioulz/fix-onboarding-ux-trigger

Conversation

@Sidnioulz
Copy link
Copy Markdown
Member

@Sidnioulz Sidnioulz commented Apr 15, 2026

What I did

Replaced the old init -> dev --initial-path=/onboarding workflow with one where init registers when onboarding must happen in the local project cache, and any subsequent dev call consumes this registered flag if no --initial-path is set, allowing the user to be onboarded.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  • Remove "skipOnbarding" from your global SB settings in your home
  • Create a new project
  • Run dev

🦋 Canary release

This pull request has been released as version 0.0.0-pr-34552-sha-a34e9165. Try it out in a new sandbox by running npx storybook@0.0.0-pr-34552-sha-a34e9165 sandbox or in an existing project with npx storybook@0.0.0-pr-34552-sha-a34e9165 upgrade.

More information
Published version 0.0.0-pr-34552-sha-a34e9165
Triggered by @Sidnioulz
Repository storybookjs/storybook
Branch sidnioulz/fix-onboarding-ux-trigger
Commit a34e9165
Datetime Wed Apr 15 14:27:55 UTC 2026 (1776263275)
Workflow run 24460240811

To request a new release of this pull request, mention the @storybookjs/core team.

core team members can create a new canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=34552

Summary by CodeRabbit

  • Tests

    • Added tests covering onboarding initial-path resolution for cached onboarding, CLI-provided paths, and agent contexts.
  • Refactor

    • Onboarding signaling now uses a persistent flag instead of injecting a CLI path.
    • Dev startup respects an explicit CLI path and agent context over the onboarding flag; explicit initial-path injection removed.

@Sidnioulz Sidnioulz requested a review from yannbf April 15, 2026 14:25
@Sidnioulz Sidnioulz added build Internal-facing build tooling & test updates ci:normal labels Apr 15, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 15, 2026

View your CI Pipeline Execution ↗ for commit 96d1021

Command Status Duration Result
nx run-many -t compile,check,knip,test,lint,fmt... ✅ Succeeded 14m 44s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-16 10:47:58 UTC

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 15, 2026

View your CI Pipeline Execution ↗ for commit a34e916


☁️ Nx Cloud last updated this comment at 2026-04-15 14:26:07 UTC

@Sidnioulz
Copy link
Copy Markdown
Member Author

@yannbf making a canary to test this because init won't run locally

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Adds cache-driven onboarding signaling: a new exported helper resolves the initial browser path by consulting an onboarding-pending cache key (with CLI and agent overrides), build-dev now uses that helper, and init sets the cache instead of injecting a CLI --initial-path flag.

Changes

Cohort / File(s) Summary
Core server onboarding
code/core/src/core-server/build-dev.ts, code/core/src/core-server/build-dev.onboarding.test.ts
Added exported async resolveOnboardingInitialPath(cliInitialPath) and integrated it into buildDevStandalone. Uses detectAgent() and cache.get('onboarding-pending'), removes the cache key on hit. Added Vitest tests covering cache hit/miss, CLI override, and agent context.
Init / create-storybook
code/lib/create-storybook/src/initiate.ts
During initiation, set cache.set('onboarding-pending', true) for new users when onboarding is supported. Removed inserting --initial-path=/onboarding into dev command and stopped computing shouldOnboard for command construction.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI / user args
    participant Init as create-storybook:initiate
    participant Cache as cache
    participant Core as core-server:buildDev
    participant Detect as detectAgent

    CLI->>Init: initiate (new user)
    Init->>Cache: set('onboarding-pending', true)
    CLI->>Core: start dev-server (may include initialPath)
    Core->>Detect: detectAgent()
    alt CLI provided initialPath
        Core->>Core: return CLI initialPath
    else not agent and no CLI path
        Core->>Cache: get('onboarding-pending')
        alt cache hit
            Core->>Cache: remove('onboarding-pending')
            Core->>Core: return '/onboarding'
        else cache miss
            Core->>Core: return undefined
        end
    else agent detected
        Core->>Core: return undefined
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
code/core/src/core-server/build-dev.onboarding.test.ts (1)

9-47: Align this test with the repository's Vitest spy-mocking conventions.

The mock at line 9 is missing the spy: true option. Additionally, mock behaviors are being set inline within test cases (lines 29, 36, 43) rather than in the beforeEach block. Refactor to use vi.mock('storybook/internal/common', { spy: true }), move all mock behavior setup to beforeEach, and use vi.mocked() to access the mocked functions per the spy-mocking guidelines.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/core/src/core-server/build-dev.onboarding.test.ts` around lines 9 - 47,
Change the top-level mock for 'storybook/internal/common' to use the spy mode
(vi.mock(..., { spy: true })) and move all per-test mock behavior into the
beforeEach block: use vi.mocked(...) to obtain typed mocks for mockCacheGet and
mockCacheRemove and call mockResolvedValue(...) or reset implementations there
instead of inside individual it() blocks; keep the assertions in the tests the
same but remove in-test mock setup so resolveOnboardingInitialPath, mockCacheGet
and mockCacheRemove are consistently prepared via beforeEach.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@code/core/src/core-server/build-dev.ts`:
- Around line 64-67: Wrap the cache calls in try/catch so cache.get and
cache.remove failures are best-effort and do not block startup: call
cache.get('onboarding-pending') inside a try, if it returns truthy attempt
cache.remove('onboarding-pending') inside its own try/catch (so a remove failure
is logged/ignored), and only return '/onboarding' when onboardingPending is
truthy; ensure no errors from cache.get or cache.remove are re-thrown (use the
existing logger or console.warn to record errors). Reference symbols:
onboardingPending, cache.get, cache.remove in build-dev.ts.

In `@code/lib/create-storybook/src/initiate.ts`:
- Line 165: The onboarding cache key is currently global ("onboarding-pending")
and can collide across repos; update the write in
create-storybook/src/initiate.ts where cache.set('onboarding-pending', true) is
called to include a project-specific namespace (e.g., append or prefix with a
project identifier such as projectRoot, repoName, or a hashed workspace id) and
ensure the corresponding read in resolveOnboardingInitialPath uses the exact
same namespaced key; modify the key construction in both the cache.set call and
the lookup in resolveOnboardingInitialPath (referencing the cache.set usage and
the resolveOnboardingInitialPath function) so onboarding state is scoped per
project.
- Around line 164-166: The onboarding cache write
(cache.set('onboarding-pending', true)) can throw and currently lets init fail;
make this persistence best-effort by wrapping the cache.set call used when
shouldOnboard && FeatureCompatibilityService.supportsOnboarding(projectType) in
a try/catch inside the init flow (or the function that contains these symbols),
await the set as before but catch and log the error (or debug) without
rethrowing so init proceeds even if cache persistence fails.

---

Nitpick comments:
In `@code/core/src/core-server/build-dev.onboarding.test.ts`:
- Around line 9-47: Change the top-level mock for 'storybook/internal/common' to
use the spy mode (vi.mock(..., { spy: true })) and move all per-test mock
behavior into the beforeEach block: use vi.mocked(...) to obtain typed mocks for
mockCacheGet and mockCacheRemove and call mockResolvedValue(...) or reset
implementations there instead of inside individual it() blocks; keep the
assertions in the tests the same but remove in-test mock setup so
resolveOnboardingInitialPath, mockCacheGet and mockCacheRemove are consistently
prepared via beforeEach.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8d6c6c7a-bd2a-4977-b24f-18149d8685fd

📥 Commits

Reviewing files that changed from the base of the PR and between 7821847 and a34e916.

📒 Files selected for processing (3)
  • code/core/src/core-server/build-dev.onboarding.test.ts
  • code/core/src/core-server/build-dev.ts
  • code/lib/create-storybook/src/initiate.ts

Comment thread code/core/src/core-server/build-dev.ts Outdated
Comment on lines +164 to +166
if (shouldOnboard && FeatureCompatibilityService.supportsOnboarding(projectType)) {
await cache.set('onboarding-pending', true);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Make onboarding cache persistence best-effort so init cannot fail after successful setup.

A failure in cache.set(...) currently bubbles up and can fail init, even though onboarding redirection is non-critical state.

Proposed fix
   const shouldOnboard = newUser;
   if (shouldOnboard && FeatureCompatibilityService.supportsOnboarding(projectType)) {
-    await cache.set('onboarding-pending', true);
+    try {
+      await cache.set('onboarding-pending', true);
+    } catch (error) {
+      logger.debug(
+        `Failed to persist onboarding state: ${
+          error instanceof Error ? error.message : String(error)
+        }`
+      );
+    }
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/lib/create-storybook/src/initiate.ts` around lines 164 - 166, The
onboarding cache write (cache.set('onboarding-pending', true)) can throw and
currently lets init fail; make this persistence best-effort by wrapping the
cache.set call used when shouldOnboard &&
FeatureCompatibilityService.supportsOnboarding(projectType) in a try/catch
inside the init flow (or the function that contains these symbols), await the
set as before but catch and log the error (or debug) without rethrowing so init
proceeds even if cache persistence fails.

Comment thread code/lib/create-storybook/src/initiate.ts Outdated
Copy link
Copy Markdown
Member Author

@Sidnioulz Sidnioulz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Managed to QA this with the dispatcher and it did work on a fresh React project with the dispatcher and a fresh Angular project with the canary.

@yannbf yannbf merged commit bb7bc99 into project/sb-agentic-setup Apr 16, 2026
14 of 18 checks passed
@yannbf yannbf deleted the sidnioulz/fix-onboarding-ux-trigger branch April 16, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Internal-facing build tooling & test updates ci:normal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants