Unverified Commit a2d55862 authored by Sam Poder's avatar Sam Poder Committed by GitHub

[turbopack] Fix component chunks for workers (#96432)

#95261 began to set `module_chunks` on browser chunks so that we can
track components this meant that chunks stopped always being plain path
strings:

```rust
if included.is_empty() && excluded.is_empty() && module_chunks.is_empty() {
    return EcmascriptChunkData::Simple(path);   // bare string
}
EcmascriptChunkData::WithRuntimeInfo { .. }     // object
```

This broke workers when I was testing on `vercel/front`.
parent 6523a33f
...@@ -21,6 +21,9 @@ declare const _TURBOPACK_WORKER_BASE_PATH_: string | null ...@@ -21,6 +21,9 @@ declare const _TURBOPACK_WORKER_BASE_PATH_: string | null
type WorkerConstructor = new (url: URL, options?: object) => Worker type WorkerConstructor = new (url: URL, options?: object) => Worker
// Mirrors the runtime's `ChunkData`.
type WorkerChunkData = string | { path: string }
/** /**
* Creates a web worker by instantiating the given WorkerConstructor with the * Creates a web worker by instantiating the given WorkerConstructor with the
* appropriate URL and options. * appropriate URL and options.
...@@ -39,7 +42,7 @@ type WorkerConstructor = new (url: URL, options?: object) => Worker ...@@ -39,7 +42,7 @@ type WorkerConstructor = new (url: URL, options?: object) => Worker
function createWorker( function createWorker(
WorkerConstructor: WorkerConstructor, WorkerConstructor: WorkerConstructor,
entrypoint: string, entrypoint: string,
moduleChunks: string[], moduleChunks: WorkerChunkData[],
workerOptions?: object workerOptions?: object
): Worker { ): Worker {
const isSharedWorker = WorkerConstructor.name === 'SharedWorker' const isSharedWorker = WorkerConstructor.name === 'SharedWorker'
...@@ -52,7 +55,12 @@ function createWorker( ...@@ -52,7 +55,12 @@ function createWorker(
_TURBOPACK_WORKER_BASE_PATH_ ?? __turbopack_chunk_base_path__ _TURBOPACK_WORKER_BASE_PATH_ ?? __turbopack_chunk_base_path__
const chunkUrls = moduleChunks const chunkUrls = moduleChunks
.map((chunk) => __turbopack_chunk_relative_url__(chunk, workerBasePath)) .map((chunk) =>
__turbopack_chunk_relative_url__(
typeof chunk === 'string' ? chunk : chunk.path,
workerBasePath
)
)
.reverse() .reverse()
const params: unknown[] = [chunkUrls, __turbopack_chunk_asset_suffix__] const params: unknown[] = [chunkUrls, __turbopack_chunk_asset_suffix__]
const globals = _TURBOPACK_WORKER_FORWARDED_GLOBALS_ const globals = _TURBOPACK_WORKER_FORWARDED_GLOBALS_
...@@ -85,7 +93,7 @@ function createWorker( ...@@ -85,7 +93,7 @@ function createWorker(
*/ */
export default function generateCreateWorker( export default function generateCreateWorker(
entrypoint: string, entrypoint: string,
moduleChunks: string[] moduleChunks: WorkerChunkData[]
) { ) {
return ( return (
WorkerConstructor: { new (url: URL, options?: object): Worker }, WorkerConstructor: { new (url: URL, options?: object): Worker },
......
...@@ -86,7 +86,7 @@ __turbopack_context__.s([ ...@@ -86,7 +86,7 @@ __turbopack_context__.s([
// other when `CHUNK_BASE_PATH` (= `assetPrefix`) is a cross-origin CDN. // other when `CHUNK_BASE_PATH` (= `assetPrefix`) is a cross-origin CDN.
// `null` falls back; an empty string is treated as a literal empty prefix. // `null` falls back; an empty string is treated as a literal empty prefix.
const workerBasePath = null ?? /*TURBOPACK member replacement*/ __turbopack_context__.b; const workerBasePath = null ?? /*TURBOPACK member replacement*/ __turbopack_context__.b;
const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(chunk, workerBasePath)).reverse(); const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(typeof chunk === 'string' ? chunk : chunk.path, workerBasePath)).reverse();
const params = [ const params = [
chunkUrls, chunkUrls,
/*TURBOPACK member replacement*/ __turbopack_context__.X /*TURBOPACK member replacement*/ __turbopack_context__.X
......
...@@ -62,7 +62,7 @@ __turbopack_context__.s([ ...@@ -62,7 +62,7 @@ __turbopack_context__.s([
// other when `CHUNK_BASE_PATH` (= `assetPrefix`) is a cross-origin CDN. // other when `CHUNK_BASE_PATH` (= `assetPrefix`) is a cross-origin CDN.
// `null` falls back; an empty string is treated as a literal empty prefix. // `null` falls back; an empty string is treated as a literal empty prefix.
const workerBasePath = null ?? /*TURBOPACK member replacement*/ __turbopack_context__.b; const workerBasePath = null ?? /*TURBOPACK member replacement*/ __turbopack_context__.b;
const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(chunk, workerBasePath)).reverse(); const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(typeof chunk === 'string' ? chunk : chunk.path, workerBasePath)).reverse();
const params = [ const params = [
chunkUrls, chunkUrls,
/*TURBOPACK member replacement*/ __turbopack_context__.X /*TURBOPACK member replacement*/ __turbopack_context__.X
......
...@@ -61,7 +61,7 @@ __turbopack_context__.s([ ...@@ -61,7 +61,7 @@ __turbopack_context__.s([
// other when `CHUNK_BASE_PATH` (= `assetPrefix`) is a cross-origin CDN. // other when `CHUNK_BASE_PATH` (= `assetPrefix`) is a cross-origin CDN.
// `null` falls back; an empty string is treated as a literal empty prefix. // `null` falls back; an empty string is treated as a literal empty prefix.
const workerBasePath = null ?? /*TURBOPACK member replacement*/ __turbopack_context__.b; const workerBasePath = null ?? /*TURBOPACK member replacement*/ __turbopack_context__.b;
const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(chunk, workerBasePath)).reverse(); const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(typeof chunk === 'string' ? chunk : chunk.path, workerBasePath)).reverse();
const params = [ const params = [
chunkUrls, chunkUrls,
/*TURBOPACK member replacement*/ __turbopack_context__.X /*TURBOPACK member replacement*/ __turbopack_context__.X
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment