Skip to content

fix(dts-plugin): handle EXIT before dev server init#4429

Merged
zhoushaw merged 5 commits intomodule-federation:mainfrom
BleedingDev:codex/dts-plugin-safe-exit
Mar 9, 2026
Merged

fix(dts-plugin): handle EXIT before dev server init#4429
zhoushaw merged 5 commits intomodule-federation:mainfrom
BleedingDev:codex/dts-plugin-safe-exit

Conversation

@BleedingDev
Copy link
Copy Markdown
Contributor

Summary

  • Prevent a crash when the dev-worker receives an EXIT RPC message before ModuleFederationDevServer is initialized.
  • Extract message handling into handleDevWorkerMessage so the behavior is deterministic and testable.
  • Keep existing runtime behavior for initialized servers (still calls moduleServer.exit() then exits process).

Why

In some startup/teardown races, the process message listener can receive RpcGMCallTypes.EXIT before moduleServer is assigned.
The previous implementation called moduleServer.exit() unconditionally, which can throw and skip normal process shutdown flow.

Changes

  • packages/dts-plugin/src/dev-worker/forkDevWorker.ts
    • Delegate message handling to a helper and pass current moduleServer + fileLog.
  • packages/dts-plugin/src/dev-worker/handleWorkerMessage.ts
    • Add a small pure handler with guarded moduleServer?.exit() behavior.
  • packages/dts-plugin/src/dev-worker/handleWorkerMessage.spec.ts
    • Add regression coverage for:
      • EXIT before server init
      • EXIT with initialized server
      • non-EXIT messages

Validation

  • pnpm nx run dts-plugin:lint
  • pnpm --filter @module-federation/dts-plugin exec vitest run src/dev-worker/handleWorkerMessage.spec.ts
  • bun --bun -e "import { handleDevWorkerMessage } from './packages/dts-plugin/src/dev-worker/handleWorkerMessage.ts'; let code=-1; handleDevWorkerMessage({ type: 'mf_exit', id: 'bun-smoke' }, { processExit: (c) => { code = c ?? -1; }, log: () => {} }); console.log(code === 0 ? 'ok' : 'bad');"

All pass locally.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 12, 2026

⚠️ No Changeset found

Latest commit: 3c5912b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 12, 2026

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 3c5912b
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/69ae1b01c4e2f500082b114e
😎 Deploy Preview https://deploy-preview-4429--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 12, 2026

Bundle Size Report

3 package(s) changed, 38 unchanged.

Package Total dist Delta ESM gzip Delta
dts-plugin 297.9 kB +523 B (+0.2%) 4.3 kB no change
runtime 16.6 kB -13 B (-0.1%) 616 B no change
runtime-core 249.3 kB -8 B (-0.0%) 477 B no change

Total dist: 6.37 MB (+502 B (+0.0%))
Total ESM gzip: 79.2 kB (no change)

@2heal1
Copy link
Copy Markdown
Member

2heal1 commented Mar 3, 2026

can you help resolve conflicts?

@BleedingDev
Copy link
Copy Markdown
Contributor Author

Sure thing, I'll jump on it once I'm at home. :)

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 9, 2026

Open in StackBlitz

@module-federation/devtools

pnpm add https://pkg.pr.new/@module-federation/devtools@4429

@module-federation/cli

pnpm add https://pkg.pr.new/@module-federation/cli@4429

create-module-federation

pnpm add https://pkg.pr.new/create-module-federation@4429

@module-federation/data-prefetch

pnpm add https://pkg.pr.new/@module-federation/data-prefetch@4429

@module-federation/dts-plugin

pnpm add https://pkg.pr.new/@module-federation/dts-plugin@4429

@module-federation/enhanced

pnpm add https://pkg.pr.new/@module-federation/enhanced@4429

@module-federation/error-codes

pnpm add https://pkg.pr.new/@module-federation/error-codes@4429

@module-federation/esbuild

pnpm add https://pkg.pr.new/@module-federation/esbuild@4429

@module-federation/managers

pnpm add https://pkg.pr.new/@module-federation/managers@4429

@module-federation/manifest

pnpm add https://pkg.pr.new/@module-federation/manifest@4429

@module-federation/metro

pnpm add https://pkg.pr.new/@module-federation/metro@4429

@module-federation/metro-plugin-rnc-cli

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rnc-cli@4429

@module-federation/metro-plugin-rnef

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rnef@4429

@module-federation/modern-js

pnpm add https://pkg.pr.new/@module-federation/modern-js@4429

@module-federation/modern-js-v3

pnpm add https://pkg.pr.new/@module-federation/modern-js-v3@4429

@module-federation/native-federation-tests

pnpm add https://pkg.pr.new/@module-federation/native-federation-tests@4429

@module-federation/native-federation-typescript

pnpm add https://pkg.pr.new/@module-federation/native-federation-typescript@4429

@module-federation/nextjs-mf

pnpm add https://pkg.pr.new/@module-federation/nextjs-mf@4429

@module-federation/node

pnpm add https://pkg.pr.new/@module-federation/node@4429

@module-federation/retry-plugin

pnpm add https://pkg.pr.new/@module-federation/retry-plugin@4429

@module-federation/rsbuild-plugin

pnpm add https://pkg.pr.new/@module-federation/rsbuild-plugin@4429

@module-federation/rspack

pnpm add https://pkg.pr.new/@module-federation/rspack@4429

@module-federation/rspress-plugin

pnpm add https://pkg.pr.new/@module-federation/rspress-plugin@4429

@module-federation/runtime

pnpm add https://pkg.pr.new/@module-federation/runtime@4429

@module-federation/runtime-core

pnpm add https://pkg.pr.new/@module-federation/runtime-core@4429

@module-federation/runtime-tools

pnpm add https://pkg.pr.new/@module-federation/runtime-tools@4429

@module-federation/sdk

pnpm add https://pkg.pr.new/@module-federation/sdk@4429

@module-federation/storybook-addon

pnpm add https://pkg.pr.new/@module-federation/storybook-addon@4429

@module-federation/third-party-dts-extractor

pnpm add https://pkg.pr.new/@module-federation/third-party-dts-extractor@4429

@module-federation/treeshake-frontend

pnpm add https://pkg.pr.new/@module-federation/treeshake-frontend@4429

@module-federation/treeshake-server

pnpm add https://pkg.pr.new/@module-federation/treeshake-server@4429

@module-federation/typescript

pnpm add https://pkg.pr.new/@module-federation/typescript@4429

@module-federation/utilities

pnpm add https://pkg.pr.new/@module-federation/utilities@4429

@module-federation/webpack-bundler-runtime

pnpm add https://pkg.pr.new/@module-federation/webpack-bundler-runtime@4429

@module-federation/bridge-react

pnpm add https://pkg.pr.new/@module-federation/bridge-react@4429

@module-federation/bridge-react-webpack-plugin

pnpm add https://pkg.pr.new/@module-federation/bridge-react-webpack-plugin@4429

@module-federation/bridge-shared

pnpm add https://pkg.pr.new/@module-federation/bridge-shared@4429

@module-federation/bridge-vue3

pnpm add https://pkg.pr.new/@module-federation/bridge-vue3@4429

@module-federation/inject-external-runtime-core-plugin

pnpm add https://pkg.pr.new/@module-federation/inject-external-runtime-core-plugin@4429

commit: af492ca

@zhoushaw zhoushaw merged commit fd206d1 into module-federation:main Mar 9, 2026
8 of 9 checks passed
@2heal1 2heal1 mentioned this pull request Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants