You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(bundler): re-install web globals after a V8 snapshot restore
The snapshot prelude replaces Node's undici-backed web globals (fetch/Headers/
Request/Response/FormData/WebSocket/EventSource/MessageEvent/CloseEvent) with
constructable stubs at build time so touching them never pulls in undici's
non-serializable native bindings — but the restored process kept the stubs, so
`globalThis.fetch` was a dead no-op after restore.
The generated snapshot-restore entry now calls a new
`globalThis.__installWebGlobalsLazy` (defined by the prelude) after installing
`__RUNTIME_REQUIRE` (which now carries `.resolve`). It re-installs the globals as
lazy accessors: the fetch family from the app's real `undici` (kept external —
e.g. `--force-external undici urllib` — so it loads for real on restore; resolved
directly, or through `urllib` under pnpm where undici is not hoisted), and
`Blob`/`File` from `node:buffer`. The accessor must not cache `undefined`, because
undici reads `globalThis.Headers` re-entrantly while its own require() is in flight.
`Blob`/`File` are no longer stubbed on `node:buffer`: they are buffer-backed,
serialize into a snapshot fine, and stay real (verified the cnpmcore snapshot
still builds → restores → serves `/-/ping` with them un-stubbed).
So `globalThis.fetch(...)` and the related constructors work normally after a
restore.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
0 commit comments