Skip to content

Comments

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

Open
BleedingDev wants to merge 3 commits intomodule-federation:mainfrom
BleedingDev:codex/dts-plugin-safe-exit
Open

fix(dts-plugin): handle EXIT before dev server init#4429
BleedingDev wants to merge 3 commits intomodule-federation:mainfrom
BleedingDev:codex/dts-plugin-safe-exit

Conversation

@BleedingDev
Copy link

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

changeset-bot bot commented Feb 12, 2026

⚠️ No Changeset found

Latest commit: 33dd994

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

netlify bot commented Feb 12, 2026

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 33dd994
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/6990dc8c128eb30008620287
😎 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
Contributor

Bundle Size Report

1 package(s) changed, 37 unchanged.

Package Total dist Delta ESM gzip Delta
dts-plugin 627.5 kB +818 B (+0.1%) 23.4 kB no change

Total dist: 6.67 MB (+818 B (+0.0%))
Total ESM gzip: 137.6 kB (no change)

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.

2 participants