remote-components 0.0.40 → 0.0.42
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/html/host.cjs +429 -312
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +429 -312
- package/dist/html/host.js.map +1 -1
- package/dist/html/remote.cjs.map +1 -1
- package/dist/html/remote.js.map +1 -1
- package/dist/internal/shared/client/remote-component.cjs +404 -304
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +10 -1
- package/dist/internal/shared/client/remote-component.js +404 -304
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/error.cjs +4 -4
- package/dist/internal/shared/error.cjs.map +1 -1
- package/dist/internal/shared/error.d.ts +5 -2
- package/dist/internal/shared/error.js +4 -4
- package/dist/internal/shared/error.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.cjs +22 -7
- package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.js +22 -7
- package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
- package/dist/internal/webpack/shared-modules.cjs +36 -1
- package/dist/internal/webpack/shared-modules.cjs.map +1 -1
- package/dist/internal/webpack/shared-modules.js +36 -1
- package/dist/internal/webpack/shared-modules.js.map +1 -1
- package/dist/next/host/client/index.cjs +415 -314
- package/dist/next/host/client/index.cjs.map +1 -1
- package/dist/next/host/client/index.js +415 -314
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/react/index.cjs +7 -6
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +7 -6
- package/dist/react/index.js.map +1 -1
- package/package.json +6 -8
|
@@ -14,6 +14,18 @@ import * as JSXRuntime from "react/jsx-runtime";
|
|
|
14
14
|
import * as ReactDOM from "react-dom";
|
|
15
15
|
import * as ReactDOMClient from "react-dom/client";
|
|
16
16
|
|
|
17
|
+
// src/shared/utils/logger.ts
|
|
18
|
+
var PREFIX = "remote-components";
|
|
19
|
+
var DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
|
|
20
|
+
function logDebug(location2, message) {
|
|
21
|
+
if (DEBUG) {
|
|
22
|
+
console.debug(`[${PREFIX}:${location2}]: ${message}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function logWarn(location2, message) {
|
|
26
|
+
console.warn(`[${PREFIX}:${location2}]: ${message}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
17
29
|
// src/shared/webpack/next-client-pages-loader.ts
|
|
18
30
|
function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
19
31
|
const self = globalThis;
|
|
@@ -128,28 +140,62 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
|
128
140
|
|
|
129
141
|
// src/shared/webpack/shared-modules.ts
|
|
130
142
|
function applySharedModules(bundle, resolve) {
|
|
143
|
+
logDebug(
|
|
144
|
+
"SharedModules",
|
|
145
|
+
`applySharedModules called for bundle: "${bundle}"`
|
|
146
|
+
);
|
|
147
|
+
logDebug(
|
|
148
|
+
"SharedModules",
|
|
149
|
+
`Shared modules to resolve: ${Object.keys(resolve)}`
|
|
150
|
+
);
|
|
131
151
|
const self = globalThis;
|
|
132
152
|
if (self.__remote_webpack_require__?.[bundle]) {
|
|
133
153
|
const modulePaths = Object.keys(
|
|
134
154
|
self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
|
|
135
155
|
);
|
|
156
|
+
logDebug(
|
|
157
|
+
"SharedModules",
|
|
158
|
+
`Available module paths in __remote_webpack_require__[${bundle}]: ${modulePaths}`
|
|
159
|
+
);
|
|
136
160
|
for (const [key, value] of Object.entries(resolve)) {
|
|
137
161
|
let ids = modulePaths.filter((p) => p === key);
|
|
138
162
|
if (ids.length === 0) {
|
|
139
163
|
ids = modulePaths.filter((p) => p.includes(key));
|
|
140
164
|
}
|
|
165
|
+
if (ids.length === 0) {
|
|
166
|
+
logDebug(
|
|
167
|
+
"SharedModules",
|
|
168
|
+
`No matching module path found for shared module "${key}"`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
141
171
|
for (let id of ids) {
|
|
142
172
|
const webpackBundle = self.__remote_webpack_require__[bundle];
|
|
143
173
|
if (webpackBundle.m) {
|
|
144
174
|
if (self.__remote_webpack_module_map__?.[bundle]?.[id]) {
|
|
145
|
-
|
|
175
|
+
const mappedId = `${self.__remote_webpack_module_map__[bundle][id]}`;
|
|
176
|
+
logDebug(
|
|
177
|
+
"SharedModules",
|
|
178
|
+
`Mapped module id: "${id}" -> "${mappedId}"`
|
|
179
|
+
);
|
|
180
|
+
id = mappedId;
|
|
146
181
|
}
|
|
147
182
|
webpackBundle.m[id] = (module) => {
|
|
148
183
|
module.exports = value;
|
|
149
184
|
};
|
|
185
|
+
} else {
|
|
186
|
+
logWarn(
|
|
187
|
+
"SharedModules",
|
|
188
|
+
`webpackBundle.m is not available for bundle "${bundle}"`
|
|
189
|
+
);
|
|
150
190
|
}
|
|
151
191
|
}
|
|
152
192
|
}
|
|
193
|
+
} else {
|
|
194
|
+
logWarn("SharedModules", `No webpack require found for bundle "${bundle}"`);
|
|
195
|
+
logDebug(
|
|
196
|
+
"SharedModules",
|
|
197
|
+
`Available bundles: ${Object.keys(self.__remote_webpack_require__ ?? {})}`
|
|
198
|
+
);
|
|
153
199
|
}
|
|
154
200
|
}
|
|
155
201
|
|
|
@@ -263,52 +309,7 @@ function getBundleKey(bundle) {
|
|
|
263
309
|
return escapeString(bundle);
|
|
264
310
|
}
|
|
265
311
|
|
|
266
|
-
// src/shared/client/
|
|
267
|
-
async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}) {
|
|
268
|
-
const self = globalThis;
|
|
269
|
-
if (!self.__remote_bundle_url__) {
|
|
270
|
-
self.__remote_bundle_url__ = {};
|
|
271
|
-
}
|
|
272
|
-
self.__remote_bundle_url__[bundle ?? "default"] = url;
|
|
273
|
-
self.__webpack_get_script_filename__ = () => null;
|
|
274
|
-
if (typeof self.__webpack_require__ !== "function" || self.__webpack_require_type__ !== "turbopack") {
|
|
275
|
-
if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
|
|
276
|
-
self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
|
|
277
|
-
self.__original_webpack_require__ = self.__webpack_require__;
|
|
278
|
-
}
|
|
279
|
-
self.__webpack_chunk_load__ = createChunkLoader(runtime);
|
|
280
|
-
self.__webpack_require__ = createModuleRequire(runtime);
|
|
281
|
-
self.__webpack_require_type__ = runtime;
|
|
282
|
-
if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
|
|
283
|
-
const remoteBundle = bundle ?? "default";
|
|
284
|
-
self.__remote_webpack_require__[remoteBundle] = self.__webpack_require__;
|
|
285
|
-
self.__remote_webpack_require__[remoteBundle].type = "turbopack";
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
if (runtime === RUNTIME_TURBOPACK) {
|
|
289
|
-
await Promise.all(
|
|
290
|
-
scripts.map((script) => {
|
|
291
|
-
if (script.src) {
|
|
292
|
-
return self.__webpack_chunk_load__?.(script.src, bundle);
|
|
293
|
-
}
|
|
294
|
-
return Promise.resolve(void 0);
|
|
295
|
-
})
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
await initializeSharedModules(
|
|
299
|
-
bundle ?? "default",
|
|
300
|
-
// include all core modules as shared
|
|
301
|
-
{
|
|
302
|
-
react: async () => (await import("react")).default,
|
|
303
|
-
"react-dom": async () => (await import("react-dom")).default,
|
|
304
|
-
"react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
|
|
305
|
-
"react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
|
|
306
|
-
"react-dom/client": async () => (await import("react-dom/client")).default,
|
|
307
|
-
...shared
|
|
308
|
-
},
|
|
309
|
-
remoteShared
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
+
// src/shared/client/chunk-loader.ts
|
|
312
313
|
function createChunkLoader(runtime) {
|
|
313
314
|
return function __turbopack_chunk_load__(chunkId, scriptBundle) {
|
|
314
315
|
const self = globalThis;
|
|
@@ -423,46 +424,232 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
423
424
|
await Promise.all(loadChunkLists);
|
|
424
425
|
}
|
|
425
426
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
427
|
+
|
|
428
|
+
// src/shared/client/turbopack-module.ts
|
|
429
|
+
function handleTurbopackModule(bundle, moduleId, id) {
|
|
430
|
+
const self = globalThis;
|
|
431
|
+
const bundleKey = getBundleKey(bundle);
|
|
432
|
+
const modules = self[`TURBOPACK_${bundleKey}`];
|
|
433
|
+
const moduleInit = findModuleInit(modules, moduleId);
|
|
434
|
+
const exports = {};
|
|
435
|
+
const moduleExports = { exports };
|
|
436
|
+
if (!self.__remote_components_turbopack_modules__) {
|
|
437
|
+
self.__remote_components_turbopack_modules__ = {};
|
|
438
|
+
}
|
|
439
|
+
if (!self.__remote_components_turbopack_modules__[bundle]) {
|
|
440
|
+
self.__remote_components_turbopack_modules__[bundle] = {};
|
|
441
|
+
}
|
|
442
|
+
if (self.__remote_components_turbopack_modules__[bundle][moduleId]) {
|
|
443
|
+
return self.__remote_components_turbopack_modules__[bundle][moduleId];
|
|
444
|
+
}
|
|
445
|
+
if (typeof moduleInit !== "function") {
|
|
446
|
+
throw new Error(
|
|
447
|
+
`Module ${id} not found in bundle ${bundle} with id ${moduleId}`
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
self.__remote_components_turbopack_modules__[bundle][moduleId] = moduleExports.exports;
|
|
451
|
+
if (!self.__remote_components_turbopack_global__) {
|
|
452
|
+
self.__remote_components_turbopack_global__ = {};
|
|
453
|
+
}
|
|
454
|
+
if (!self.__remote_components_turbopack_global__[bundle]) {
|
|
455
|
+
self.__remote_components_turbopack_global__[bundle] = {};
|
|
456
|
+
}
|
|
457
|
+
const allModules = modules?.flat() ?? [];
|
|
458
|
+
moduleInit(
|
|
459
|
+
createTurbopackContext(
|
|
460
|
+
bundle,
|
|
461
|
+
exports,
|
|
462
|
+
moduleExports,
|
|
463
|
+
allModules,
|
|
464
|
+
moduleInit,
|
|
465
|
+
id,
|
|
466
|
+
self
|
|
467
|
+
),
|
|
468
|
+
moduleExports,
|
|
469
|
+
exports
|
|
470
|
+
);
|
|
471
|
+
if (self.__remote_components_turbopack_modules__[bundle][moduleId] !== moduleExports.exports) {
|
|
472
|
+
self.__remote_components_turbopack_modules__[bundle][moduleId] = moduleExports.exports;
|
|
473
|
+
}
|
|
474
|
+
return moduleExports.exports;
|
|
475
|
+
}
|
|
476
|
+
function findModuleInit(modules, moduleId) {
|
|
477
|
+
const allModules = modules?.flat() ?? [];
|
|
478
|
+
if (typeof allModules[1] === "string" || typeof allModules[1] === "number") {
|
|
479
|
+
const normalizedId = /^[0-9]+$/.test(moduleId) ? Number(moduleId) : moduleId;
|
|
480
|
+
let moduleIdIndex = allModules.indexOf(normalizedId);
|
|
481
|
+
if (moduleIdIndex === -1) {
|
|
482
|
+
moduleIdIndex = allModules.findIndex(
|
|
483
|
+
(bundleEntry) => typeof bundleEntry === "string" && bundleEntry.startsWith(moduleId) || bundleEntry === normalizedId
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
if (moduleIdIndex !== -1) {
|
|
487
|
+
while (typeof allModules[moduleIdIndex] !== "function" && moduleIdIndex < allModules.length) {
|
|
488
|
+
moduleIdIndex++;
|
|
437
489
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
490
|
+
return allModules[moduleIdIndex];
|
|
491
|
+
}
|
|
492
|
+
} else {
|
|
493
|
+
return allModules.find(
|
|
494
|
+
(bundleEntry) => typeof bundleEntry === "object" && bundleEntry !== null && moduleId in bundleEntry
|
|
495
|
+
)?.[moduleId];
|
|
496
|
+
}
|
|
497
|
+
return void 0;
|
|
498
|
+
}
|
|
499
|
+
function createTurbopackContext(bundle, exports, moduleExports, allModules, moduleInit, id, self) {
|
|
500
|
+
return {
|
|
501
|
+
// HMR not implemented for Remote Components
|
|
502
|
+
k: {
|
|
503
|
+
register() {
|
|
504
|
+
},
|
|
505
|
+
registerExports() {
|
|
506
|
+
},
|
|
507
|
+
signature() {
|
|
508
|
+
return (fn) => fn;
|
|
441
509
|
}
|
|
442
|
-
|
|
443
|
-
|
|
510
|
+
},
|
|
511
|
+
// ESM exports setup
|
|
512
|
+
s(bindings, esmId) {
|
|
513
|
+
let mod = exports;
|
|
514
|
+
if (typeof esmId === "string" || typeof esmId === "number") {
|
|
515
|
+
if (!self.__remote_components_turbopack_modules__) {
|
|
516
|
+
self.__remote_components_turbopack_modules__ = {};
|
|
517
|
+
}
|
|
518
|
+
if (!self.__remote_components_turbopack_modules__[bundle]) {
|
|
519
|
+
self.__remote_components_turbopack_modules__[bundle] = {};
|
|
520
|
+
}
|
|
521
|
+
if (!self.__remote_components_turbopack_modules__[bundle][esmId]) {
|
|
522
|
+
self.__remote_components_turbopack_modules__[bundle][esmId] = {};
|
|
523
|
+
}
|
|
524
|
+
mod = self.__remote_components_turbopack_modules__[bundle][esmId];
|
|
444
525
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
526
|
+
Object.defineProperty(mod, "__esModule", { value: true });
|
|
527
|
+
if (Array.isArray(bindings)) {
|
|
528
|
+
let i = 0;
|
|
529
|
+
while (i < bindings.length) {
|
|
530
|
+
const propName = bindings[i++];
|
|
531
|
+
const tagOrFunc = bindings[i++];
|
|
532
|
+
if (typeof tagOrFunc === "number") {
|
|
533
|
+
Object.defineProperty(mod, propName, {
|
|
534
|
+
value: bindings[i++],
|
|
535
|
+
enumerable: true,
|
|
536
|
+
writable: false
|
|
537
|
+
});
|
|
538
|
+
} else {
|
|
539
|
+
const getterFn = tagOrFunc;
|
|
540
|
+
if (typeof bindings[i] === "function") {
|
|
541
|
+
const setterFn = bindings[i++];
|
|
542
|
+
Object.defineProperty(mod, propName, {
|
|
543
|
+
get: getterFn,
|
|
544
|
+
set: setterFn,
|
|
545
|
+
enumerable: true
|
|
546
|
+
});
|
|
547
|
+
} else {
|
|
548
|
+
Object.defineProperty(mod, propName, {
|
|
549
|
+
get: getterFn,
|
|
550
|
+
enumerable: true
|
|
551
|
+
});
|
|
552
|
+
}
|
|
452
553
|
}
|
|
453
|
-
|
|
554
|
+
}
|
|
454
555
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
556
|
+
},
|
|
557
|
+
// import
|
|
558
|
+
i(importId) {
|
|
559
|
+
let mod;
|
|
560
|
+
if (typeof importId === "string") {
|
|
561
|
+
const { exportSource, exportName } = /\s+<export (?<exportSource>.*?) as (?<exportName>.*?)>$/.exec(
|
|
562
|
+
importId
|
|
563
|
+
)?.groups ?? {};
|
|
564
|
+
const normalizedId = importId.replace(
|
|
565
|
+
/\s+<export(?<specifier>.*)>$/,
|
|
566
|
+
""
|
|
461
567
|
);
|
|
568
|
+
mod = self.__webpack_require__?.(`[${bundle}] ${normalizedId}`);
|
|
569
|
+
if (mod && exportSource && exportName && (exportSource === "*" || typeof mod[exportSource] !== "undefined") && typeof mod[exportName] === "undefined") {
|
|
570
|
+
if (exportSource === "*") {
|
|
571
|
+
mod[exportName] = mod;
|
|
572
|
+
} else {
|
|
573
|
+
mod[exportName] = mod[exportSource];
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
} else {
|
|
577
|
+
mod = self.__webpack_require__?.(`[${bundle}] ${importId}`);
|
|
462
578
|
}
|
|
463
|
-
|
|
579
|
+
if (typeof mod !== "object" || mod === null) {
|
|
580
|
+
mod = { default: mod };
|
|
581
|
+
} else if (!("default" in mod) && mod.toString() !== "[object Module]") {
|
|
582
|
+
try {
|
|
583
|
+
mod.default = mod;
|
|
584
|
+
} catch {
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return mod;
|
|
588
|
+
},
|
|
589
|
+
// require
|
|
590
|
+
r(requireId) {
|
|
591
|
+
return self.__webpack_require__?.(`[${bundle}] ${requireId}`);
|
|
592
|
+
},
|
|
593
|
+
// value exports
|
|
594
|
+
v(value) {
|
|
595
|
+
if (typeof value === "function") {
|
|
596
|
+
exports.default = value((vid) => {
|
|
597
|
+
return self.__webpack_require__?.(`[${bundle}] ${vid}`);
|
|
598
|
+
});
|
|
599
|
+
} else {
|
|
600
|
+
moduleExports.exports = value;
|
|
601
|
+
}
|
|
602
|
+
},
|
|
603
|
+
// async module initializer
|
|
604
|
+
async a(mod) {
|
|
605
|
+
let result;
|
|
606
|
+
await mod(
|
|
607
|
+
() => {
|
|
608
|
+
},
|
|
609
|
+
(value) => result = value
|
|
610
|
+
);
|
|
611
|
+
exports.default = result;
|
|
612
|
+
},
|
|
613
|
+
// async module loader
|
|
614
|
+
async A(Aid) {
|
|
615
|
+
const mod = self.__webpack_require__?.(`[${bundle}] ${Aid}`);
|
|
616
|
+
return mod.default(
|
|
617
|
+
(parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
|
|
618
|
+
);
|
|
619
|
+
},
|
|
620
|
+
// chunk loader
|
|
621
|
+
l(url) {
|
|
622
|
+
const moduleInitIndex = allModules.indexOf(moduleInit);
|
|
623
|
+
if (moduleInitIndex !== -1) {
|
|
624
|
+
const scriptIndex = allModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
|
|
625
|
+
if (scriptIndex !== -1) {
|
|
626
|
+
const script = allModules[scriptIndex];
|
|
627
|
+
const scriptSrc = script.getAttribute("data-turbopack-src") || "";
|
|
628
|
+
const nextIndex = scriptSrc.indexOf("/_next");
|
|
629
|
+
const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
|
|
630
|
+
const bundleUrl = `[${bundle}] ${baseUrl}/_next/${url}`;
|
|
631
|
+
return self.__webpack_chunk_load__?.(bundleUrl, bundle);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
throw new Error(
|
|
635
|
+
`Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
|
|
636
|
+
);
|
|
637
|
+
},
|
|
638
|
+
// global object for this bundle
|
|
639
|
+
g: self.__remote_components_turbopack_global__?.[bundle],
|
|
640
|
+
m: moduleExports,
|
|
641
|
+
e: exports
|
|
464
642
|
};
|
|
465
643
|
}
|
|
644
|
+
|
|
645
|
+
// src/shared/client/turbopack-patterns.ts
|
|
646
|
+
var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
|
|
647
|
+
var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
|
|
648
|
+
var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
|
|
649
|
+
var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
|
|
650
|
+
var ASYNC_MODULE_ALL_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<vCb>parentImport|t)=>Promise\.all\(\["[^"]+"\]\.map\((?<mapCb>chunk|t)=>\k<ctx>\.l\(\k<mapCb>\)\)\)\.then\(\(\)=>\k<vCb>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
|
|
651
|
+
|
|
652
|
+
// src/shared/client/shared-modules.ts
|
|
466
653
|
async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {}) {
|
|
467
654
|
const self = globalThis;
|
|
468
655
|
self.__remote_shared_modules__ = self.__remote_shared_modules__ ?? {};
|
|
@@ -479,14 +666,12 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
|
|
|
479
666
|
return false;
|
|
480
667
|
}
|
|
481
668
|
const funcCode = idOrFunc.toString();
|
|
482
|
-
return
|
|
669
|
+
return REMOTE_SHARED_MARKER_RE.test(funcCode);
|
|
483
670
|
});
|
|
484
671
|
if (sharedModuleInitializerIndex > 0) {
|
|
485
672
|
const sharedModuleInitializerCode = allModules[sharedModuleInitializerIndex].toString();
|
|
486
673
|
const sharedModuleInitializerId = allModules[sharedModuleInitializerIndex - 1];
|
|
487
|
-
const { sharedModuleId } =
|
|
488
|
-
sharedModuleInitializerCode
|
|
489
|
-
)?.groups ?? {};
|
|
674
|
+
const { sharedModuleId } = REMOTE_SHARED_ASSIGNMENT_RE.exec(sharedModuleInitializerCode)?.groups ?? {};
|
|
490
675
|
if (sharedModuleId) {
|
|
491
676
|
const { default: sharedModuleInitializerInstance } = handleTurbopackModule(
|
|
492
677
|
bundle,
|
|
@@ -498,33 +683,11 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
|
|
|
498
683
|
}
|
|
499
684
|
if (sharedModuleInitializer) {
|
|
500
685
|
const { shared } = await sharedModuleInitializer;
|
|
501
|
-
const sharedModuleIds =
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
const newAllModules = self[`TURBOPACK_${bundleKey}`]?.flat() ?? [];
|
|
507
|
-
const asyncSharedModuleIdIndex = newAllModules.indexOf(
|
|
508
|
-
asyncSharedModuleIdNumber
|
|
509
|
-
);
|
|
510
|
-
if (asyncSharedModuleIdIndex !== -1 && typeof newAllModules[asyncSharedModuleIdIndex + 1] === "function") {
|
|
511
|
-
asyncSharedModule = newAllModules[asyncSharedModuleIdIndex + 1];
|
|
512
|
-
}
|
|
513
|
-
if (asyncSharedModule) {
|
|
514
|
-
const asyncSharedModuleCode = asyncSharedModule.toString();
|
|
515
|
-
const { sharedModuleId } = /e=>{e\.v\(e=>Promise\.resolve\(\)\.then\(\(\)=>e\((?<sharedModuleId>[0-9]+)\)\)\)}/.exec(
|
|
516
|
-
asyncSharedModuleCode
|
|
517
|
-
)?.groups ?? /e=>{e\.v\(t=>Promise\.all\(\["[^"]+"\].map\(t=>e\.l\(t\)\)\)\.then\(\(\)=>t\((?<sharedModuleId>[0-9]+)\)\)\)}/.exec(
|
|
518
|
-
asyncSharedModuleCode
|
|
519
|
-
)?.groups ?? {};
|
|
520
|
-
acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(
|
|
521
|
-
"__remote_shared_module_",
|
|
522
|
-
""
|
|
523
|
-
);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
return acc;
|
|
527
|
-
}, {});
|
|
686
|
+
const sharedModuleIds = extractSharedModuleIds(
|
|
687
|
+
shared,
|
|
688
|
+
bundleKey,
|
|
689
|
+
self
|
|
690
|
+
);
|
|
528
691
|
return Promise.all(
|
|
529
692
|
Object.entries(sharedModuleIds).map(async ([id, module]) => {
|
|
530
693
|
if (self.__remote_shared_modules__?.[bundle]) {
|
|
@@ -548,6 +711,31 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
|
|
|
548
711
|
})
|
|
549
712
|
);
|
|
550
713
|
}
|
|
714
|
+
function extractSharedModuleIds(shared, bundleKey, self) {
|
|
715
|
+
return Object.entries(shared).filter(([, value]) => typeof value === "function").reduce((acc, [key, value]) => {
|
|
716
|
+
const { asyncSharedModuleId } = ASYNC_MODULE_LOADER_RE.exec(value.toString())?.groups ?? {};
|
|
717
|
+
if (asyncSharedModuleId) {
|
|
718
|
+
const asyncSharedModuleIdNumber = Number(asyncSharedModuleId);
|
|
719
|
+
let asyncSharedModule;
|
|
720
|
+
const newAllModules = self[`TURBOPACK_${bundleKey}`]?.flat() ?? [];
|
|
721
|
+
const asyncSharedModuleIdIndex = newAllModules.indexOf(
|
|
722
|
+
asyncSharedModuleIdNumber
|
|
723
|
+
);
|
|
724
|
+
if (asyncSharedModuleIdIndex !== -1 && typeof newAllModules[asyncSharedModuleIdIndex + 1] === "function") {
|
|
725
|
+
asyncSharedModule = newAllModules[asyncSharedModuleIdIndex + 1];
|
|
726
|
+
}
|
|
727
|
+
if (asyncSharedModule) {
|
|
728
|
+
const asyncSharedModuleCode = asyncSharedModule.toString();
|
|
729
|
+
const { sharedModuleId } = ASYNC_MODULE_RESOLVE_RE.exec(asyncSharedModuleCode)?.groups ?? ASYNC_MODULE_ALL_RE.exec(asyncSharedModuleCode)?.groups ?? {};
|
|
730
|
+
acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(
|
|
731
|
+
"__remote_shared_module_",
|
|
732
|
+
""
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return acc;
|
|
737
|
+
}, {});
|
|
738
|
+
}
|
|
551
739
|
function getSharedModule(bundle, id) {
|
|
552
740
|
const self = globalThis;
|
|
553
741
|
for (const [key, value] of Object.entries(
|
|
@@ -559,210 +747,100 @@ function getSharedModule(bundle, id) {
|
|
|
559
747
|
}
|
|
560
748
|
return null;
|
|
561
749
|
}
|
|
562
|
-
|
|
750
|
+
|
|
751
|
+
// src/shared/client/webpack-adapter.ts
|
|
752
|
+
async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}) {
|
|
563
753
|
const self = globalThis;
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
(bundleEntry) => typeof bundleEntry === "string" && bundleEntry.startsWith(moduleId) || bundleEntry === normalizedId
|
|
574
|
-
);
|
|
754
|
+
if (!self.__remote_bundle_url__) {
|
|
755
|
+
self.__remote_bundle_url__ = {};
|
|
756
|
+
}
|
|
757
|
+
self.__remote_bundle_url__[bundle ?? "default"] = url;
|
|
758
|
+
self.__webpack_get_script_filename__ = () => null;
|
|
759
|
+
if (typeof self.__webpack_require__ !== "function" || self.__webpack_require_type__ !== "turbopack") {
|
|
760
|
+
if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
|
|
761
|
+
self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
|
|
762
|
+
self.__original_webpack_require__ = self.__webpack_require__;
|
|
575
763
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
764
|
+
self.__webpack_chunk_load__ = createChunkLoader(runtime);
|
|
765
|
+
self.__webpack_require__ = createModuleRequire(runtime);
|
|
766
|
+
self.__webpack_require_type__ = runtime;
|
|
767
|
+
if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
|
|
768
|
+
const remoteBundle = bundle ?? "default";
|
|
769
|
+
self.__remote_webpack_require__[remoteBundle] = self.__webpack_require__;
|
|
770
|
+
self.__remote_webpack_require__[remoteBundle].type = "turbopack";
|
|
581
771
|
}
|
|
582
|
-
} else {
|
|
583
|
-
moduleInit = allModules.find(
|
|
584
|
-
(bundleEntry) => typeof bundleEntry === "object" && bundleEntry !== null && moduleId in bundleEntry
|
|
585
|
-
)?.[moduleId];
|
|
586
|
-
}
|
|
587
|
-
const exports = {};
|
|
588
|
-
const moduleExports = { exports };
|
|
589
|
-
if (!self.__remote_components_turbopack_modules__) {
|
|
590
|
-
self.__remote_components_turbopack_modules__ = {};
|
|
591
|
-
}
|
|
592
|
-
if (!self.__remote_components_turbopack_modules__[bundle]) {
|
|
593
|
-
self.__remote_components_turbopack_modules__[bundle] = {};
|
|
594
772
|
}
|
|
595
|
-
if (
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
773
|
+
if (runtime === RUNTIME_TURBOPACK) {
|
|
774
|
+
await Promise.all(
|
|
775
|
+
scripts.map((script) => {
|
|
776
|
+
if (script.src) {
|
|
777
|
+
return self.__webpack_chunk_load__?.(script.src, bundle);
|
|
778
|
+
}
|
|
779
|
+
return Promise.resolve(void 0);
|
|
780
|
+
})
|
|
601
781
|
);
|
|
602
782
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
});
|
|
651
|
-
} else {
|
|
652
|
-
const getterFn = tagOrFunc;
|
|
653
|
-
if (typeof bindings[i] === "function") {
|
|
654
|
-
const setterFn = bindings[i++];
|
|
655
|
-
Object.defineProperty(mod, propName, {
|
|
656
|
-
get: getterFn,
|
|
657
|
-
set: setterFn,
|
|
658
|
-
enumerable: true
|
|
659
|
-
});
|
|
660
|
-
} else {
|
|
661
|
-
Object.defineProperty(mod, propName, {
|
|
662
|
-
get: getterFn,
|
|
663
|
-
enumerable: true
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
},
|
|
670
|
-
// import
|
|
671
|
-
i(importId) {
|
|
672
|
-
let mod;
|
|
673
|
-
if (typeof importId === "string") {
|
|
674
|
-
const { exportSource, exportName } = /\s+<export (?<exportSource>.*?) as (?<exportName>.*?)>$/.exec(
|
|
675
|
-
importId
|
|
676
|
-
)?.groups ?? {};
|
|
677
|
-
const normalizedId = importId.replace(
|
|
678
|
-
/\s+<export(?<specifier>.*)>$/,
|
|
679
|
-
""
|
|
680
|
-
);
|
|
681
|
-
mod = self.__webpack_require__?.(
|
|
682
|
-
`[${bundle}] ${normalizedId}`
|
|
683
|
-
);
|
|
684
|
-
if (exportSource && exportName && (exportSource === "*" || typeof mod[exportSource] !== "undefined") && typeof mod[exportName] === "undefined") {
|
|
685
|
-
if (exportSource === "*") {
|
|
686
|
-
mod[exportName] = mod;
|
|
687
|
-
} else {
|
|
688
|
-
mod[exportName] = mod[exportSource];
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
} else {
|
|
692
|
-
mod = self.__webpack_require__?.(`[${bundle}] ${importId}`);
|
|
693
|
-
}
|
|
694
|
-
if (typeof mod !== "object") {
|
|
695
|
-
mod = { default: mod };
|
|
696
|
-
} else if (!("default" in mod) && // eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
697
|
-
mod.toString() !== "[object Module]") {
|
|
698
|
-
try {
|
|
699
|
-
mod.default = mod;
|
|
700
|
-
} catch {
|
|
783
|
+
const coreShared = {
|
|
784
|
+
react: async () => (await import("react")).default,
|
|
785
|
+
"react-dom": async () => (await import("react-dom")).default,
|
|
786
|
+
"react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
|
|
787
|
+
"react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
|
|
788
|
+
"react-dom/client": async () => (await import("react-dom/client")).default,
|
|
789
|
+
...shared
|
|
790
|
+
};
|
|
791
|
+
await initializeSharedModules(
|
|
792
|
+
bundle ?? "default",
|
|
793
|
+
// include all core modules as shared
|
|
794
|
+
coreShared,
|
|
795
|
+
remoteShared
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
function createModuleRequire(runtime) {
|
|
799
|
+
return (id) => {
|
|
800
|
+
const self = globalThis;
|
|
801
|
+
const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? {
|
|
802
|
+
bundle: "default",
|
|
803
|
+
id
|
|
804
|
+
};
|
|
805
|
+
const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
|
|
806
|
+
logDebug("WebpackAdapter", `remoteRuntime: "${remoteRuntime}"`);
|
|
807
|
+
try {
|
|
808
|
+
if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
|
|
809
|
+
return self.__remote_webpack_require__?.[bundle]?.(moduleId);
|
|
810
|
+
}
|
|
811
|
+
const sharedModuleId = moduleId ?? id;
|
|
812
|
+
const sharedModule = getSharedModule(bundle ?? "default", sharedModuleId);
|
|
813
|
+
if (sharedModule) {
|
|
814
|
+
return sharedModule;
|
|
815
|
+
}
|
|
816
|
+
if (bundle && moduleId) {
|
|
817
|
+
return handleTurbopackModule(bundle, moduleId, id);
|
|
818
|
+
}
|
|
819
|
+
throw new Error(`Module "${id}" not found.`);
|
|
820
|
+
} catch (requireError) {
|
|
821
|
+
logWarn(
|
|
822
|
+
"WebpackAdapter",
|
|
823
|
+
`Module require failed: ${String(requireError)}`
|
|
824
|
+
);
|
|
825
|
+
if (typeof self.__original_webpack_require__ !== "function") {
|
|
826
|
+
throw new RemoteComponentsError(
|
|
827
|
+
`Module "${id}" not found in remote component bundle "${bundle}".`,
|
|
828
|
+
{
|
|
829
|
+
cause: requireError instanceof Error ? requireError : void 0
|
|
701
830
|
}
|
|
702
|
-
}
|
|
703
|
-
return mod;
|
|
704
|
-
},
|
|
705
|
-
// require
|
|
706
|
-
r(requireId) {
|
|
707
|
-
return self.__webpack_require__?.(`[${bundle}] ${requireId}`);
|
|
708
|
-
},
|
|
709
|
-
// value exports
|
|
710
|
-
v(value) {
|
|
711
|
-
if (typeof value === "function") {
|
|
712
|
-
exports.default = value((vid) => {
|
|
713
|
-
return self.__webpack_require__?.(`[${bundle}] ${vid}`);
|
|
714
|
-
});
|
|
715
|
-
} else {
|
|
716
|
-
moduleExports.exports = value;
|
|
717
|
-
}
|
|
718
|
-
},
|
|
719
|
-
// async module initializer
|
|
720
|
-
async a(mod) {
|
|
721
|
-
let result;
|
|
722
|
-
await mod(
|
|
723
|
-
() => {
|
|
724
|
-
},
|
|
725
|
-
(value) => result = value
|
|
726
831
|
);
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
},
|
|
736
|
-
// chunk loader
|
|
737
|
-
l(url) {
|
|
738
|
-
const moduleInitIndex = allModules.indexOf(moduleInit);
|
|
739
|
-
if (moduleInitIndex !== -1) {
|
|
740
|
-
const scriptIndex = allModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
|
|
741
|
-
if (scriptIndex !== -1) {
|
|
742
|
-
const script = allModules[scriptIndex];
|
|
743
|
-
const scriptSrc = script.getAttribute("data-turbopack-src") || "";
|
|
744
|
-
const nextIndex = scriptSrc.indexOf("/_next");
|
|
745
|
-
const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
|
|
746
|
-
const bundleUrl = `[${bundle}] ${baseUrl}/_next/${url}`;
|
|
747
|
-
return self.__webpack_chunk_load__?.(bundleUrl, bundle);
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
throw new Error(
|
|
751
|
-
`Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
|
|
832
|
+
}
|
|
833
|
+
try {
|
|
834
|
+
logDebug("WebpackAdapter", "Falling back to original webpack require");
|
|
835
|
+
return self.__original_webpack_require__(id);
|
|
836
|
+
} catch (originalError) {
|
|
837
|
+
throw new RemoteComponentsError(
|
|
838
|
+
`Module "${id}" not found in remote component bundle "${bundle}".`,
|
|
839
|
+
{ cause: originalError instanceof Error ? originalError : void 0 }
|
|
752
840
|
);
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
m: moduleExports,
|
|
757
|
-
e: exports
|
|
758
|
-
},
|
|
759
|
-
moduleExports,
|
|
760
|
-
exports
|
|
761
|
-
);
|
|
762
|
-
if (self.__remote_components_turbopack_modules__[bundle][moduleId] !== moduleExports.exports) {
|
|
763
|
-
self.__remote_components_turbopack_modules__[bundle][moduleId] = moduleExports.exports;
|
|
764
|
-
}
|
|
765
|
-
return moduleExports.exports;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
};
|
|
766
844
|
}
|
|
767
845
|
|
|
768
846
|
// src/shared/client/component-loader.ts
|
|
@@ -790,6 +868,18 @@ async function loadRemoteComponent({
|
|
|
790
868
|
await loadScripts(scripts);
|
|
791
869
|
}
|
|
792
870
|
const hostShared = await shared;
|
|
871
|
+
logDebug(
|
|
872
|
+
"ComponentLoader",
|
|
873
|
+
`loadRemoteComponent: bundle="${bundle}", name="${name}"`
|
|
874
|
+
);
|
|
875
|
+
logDebug(
|
|
876
|
+
"ComponentLoader",
|
|
877
|
+
`Host shared modules available: ${Object.keys(hostShared)}`
|
|
878
|
+
);
|
|
879
|
+
logDebug(
|
|
880
|
+
"ComponentLoader",
|
|
881
|
+
`Remote shared modules requested: ${JSON.stringify(remoteShared)}`
|
|
882
|
+
);
|
|
793
883
|
await setupWebpackRuntime(
|
|
794
884
|
runtime,
|
|
795
885
|
scripts,
|
|
@@ -809,6 +899,11 @@ async function loadRemoteComponent({
|
|
|
809
899
|
(acc, [key, value]) => {
|
|
810
900
|
if (typeof hostShared[value] !== "undefined") {
|
|
811
901
|
acc[key.replace(/^\(ssr\)\/(?<relative>\.\/)?/, "")] = hostShared[value];
|
|
902
|
+
} else {
|
|
903
|
+
logDebug(
|
|
904
|
+
"ComponentLoader",
|
|
905
|
+
`Remote requests "${value}" but host doesn't provide it`
|
|
906
|
+
);
|
|
812
907
|
}
|
|
813
908
|
return acc;
|
|
814
909
|
},
|
|
@@ -824,6 +919,11 @@ async function loadRemoteComponent({
|
|
|
824
919
|
})
|
|
825
920
|
);
|
|
826
921
|
applySharedModules(bundle, resolve);
|
|
922
|
+
} else {
|
|
923
|
+
logWarn(
|
|
924
|
+
"ComponentLoader",
|
|
925
|
+
"No bundle specified, skipping shared module setup"
|
|
926
|
+
);
|
|
827
927
|
}
|
|
828
928
|
if (data.length > 0) {
|
|
829
929
|
return await loadRSCComponent(rscName ?? name, data);
|