Skip to content

Conversation

@yannbf
Copy link
Member

@yannbf yannbf commented Nov 3, 2025

Closes #

What I did

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

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This pull request has been released as version 0.0.0-pr-32929-sha-f3d21dc6. Try it out in a new sandbox by running npx [email protected] sandbox or in an existing project with npx [email protected] upgrade.

More information
Published version 0.0.0-pr-32929-sha-f3d21dc6
Triggered by @yannbf
Repository storybookjs/storybook
Branch yann/fix-init-issue
Commit f3d21dc6
Datetime Tue Nov 4 08:47:21 UTC 2025 (1762246041)
Workflow run 19062871569

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=32929

Summary by CodeRabbit

Release Notes

  • Refactor
    • Improved internal Storybook initialization process with enhanced process management and error handling to increase reliability during setup and project onboarding.

@yannbf yannbf self-assigned this Nov 3, 2025
@yannbf yannbf added bug cli patch:yes Bugfix & documentation PR that need to be picked to main branch ci:normal labels Nov 3, 2025
@nx-cloud
Copy link

nx-cloud bot commented Nov 3, 2025

View your CI Pipeline Execution ↗ for commit f3d21dc

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 48s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-03 12:35:14 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 3, 2025

📝 Walkthrough

Walkthrough

The initiate.ts file has been refactored to extract Storybook dev server spawning logic into an internal helper function. The spawning mechanism was changed from a synchronous package manager call to using execa.command for improved subprocess management.

Changes

Cohort / File(s) Summary
Storybook dev server initialization refactor
code/lib/create-storybook/src/initiate.ts
Introduced runStorybookDev helper function to encapsulate dev server spawning logic. Replaced synchronous packageManager.runPackageCommandSync with execa.command for subprocess spawning. Added execa import with lint suppression and logger message before spawn. Error handling semantics preserved.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review the execa.command subprocess spawning to ensure it correctly replaces the synchronous behavior and handles the project directory context
  • Verify error handling logic catches and swallows errors appropriately from the spawned process
  • Confirm the helper function properly encapsulates onboarding flag logic and command flag assembly
✨ Finishing touches
  • 📝 Generate docstrings

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

Copy link
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: 2

🧹 Nitpick comments (1)
code/lib/create-storybook/src/initiate.ts (1)

592-592: Replace console.log with the logger.

The code uses console.log directly, which violates the coding guidelines for this file. Use the imported logger instead.

As per coding guidelines, apply this diff:

-      console.log(err);
+      logger.error(err);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 03cae6b and f3d21dc.

📒 Files selected for processing (1)
  • code/lib/create-storybook/src/initiate.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{js,jsx,json,html,ts,tsx,mjs}: Run Prettier formatting on changed files before committing
Run ESLint on changed files and fix all errors/warnings before committing (use yarn lint:js:cmd <file>)

Files:

  • code/lib/create-storybook/src/initiate.ts
**/*.{ts,tsx,js,jsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Export functions from modules when they need to be unit-tested

Files:

  • code/lib/create-storybook/src/initiate.ts
code/**/*.{ts,tsx,js,jsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

In application code, use Storybook loggers instead of console.* (client code: storybook/internal/client-logger; server code: storybook/internal/node-logger)

Files:

  • code/lib/create-storybook/src/initiate.ts
{code/**,scripts/**}/**/*.{ts,tsx,js,jsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Do not use console.log, console.warn, or console.error directly unless in isolated files where importing loggers would significantly increase bundle size

Files:

  • code/lib/create-storybook/src/initiate.ts
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-13T13:33:14.659Z
Learning: Applies to test-storybooks/** : Maintain test Storybook configurations under `test-storybooks/` for E2E and visual testing scenarios
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-13T13:33:14.659Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx,mjs} : In application code, use Storybook loggers instead of `console.*` (client code: `storybook/internal/client-logger`; server code: `storybook/internal/node-logger`)
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-13T13:33:14.659Z
Learning: Applies to scripts/**/*.{ts,js,mjs} : In Node.js scripts, use `storybook/internal/node-logger` instead of `console.*`
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-13T13:33:14.659Z
Learning: Applies to code/.storybook/** : Place internal UI Storybook configuration in `code/.storybook/` and maintain it there
Learnt from: mrginglymus
Repo: storybookjs/storybook PR: 32556
File: code/core/package.json:309-313
Timestamp: 2025-09-29T13:20:23.346Z
Learning: The `fast-printf` dependency in Storybook's core package is bundled into the final distribution during the build process, so it should remain in devDependencies rather than being moved to dependencies, following the same pattern as other bundled dependencies like `open`.
Learnt from: ndelangen
Repo: storybookjs/storybook PR: 32484
File: code/core/package.json:326-326
Timestamp: 2025-09-17T07:31:04.432Z
Learning: In Storybook's core package, dependencies like `open` are bundled into the final distribution during the build process, so they should remain in devDependencies rather than being moved to dependencies. End users don't need these packages as separate runtime dependencies since they're included in the bundled code.
📚 Learning: 2025-10-13T13:33:14.659Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-13T13:33:14.659Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx,mjs} : In application code, use Storybook loggers instead of `console.*` (client code: `storybook/internal/client-logger`; server code: `storybook/internal/node-logger`)

Applied to files:

  • code/lib/create-storybook/src/initiate.ts
📚 Learning: 2025-10-13T13:33:14.659Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-13T13:33:14.659Z
Learning: Applies to test-storybooks/** : Maintain test Storybook configurations under `test-storybooks/` for E2E and visual testing scenarios

Applied to files:

  • code/lib/create-storybook/src/initiate.ts
📚 Learning: 2025-10-13T13:33:14.659Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-13T13:33:14.659Z
Learning: Applies to code/.storybook/** : Place internal UI Storybook configuration in `code/.storybook/` and maintain it there

Applied to files:

  • code/lib/create-storybook/src/initiate.ts
📚 Learning: 2025-09-17T07:31:04.432Z
Learnt from: ndelangen
Repo: storybookjs/storybook PR: 32484
File: code/core/package.json:326-326
Timestamp: 2025-09-17T07:31:04.432Z
Learning: In Storybook's core package, dependencies like `open` are bundled into the final distribution during the build process, so they should remain in devDependencies rather than being moved to dependencies. End users don't need these packages as separate runtime dependencies since they're included in the bundled code.

Applied to files:

  • code/lib/create-storybook/src/initiate.ts
📚 Learning: 2025-09-29T13:20:23.346Z
Learnt from: mrginglymus
Repo: storybookjs/storybook PR: 32556
File: code/core/package.json:309-313
Timestamp: 2025-09-29T13:20:23.346Z
Learning: The `fast-printf` dependency in Storybook's core package is bundled into the final distribution during the build process, so it should remain in devDependencies rather than being moved to dependencies, following the same pattern as other bundled dependencies like `open`.

Applied to files:

  • code/lib/create-storybook/src/initiate.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (2)
code/lib/create-storybook/src/initiate.ts (2)

812-813: LGTM!

The delegation to the new helper function is clean and properly awaited.


35-36: The original review comment is incorrect.

The dependency verification shows execa is properly declared in devDependencies with version ^5.0.0. The eslint-disable-next-line depend/ban-dependencies suppression is an established pattern in Storybook for bundled development dependencies (consistent with how fast-printf is handled per the codebase conventions).

Additionally, the fire-and-forget pattern for execa.command() at line 858 is intentional and documented in the code comment explaining it spawns a subprocess in the user's project directory to avoid path issues.

Likely an incorrect or invalid review comment.

Comment on lines +830 to +838
const supportsOnboarding = [
ProjectType.REACT_SCRIPTS,
ProjectType.REACT,
ProjectType.WEBPACK_REACT,
ProjectType.REACT_PROJECT,
ProjectType.NEXTJS,
ProjectType.VUE3,
ProjectType.ANGULAR,
].includes(projectType);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Use the existing ONBOARDING_PROJECT_TYPES constant.

The supportsOnboarding check duplicates the ONBOARDING_PROJECT_TYPES constant defined at lines 66-75. This creates a maintenance burden if the list changes.

Apply this diff to use the existing constant:

-    const supportsOnboarding = [
-      ProjectType.REACT_SCRIPTS,
-      ProjectType.REACT,
-      ProjectType.WEBPACK_REACT,
-      ProjectType.REACT_PROJECT,
-      ProjectType.NEXTJS,
-      ProjectType.VUE3,
-      ProjectType.ANGULAR,
-    ].includes(projectType);
+    const supportsOnboarding = ONBOARDING_PROJECT_TYPES.includes(projectType);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const supportsOnboarding = [
ProjectType.REACT_SCRIPTS,
ProjectType.REACT,
ProjectType.WEBPACK_REACT,
ProjectType.REACT_PROJECT,
ProjectType.NEXTJS,
ProjectType.VUE3,
ProjectType.ANGULAR,
].includes(projectType);
const supportsOnboarding = ONBOARDING_PROJECT_TYPES.includes(projectType);
🤖 Prompt for AI Agents
In code/lib/create-storybook/src/initiate.ts around lines 830 to 838, the
supportsOnboarding variable re-declares the list of onboarding project types
instead of using the existing ONBOARDING_PROJECT_TYPES constant defined earlier
(lines 66-75); replace the inline array with
ONBOARDING_PROJECT_TYPES.includes(projectType) so the check reuses the canonical
constant (ensure the constant is in scope/imported if necessary).

Comment on lines +858 to +860
execa.command(`${storybookCommand} ${flags.join(' ')}`, {
stdio: 'inherit',
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Missing await on the execa.command call.

The execa.command() call at line 858 is not awaited, which means the function returns immediately without waiting for the Storybook dev server to start. This appears unintentional based on the async function signature and may cause issues if the caller expects the process to complete or if error handling is needed.

If the intent is to spawn a long-running dev server and return immediately (fire-and-forget), consider:

  1. Removing the try-catch wrapper since errors won't be caught from an unawaited promise
  2. Adding a comment explaining the fire-and-forget pattern
  3. Optionally handling the returned ChildProcess for cleanup

If the process should be awaited, apply this diff:

-    execa.command(`${storybookCommand} ${flags.join(' ')}`, {
+    await execa.command(`${storybookCommand} ${flags.join(' ')}`, {
       stdio: 'inherit',
     });

🏁 Script executed:

#!/bin/bash
# View the file context around lines 858-860 with surrounding code and try-catch wrapper
sed -n '820,900p' code/lib/create-storybook/src/initiate.ts

Length of output: 1375


🏁 Script executed:

#!/bin/bash
# Search for similar execa patterns with fire-and-forget or .catch() usage
rg -n -B2 -A2 'execa\.(command|.*)\(' code/ --type ts --type tsx | head -100

Length of output: 27


🏁 Script executed:

#!/bin/bash
# Search for execa patterns in TypeScript files to find similar patterns
rg -n 'execa\.' code/ -g '*.ts' -A3 | head -150

Length of output: 626


🏁 Script executed:

#!/bin/bash
# View context around the awaited execa call for comparison
sed -n '180,210p' code/lib/create-storybook/src/scaffold-new-project.ts

Length of output: 796


🏁 Script executed:

#!/bin/bash
# Search for .catch() patterns on execa or similar async calls
rg -n '\.catch\(' code/lib/create-storybook/ -g '*.ts' -B2 -A2

Length of output: 744


Await the execa.command() call.

The review comment is correct. The initiate() function is called with await in code/lib/create-storybook/src/bin/run.ts:59 (.catch(() => process.exit(1))), which means the caller expects the returned promise to complete before handling errors. Without awaiting execa.command() at line 858, the function returns immediately and breaks the promise chain, making the try-catch ineffective.

Apply this fix:

-    execa.command(`${storybookCommand} ${flags.join(' ')}`, {
+    await execa.command(`${storybookCommand} ${flags.join(' ')}`, {
       stdio: 'inherit',
     });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
execa.command(`${storybookCommand} ${flags.join(' ')}`, {
stdio: 'inherit',
});
await execa.command(`${storybookCommand} ${flags.join(' ')}`, {
stdio: 'inherit',
});
🤖 Prompt for AI Agents
In code/lib/create-storybook/src/initiate.ts around lines 858 to 860, the
execa.command(...) call is not awaited so the function returns before the
spawned process completes, breaking the caller's promise chain and error
handling; update the code to either prepend await to execa.command(...) or
return the execa.command(...) promise so the initiate() function only resolves
after the command finishes, ensuring errors are propagated to the caller.

@yannbf yannbf merged commit c6a705d into next Nov 4, 2025
62 of 67 checks passed
@yannbf yannbf deleted the yann/fix-init-issue branch November 4, 2025 11:17
ndelangen pushed a commit that referenced this pull request Nov 4, 2025
CLI: Fix issue with running Storybook after being initialized
(cherry picked from commit c6a705d)
@github-actions github-actions bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Nov 4, 2025
@yannbf yannbf added the empathy label Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal cli empathy patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants