Commit a182187
fix: use vm.Script with CJS bundle for leak-free SSR
Replace vm.SourceTextModule with vm.Script to avoid memory retention
through Node.js timer infrastructure. The CJS bundle is compiled once
and run in a fresh vm.createContext per request for full isolation.
Key design decisions:
- Per-request vm.createContext with isolated document, window, timers
- Immediate-execution setTimeout(fn, 0) to let Ember's run loop flush
synchronously without creating real timer entries
- Wrapped fetch to prevent retention chains from vm.Context to global
- process stub (env only) to avoid timer infrastructure references
- Nothing set on the real global object per request
Requires the SSR build to output CJS format (format: 'cjs',
inlineDynamicImports: true in vite config).
Also requires ember-source >= 6.11.1 which fixes a FastBoot destroy
crash (emberjs/ember.js#21144) that prevented proper cleanup of
per-request Application state.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>1 parent 2d08f1a commit a182187
2 files changed
Lines changed: 119 additions & 289 deletions
0 commit comments