Skip to content

CLI: Exit process after successful build#34735

Open
torleifhalseth wants to merge 2 commits into
storybookjs:nextfrom
torleifhalseth:fix/build-not-exiting
Open

CLI: Exit process after successful build#34735
torleifhalseth wants to merge 2 commits into
storybookjs:nextfrom
torleifhalseth:fix/build-not-exiting

Conversation

@torleifhalseth
Copy link
Copy Markdown

@torleifhalseth torleifhalseth commented May 7, 2026

Closes #34446

What I did

When running storybook build, the process hangs after completing because open handles (e.g. telemetry, watchers) keep the event loop alive. This adds process.exit(0) after the success log to ensure the CLI exits cleanly.

This is a minimal, targeted fix: once the build completes and the success message is logged, we explicitly exit the process rather than waiting for all handles to be released.

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

Caution

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

  1. Run yarn storybook build in a project (or sandbox)
  2. Observe that the process exits immediately after printing "Storybook build completed successfully" instead of hanging

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 PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

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

Summary by CodeRabbit

  • Bug Fixes
    • The build command now reliably terminates with a success exit code on completion, ensuring processes end cleanly after successful builds. This improves reliability for automated build pipelines, CI jobs, and scripts that depend on correct exit status.

@torleifhalseth torleifhalseth marked this pull request as ready for review May 7, 2026 10:25
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6cdcbaf2-55cb-4c45-b6ea-cbe63f2435bb

📥 Commits

Reviewing files that changed from the base of the PR and between 6b4d21a and 9bfb9f3.

📒 Files selected for processing (1)
  • code/core/src/bin/core.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • code/core/src/bin/core.ts

📝 Walkthrough

Walkthrough

The shared CLI postAction hook now calls process.exit(0) early when the executed command name is build; the rest of the postAction hook remains unchanged.

Changes

Build Command Exit Behavior

Layer / File(s) Summary
postAction Hook
code/core/src/bin/core.ts
Adds an early process.exit(0) in the postAction hook when the command name is build.
postAction Hook (remainder)
code/core/src/bin/core.ts
The remainder of the postAction hook (teardown/closure) remains present after the inserted exit call.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@code/core/src/bin/core.ts`:
- Around line 191-192: The explicit process.exit(0) after logger.outro prevents
the shared postAction hook from running and breaks --logfile; remove the direct
call to process.exit(0) in the build flow (the code block containing
logger.outro('Storybook build completed successfully')) and instead return
normally from the build action so the postAction function (the shared postAction
hook invoked elsewhere) can run and write debug logs; if an immediate exit is
truly required, invoke postAction manually before calling process.exit, but
prefer removing process.exit(0) so postAction executes naturally.
🪄 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: 5d59d107-c3d6-40de-bb98-99ace3eccd54

📥 Commits

Reviewing files that changed from the base of the PR and between 228542d and d83285d.

📒 Files selected for processing (1)
  • code/core/src/bin/core.ts

Comment thread code/core/src/bin/core.ts Outdated
@torleifhalseth torleifhalseth force-pushed the fix/build-not-exiting branch from d83285d to 6b4d21a Compare May 7, 2026 11:01
When running `storybook build`, the process hangs after completing
because open handles (e.g. telemetry, watchers) keep the event loop
alive. Add `process.exit(0)` after the success log to ensure the CLI
exits cleanly.

Closes storybookjs#34446
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Empathy Queue (prioritized)

Development

Successfully merging this pull request may close these issues.

storybook build not exiting

2 participants