remote-components 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/nextjs.cjs +122 -62
- package/dist/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.js +116 -56
- package/dist/config/nextjs.js.map +1 -1
- package/dist/config/webpack.cjs +5 -1
- package/dist/config/webpack.cjs.map +1 -1
- package/dist/config/webpack.js +5 -1
- package/dist/config/webpack.js.map +1 -1
- package/dist/host/defaults/app.cjs +2 -5
- package/dist/host/defaults/app.cjs.map +1 -1
- package/dist/host/defaults/app.d.ts +1 -3
- package/dist/host/defaults/app.js +1 -4
- package/dist/host/defaults/app.js.map +1 -1
- package/dist/host/defaults/pages.cjs +2 -5
- package/dist/host/defaults/pages.cjs.map +1 -1
- package/dist/host/defaults/pages.d.ts +1 -3
- package/dist/host/defaults/pages.js +1 -4
- package/dist/host/defaults/pages.js.map +1 -1
- package/dist/host/defaults/shared.cjs +32 -0
- package/dist/host/defaults/shared.cjs.map +1 -0
- package/dist/host/defaults/shared.d.ts +3 -0
- package/dist/host/defaults/shared.js +8 -0
- package/dist/host/defaults/shared.js.map +1 -0
- package/dist/host/html.cjs +533 -351
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +533 -351
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +494 -285
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +468 -259
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/react.cjs +412 -241
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +412 -241
- package/dist/host/react.js.map +1 -1
- package/dist/internal/config/webpack/apply-shared-modules.cjs +6 -4
- package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -1
- package/dist/internal/config/webpack/apply-shared-modules.js +6 -4
- package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -1
- package/dist/internal/config/webpack/next-client-pages-loader.cjs +6 -7
- package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
- package/dist/internal/config/webpack/next-client-pages-loader.js +6 -7
- package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
- package/dist/internal/host/nextjs/app-client.cjs +6 -22
- package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
- package/dist/internal/host/nextjs/app-client.js +5 -11
- package/dist/internal/host/nextjs/app-client.js.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.cjs +19 -39
- package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.js +31 -39
- package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
- package/dist/internal/host/nextjs/image-shared.cjs +39 -3
- package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
- package/dist/internal/host/nextjs/image-shared.d.ts +5 -10
- package/dist/internal/host/nextjs/image-shared.js +29 -3
- package/dist/internal/host/nextjs/image-shared.js.map +1 -1
- package/dist/internal/host/nextjs/shared-import.cjs +46 -0
- package/dist/internal/host/nextjs/shared-import.cjs.map +1 -0
- package/dist/internal/host/nextjs/shared-import.d.ts +3 -0
- package/dist/internal/host/nextjs/shared-import.js +12 -0
- package/dist/internal/host/nextjs/shared-import.js.map +1 -0
- package/dist/internal/host/server/fetch-remote-component.cjs +2 -1
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.js +2 -1
- package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
- package/dist/internal/host/shared/polyfill.cjs +8 -7
- package/dist/internal/host/shared/polyfill.cjs.map +1 -1
- package/dist/internal/host/shared/polyfill.js +8 -7
- package/dist/internal/host/shared/polyfill.js.map +1 -1
- package/dist/internal/host/shared/shared-module-resolver.cjs +117 -0
- package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -0
- package/dist/internal/host/shared/shared-module-resolver.d.ts +64 -0
- package/dist/internal/host/shared/shared-module-resolver.js +78 -0
- package/dist/internal/host/shared/shared-module-resolver.js.map +1 -0
- package/dist/internal/remote/nextjs/next-internals.cjs +53 -0
- package/dist/internal/remote/nextjs/next-internals.cjs.map +1 -0
- package/dist/internal/remote/nextjs/next-internals.d.ts +42 -0
- package/dist/internal/remote/nextjs/next-internals.js +26 -0
- package/dist/internal/remote/nextjs/next-internals.js.map +1 -0
- package/dist/internal/runtime/html/apply-origin.cjs +11 -32
- package/dist/internal/runtime/html/apply-origin.cjs.map +1 -1
- package/dist/internal/runtime/html/apply-origin.js +11 -32
- package/dist/internal/runtime/html/apply-origin.js.map +1 -1
- package/dist/internal/runtime/html/html-spec.cjs +78 -0
- package/dist/internal/runtime/html/html-spec.cjs.map +1 -0
- package/dist/internal/runtime/html/html-spec.d.ts +23 -0
- package/dist/internal/runtime/html/html-spec.js +41 -0
- package/dist/internal/runtime/html/html-spec.js.map +1 -0
- package/dist/internal/runtime/html/parse-remote-html.cjs +15 -12
- package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
- package/dist/internal/runtime/html/parse-remote-html.js +29 -12
- package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
- package/dist/internal/runtime/html/rewrite-srcset.cjs +38 -0
- package/dist/internal/runtime/html/rewrite-srcset.cjs.map +1 -0
- package/dist/internal/runtime/html/rewrite-srcset.d.ts +12 -0
- package/dist/internal/runtime/html/rewrite-srcset.js +14 -0
- package/dist/internal/runtime/html/rewrite-srcset.js.map +1 -0
- package/dist/internal/runtime/loaders/component-loader.cjs +25 -44
- package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/component-loader.d.ts +3 -1
- package/dist/internal/runtime/loaders/component-loader.js +28 -44
- package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
- package/dist/internal/runtime/loaders/script-loader.cjs +7 -0
- package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/script-loader.js +7 -0
- package/dist/internal/runtime/loaders/script-loader.js.map +1 -1
- package/dist/internal/runtime/loaders/static-loader.cjs +15 -21
- package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/static-loader.d.ts +3 -1
- package/dist/internal/runtime/loaders/static-loader.js +15 -21
- package/dist/internal/runtime/loaders/static-loader.js.map +1 -1
- package/dist/internal/runtime/namespace.cjs +82 -0
- package/dist/internal/runtime/namespace.cjs.map +1 -0
- package/dist/internal/runtime/namespace.d.ts +5 -0
- package/dist/internal/runtime/namespace.js +58 -0
- package/dist/internal/runtime/namespace.js.map +1 -0
- package/dist/internal/runtime/rsc-imports.cjs +86 -0
- package/dist/internal/runtime/rsc-imports.cjs.map +1 -0
- package/dist/internal/runtime/rsc-imports.d.ts +39 -0
- package/dist/internal/runtime/rsc-imports.js +50 -0
- package/dist/internal/runtime/rsc-imports.js.map +1 -0
- package/dist/internal/{host/shared/resolved-data.cjs → runtime/rsc-runtime.cjs} +3 -3
- package/dist/internal/runtime/rsc-runtime.cjs.map +1 -0
- package/dist/internal/runtime/rsc-runtime.d.ts +37 -0
- package/dist/internal/runtime/rsc-runtime.js +1 -0
- package/dist/internal/runtime/rsc.cjs +23 -12
- package/dist/internal/runtime/rsc.cjs.map +1 -1
- package/dist/internal/runtime/rsc.d.ts +19 -2
- package/dist/internal/runtime/rsc.js +20 -11
- package/dist/internal/runtime/rsc.js.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.cjs +53 -35
- package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.d.ts +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.js +53 -35
- package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/module.cjs +19 -17
- package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/module.d.ts +23 -1
- package/dist/internal/runtime/turbopack/module.js +19 -18
- package/dist/internal/runtime/turbopack/module.js.map +1 -1
- package/dist/internal/runtime/turbopack/patterns.cjs +26 -10
- package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/patterns.d.ts +44 -49
- package/dist/internal/runtime/turbopack/patterns.js +23 -7
- package/dist/internal/runtime/turbopack/patterns.js.map +1 -1
- package/dist/internal/runtime/turbopack/{webpack-runtime.cjs → remote-scope-setup.cjs} +35 -32
- package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -0
- package/dist/internal/runtime/turbopack/remote-scope-setup.d.ts +25 -0
- package/dist/internal/runtime/turbopack/{webpack-runtime.js → remote-scope-setup.js} +36 -19
- package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -0
- package/dist/internal/runtime/turbopack/remote-scope.cjs +4 -6
- package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope.d.ts +20 -1
- package/dist/internal/runtime/turbopack/remote-scope.js +4 -6
- package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.cjs +23 -15
- package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.d.ts +13 -1
- package/dist/internal/runtime/turbopack/shared-modules.js +25 -18
- package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
- package/dist/internal/runtime/types.cjs.map +1 -1
- package/dist/internal/runtime/types.d.ts +5 -41
- package/dist/internal/utils/logger.cjs +1 -1
- package/dist/internal/utils/logger.cjs.map +1 -1
- package/dist/internal/utils/logger.d.ts +2 -2
- package/dist/internal/utils/logger.js +1 -1
- package/dist/internal/utils/logger.js.map +1 -1
- package/dist/internal/utils/project-id-env.cjs +31 -0
- package/dist/internal/utils/project-id-env.cjs.map +1 -0
- package/dist/internal/utils/project-id-env.d.ts +7 -0
- package/dist/internal/utils/project-id-env.js +7 -0
- package/dist/internal/utils/project-id-env.js.map +1 -0
- package/dist/internal/utils/project-id.cjs +46 -0
- package/dist/internal/utils/project-id.cjs.map +1 -0
- package/dist/internal/utils/project-id.d.ts +8 -0
- package/dist/internal/utils/project-id.js +22 -0
- package/dist/internal/utils/project-id.js.map +1 -0
- package/dist/remote/defaults/app.cjs +2 -5
- package/dist/remote/defaults/app.cjs.map +1 -1
- package/dist/remote/defaults/app.d.ts +1 -3
- package/dist/remote/defaults/app.js +1 -4
- package/dist/remote/defaults/app.js.map +1 -1
- package/dist/remote/defaults/pages.cjs +2 -5
- package/dist/remote/defaults/pages.cjs.map +1 -1
- package/dist/remote/defaults/pages.d.ts +1 -3
- package/dist/remote/defaults/pages.js +1 -4
- package/dist/remote/defaults/pages.js.map +1 -1
- package/dist/remote/defaults/shared.cjs +32 -0
- package/dist/remote/defaults/shared.cjs.map +1 -0
- package/dist/remote/defaults/shared.d.ts +3 -0
- package/dist/remote/defaults/shared.js +8 -0
- package/dist/remote/defaults/shared.js.map +1 -0
- package/dist/remote/html.cjs +78 -22
- package/dist/remote/html.cjs.map +1 -1
- package/dist/remote/html.js +78 -22
- package/dist/remote/html.js.map +1 -1
- package/dist/remote/nextjs/app.cjs +16 -56
- package/dist/remote/nextjs/app.cjs.map +1 -1
- package/dist/remote/nextjs/app.js +26 -46
- package/dist/remote/nextjs/app.js.map +1 -1
- package/dist/remote/nextjs/pages.cjs +2 -1
- package/dist/remote/nextjs/pages.cjs.map +1 -1
- package/dist/remote/nextjs/pages.js +2 -1
- package/dist/remote/nextjs/pages.js.map +1 -1
- package/dist/types-59251814.d.ts +94 -0
- package/package.json +1 -1
- package/dist/internal/host/shared/resolved-data.cjs.map +0 -1
- package/dist/internal/host/shared/resolved-data.d.ts +0 -48
- package/dist/internal/host/shared/resolved-data.js +0 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +0 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +0 -23
- package/dist/internal/runtime/turbopack/webpack-runtime.js.map +0 -1
- /package/dist/internal/{host/shared/resolved-data.js.map → runtime/rsc-runtime.js.map} +0 -0
|
@@ -17,6 +17,18 @@ function fixPayload(payload) {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
function buildRSCChunks(rscName, data) {
|
|
21
|
+
const chunks = [];
|
|
22
|
+
for (const chunk of data) {
|
|
23
|
+
for (const line of chunk.split("\n")) {
|
|
24
|
+
const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
|
|
25
|
+
if (match?.groups?.rsc) {
|
|
26
|
+
chunks.push(JSON.parse(`"${match.groups.rsc}"`));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return chunks;
|
|
31
|
+
}
|
|
20
32
|
function createRSCStream(rscName, data) {
|
|
21
33
|
return new ReadableStream({
|
|
22
34
|
type: "bytes",
|
|
@@ -24,16 +36,11 @@ function createRSCStream(rscName, data) {
|
|
|
24
36
|
const encoder = new TextEncoder();
|
|
25
37
|
const self = globalThis;
|
|
26
38
|
if (data.length > 0) {
|
|
27
|
-
data
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
self[rscName] = self[rscName] ?? [];
|
|
33
|
-
self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
});
|
|
39
|
+
const parsed = buildRSCChunks(rscName, data);
|
|
40
|
+
if (parsed.length > 0) {
|
|
41
|
+
self[rscName] = self[rscName] ?? [];
|
|
42
|
+
self[rscName].push(...parsed);
|
|
43
|
+
}
|
|
37
44
|
}
|
|
38
45
|
const allChunks = (self[rscName] ?? [`0:[null]
|
|
39
46
|
`]).join("");
|
|
@@ -63,6 +70,8 @@ function createRSCStream(rscName, data) {
|
|
|
63
70
|
});
|
|
64
71
|
}
|
|
65
72
|
export {
|
|
66
|
-
|
|
73
|
+
buildRSCChunks,
|
|
74
|
+
createRSCStream,
|
|
75
|
+
fixPayload
|
|
67
76
|
};
|
|
68
77
|
//# sourceMappingURL=rsc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/rsc.ts"],"sourcesContent":["import { ReadableStream } from 'web-streams-polyfill';\n\n/**\n * Fixes RSC payload to
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/rsc.ts"],"sourcesContent":["import { ReadableStream } from 'web-streams-polyfill';\n\n/**\n * Fixes RSC payload arrays to be compatible with React JSX development runtime.\n * React elements in the wire format are 4-element arrays (`['$', type, key, props]`);\n * the dev runtime expects 7 elements with debug info in positions 4-6.\n */\nexport function fixPayload(payload: unknown): void {\n if (Array.isArray(payload)) {\n if (payload[0] === '$') {\n // React element — fix props recursively, then pad to 7 elements\n fixPayload(payload[3]);\n if (payload.length === 4) {\n payload.push(null, null, 1);\n }\n } else {\n for (const item of payload) {\n fixPayload(item);\n }\n }\n } else if (typeof payload === 'object' && payload !== null) {\n for (const key in payload) {\n fixPayload((payload as Record<string, unknown>)[key]);\n }\n }\n}\n\n/**\n * Parses raw RSC script chunks (the `self[\"name\"].push(\"...\")` format produced\n * by `<RemoteComponentData>`) into a flat array of flight-data strings.\n *\n * This is a pure function — it reads from `data` only, never from `globalThis`.\n */\nexport function buildRSCChunks(rscName: string, data: string[]): string[] {\n const chunks: string[] = [];\n\n for (const chunk of data) {\n for (const line of chunk.split('\\n')) {\n const match = /\\.push\\(\"(?<rsc>.*)\"\\);$/.exec(line);\n if (match?.groups?.rsc) {\n chunks.push(JSON.parse(`\"${match.groups.rsc}\"`) as string);\n }\n }\n }\n\n return chunks;\n}\n\n/**\n * Processes RSC flight data and creates a ReadableStream.\n *\n * First checks `data` for inline script chunks (parsed via {@link buildRSCChunks}),\n * merging them onto `globalThis[rscName]`. Then consumes the global array\n * (or falls back to an empty RSC payload) and pipes fixed chunks into the stream.\n */\nexport function createRSCStream(\n rscName: string,\n data: string[],\n): ReadableStream<Uint8Array> {\n return new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n const self = globalThis as typeof globalThis &\n Record<string, string[] | null>;\n\n // Parse inline script chunks and merge onto the global array\n if (data.length > 0) {\n const parsed = buildRSCChunks(rscName, data);\n if (parsed.length > 0) {\n self[rscName] = self[rscName] ?? [];\n self[rscName].push(...parsed);\n }\n }\n\n // Consume the global RSC flight data, falling back to an empty payload\n const allChunks = (self[rscName] ?? [`0:[null]\\n`]).join('');\n self[rscName] = null;\n\n // Process each line in the RSC flight data\n allChunks.split('\\n').forEach((chunk) => {\n if (chunk.length > 0) {\n const { before, id, prefix, payload } =\n /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\\[.*\\])/.exec(\n chunk,\n )?.groups ?? {};\n\n if (payload) {\n const jsonPayload = JSON.parse(payload) as unknown[];\n fixPayload(jsonPayload);\n const reconstruct = `${before ?? ''}${id}:${prefix ?? ''}${JSON.stringify(jsonPayload)}`;\n controller.enqueue(encoder.encode(`${reconstruct}\\n`));\n } else {\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n } else {\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n });\n controller.close();\n },\n });\n}\n"],"mappings":"AAAA,SAAS,sBAAsB;AAOxB,SAAS,WAAW,SAAwB;AACjD,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,QAAI,QAAQ,CAAC,MAAM,KAAK;AAEtB,iBAAW,QAAQ,CAAC,CAAC;AACrB,UAAI,QAAQ,WAAW,GAAG;AACxB,gBAAQ,KAAK,MAAM,MAAM,CAAC;AAAA,MAC5B;AAAA,IACF,OAAO;AACL,iBAAW,QAAQ,SAAS;AAC1B,mBAAW,IAAI;AAAA,MACjB;AAAA,IACF;AAAA,EACF,WAAW,OAAO,YAAY,YAAY,YAAY,MAAM;AAC1D,eAAW,OAAO,SAAS;AACzB,iBAAY,QAAoC,GAAG,CAAC;AAAA,IACtD;AAAA,EACF;AACF;AAQO,SAAS,eAAe,SAAiB,MAA0B;AACxE,QAAM,SAAmB,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AAO,GAAG;AAAA,CAAS,CAAC;AAAA,QACjD;AAAA,MACF,CAAC;AACD,iBAAW,MAAM;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -23,6 +23,7 @@ __export(chunk_loader_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(chunk_loader_exports);
|
|
25
25
|
var import_constants = require("#internal/runtime/constants");
|
|
26
|
+
var import_namespace = require("#internal/runtime/namespace");
|
|
26
27
|
var import_patterns = require("#internal/runtime/patterns");
|
|
27
28
|
var import_protected_rc_fallback = require("#internal/runtime/url/protected-rc-fallback");
|
|
28
29
|
var import_error = require("#internal/utils/error");
|
|
@@ -35,6 +36,7 @@ function loadChunkWithScope(scope, chunkId) {
|
|
|
35
36
|
`loadChunkWithScope: "${chunkId}" (scope: "${scope.scopedName}")`
|
|
36
37
|
);
|
|
37
38
|
const self = globalThis;
|
|
39
|
+
const ns = (0, import_namespace.getNamespace)();
|
|
38
40
|
const { bundle, path, prefix } = (0, import_remote_scope.parseRemoteId)(chunkId);
|
|
39
41
|
const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : scope.runtime;
|
|
40
42
|
if (remoteRuntime === import_constants.RUNTIME_WEBPACK) {
|
|
@@ -45,35 +47,31 @@ function loadChunkWithScope(scope, chunkId) {
|
|
|
45
47
|
if (url.endsWith(".css")) {
|
|
46
48
|
return;
|
|
47
49
|
}
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {
|
|
52
|
-
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
50
|
+
if (ns.chunkCache[url]) {
|
|
51
|
+
(0, import_logger.logDebug)("ChunkLoader", `Cache hit for "${chunkId}" (url="${url}")`);
|
|
52
|
+
return ns.chunkCache[url];
|
|
53
53
|
}
|
|
54
54
|
const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;
|
|
55
55
|
if (resolvedUrl !== url) {
|
|
56
56
|
(0, import_logger.logDebug)("ChunkLoader", `Proxied chunk URL: "${url}" \u2192 "${resolvedUrl}"`);
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
);
|
|
76
|
-
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
58
|
+
ns.chunkCache[url] = new Promise((resolve, reject) => {
|
|
59
|
+
fetch(resolvedUrl).then((res) => res.text()).then((code) => {
|
|
60
|
+
const hasTurbopack = import_patterns2.TURBOPACK_GLOBAL_RE.test(code);
|
|
61
|
+
if (hasTurbopack) {
|
|
62
|
+
return handleTurbopackChunk(code, scope, url);
|
|
63
|
+
}
|
|
64
|
+
}).then(resolve).catch((error) => {
|
|
65
|
+
const isProxied = (0, import_protected_rc_fallback.isProxiedUrl)(resolvedUrl);
|
|
66
|
+
if (isProxied) {
|
|
67
|
+
reject((0, import_error.failedProxiedAssetError)("chunk", url, resolvedUrl));
|
|
68
|
+
} else {
|
|
69
|
+
(0, import_logger.warnCrossOriginFetchError)("ChunkLoader", url);
|
|
70
|
+
reject(error);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
return ns.chunkCache[url];
|
|
77
75
|
}
|
|
78
76
|
function createChunkDispatcher() {
|
|
79
77
|
return function __chunk_dispatcher__(chunkId, scriptBundle) {
|
|
@@ -122,19 +120,39 @@ async function handleTurbopackChunk(code, scope, url) {
|
|
|
122
120
|
`//# sourceMappingURL=${new URL(".", new URL(url, scope.url)).href}$1$2.js.map`
|
|
123
121
|
);
|
|
124
122
|
if (!self[`TURBOPACK_${globalKey}`]) {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
123
|
+
const wrapPush = (target) => {
|
|
124
|
+
const originalPush = target.push;
|
|
125
|
+
if (typeof originalPush !== "function")
|
|
126
|
+
return target;
|
|
127
|
+
target.push = (...items) => {
|
|
128
|
+
for (const item of items) {
|
|
129
|
+
if (Array.isArray(item)) {
|
|
130
|
+
for (const entry of item) {
|
|
131
|
+
scope.turbopackModules.push(entry);
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
scope.turbopackModules.push(item);
|
|
135
|
+
}
|
|
132
136
|
}
|
|
133
|
-
return
|
|
134
|
-
}
|
|
135
|
-
|
|
137
|
+
return originalPush.apply(target, items);
|
|
138
|
+
};
|
|
139
|
+
return target;
|
|
136
140
|
};
|
|
137
|
-
|
|
141
|
+
const globalProp = `TURBOPACK_${globalKey}`;
|
|
142
|
+
let currentValue = wrapPush([]);
|
|
143
|
+
Object.defineProperty(self, globalProp, {
|
|
144
|
+
get() {
|
|
145
|
+
return currentValue;
|
|
146
|
+
},
|
|
147
|
+
set(newValue) {
|
|
148
|
+
if (newValue && typeof newValue === "object") {
|
|
149
|
+
wrapPush(newValue);
|
|
150
|
+
}
|
|
151
|
+
currentValue = newValue;
|
|
152
|
+
},
|
|
153
|
+
configurable: true,
|
|
154
|
+
enumerable: true
|
|
155
|
+
});
|
|
138
156
|
}
|
|
139
157
|
await new Promise((scriptResolve, scriptReject) => {
|
|
140
158
|
const blob = new Blob([transformedCode], {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/turbopack/chunk-loader.ts"],"sourcesContent":["import { RUNTIME_WEBPACK } from '#internal/runtime/constants';\nimport { collapseDoubleSlashes } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport {\n logDebug,\n logWarn,\n warnCrossOriginFetchError,\n} from '#internal/utils/logger';\nimport { TURBOPACK_GLOBAL_RE } from './patterns';\nimport {\n formatRemoteId,\n getScope,\n parseRemoteId,\n type RemoteScope,\n} from './remote-scope';\n\n/**\n * Loads a chunk using a specific scope. All state (base URL, proxy callback,\n * TURBOPACK global key) comes from the scope — no global lookups needed.\n *\n * This is the primary chunk loader called directly from:\n * - setupWebpackRuntime (initial chunks)\n * - TurbopackContext.l (module-level chunk loading)\n * - handleTurbopackChunk (CHUNK_LIST additional chunks)\n *\n * The global chunk dedup cache is keyed by absolute URL, so different origins\n * naturally get separate cache entries even when sharing a bundle name.\n */\nexport function loadChunkWithScope(\n scope: RemoteScope,\n chunkId: string,\n): Promise<unknown> | undefined {\n logDebug(\n 'ChunkLoader',\n `loadChunkWithScope: \"${chunkId}\" (scope: \"${scope.scopedName}\")`,\n );\n const self = globalThis as GlobalScope;\n\n const { bundle, path, prefix } = parseRemoteId(chunkId);\n\n // Skip webpack runtime chunks\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : scope.runtime;\n if (remoteRuntime === RUNTIME_WEBPACK) {\n return Promise.resolve(undefined);\n }\n\n const rawPath = path ? collapseDoubleSlashes(`${prefix}${path}`) : '/';\n const url = new URL(rawPath, scope.url).href;\n\n if (url.endsWith('.css')) {\n return;\n }\n\n // Global dedup cache keyed by absolute URL\n if (!self.__remote_components_turbopack_chunk_loader_promise__) {\n self.__remote_components_turbopack_chunk_loader_promise__ = {};\n }\n if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {\n return self.__remote_components_turbopack_chunk_loader_promise__[url];\n }\n\n const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;\n if (resolvedUrl !== url) {\n logDebug('ChunkLoader', `Proxied chunk URL: \"${url}\" → \"${resolvedUrl}\"`);\n }\n\n self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise(\n (resolve, reject) => {\n fetch(resolvedUrl)\n .then((res) => res.text())\n .then((code) => {\n const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);\n if (hasTurbopack) {\n return handleTurbopackChunk(code, scope, url);\n }\n // Chunk doesn't contain Turbopack globals — nothing to process\n })\n .then(resolve)\n .catch((error) => {\n const isProxied = isProxiedUrl(resolvedUrl);\n if (isProxied) {\n reject(failedProxiedAssetError('chunk', url, resolvedUrl));\n } else {\n warnCrossOriginFetchError('ChunkLoader', url);\n reject(error);\n }\n });\n },\n );\n\n return self.__remote_components_turbopack_chunk_loader_promise__[url];\n}\n\n/**\n * Creates the global `__webpack_chunk_load__` dispatcher.\n * This is a thin wrapper called only by external code (React's RSC runtime).\n * It parses the chunkId, resolves the correct scope, and delegates to\n * `loadChunkWithScope`.\n */\nexport function createChunkDispatcher(): (\n chunkId: string,\n scriptBundle?: string,\n) => Promise<unknown> | undefined {\n return function __chunk_dispatcher__(chunkId: string, scriptBundle?: string) {\n logDebug('ChunkDispatcher', `Dispatching chunk: \"${chunkId}\"`);\n\n const { bundle } = parseRemoteId(chunkId);\n const bundleName = bundle || scriptBundle || 'default';\n\n // Works with both the scoped name (Next.js hosts with server-side\n // rewriting) and the plain bundle name (static/HTML hosts).\n const scope = getScope(bundleName);\n\n logDebug(\n 'ChunkDispatcher',\n `Scope resolution: bundle=\"${bundleName}\", scope=${scope?.scopedName ?? 'null'}`,\n );\n\n if (!scope) {\n logWarn('ChunkDispatcher', `No scope found for bundle \"${bundleName}\"`);\n return Promise.resolve(undefined);\n }\n\n return loadChunkWithScope(scope, chunkId);\n };\n}\n\n/**\n * Handles Turbopack chunk loading by transforming the chunk code to isolate\n * global variables per bundle and dynamically loading the transformed script.\n * Receives scope directly — no global state lookups needed.\n */\nasync function handleTurbopackChunk(\n code: string,\n scope: RemoteScope,\n url: string,\n): Promise<void> {\n // skip this chunk as it is not needed for remote components\n if (/importScripts\\(\\.\\.\\.self.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {\n const preloadLinks = document.querySelectorAll(\n `link[rel=\"preload\"][href=\"${new URL(url).pathname}\"]`,\n );\n preloadLinks.forEach((preloadLink) => preloadLink.remove());\n return;\n }\n\n const self = globalThis as GlobalScope;\n const { globalKey } = scope;\n\n // replace global variables with scope-specific ones to prevent collisions\n // between multiple remote component bundles\n const transformedCode = code\n .replace(\n /globalThis\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `globalThis[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(\n /self\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `self[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(/globalThis\\.TURBOPACK/g, `globalThis.TURBOPACK_${globalKey}`)\n .replace(/self\\.TURBOPACK(?!_)/g, `self.TURBOPACK_${globalKey}`)\n .replace(\n /TURBOPACK_WORKER_LOCATION/g,\n `TURBOPACK_WORKER_LOCATION_${globalKey}`,\n )\n .replace(\n /TURBOPACK_NEXT_CHUNK_URLS/g,\n `TURBOPACK_NEXT_CHUNK_URLS_${globalKey}`,\n )\n .replace(\n /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,\n `TURBOPACK_CHUNK_UPDATE_LISTENERS_${globalKey}`,\n )\n .replace(/__next_require__/g, `__${globalKey}_next_require__`)\n .replace(\n /\\/\\/# sourceMappingURL=(?<name>.+)(?<optional>\\._)?\\.js\\.map/g,\n `//# sourceMappingURL=${new URL('.', new URL(url, scope.url)).href}$1$2.js.map`,\n );\n\n // Initialize TURBOPACK bundle with push interceptor\n if (!self[`TURBOPACK_${globalKey}`]) {\n const chunkData: unknown[][] = [];\n const turbopackObject = {\n push: (item: unknown) => {\n if (Array.isArray(item)) {\n chunkData.push(item);\n } else {\n chunkData.push([item]);\n }\n return chunkData.length;\n },\n __chunks__: chunkData,\n };\n self[`TURBOPACK_${globalKey}`] = turbopackObject as unknown as Record<\n string,\n unknown\n >;\n }\n\n // load the script dynamically using a Blob URL\n await new Promise<void>((scriptResolve, scriptReject) => {\n const blob = new Blob([transformedCode], {\n type: 'application/javascript; charset=UTF-8',\n });\n const scriptUrl = URL.createObjectURL(blob);\n const script = document.createElement('script');\n script.setAttribute('data-turbopack-src', url);\n script.src = scriptUrl;\n script.async = true;\n script.onload = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptResolve(undefined);\n script.remove();\n };\n script.onerror = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptReject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${script.src}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n script.remove();\n };\n document.head.appendChild(script);\n });\n\n // process any additional chunks that were registered during script execution\n // These CHUNK_LIST chunks load directly via scope — no global dispatch needed.\n const chunkLists = self[`TURBOPACK_${globalKey}_CHUNK_LISTS`] as\n | { chunks: string[] }[]\n | undefined;\n const loadChunkPromises: (Promise<unknown> | undefined)[] = [];\n while (chunkLists?.length) {\n const { chunks } = chunkLists.shift() ?? { chunks: [] };\n if (chunks.length > 0) {\n for (const id of chunks) {\n const baseUrl = url.slice(0, url.indexOf('/_next'));\n const chunkLoadResult = loadChunkWithScope(\n scope,\n formatRemoteId(scope, `${baseUrl}/_next/${id}`),\n );\n if (chunkLoadResult) {\n loadChunkPromises.push(chunkLoadResult);\n }\n }\n }\n }\n if (loadChunkPromises.length > 0) {\n await Promise.all(loadChunkPromises);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAgC;AAChC,sBAAsC;AAEtC,mCAA6B;AAC7B,mBAGO;AACP,oBAIO;AACP,IAAAA,mBAAoC;AACpC,0BAKO;AAcA,SAAS,mBACd,OACA,SAC8B;AAC9B;AAAA,IACE;AAAA,IACA,wBAAwB,qBAAqB,MAAM;AAAA,EACrD;AACA,QAAM,OAAO;AAEb,QAAM,EAAE,QAAQ,MAAM,OAAO,QAAI,mCAAc,OAAO;AAGtD,QAAM,gBAAgB,KAAK,6BA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A,MACF;AAAA,IACF;AAAA,EACF;AACA,MAAI,kBAAkB,SAAS,GAAG;AAChC,UAAM,QAAQ,IAAI,iBAAiB;AAAA,EACrC;AACF;","names":["import_patterns"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/turbopack/chunk-loader.ts"],"sourcesContent":["import { RUNTIME_WEBPACK } from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { collapseDoubleSlashes } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport {\n logDebug,\n logWarn,\n warnCrossOriginFetchError,\n} from '#internal/utils/logger';\nimport { TURBOPACK_GLOBAL_RE } from './patterns';\nimport {\n formatRemoteId,\n getScope,\n parseRemoteId,\n type RemoteScope,\n} from './remote-scope';\n\n/**\n * Loads a chunk using a specific scope. All state (base URL, proxy callback,\n * TURBOPACK global key) comes from the scope — no global lookups needed.\n *\n * This is the primary chunk loader called directly from:\n * - setupRemoteScope (initial chunks)\n * - TurbopackContext.l (module-level chunk loading)\n * - handleTurbopackChunk (CHUNK_LIST additional chunks)\n *\n * The global chunk dedup cache is keyed by absolute URL, so different origins\n * naturally get separate cache entries even when sharing a bundle name.\n */\nexport function loadChunkWithScope(\n scope: RemoteScope,\n chunkId: string,\n): Promise<unknown> | undefined {\n logDebug(\n 'ChunkLoader',\n `loadChunkWithScope: \"${chunkId}\" (scope: \"${scope.scopedName}\")`,\n );\n const self = globalThis as GlobalScope;\n const ns = getNamespace();\n\n const { bundle, path, prefix } = parseRemoteId(chunkId);\n\n // Skip webpack runtime chunks\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : scope.runtime;\n if (remoteRuntime === RUNTIME_WEBPACK) {\n return Promise.resolve(undefined);\n }\n\n const rawPath = path ? collapseDoubleSlashes(`${prefix}${path}`) : '/';\n const url = new URL(rawPath, scope.url).href;\n\n if (url.endsWith('.css')) {\n return;\n }\n\n if (ns.chunkCache[url]) {\n logDebug('ChunkLoader', `Cache hit for \"${chunkId}\" (url=\"${url}\")`);\n return ns.chunkCache[url];\n }\n\n const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;\n if (resolvedUrl !== url) {\n logDebug('ChunkLoader', `Proxied chunk URL: \"${url}\" → \"${resolvedUrl}\"`);\n }\n\n ns.chunkCache[url] = new Promise((resolve, reject) => {\n fetch(resolvedUrl)\n .then((res) => res.text())\n .then((code) => {\n const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);\n if (hasTurbopack) {\n return handleTurbopackChunk(code, scope, url);\n }\n // Chunk doesn't contain Turbopack globals — nothing to process\n })\n .then(resolve)\n .catch((error) => {\n const isProxied = isProxiedUrl(resolvedUrl);\n if (isProxied) {\n reject(failedProxiedAssetError('chunk', url, resolvedUrl));\n } else {\n warnCrossOriginFetchError('ChunkLoader', url);\n reject(error);\n }\n });\n });\n\n return ns.chunkCache[url];\n}\n\n/**\n * Creates the global `__webpack_chunk_load__` dispatcher.\n * This is a thin wrapper called only by external code (React's RSC runtime).\n * It parses the chunkId, resolves the correct scope, and delegates to\n * `loadChunkWithScope`.\n */\nexport function createChunkDispatcher(): (\n chunkId: string,\n scriptBundle?: string,\n) => Promise<unknown> | undefined {\n return function __chunk_dispatcher__(chunkId: string, scriptBundle?: string) {\n logDebug('ChunkDispatcher', `Dispatching chunk: \"${chunkId}\"`);\n\n const { bundle } = parseRemoteId(chunkId);\n const bundleName = bundle || scriptBundle || 'default';\n\n // Works with both the scoped name (Next.js hosts with server-side\n // rewriting) and the plain bundle name (static/HTML hosts).\n const scope = getScope(bundleName);\n\n logDebug(\n 'ChunkDispatcher',\n `Scope resolution: bundle=\"${bundleName}\", scope=${scope?.scopedName ?? 'null'}`,\n );\n\n if (!scope) {\n logWarn('ChunkDispatcher', `No scope found for bundle \"${bundleName}\"`);\n return Promise.resolve(undefined);\n }\n\n return loadChunkWithScope(scope, chunkId);\n };\n}\n\n/**\n * Handles Turbopack chunk loading by transforming the chunk code to isolate\n * global variables per bundle and dynamically loading the transformed script.\n * Receives scope directly — no global state lookups needed.\n */\nasync function handleTurbopackChunk(\n code: string,\n scope: RemoteScope,\n url: string,\n): Promise<void> {\n // skip this chunk as it is not needed for remote components\n if (/importScripts\\(\\.\\.\\.self.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {\n const preloadLinks = document.querySelectorAll(\n `link[rel=\"preload\"][href=\"${new URL(url).pathname}\"]`,\n );\n preloadLinks.forEach((preloadLink) => preloadLink.remove());\n return;\n }\n\n const self = globalThis as GlobalScope;\n const { globalKey } = scope;\n\n // replace global variables with scope-specific ones to prevent collisions\n // between multiple remote component bundles\n const transformedCode = code\n .replace(\n /globalThis\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `globalThis[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(\n /self\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `self[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(/globalThis\\.TURBOPACK/g, `globalThis.TURBOPACK_${globalKey}`)\n .replace(/self\\.TURBOPACK(?!_)/g, `self.TURBOPACK_${globalKey}`)\n .replace(\n /TURBOPACK_WORKER_LOCATION/g,\n `TURBOPACK_WORKER_LOCATION_${globalKey}`,\n )\n .replace(\n /TURBOPACK_NEXT_CHUNK_URLS/g,\n `TURBOPACK_NEXT_CHUNK_URLS_${globalKey}`,\n )\n .replace(\n /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,\n `TURBOPACK_CHUNK_UPDATE_LISTENERS_${globalKey}`,\n )\n .replace(/__next_require__/g, `__${globalKey}_next_require__`)\n .replace(\n /\\/\\/# sourceMappingURL=(?<name>.+)(?<optional>\\._)?\\.js\\.map/g,\n `//# sourceMappingURL=${new URL('.', new URL(url, scope.url)).href}$1$2.js.map`,\n );\n\n // Initialize TURBOPACK bundle as a real Array with a push interceptor.\n // Must be a true Array instance so Next.js 15.x turbopack runtimes whose\n // module-system IIFE guards with `Array.isArray(globalThis.TURBOPACK)`\n // don't bail out after we rewrite the global name.\n //\n // The interceptor captures module entries into scope.turbopackModules —\n // a flat array we control. We use Object.defineProperty to intercept\n // when the turbopack runtime replaces the global with a deferred-loading\n // dispatcher (canary builds), wrapping the replacement's push too.\n //\n // The scope is reused across loads of different components from the same\n // remote (see setupRemoteScope), so subsequent loads accumulate into\n // the same turbopackModules array. Chunk cache deduplication means\n // handleTurbopackChunk only runs once per unique chunk URL — all captured\n // modules remain available for any component that needs them.\n if (!self[`TURBOPACK_${globalKey}`]) {\n const wrapPush = <T extends { push?: (...args: unknown[]) => unknown }>(\n target: T,\n ): T => {\n const originalPush = target.push;\n if (typeof originalPush !== 'function') return target;\n target.push = (...items: unknown[]) => {\n for (const item of items) {\n if (Array.isArray(item)) {\n for (const entry of item) {\n scope.turbopackModules.push(entry);\n }\n } else {\n scope.turbopackModules.push(item);\n }\n }\n return originalPush.apply(target, items);\n };\n return target;\n };\n\n const globalProp = `TURBOPACK_${globalKey}`;\n let currentValue: unknown = wrapPush([] as unknown[]);\n Object.defineProperty(self, globalProp, {\n get() {\n return currentValue;\n },\n set(newValue: unknown) {\n // When the turbopack runtime replaces the array with a dispatcher,\n // wrap the new object's push so we keep capturing module entries.\n if (newValue && typeof newValue === 'object') {\n wrapPush(newValue as { push?: (...args: unknown[]) => unknown });\n }\n currentValue = newValue;\n },\n configurable: true,\n enumerable: true,\n });\n }\n\n // load the script dynamically using a Blob URL\n await new Promise<void>((scriptResolve, scriptReject) => {\n const blob = new Blob([transformedCode], {\n type: 'application/javascript; charset=UTF-8',\n });\n const scriptUrl = URL.createObjectURL(blob);\n const script = document.createElement('script');\n script.setAttribute('data-turbopack-src', url);\n script.src = scriptUrl;\n script.async = true;\n script.onload = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptResolve(undefined);\n script.remove();\n };\n script.onerror = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptReject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${script.src}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n script.remove();\n };\n document.head.appendChild(script);\n });\n\n // process any additional chunks that were registered during script execution\n // These CHUNK_LIST chunks load directly via scope — no global dispatch needed.\n const chunkLists = self[`TURBOPACK_${globalKey}_CHUNK_LISTS`] as\n | { chunks: string[] }[]\n | undefined;\n const loadChunkPromises: (Promise<unknown> | undefined)[] = [];\n while (chunkLists?.length) {\n const { chunks } = chunkLists.shift() ?? { chunks: [] };\n if (chunks.length > 0) {\n for (const id of chunks) {\n const baseUrl = url.slice(0, url.indexOf('/_next'));\n const chunkLoadResult = loadChunkWithScope(\n scope,\n formatRemoteId(scope, `${baseUrl}/_next/${id}`),\n );\n if (chunkLoadResult) {\n loadChunkPromises.push(chunkLoadResult);\n }\n }\n }\n }\n if (loadChunkPromises.length > 0) {\n await Promise.all(loadChunkPromises);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAgC;AAChC,uBAA6B;AAC7B,sBAAsC;AAEtC,mCAA6B;AAC7B,mBAGO;AACP,oBAIO;AACP,IAAAA,mBAAoC;AACpC,0BAKO;AAcA,SAAS,mBACd,OACA,SAC8B;AAC9B;AAAA,IACE;AAAA,IACA,wBAAwB,qBAAqB,MAAM;AAAA,EACrD;AACA,QAAM,OAAO;AACb,QAAM,SAAK,+BAAa;AAExB,QAAM,EAAE,QAAQ,MAAM,OAAO,QAAI,mCAAc,OAAO;AAGtD,QAAM,gBAAgB,KAAK,6BAA6B,UAAU,SAAS,IACvE,KAAK,2BAA2B,UAAU,SAAS,GAAG,QAAQ,YAC9D,MAAM;AACV,MAAI,kBAAkB,kCAAiB;AACrC,WAAO,QAAQ,QAAQ,MAAS;AAAA,EAClC;AAEA,QAAM,UAAU,WAAO,uCAAsB,GAAG,SAAS,M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,QAAQ,CAAC;AAClD,cAAM,kBAAkB;AAAA,UACtB;AAAA,cACA,oCAAe,OAAO,GAAG,iBAAiB,IAAI;AAAA,QAChD;AACA,YAAI,iBAAiB;AACnB,4BAAkB,KAAK,eAAe;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,MAAI,kBAAkB,SAAS,GAAG;AAChC,UAAM,QAAQ,IAAI,iBAAiB;AAAA,EACrC;AACF;","names":["import_patterns"]}
|
|
@@ -7,7 +7,7 @@ import '../constants.js';
|
|
|
7
7
|
* TURBOPACK global key) comes from the scope — no global lookups needed.
|
|
8
8
|
*
|
|
9
9
|
* This is the primary chunk loader called directly from:
|
|
10
|
-
* -
|
|
10
|
+
* - setupRemoteScope (initial chunks)
|
|
11
11
|
* - TurbopackContext.l (module-level chunk loading)
|
|
12
12
|
* - handleTurbopackChunk (CHUNK_LIST additional chunks)
|
|
13
13
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RUNTIME_WEBPACK } from "#internal/runtime/constants";
|
|
2
|
+
import { getNamespace } from "#internal/runtime/namespace";
|
|
2
3
|
import { collapseDoubleSlashes } from "#internal/runtime/patterns";
|
|
3
4
|
import { isProxiedUrl } from "#internal/runtime/url/protected-rc-fallback";
|
|
4
5
|
import {
|
|
@@ -22,6 +23,7 @@ function loadChunkWithScope(scope, chunkId) {
|
|
|
22
23
|
`loadChunkWithScope: "${chunkId}" (scope: "${scope.scopedName}")`
|
|
23
24
|
);
|
|
24
25
|
const self = globalThis;
|
|
26
|
+
const ns = getNamespace();
|
|
25
27
|
const { bundle, path, prefix } = parseRemoteId(chunkId);
|
|
26
28
|
const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : scope.runtime;
|
|
27
29
|
if (remoteRuntime === RUNTIME_WEBPACK) {
|
|
@@ -32,35 +34,31 @@ function loadChunkWithScope(scope, chunkId) {
|
|
|
32
34
|
if (url.endsWith(".css")) {
|
|
33
35
|
return;
|
|
34
36
|
}
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {
|
|
39
|
-
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
37
|
+
if (ns.chunkCache[url]) {
|
|
38
|
+
logDebug("ChunkLoader", `Cache hit for "${chunkId}" (url="${url}")`);
|
|
39
|
+
return ns.chunkCache[url];
|
|
40
40
|
}
|
|
41
41
|
const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;
|
|
42
42
|
if (resolvedUrl !== url) {
|
|
43
43
|
logDebug("ChunkLoader", `Proxied chunk URL: "${url}" \u2192 "${resolvedUrl}"`);
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
);
|
|
63
|
-
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
45
|
+
ns.chunkCache[url] = new Promise((resolve, reject) => {
|
|
46
|
+
fetch(resolvedUrl).then((res) => res.text()).then((code) => {
|
|
47
|
+
const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);
|
|
48
|
+
if (hasTurbopack) {
|
|
49
|
+
return handleTurbopackChunk(code, scope, url);
|
|
50
|
+
}
|
|
51
|
+
}).then(resolve).catch((error) => {
|
|
52
|
+
const isProxied = isProxiedUrl(resolvedUrl);
|
|
53
|
+
if (isProxied) {
|
|
54
|
+
reject(failedProxiedAssetError("chunk", url, resolvedUrl));
|
|
55
|
+
} else {
|
|
56
|
+
warnCrossOriginFetchError("ChunkLoader", url);
|
|
57
|
+
reject(error);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
return ns.chunkCache[url];
|
|
64
62
|
}
|
|
65
63
|
function createChunkDispatcher() {
|
|
66
64
|
return function __chunk_dispatcher__(chunkId, scriptBundle) {
|
|
@@ -109,19 +107,39 @@ async function handleTurbopackChunk(code, scope, url) {
|
|
|
109
107
|
`//# sourceMappingURL=${new URL(".", new URL(url, scope.url)).href}$1$2.js.map`
|
|
110
108
|
);
|
|
111
109
|
if (!self[`TURBOPACK_${globalKey}`]) {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
110
|
+
const wrapPush = (target) => {
|
|
111
|
+
const originalPush = target.push;
|
|
112
|
+
if (typeof originalPush !== "function")
|
|
113
|
+
return target;
|
|
114
|
+
target.push = (...items) => {
|
|
115
|
+
for (const item of items) {
|
|
116
|
+
if (Array.isArray(item)) {
|
|
117
|
+
for (const entry of item) {
|
|
118
|
+
scope.turbopackModules.push(entry);
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
scope.turbopackModules.push(item);
|
|
122
|
+
}
|
|
119
123
|
}
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
|
|
124
|
+
return originalPush.apply(target, items);
|
|
125
|
+
};
|
|
126
|
+
return target;
|
|
123
127
|
};
|
|
124
|
-
|
|
128
|
+
const globalProp = `TURBOPACK_${globalKey}`;
|
|
129
|
+
let currentValue = wrapPush([]);
|
|
130
|
+
Object.defineProperty(self, globalProp, {
|
|
131
|
+
get() {
|
|
132
|
+
return currentValue;
|
|
133
|
+
},
|
|
134
|
+
set(newValue) {
|
|
135
|
+
if (newValue && typeof newValue === "object") {
|
|
136
|
+
wrapPush(newValue);
|
|
137
|
+
}
|
|
138
|
+
currentValue = newValue;
|
|
139
|
+
},
|
|
140
|
+
configurable: true,
|
|
141
|
+
enumerable: true
|
|
142
|
+
});
|
|
125
143
|
}
|
|
126
144
|
await new Promise((scriptResolve, scriptReject) => {
|
|
127
145
|
const blob = new Blob([transformedCode], {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/turbopack/chunk-loader.ts"],"sourcesContent":["import { RUNTIME_WEBPACK } from '#internal/runtime/constants';\nimport { collapseDoubleSlashes } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport {\n logDebug,\n logWarn,\n warnCrossOriginFetchError,\n} from '#internal/utils/logger';\nimport { TURBOPACK_GLOBAL_RE } from './patterns';\nimport {\n formatRemoteId,\n getScope,\n parseRemoteId,\n type RemoteScope,\n} from './remote-scope';\n\n/**\n * Loads a chunk using a specific scope. All state (base URL, proxy callback,\n * TURBOPACK global key) comes from the scope — no global lookups needed.\n *\n * This is the primary chunk loader called directly from:\n * - setupWebpackRuntime (initial chunks)\n * - TurbopackContext.l (module-level chunk loading)\n * - handleTurbopackChunk (CHUNK_LIST additional chunks)\n *\n * The global chunk dedup cache is keyed by absolute URL, so different origins\n * naturally get separate cache entries even when sharing a bundle name.\n */\nexport function loadChunkWithScope(\n scope: RemoteScope,\n chunkId: string,\n): Promise<unknown> | undefined {\n logDebug(\n 'ChunkLoader',\n `loadChunkWithScope: \"${chunkId}\" (scope: \"${scope.scopedName}\")`,\n );\n const self = globalThis as GlobalScope;\n\n const { bundle, path, prefix } = parseRemoteId(chunkId);\n\n // Skip webpack runtime chunks\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : scope.runtime;\n if (remoteRuntime === RUNTIME_WEBPACK) {\n return Promise.resolve(undefined);\n }\n\n const rawPath = path ? collapseDoubleSlashes(`${prefix}${path}`) : '/';\n const url = new URL(rawPath, scope.url).href;\n\n if (url.endsWith('.css')) {\n return;\n }\n\n // Global dedup cache keyed by absolute URL\n if (!self.__remote_components_turbopack_chunk_loader_promise__) {\n self.__remote_components_turbopack_chunk_loader_promise__ = {};\n }\n if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {\n return self.__remote_components_turbopack_chunk_loader_promise__[url];\n }\n\n const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;\n if (resolvedUrl !== url) {\n logDebug('ChunkLoader', `Proxied chunk URL: \"${url}\" → \"${resolvedUrl}\"`);\n }\n\n self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise(\n (resolve, reject) => {\n fetch(resolvedUrl)\n .then((res) => res.text())\n .then((code) => {\n const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);\n if (hasTurbopack) {\n return handleTurbopackChunk(code, scope, url);\n }\n // Chunk doesn't contain Turbopack globals — nothing to process\n })\n .then(resolve)\n .catch((error) => {\n const isProxied = isProxiedUrl(resolvedUrl);\n if (isProxied) {\n reject(failedProxiedAssetError('chunk', url, resolvedUrl));\n } else {\n warnCrossOriginFetchError('ChunkLoader', url);\n reject(error);\n }\n });\n },\n );\n\n return self.__remote_components_turbopack_chunk_loader_promise__[url];\n}\n\n/**\n * Creates the global `__webpack_chunk_load__` dispatcher.\n * This is a thin wrapper called only by external code (React's RSC runtime).\n * It parses the chunkId, resolves the correct scope, and delegates to\n * `loadChunkWithScope`.\n */\nexport function createChunkDispatcher(): (\n chunkId: string,\n scriptBundle?: string,\n) => Promise<unknown> | undefined {\n return function __chunk_dispatcher__(chunkId: string, scriptBundle?: string) {\n logDebug('ChunkDispatcher', `Dispatching chunk: \"${chunkId}\"`);\n\n const { bundle } = parseRemoteId(chunkId);\n const bundleName = bundle || scriptBundle || 'default';\n\n // Works with both the scoped name (Next.js hosts with server-side\n // rewriting) and the plain bundle name (static/HTML hosts).\n const scope = getScope(bundleName);\n\n logDebug(\n 'ChunkDispatcher',\n `Scope resolution: bundle=\"${bundleName}\", scope=${scope?.scopedName ?? 'null'}`,\n );\n\n if (!scope) {\n logWarn('ChunkDispatcher', `No scope found for bundle \"${bundleName}\"`);\n return Promise.resolve(undefined);\n }\n\n return loadChunkWithScope(scope, chunkId);\n };\n}\n\n/**\n * Handles Turbopack chunk loading by transforming the chunk code to isolate\n * global variables per bundle and dynamically loading the transformed script.\n * Receives scope directly — no global state lookups needed.\n */\nasync function handleTurbopackChunk(\n code: string,\n scope: RemoteScope,\n url: string,\n): Promise<void> {\n // skip this chunk as it is not needed for remote components\n if (/importScripts\\(\\.\\.\\.self.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {\n const preloadLinks = document.querySelectorAll(\n `link[rel=\"preload\"][href=\"${new URL(url).pathname}\"]`,\n );\n preloadLinks.forEach((preloadLink) => preloadLink.remove());\n return;\n }\n\n const self = globalThis as GlobalScope;\n const { globalKey } = scope;\n\n // replace global variables with scope-specific ones to prevent collisions\n // between multiple remote component bundles\n const transformedCode = code\n .replace(\n /globalThis\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `globalThis[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(\n /self\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `self[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(/globalThis\\.TURBOPACK/g, `globalThis.TURBOPACK_${globalKey}`)\n .replace(/self\\.TURBOPACK(?!_)/g, `self.TURBOPACK_${globalKey}`)\n .replace(\n /TURBOPACK_WORKER_LOCATION/g,\n `TURBOPACK_WORKER_LOCATION_${globalKey}`,\n )\n .replace(\n /TURBOPACK_NEXT_CHUNK_URLS/g,\n `TURBOPACK_NEXT_CHUNK_URLS_${globalKey}`,\n )\n .replace(\n /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,\n `TURBOPACK_CHUNK_UPDATE_LISTENERS_${globalKey}`,\n )\n .replace(/__next_require__/g, `__${globalKey}_next_require__`)\n .replace(\n /\\/\\/# sourceMappingURL=(?<name>.+)(?<optional>\\._)?\\.js\\.map/g,\n `//# sourceMappingURL=${new URL('.', new URL(url, scope.url)).href}$1$2.js.map`,\n );\n\n // Initialize TURBOPACK bundle with push interceptor\n if (!self[`TURBOPACK_${globalKey}`]) {\n const chunkData: unknown[][] = [];\n const turbopackObject = {\n push: (item: unknown) => {\n if (Array.isArray(item)) {\n chunkData.push(item);\n } else {\n chunkData.push([item]);\n }\n return chunkData.length;\n },\n __chunks__: chunkData,\n };\n self[`TURBOPACK_${globalKey}`] = turbopackObject as unknown as Record<\n string,\n unknown\n >;\n }\n\n // load the script dynamically using a Blob URL\n await new Promise<void>((scriptResolve, scriptReject) => {\n const blob = new Blob([transformedCode], {\n type: 'application/javascript; charset=UTF-8',\n });\n const scriptUrl = URL.createObjectURL(blob);\n const script = document.createElement('script');\n script.setAttribute('data-turbopack-src', url);\n script.src = scriptUrl;\n script.async = true;\n script.onload = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptResolve(undefined);\n script.remove();\n };\n script.onerror = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptReject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${script.src}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n script.remove();\n };\n document.head.appendChild(script);\n });\n\n // process any additional chunks that were registered during script execution\n // These CHUNK_LIST chunks load directly via scope — no global dispatch needed.\n const chunkLists = self[`TURBOPACK_${globalKey}_CHUNK_LISTS`] as\n | { chunks: string[] }[]\n | undefined;\n const loadChunkPromises: (Promise<unknown> | undefined)[] = [];\n while (chunkLists?.length) {\n const { chunks } = chunkLists.shift() ?? { chunks: [] };\n if (chunks.length > 0) {\n for (const id of chunks) {\n const baseUrl = url.slice(0, url.indexOf('/_next'));\n const chunkLoadResult = loadChunkWithScope(\n scope,\n formatRemoteId(scope, `${baseUrl}/_next/${id}`),\n );\n if (chunkLoadResult) {\n loadChunkPromises.push(chunkLoadResult);\n }\n }\n }\n }\n if (loadChunkPromises.length > 0) {\n await Promise.all(loadChunkPromises);\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AAEtC,SAAS,oBAAoB;AAC7B;AAAA,EACE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AAE,OAAO,IAAI,WAAW,MAAM,KAAK,EAAE,QAAQ,CAAC,EAAE;AACtD,QAAI,OAAO,SAAS,GAAG;AACrB,iBAAW,MAAM,QAAQ;AACvB,cAAM,UAAU,IAAI,MAAM,GAAG,IAAI,QAAQ,QAAQ,CAAC;AAClD,cAAM,kBAAkB;AAAA,UACtB;AAAA,UACA,eAAe,OAAO,GAAG,iBAAiB,IAAI;AAAA,QAChD;AACA,YAAI,iBAAiB;AACnB,4BAAkB,KAAK,eAAe;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,MAAI,kBAAkB,SAAS,GAAG;AAChC,UAAM,QAAQ,IAAI,iBAAiB;AAAA,EACrC;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/turbopack/chunk-loader.ts"],"sourcesContent":["import { RUNTIME_WEBPACK } from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { collapseDoubleSlashes } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport {\n logDebug,\n logWarn,\n warnCrossOriginFetchError,\n} from '#internal/utils/logger';\nimport { TURBOPACK_GLOBAL_RE } from './patterns';\nimport {\n formatRemoteId,\n getScope,\n parseRemoteId,\n type RemoteScope,\n} from './remote-scope';\n\n/**\n * Loads a chunk using a specific scope. All state (base URL, proxy callback,\n * TURBOPACK global key) comes from the scope — no global lookups needed.\n *\n * This is the primary chunk loader called directly from:\n * - setupRemoteScope (initial chunks)\n * - TurbopackContext.l (module-level chunk loading)\n * - handleTurbopackChunk (CHUNK_LIST additional chunks)\n *\n * The global chunk dedup cache is keyed by absolute URL, so different origins\n * naturally get separate cache entries even when sharing a bundle name.\n */\nexport function loadChunkWithScope(\n scope: RemoteScope,\n chunkId: string,\n): Promise<unknown> | undefined {\n logDebug(\n 'ChunkLoader',\n `loadChunkWithScope: \"${chunkId}\" (scope: \"${scope.scopedName}\")`,\n );\n const self = globalThis as GlobalScope;\n const ns = getNamespace();\n\n const { bundle, path, prefix } = parseRemoteId(chunkId);\n\n // Skip webpack runtime chunks\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : scope.runtime;\n if (remoteRuntime === RUNTIME_WEBPACK) {\n return Promise.resolve(undefined);\n }\n\n const rawPath = path ? collapseDoubleSlashes(`${prefix}${path}`) : '/';\n const url = new URL(rawPath, scope.url).href;\n\n if (url.endsWith('.css')) {\n return;\n }\n\n if (ns.chunkCache[url]) {\n logDebug('ChunkLoader', `Cache hit for \"${chunkId}\" (url=\"${url}\")`);\n return ns.chunkCache[url];\n }\n\n const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;\n if (resolvedUrl !== url) {\n logDebug('ChunkLoader', `Proxied chunk URL: \"${url}\" → \"${resolvedUrl}\"`);\n }\n\n ns.chunkCache[url] = new Promise((resolve, reject) => {\n fetch(resolvedUrl)\n .then((res) => res.text())\n .then((code) => {\n const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);\n if (hasTurbopack) {\n return handleTurbopackChunk(code, scope, url);\n }\n // Chunk doesn't contain Turbopack globals — nothing to process\n })\n .then(resolve)\n .catch((error) => {\n const isProxied = isProxiedUrl(resolvedUrl);\n if (isProxied) {\n reject(failedProxiedAssetError('chunk', url, resolvedUrl));\n } else {\n warnCrossOriginFetchError('ChunkLoader', url);\n reject(error);\n }\n });\n });\n\n return ns.chunkCache[url];\n}\n\n/**\n * Creates the global `__webpack_chunk_load__` dispatcher.\n * This is a thin wrapper called only by external code (React's RSC runtime).\n * It parses the chunkId, resolves the correct scope, and delegates to\n * `loadChunkWithScope`.\n */\nexport function createChunkDispatcher(): (\n chunkId: string,\n scriptBundle?: string,\n) => Promise<unknown> | undefined {\n return function __chunk_dispatcher__(chunkId: string, scriptBundle?: string) {\n logDebug('ChunkDispatcher', `Dispatching chunk: \"${chunkId}\"`);\n\n const { bundle } = parseRemoteId(chunkId);\n const bundleName = bundle || scriptBundle || 'default';\n\n // Works with both the scoped name (Next.js hosts with server-side\n // rewriting) and the plain bundle name (static/HTML hosts).\n const scope = getScope(bundleName);\n\n logDebug(\n 'ChunkDispatcher',\n `Scope resolution: bundle=\"${bundleName}\", scope=${scope?.scopedName ?? 'null'}`,\n );\n\n if (!scope) {\n logWarn('ChunkDispatcher', `No scope found for bundle \"${bundleName}\"`);\n return Promise.resolve(undefined);\n }\n\n return loadChunkWithScope(scope, chunkId);\n };\n}\n\n/**\n * Handles Turbopack chunk loading by transforming the chunk code to isolate\n * global variables per bundle and dynamically loading the transformed script.\n * Receives scope directly — no global state lookups needed.\n */\nasync function handleTurbopackChunk(\n code: string,\n scope: RemoteScope,\n url: string,\n): Promise<void> {\n // skip this chunk as it is not needed for remote components\n if (/importScripts\\(\\.\\.\\.self.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {\n const preloadLinks = document.querySelectorAll(\n `link[rel=\"preload\"][href=\"${new URL(url).pathname}\"]`,\n );\n preloadLinks.forEach((preloadLink) => preloadLink.remove());\n return;\n }\n\n const self = globalThis as GlobalScope;\n const { globalKey } = scope;\n\n // replace global variables with scope-specific ones to prevent collisions\n // between multiple remote component bundles\n const transformedCode = code\n .replace(\n /globalThis\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `globalThis[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(\n /self\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `self[\"TURBOPACK_${globalKey}\"]`,\n )\n .replace(/globalThis\\.TURBOPACK/g, `globalThis.TURBOPACK_${globalKey}`)\n .replace(/self\\.TURBOPACK(?!_)/g, `self.TURBOPACK_${globalKey}`)\n .replace(\n /TURBOPACK_WORKER_LOCATION/g,\n `TURBOPACK_WORKER_LOCATION_${globalKey}`,\n )\n .replace(\n /TURBOPACK_NEXT_CHUNK_URLS/g,\n `TURBOPACK_NEXT_CHUNK_URLS_${globalKey}`,\n )\n .replace(\n /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,\n `TURBOPACK_CHUNK_UPDATE_LISTENERS_${globalKey}`,\n )\n .replace(/__next_require__/g, `__${globalKey}_next_require__`)\n .replace(\n /\\/\\/# sourceMappingURL=(?<name>.+)(?<optional>\\._)?\\.js\\.map/g,\n `//# sourceMappingURL=${new URL('.', new URL(url, scope.url)).href}$1$2.js.map`,\n );\n\n // Initialize TURBOPACK bundle as a real Array with a push interceptor.\n // Must be a true Array instance so Next.js 15.x turbopack runtimes whose\n // module-system IIFE guards with `Array.isArray(globalThis.TURBOPACK)`\n // don't bail out after we rewrite the global name.\n //\n // The interceptor captures module entries into scope.turbopackModules —\n // a flat array we control. We use Object.defineProperty to intercept\n // when the turbopack runtime replaces the global with a deferred-loading\n // dispatcher (canary builds), wrapping the replacement's push too.\n //\n // The scope is reused across loads of different components from the same\n // remote (see setupRemoteScope), so subsequent loads accumulate into\n // the same turbopackModules array. Chunk cache deduplication means\n // handleTurbopackChunk only runs once per unique chunk URL — all captured\n // modules remain available for any component that needs them.\n if (!self[`TURBOPACK_${globalKey}`]) {\n const wrapPush = <T extends { push?: (...args: unknown[]) => unknown }>(\n target: T,\n ): T => {\n const originalPush = target.push;\n if (typeof originalPush !== 'function') return target;\n target.push = (...items: unknown[]) => {\n for (const item of items) {\n if (Array.isArray(item)) {\n for (const entry of item) {\n scope.turbopackModules.push(entry);\n }\n } else {\n scope.turbopackModules.push(item);\n }\n }\n return originalPush.apply(target, items);\n };\n return target;\n };\n\n const globalProp = `TURBOPACK_${globalKey}`;\n let currentValue: unknown = wrapPush([] as unknown[]);\n Object.defineProperty(self, globalProp, {\n get() {\n return currentValue;\n },\n set(newValue: unknown) {\n // When the turbopack runtime replaces the array with a dispatcher,\n // wrap the new object's push so we keep capturing module entries.\n if (newValue && typeof newValue === 'object') {\n wrapPush(newValue as { push?: (...args: unknown[]) => unknown });\n }\n currentValue = newValue;\n },\n configurable: true,\n enumerable: true,\n });\n }\n\n // load the script dynamically using a Blob URL\n await new Promise<void>((scriptResolve, scriptReject) => {\n const blob = new Blob([transformedCode], {\n type: 'application/javascript; charset=UTF-8',\n });\n const scriptUrl = URL.createObjectURL(blob);\n const script = document.createElement('script');\n script.setAttribute('data-turbopack-src', url);\n script.src = scriptUrl;\n script.async = true;\n script.onload = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptResolve(undefined);\n script.remove();\n };\n script.onerror = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptReject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${script.src}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n script.remove();\n };\n document.head.appendChild(script);\n });\n\n // process any additional chunks that were registered during script execution\n // These CHUNK_LIST chunks load directly via scope — no global dispatch needed.\n const chunkLists = self[`TURBOPACK_${globalKey}_CHUNK_LISTS`] as\n | { chunks: string[] }[]\n | undefined;\n const loadChunkPromises: (Promise<unknown> | undefined)[] = [];\n while (chunkLists?.length) {\n const { chunks } = chunkLists.shift() ?? { chunks: [] };\n if (chunks.length > 0) {\n for (const id of chunks) {\n const baseUrl = url.slice(0, url.indexOf('/_next'));\n const chunkLoadResult = loadChunkWithScope(\n scope,\n formatRemoteId(scope, `${baseUrl}/_next/${id}`),\n );\n if (chunkLoadResult) {\n loadChunkPromises.push(chunkLoadResult);\n }\n }\n }\n }\n if (loadChunkPromises.length > 0) {\n await Promise.all(loadChunkPromises);\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AAEtC,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAcA,SAAS,mBACd,OACA,SAC8B;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OAAO;AAAA,QACxC;AAAA,MACF;AACA,aAAO,OAAO;AAAA,IAChB;AACA,aAAS,KAAK,YAAY,MAAM;AAAA,EAClC,CAAC;AAID,QAAM,aAAa,KAAK,aAAa,uBAAuB;AAG5D,QAAM,oBAAsD,CAAC;AAC7D,SAAO,YAAY,QAAQ;AACzB,UAAM,EAAE,OAAO,IAAI,WAAW,MAAM,KAAK,EAAE,QAAQ,CAAC,EAAE;AACtD,QAAI,OAAO,SAAS,GAAG;AACrB,iBAAW,MAAM,QAAQ;AACvB,cAAM,UAAU,IAAI,MAAM,GAAG,IAAI,QAAQ,QAAQ,CAAC;AAClD,cAAM,kBAAkB;AAAA,UACtB;AAAA,UACA,eAAe,OAAO,GAAG,iBAAiB,IAAI;AAAA,QAChD;AACA,YAAI,iBAAiB;AACnB,4BAAkB,KAAK,eAAe;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,MAAI,kBAAkB,SAAS,GAAG;AAChC,UAAM,QAAQ,IAAI,iBAAiB;AAAA,EACrC;AACF;","names":[]}
|
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var module_exports = {};
|
|
20
20
|
__export(module_exports, {
|
|
21
|
+
findModuleInit: () => findModuleInit,
|
|
21
22
|
handleTurbopackModule: () => handleTurbopackModule,
|
|
22
23
|
requireModule: () => requireModule
|
|
23
24
|
});
|
|
@@ -31,10 +32,8 @@ function requireModule(scope, moduleId, fullId) {
|
|
|
31
32
|
if (scope.moduleCache[idStr])
|
|
32
33
|
return scope.moduleCache[idStr];
|
|
33
34
|
const sharedModule = (0, import_shared_modules.getSharedModule)(scope, moduleId);
|
|
34
|
-
if (sharedModule)
|
|
35
|
-
scope.moduleCache[idStr] = sharedModule;
|
|
35
|
+
if (sharedModule)
|
|
36
36
|
return sharedModule;
|
|
37
|
-
}
|
|
38
37
|
return handleTurbopackModule(
|
|
39
38
|
scope,
|
|
40
39
|
idStr,
|
|
@@ -42,19 +41,10 @@ function requireModule(scope, moduleId, fullId) {
|
|
|
42
41
|
);
|
|
43
42
|
}
|
|
44
43
|
function handleTurbopackModule(scope, moduleId, id) {
|
|
45
|
-
const self = globalThis;
|
|
46
44
|
if (scope.moduleCache[moduleId]) {
|
|
47
45
|
return scope.moduleCache[moduleId];
|
|
48
46
|
}
|
|
49
|
-
const
|
|
50
|
-
let modules;
|
|
51
|
-
if (raw && typeof raw === "object" && "__chunks__" in raw) {
|
|
52
|
-
modules = raw.__chunks__.flat();
|
|
53
|
-
} else if (Array.isArray(raw)) {
|
|
54
|
-
modules = raw.flat();
|
|
55
|
-
} else {
|
|
56
|
-
modules = raw;
|
|
57
|
-
}
|
|
47
|
+
const modules = (0, import_shared_modules.getTurbopackModules)(scope);
|
|
58
48
|
if (!modules) {
|
|
59
49
|
(0, import_logger.logError)(
|
|
60
50
|
"TurbopackModule",
|
|
@@ -104,9 +94,17 @@ function findModuleInit(modules, moduleId) {
|
|
|
104
94
|
if (idx >= 0) {
|
|
105
95
|
return flat.slice(idx + 1).find((e) => typeof e === "function");
|
|
106
96
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
97
|
+
for (const entry of flat) {
|
|
98
|
+
if (!entry || typeof entry !== "object")
|
|
99
|
+
continue;
|
|
100
|
+
const obj = entry;
|
|
101
|
+
if (moduleId in obj)
|
|
102
|
+
return obj[moduleId];
|
|
103
|
+
const prefixKey = Object.keys(obj).find((k) => k.startsWith(moduleId));
|
|
104
|
+
if (prefixKey)
|
|
105
|
+
return obj[prefixKey];
|
|
106
|
+
}
|
|
107
|
+
return void 0;
|
|
110
108
|
}
|
|
111
109
|
function createTurbopackContext(scope, exports, moduleExports, modules, moduleInit, id) {
|
|
112
110
|
const scopedRequire = (moduleId) => requireModule(scope, moduleId, (0, import_remote_scope.formatRemoteId)(scope, String(moduleId)));
|
|
@@ -185,7 +183,10 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
|
|
|
185
183
|
}
|
|
186
184
|
if (typeof mod !== "object" || mod === null) {
|
|
187
185
|
mod = { default: mod };
|
|
188
|
-
} else if (!("default" in mod) &&
|
|
186
|
+
} else if (!("default" in mod) && // ES module namespace objects have a null prototype, so calling
|
|
187
|
+
// mod.toString() directly throws. Use Object.prototype.toString
|
|
188
|
+
// to safely detect them.
|
|
189
|
+
Object.prototype.toString.call(mod) !== "[object Module]") {
|
|
189
190
|
try {
|
|
190
191
|
mod.default = mod;
|
|
191
192
|
} catch {
|
|
@@ -250,6 +251,7 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
|
|
|
250
251
|
}
|
|
251
252
|
// Annotate the CommonJS export names for ESM import in node:
|
|
252
253
|
0 && (module.exports = {
|
|
254
|
+
findModuleInit,
|
|
253
255
|
handleTurbopackModule,
|
|
254
256
|
requireModule
|
|
255
257
|
});
|