Skip to content

fix(modules): run a module's teardown before invalidating its context - #20

Merged
Upd4ting merged 1 commit into
mainfrom
fix/teardown-under-active-context
Sep 17, 2026
Merged

Upd4ting merged 1 commit into
mainfrom
fix/teardown-under-active-context

Conversation

@Upd4ting

Copy link
Copy Markdown
Member

Summary

Events.ModuleDestroyed invalidated the module context before running the owner's async cleanups, register cleanups and unregisterOwner on the registering proxies. Any disposer that called an interface function facade bound to that owner threw ModuleContextInvalidatedError (assertActiveModuleContext <- runWithCapturedModuleContext), so a module's own un-registration could never run under its own context. In DMS this left every page route registered against a dead context after a dev hot reload (138 teardown warnings, /dms/sitelayout 500 forever, no reload event).

releaseOwnerRegistrations() now runs first and the context is invalidated in a finally afterwards. Test teardown-module-context.test.ts reproduces the production failure (red without the fix) and pins that the context is still invalidated once teardown is done.

Validation

pnpm lint, format, pnpm build, pnpm test (77), test:package, knip: pass. Verified end to end in the DMS playground with the patched package linked: 0 teardown warnings across two hot reloads.

Release: 0.0.13 (patch). Fleet consumers pin ^0.0.12, so their ranges must move to >=0.0.13 <1.0.0 to pick it up.

A module's registrations are released by calling the providing module's
unregister functions, through interface facades the core bound to the module
that registered them. Those calls are the module's own last work, but
`Events.ModuleDestroyed` invalidated its execution context before running any
of them, so every facade threw `ModuleContextInvalidatedError` and the
registration stayed in the provider for the life of the process — a DMS hot
reload left 138 page routes bound to a dead context and every one of them
answering 500.

Run the async detachments, the register cleanups and `unregisterOwner` first,
and invalidate the context once they are done.
@Upd4ting
Upd4ting merged commit 52873d1 into main Sep 17, 2026
2 checks passed
@Upd4ting
Upd4ting deleted the fix/teardown-under-active-context branch September 17, 2026 04:06
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.

2 participants