Skip to content

CLI: Fix Ctrl+C termination on Windows after npm create storybook@latest#33960

Closed
Copilot wants to merge 3 commits into
nextfrom
copilot/fix-npm-create-storybook-termination
Closed

CLI: Fix Ctrl+C termination on Windows after npm create storybook@latest#33960
Copilot wants to merge 3 commits into
nextfrom
copilot/fix-npm-create-storybook-termination

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 28, 2026

On Windows, after npm create storybook@latest completes and auto-starts the dev server, Ctrl+C has no effect — the only escape is closing the terminal.

Root Cause

The root cause is a known issue in @clack/core (bombshell-dev/clack#408): the block() function (used internally by spinners during dependency installation) sets stdin.setRawMode(true) on all platforms, but intentionally skips setRawMode(false) cleanup on Windows (!isWindows && setRawMode(false)). After init completes, stdin remains in raw mode, causing Ctrl+C to emit \x03 as a character instead of triggering SIGINT — so no signal handler ever fires.

Changes

  • Restore stdin cooked mode before starting dev server: After doInitiate() completes on Windows, explicitly calls process.stdin.setRawMode(false) (when stdin is a TTY and still in raw mode) to work around the clack bug and ensure Ctrl+C correctly triggers SIGINT.
// Workaround for https://github.com/bombshell-dev/clack/issues/408
if (process.platform === 'win32' && process.stdin.isTTY && process.stdin.isRaw) {
  process.stdin.setRawMode(false);
}
  • Explicit signal handling in runStorybookDev (defense-in-depth): Register SIGINT/SIGTERM handlers before awaiting the subprocess. On signal:
    • Windows: spawnSync('taskkill', ['/T', '/F', '/PID', <pid>]) — forcefully kills the entire process tree, bypassing any residual cmd.exe batch-job prompt interception
    • Non-Windows: subprocess.kill() — standard kill, sufficient since Unix process groups already propagate signals
    • process.exit(0) — ensures the parent exits cleanly in both cases
  • Cleanup: process.off in a finally block removes handlers if the subprocess exits normally
  • Removed the stale commented-out process.on('SIGINT', ...) placeholder

No new dependencies — spawnSync is a Node.js built-in. taskkill /T /F is available on all Windows versions.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: After running npm create storybook@latest in Windows, the program cannot be terminated using Ctrl+C</issue_title>
<issue_description>### Describe the bug

This issue occurs in both PowerShell and CMD.

After npm create storybook@latest completes, Storybook automatically runs, and at this point, it cannot be stopped with Ctrl+C; the only way to terminate it is by closing the command line.

Reproduction link

...

Reproduction steps

In PowerShell or CMD

  1. npm create storybook@latest
  2. cd vite-project
  3. npm create storybook@latest
  4. Ctrl+C

System

│  System:
│  OS: Windows 11 10.0.22631
│  CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H
│  Binaries:
│  Node: 24.7.0 - C:\nvm4w\nodejs\node.EXE
│  Yarn: 4.10.3 - C:\nvm4w\nodejs\yarn.CMD
│  npm: 11.5.1 - C:\nvm4w\nodejs\npm.CMD <----- active
│  pnpm: 10.17.1 - C:\nvm4w\nodejs\pnpm.CMD
│  Browsers:
│  Chrome: 145.0.7632.117

Additional context

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Summary by CodeRabbit

  • Bug Fixes
    • Improved process termination reliability when stopping the Storybook dev server, particularly on Windows platforms.
    • Enhanced signal handling to ensure Ctrl+C properly shuts down all child processes without leaving orphaned processes behind.

…book dev after init

Co-authored-by: valentinpalkovic <5889929+valentinpalkovic@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug with terminating storybook on Windows fix: Ctrl+C cannot terminate Storybook dev server on Windows after npm create storybook@latest Feb 28, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 28, 2026

Fails
🚫

PR is not labeled with one of: ["cleanup","BREAKING CHANGE","feature request","bug","documentation","maintenance","build","dependencies"]

🚫 PR description is missing the mandatory "#### Manual testing" section. Please add it so that reviewers know how to manually test your changes.

Generated by 🚫 dangerJS against 415398c

@ia319
Copy link
Copy Markdown
Member

ia319 commented Mar 1, 2026

@copilot
Consider addressing bombshell-dev/clack#408 as the root cause for the fix.

The block() function of @clack/core sets stdin.setRawMode(true) on all platforms, but intentionally skips cleanup on Windows (!isWindows && setRawMode(false)). This causes raw mode to remain active after the spinner from a dependency installation ends. As a result, Ctrl+C is treated as a regular character \x03, which does not trigger SIGINT, preventing interruption.

@valentinpalkovic
Copy link
Copy Markdown
Contributor

@copilot

Consider addressing bombshell-dev/clack#408 as the root cause for the fix.

The block() function of @clack/core sets stdin.setRawMode(true) on all platforms, but intentionally skips cleanup on Windows (!isWindows && setRawMode(false)). This causes raw mode to remain active after the spinner from a dependency installation ends. As a result, Ctrl+C is treated as a regular character \x03, which does not trigger SIGINT, preventing interruption.

… Ctrl+C

Co-authored-by: valentinpalkovic <5889929+valentinpalkovic@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 2, 2026

@copilot
Consider addressing bombshell-dev/clack#408 as the root cause for the fix.

...

Good catch — that's the real root cause. Fixed in 415398c.

@clack/core's block() function (called internally by spinners) sets stdin.setRawMode(true) on all platforms but intentionally skips setRawMode(false) on Windows during cleanup (!isWindows && setRawMode(false)). After the init process completes, stdin remains in raw mode, so Ctrl+C emits \x03 as a raw character instead of triggering SIGINT — meaning signal handlers never fire.

The fix explicitly calls process.stdin.setRawMode(false) right before starting the dev server on Windows (when stdin is a TTY and is in raw mode), restoring normal interrupt behavior. The existing SIGINT/SIGTERM handler with taskkill provides additional defense-in-depth for process tree cleanup.

@copilot

Consider addressing bombshell-dev/clack#408 as the root cause for the fix.
...

Addressed in 415398c. Added process.stdin.setRawMode(false) before starting the dev server on Windows to work around bombshell-dev/clack#408.

@valentinpalkovic valentinpalkovic changed the title fix: Ctrl+C cannot terminate Storybook dev server on Windows after npm create storybook@latest CLI: Fix Ctrl+C termination on Windows after npm create storybook@latest Mar 6, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Mar 6, 2026

View your CI Pipeline Execution ↗ for commit 415398c

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ❌ Failed 10m 1s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-06 08:12:15 UTC

@valentinpalkovic valentinpalkovic marked this pull request as ready for review March 6, 2026 08:01
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 6, 2026

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: 3c4bca19-ffc3-4a01-ad88-51345a7626e9

📥 Commits

Reviewing files that changed from the base of the PR and between 2b8e827 and 415398c.

📒 Files selected for processing (1)
  • code/lib/create-storybook/src/initiate.ts

📝 Walkthrough

Walkthrough

Modified the Storybook dev initialization process to handle clean process termination across platforms. Added Windows-specific subprocess tree cleanup using taskkill and signal handlers, along with stdin raw-mode reset for Windows TTY environments. These changes ensure reliable Ctrl+C behavior and proper process cleanup.

Changes

Cohort / File(s) Summary
Process Termination & Signal Handling
code/lib/create-storybook/src/initiate.ts
Added Windows-specific signal handlers (SIGINT/SIGTERM) to kill subprocess tree via taskkill; Unix platforms use subprocess.kill(). Added stdin raw-mode reset for Windows TTY. Introduced cleanup via finally block to unregister handlers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • storybookjs/storybook#32929: Modifies the same runStorybookDev function with subprocess spawning logic that directly relates to the signal handling and cleanup mechanisms introduced here.
✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)

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

@storybook-app-bot
Copy link
Copy Markdown

Package Benchmarks

Commit: 415398c, ran on 6 March 2026 at 08:12:20 UTC

The following packages have significant changes to their size or dependencies:

@storybook/builder-webpack5

Before After Difference
Dependency count 185 185 0
Self size 76 KB 76 KB 0 B
Dependency size 32.19 MB 32.17 MB 🎉 -19 KB 🎉
Bundle Size Analyzer Link Link

@storybook/angular

Before After Difference
Dependency count 185 185 0
Self size 139 KB 139 KB 0 B
Dependency size 30.40 MB 30.38 MB 🎉 -19 KB 🎉
Bundle Size Analyzer Link Link

@storybook/ember

Before After Difference
Dependency count 189 189 0
Self size 15 KB 15 KB 🚨 +18 B 🚨
Dependency size 28.90 MB 28.88 MB 🎉 -19 KB 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 534 534 0
Self size 648 KB 648 KB 🎉 -120 B 🎉
Dependency size 59.86 MB 59.84 MB 🎉 -19 KB 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs-vite

Before After Difference
Dependency count 92 92 0
Self size 1.12 MB 1.12 MB 0 B
Dependency size 22.47 MB 22.45 MB 🎉 -19 KB 🎉
Bundle Size Analyzer Link Link

@storybook/react-native-web-vite

Before After Difference
Dependency count 124 124 0
Self size 30 KB 30 KB 0 B
Dependency size 23.76 MB 23.74 MB 🎉 -19 KB 🎉
Bundle Size Analyzer Link Link

@storybook/react-vite

Before After Difference
Dependency count 82 82 0
Self size 35 KB 35 KB 0 B
Dependency size 20.25 MB 20.24 MB 🎉 -19 KB 🎉
Bundle Size Analyzer Link Link

@storybook/react-webpack5

Before After Difference
Dependency count 271 271 0
Self size 24 KB 24 KB 🚨 +12 B 🚨
Dependency size 44.53 MB 44.51 MB 🎉 -19 KB 🎉
Bundle Size Analyzer Link Link

@storybook/server-webpack5

Before After Difference
Dependency count 197 197 0
Self size 16 KB 16 KB 🎉 -12 B 🎉
Dependency size 33.44 MB 33.42 MB 🎉 -19 KB 🎉
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 183 183 0
Self size 779 KB 779 KB 0 B
Dependency size 67.35 MB 67.32 MB 🎉 -27 KB 🎉
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 176 176 0
Self size 32 KB 32 KB 0 B
Dependency size 65.87 MB 65.85 MB 🎉 -28 KB 🎉
Bundle Size Analyzer Link Link

@storybook/preset-react-webpack

Before After Difference
Dependency count 167 167 0
Self size 18 KB 18 KB 0 B
Dependency size 31.40 MB 31.38 MB 🎉 -19 KB 🎉
Bundle Size Analyzer Link Link

@storybook/react

Before After Difference
Dependency count 58 58 0
Self size 1.19 MB 1.19 MB 🚨 +6 B 🚨
Dependency size 13.21 MB 13.19 MB 🎉 -19 KB 🎉
Bundle Size Analyzer Link Link

@valentinpalkovic
Copy link
Copy Markdown
Contributor

I am closing this since we are waiting for a proper resolution of bombshell-dev/clack#408

@github-project-automation github-project-automation Bot moved this from In Progress to Done in Core Team Projects Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: After running npm create storybook@latest in Windows, the program cannot be terminated using Ctrl+C

3 participants