next.js
99ff7757 - fix(turbopack): resolve worker loader id via the worker entry marker's ident

Commit
1 day ago
fix(turbopack): resolve worker loader id via the worker entry marker's ident The previous commit made `WorkerAssetReference` resolve to a non-chunkable `WorkerEntryModule` marker that is excluded from the enclosing chunk group, but left the `new Worker(...)` code generation resolving through `PatternMapping` with `ResolveType::ChunkItem`. That path requires the resolved module to be a chunkable module with a module id in the current chunk group, so it rejected the marker: non-ecmascript placeable asset ... (ecmascript, worker loader) is not placeable in ESM chunks which broke every worker: the `require()` for the loader was never emitted, so no worker ever started. Dynamic imports don't hit this because their codegen never asks `resolve_reference()` for the id — it looks the loader up by ident via `ChunkingContext::async_loader_chunk_item_ident`. Add the worker equivalent: - Add `ResolveType::WorkerLoader` and handle it in `to_single_pattern_mapping` *before* the chunkable downcast, deriving a `ModuleLoader` id from the marker's ident. - Use it from `WorkerAssetReferenceCodeGen`, so the generated code still emits `__turbopack_require__(loader_id)`. - Add `WorkerEntryModule::asset_ident_for(inner, worker_type)` and route *both* the marker's and the late `WorkerLoaderModule`'s `ident()` through it. That last part is load-bearing: `ModuleIdStrategy` keys ids by the resolved `Vc<AssetIdent>`, not by ident content, so an equal-but-separately-computed ident would miss the lookup and fail with "ModuleId not found for ident". The marker is the module that appears in the module graph (and is therefore registered in the global module id map), while the loader is what actually becomes the chunk item, so the two have to share one memoized ident. This mirrors `AsyncLoaderModule::asset_ident_for`. Also document why the worker bootstrap must load the worker's own chunks last: a worker loader has the same module id in every chunk group but a different chunk list per group, so loading its own chunks last is what makes a nested worker pick up the correctly-pruned list. Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
Parents
Loading