Skip to content

fix(react): close the TypeScript watch program when the dev server closes - #595

Merged
fi3ework merged 1 commit into
mainfrom
fix/docgen-ts-plugin-592
Oct 10, 2026
Merged

fi3ework merged 1 commit into
mainfrom
fix/docgen-ts-plugin-592

Conversation

@fi3ework

Copy link
Copy Markdown
Member

Summary

With reactDocgen: 'react-docgen-typescript', the dev server starts a TypeScript watch program whose cleanup was registered only on onCloseBuild. Rsbuild fires that hook for build instances only; closing a dev server fires onCloseDevServer (@rsbuild/core dist/m.js: closeServerResources → onCloseDevServer.callBatch(), while onCloseBuild.callBatch() is reached only from build()). So in dev mode closeWatch() never ran and every ts.sys.watchFile / watchDirectory watcher stayed open until the process exited.

This registers one close handler on both hooks, matching the vendored Vite plugin's closeBundle, which runs after a build and on dev server close. closeWatch is typed CloseWatch | undefined and called with ?.() so a close hook that fires before modifyRsbuildConfig ran no longer throws.

Part of #592 (first checkbox).

Impact

Not observable with the storybook dev CLI: every bail path is followed by process.exit, and the OS releases the watchers. It matters for programmatic dev-mode callers that catch a startup failure and keep the process alive, where the open watchers kept the event loop running and leaked file descriptors.

Test

__tests__/index.test.ts — the file watchers helper now wraps the ts.sys watchers and reports how many are still open after a given close hook fires. New case: closes every file watcher when the dev server closes. Without the onCloseDevServer registration it fails with expected 581 to be +0; with it, 13/13 pass.

pnpm check passes. No change to .agents/skills/storybook-check/manifest.json: index.ts is in localOnlyFiles (vendored from the Vite plugin, not ported from upstream Storybook).

…oses

With `reactDocgen: 'react-docgen-typescript'` the dev server starts a
TypeScript watch program, but its cleanup was registered only on
`onCloseBuild`. Rsbuild fires that hook for build instances only; closing
a dev server fires `onCloseDevServer`, so the watch program and all of its
file watchers stayed open until the process exited.

Register one idempotent close handler on both hooks, matching the Vite
plugin's `closeBundle`, which runs after a build and on dev server close.

Part of #592
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T08:52:48.910531Z 974569a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@fi3ework
fi3ework enabled auto-merge (squash) October 10, 2026 08:58
@fi3ework
fi3ework merged commit e669be1 into main Oct 10, 2026
9 checks passed
@fi3ework
fi3ework deleted the fix/docgen-ts-plugin-592 branch October 10, 2026 09:09
@fi3ework fi3ework mentioned this pull request Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant