fix(ext/node): run register() hooks in worker thread, add --experimental-loader flag (#33906)
Two related features that together bring Node.js module loader hooks much closer to compatibility: ### 1. Worker-thread architecture for `module.register()` Rearchitects `module.register()` to run async hooks in a dedicated Web Worker thread, matching Node.js's "hooks thread" design. Previously, hook modules were loaded on the main thread, causing deadlocks when the hook module's own imports went through the hook infrastructure. **How it works:** - On first `register()` call, a Web Worker is spawned with inline bootstrap code - The hook module is loaded inside the worker (separate event loop, no deadlock) - Resolve/load requests are forwarded from the main thread to the worker via `postMessage` - Sync hooks from `registerHooks()` still run on the main thread (per Node.js spec, sync before async) ### 2. `--experimental-loader` CLI flag Adds `--experimental-loader` (with `--loader` alias) as a hidden CLI flag for Node.js compatibility. Before the main module runs, each loader module is eagerly imported and its resolve/load hooks are registered. ### 3. Fix sync resolve panic (#33901) Adds a `resolve_cache` to `LoaderHookRegistry` that caches resolve results from the async load phase. During V8's synchronous module instantiation callback, the cache is checked first, returning a sync result instead of panicking on an async response. Closes #23201 Fixes #33901
B
Bartek Iwańczuk committed
5aaeb48186e347a8fa8a53ec2e4b1c51b552b032
Parent: d9f981f
Committed by GitHub <noreply@github.com>
on 5/8/2026, 9:55:09 AM