remote-components 0.3.3 → 0.3.5
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 +86 -37
- package/dist/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.js +86 -37
- 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/html.cjs +861 -617
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +861 -617
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +700 -383
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +674 -357
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/nextjs/app.cjs +34 -2
- package/dist/host/nextjs/app.cjs.map +1 -1
- package/dist/host/nextjs/app.js +35 -3
- package/dist/host/nextjs/app.js.map +1 -1
- package/dist/host/react.cjs +641 -352
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +641 -352
- 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 +42 -27
- package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
- package/dist/internal/host/nextjs/app-client.js +42 -27
- 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/remote-component-links.cjs +24 -13
- package/dist/internal/host/nextjs/remote-component-links.cjs.map +1 -1
- package/dist/internal/host/nextjs/remote-component-links.d.ts +3 -0
- package/dist/internal/host/nextjs/remote-component-links.js +24 -13
- package/dist/internal/host/nextjs/remote-component-links.js.map +1 -1
- 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/lifecycle.cjs +69 -0
- package/dist/internal/host/shared/lifecycle.cjs.map +1 -0
- package/dist/internal/host/shared/lifecycle.d.ts +34 -0
- package/dist/internal/host/shared/lifecycle.js +44 -0
- package/dist/internal/host/shared/lifecycle.js.map +1 -0
- package/dist/internal/host/shared/pipeline.cjs +222 -0
- package/dist/internal/host/shared/pipeline.cjs.map +1 -0
- package/dist/internal/host/shared/pipeline.d.ts +153 -0
- package/dist/internal/host/shared/pipeline.js +200 -0
- package/dist/internal/host/shared/pipeline.js.map +1 -0
- 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/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/runtime/rsc-runtime.cjs +17 -0
- 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-runtime.js.map +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 +17 -4
- 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 +16 -4
- 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 +21 -15
- package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.d.ts +9 -2
- package/dist/internal/runtime/turbopack/shared-modules.js +24 -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/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 +14 -55
- package/dist/remote/nextjs/app.cjs.map +1 -1
- package/dist/remote/nextjs/app.js +24 -45
- package/dist/remote/nextjs/app.js.map +1 -1
- package/dist/types-59251814.d.ts +94 -0
- package/package.json +2 -2
- 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
|
@@ -73,7 +73,10 @@ __export(app_client_only_exports, {
|
|
|
73
73
|
RemoteComponentsClientProvider: () => RemoteComponentsClientProvider
|
|
74
74
|
});
|
|
75
75
|
module.exports = __toCommonJS(app_client_only_exports);
|
|
76
|
-
var
|
|
76
|
+
var import_react6 = require("react");
|
|
77
|
+
|
|
78
|
+
// src/host/nextjs/image-shared.ts
|
|
79
|
+
var import_react = require("react");
|
|
77
80
|
|
|
78
81
|
// src/utils/index.ts
|
|
79
82
|
function escapeString(str) {
|
|
@@ -101,6 +104,62 @@ function getBundleKey(bundle) {
|
|
|
101
104
|
return escapeString(bundle);
|
|
102
105
|
}
|
|
103
106
|
|
|
107
|
+
// src/runtime/namespace.ts
|
|
108
|
+
var SHADOW_ROOT_PREFIX = "__remote_components_shadowroot_";
|
|
109
|
+
var LEGACY_ALIASES = [
|
|
110
|
+
{ global: "__remote_component_scopes__", prop: "scopes" },
|
|
111
|
+
{
|
|
112
|
+
global: "__remote_components_turbopack_chunk_loader_promise__",
|
|
113
|
+
prop: "chunkCache"
|
|
114
|
+
},
|
|
115
|
+
{ global: "__remote_script_entrypoint_mount__", prop: "mountFns" },
|
|
116
|
+
{ global: "__remote_script_entrypoint_unmount__", prop: "unmountFns" },
|
|
117
|
+
{ global: "__remote_bundle_url__", prop: "bundleUrls" },
|
|
118
|
+
{ global: "__rc_module_registry__", prop: "moduleRegistry" },
|
|
119
|
+
{
|
|
120
|
+
global: "__remote_component_host_shared_modules__",
|
|
121
|
+
prop: "hostSharedModules"
|
|
122
|
+
},
|
|
123
|
+
{ global: "__remote_next_css__", prop: "cssCache" }
|
|
124
|
+
];
|
|
125
|
+
function getNamespace() {
|
|
126
|
+
const g = globalThis;
|
|
127
|
+
const existing = g.__remote_components__;
|
|
128
|
+
if (existing) {
|
|
129
|
+
return existing;
|
|
130
|
+
}
|
|
131
|
+
const ns = {
|
|
132
|
+
scopes: /* @__PURE__ */ new Map(),
|
|
133
|
+
chunkCache: {},
|
|
134
|
+
mountFns: {},
|
|
135
|
+
unmountFns: {},
|
|
136
|
+
bundleUrls: {},
|
|
137
|
+
moduleRegistry: {},
|
|
138
|
+
dispatcherRuntime: void 0,
|
|
139
|
+
hostSharedModules: {},
|
|
140
|
+
cssCache: {},
|
|
141
|
+
shadowRoots: {}
|
|
142
|
+
};
|
|
143
|
+
const nsRecord = ns;
|
|
144
|
+
for (const { global, prop } of LEGACY_ALIASES) {
|
|
145
|
+
const legacyValue = g[global];
|
|
146
|
+
if (legacyValue != null) {
|
|
147
|
+
nsRecord[prop] = legacyValue;
|
|
148
|
+
}
|
|
149
|
+
g[global] = ns[prop];
|
|
150
|
+
}
|
|
151
|
+
const gRecord = g;
|
|
152
|
+
for (const key of Object.keys(gRecord)) {
|
|
153
|
+
if (key.startsWith(SHADOW_ROOT_PREFIX)) {
|
|
154
|
+
const suffix = key.slice(SHADOW_ROOT_PREFIX.length);
|
|
155
|
+
ns.shadowRoots[suffix] = gRecord[key];
|
|
156
|
+
delete gRecord[key];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
g.__remote_components__ = ns;
|
|
160
|
+
return ns;
|
|
161
|
+
}
|
|
162
|
+
|
|
104
163
|
// src/runtime/patterns.ts
|
|
105
164
|
var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
106
165
|
var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
@@ -225,7 +284,7 @@ Docs: ${CORS_DOCS_URL}`
|
|
|
225
284
|
|
|
226
285
|
// src/utils/logger.ts
|
|
227
286
|
var PREFIX = "remote-components";
|
|
228
|
-
var DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
|
|
287
|
+
var DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true" || typeof process !== "undefined" && process.env.RC_DEBUG === "true";
|
|
229
288
|
function logDebug(location2, message) {
|
|
230
289
|
if (DEBUG) {
|
|
231
290
|
console.debug(`[${PREFIX}:${location2}]: ${message}`);
|
|
@@ -257,11 +316,7 @@ function warnCrossOriginFetchError(logLocation, url) {
|
|
|
257
316
|
|
|
258
317
|
// src/runtime/turbopack/remote-scope.ts
|
|
259
318
|
function getRegistry() {
|
|
260
|
-
|
|
261
|
-
if (!self.__remote_component_scopes__) {
|
|
262
|
-
self.__remote_component_scopes__ = /* @__PURE__ */ new Map();
|
|
263
|
-
}
|
|
264
|
-
return self.__remote_component_scopes__;
|
|
319
|
+
return getNamespace().scopes;
|
|
265
320
|
}
|
|
266
321
|
function createScope(name, url, runtime, resolveClientUrl) {
|
|
267
322
|
const isCrossOrigin = url.origin !== location.origin;
|
|
@@ -279,7 +334,8 @@ function createScope(name, url, runtime, resolveClientUrl) {
|
|
|
279
334
|
resolveClientUrl,
|
|
280
335
|
moduleCache: {},
|
|
281
336
|
sharedModules: {},
|
|
282
|
-
moduleGlobal: {}
|
|
337
|
+
moduleGlobal: {},
|
|
338
|
+
turbopackModules: []
|
|
283
339
|
};
|
|
284
340
|
}
|
|
285
341
|
function registerScope(scope) {
|
|
@@ -376,16 +432,41 @@ function createImageLoaderSharedEntries({
|
|
|
376
432
|
bound,
|
|
377
433
|
unbound
|
|
378
434
|
} = {}) {
|
|
379
|
-
const
|
|
435
|
+
const loaderEntry = (bundle) => {
|
|
380
436
|
const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);
|
|
381
437
|
return Promise.resolve({
|
|
382
438
|
default: createRemoteImageLoader(bundle, resolveClientUrl),
|
|
383
439
|
__esModule: true
|
|
384
440
|
});
|
|
385
441
|
};
|
|
442
|
+
const imageEntry = async (bundle) => {
|
|
443
|
+
const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);
|
|
444
|
+
const rawLoader = createRemoteImageLoader(bundle, resolveClientUrl);
|
|
445
|
+
const remoteLoader = Object.assign(
|
|
446
|
+
(p) => rawLoader({ ...p, config: { path: "/_next/image" } }),
|
|
447
|
+
{ __next_img_default: true }
|
|
448
|
+
);
|
|
449
|
+
const mod = await import("next/image");
|
|
450
|
+
const OriginalImage = mod.default;
|
|
451
|
+
const RemoteImage = (0, import_react.forwardRef)(
|
|
452
|
+
(props, ref) => (0, import_react.createElement)(OriginalImage, {
|
|
453
|
+
...props,
|
|
454
|
+
loader: props.loader ?? remoteLoader,
|
|
455
|
+
ref
|
|
456
|
+
})
|
|
457
|
+
);
|
|
458
|
+
RemoteImage.displayName = "RemoteImage";
|
|
459
|
+
return { ...mod, default: RemoteImage, __esModule: true };
|
|
460
|
+
};
|
|
386
461
|
return {
|
|
387
|
-
"next/dist/shared/lib/image-loader":
|
|
388
|
-
"next/dist/esm/shared/lib/image-loader":
|
|
462
|
+
"next/dist/shared/lib/image-loader": loaderEntry,
|
|
463
|
+
"next/dist/esm/shared/lib/image-loader": loaderEntry,
|
|
464
|
+
// Can be removed once 0.2.x support is dropped.
|
|
465
|
+
"next/image": imageEntry,
|
|
466
|
+
// Can be removed once 0.2.x support is dropped.
|
|
467
|
+
"next/dist/client/image-component": imageEntry,
|
|
468
|
+
// Can be removed once 0.2.x support is dropped.
|
|
469
|
+
"next/dist/api/image": imageEntry
|
|
389
470
|
};
|
|
390
471
|
}
|
|
391
472
|
|
|
@@ -403,7 +484,7 @@ async function tryImportShared() {
|
|
|
403
484
|
var import_context3 = require("#internal/host/react/context");
|
|
404
485
|
|
|
405
486
|
// src/host/react/index.tsx
|
|
406
|
-
var
|
|
487
|
+
var import_react4 = require("react");
|
|
407
488
|
var import_react_dom = require("react-dom");
|
|
408
489
|
var import_context2 = require("#internal/host/react/context");
|
|
409
490
|
|
|
@@ -462,12 +543,30 @@ function getClientOrServerUrl(src, serverFallback) {
|
|
|
462
543
|
return typeof src === "string" ? new URL(src, fallback) : src;
|
|
463
544
|
}
|
|
464
545
|
|
|
546
|
+
// src/host/shared/lifecycle.ts
|
|
547
|
+
function makeReactEmitter(callbacks) {
|
|
548
|
+
return {
|
|
549
|
+
beforeLoad(src) {
|
|
550
|
+
callbacks.onBeforeLoad?.(src);
|
|
551
|
+
},
|
|
552
|
+
load(src) {
|
|
553
|
+
callbacks.onLoad?.(src);
|
|
554
|
+
},
|
|
555
|
+
error(error, _src) {
|
|
556
|
+
callbacks.onError?.(error);
|
|
557
|
+
},
|
|
558
|
+
change(info) {
|
|
559
|
+
callbacks.onChange?.(info);
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
|
|
465
564
|
// src/host/shared/polyfill.tsx
|
|
466
565
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
467
566
|
function sharedPolyfills(shared2, resolveClientUrl) {
|
|
468
|
-
const
|
|
567
|
+
const hostShared = getNamespace().hostSharedModules;
|
|
469
568
|
const polyfill = {
|
|
470
|
-
"next/dist/client/components/navigation":
|
|
569
|
+
"next/dist/client/components/navigation": hostShared["next/navigation"] ?? shared2?.["next/navigation"] ?? (() => Promise.resolve({
|
|
471
570
|
useRouter() {
|
|
472
571
|
return {
|
|
473
572
|
push: (routerUrl) => {
|
|
@@ -498,7 +597,7 @@ function sharedPolyfills(shared2, resolveClientUrl) {
|
|
|
498
597
|
},
|
|
499
598
|
__esModule: true
|
|
500
599
|
})),
|
|
501
|
-
"next/dist/client/app-dir/link":
|
|
600
|
+
"next/dist/client/app-dir/link": hostShared["next/link"] ?? shared2?.["next/link"] ?? (() => Promise.resolve({
|
|
502
601
|
default: ({
|
|
503
602
|
scroll: _,
|
|
504
603
|
replace,
|
|
@@ -548,7 +647,7 @@ function sharedPolyfills(shared2, resolveClientUrl) {
|
|
|
548
647
|
},
|
|
549
648
|
__esModule: true
|
|
550
649
|
})),
|
|
551
|
-
"next/dist/client/app-dir/form":
|
|
650
|
+
"next/dist/client/app-dir/form": hostShared["next/form"] ?? shared2?.["next/form"] ?? (() => Promise.resolve({
|
|
552
651
|
default: () => {
|
|
553
652
|
throw new Error("Next.js <Form> component not implemented");
|
|
554
653
|
},
|
|
@@ -559,17 +658,17 @@ function sharedPolyfills(shared2, resolveClientUrl) {
|
|
|
559
658
|
// This gives us full next/image fidelity (fill, priority, srcSet, blur
|
|
560
659
|
// placeholders, error handling) while routing image optimization through the
|
|
561
660
|
// remote app's /_next/image endpoint.
|
|
562
|
-
"next/dist/shared/lib/image-loader":
|
|
661
|
+
"next/dist/shared/lib/image-loader": hostShared["next/dist/shared/lib/image-loader"] ?? shared2?.["next/dist/shared/lib/image-loader"] ?? ((bundle) => Promise.resolve({
|
|
563
662
|
default: createRemoteImageLoader(bundle, resolveClientUrl),
|
|
564
663
|
__esModule: true
|
|
565
664
|
})),
|
|
566
|
-
"next/dist/client/script":
|
|
665
|
+
"next/dist/client/script": hostShared["next/script"] ?? shared2?.["next/script"] ?? (() => Promise.resolve({
|
|
567
666
|
// TODO: implement <Script> component for non-Next.js host applications
|
|
568
667
|
// do not throw an error for now
|
|
569
668
|
default: () => null,
|
|
570
669
|
__esModule: true
|
|
571
670
|
})),
|
|
572
|
-
"next/router":
|
|
671
|
+
"next/router": hostShared["next/router"] ?? shared2?.["next/router"] ?? (() => (
|
|
573
672
|
// TODO: incomplete implementation
|
|
574
673
|
Promise.resolve({
|
|
575
674
|
useRouter() {
|
|
@@ -605,34 +704,70 @@ function sharedPolyfills(shared2, resolveClientUrl) {
|
|
|
605
704
|
return polyfill;
|
|
606
705
|
}
|
|
607
706
|
|
|
608
|
-
// src/host/shared/
|
|
609
|
-
|
|
707
|
+
// src/host/shared/shared-module-resolver.ts
|
|
708
|
+
var CORE_REACT_PATH_MAP = {
|
|
709
|
+
react: "/react/index.js",
|
|
710
|
+
"react/jsx-dev-runtime": "/react/jsx-dev-runtime.js",
|
|
711
|
+
"react/jsx-runtime": "/react/jsx-runtime.js",
|
|
712
|
+
"react-dom": "/react-dom/index.js",
|
|
713
|
+
"react-dom/client": "/react-dom/client.js"
|
|
714
|
+
};
|
|
715
|
+
var VENDOR_SHARED = Object.fromEntries(
|
|
716
|
+
Object.entries(CORE_REACT_PATH_MAP).filter(([key]) => key !== "react-dom/client").map(([key, path]) => [key, `'${path}'`])
|
|
717
|
+
);
|
|
718
|
+
function buildCoreShared(userShared) {
|
|
610
719
|
return {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
720
|
+
react: async () => (await import("react")).default,
|
|
721
|
+
"react-dom": async () => (await import("react-dom")).default,
|
|
722
|
+
"react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
|
|
723
|
+
"react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
|
|
724
|
+
"react-dom/client": async () => (await import("react-dom/client")).default,
|
|
725
|
+
...userShared
|
|
617
726
|
};
|
|
618
727
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
728
|
+
function buildHostShared(userShared, resolveClientUrl, options) {
|
|
729
|
+
const self = globalThis;
|
|
730
|
+
const result = {
|
|
731
|
+
...sharedPolyfills(userShared, resolveClientUrl),
|
|
732
|
+
...self.__remote_component_host_shared_modules__,
|
|
733
|
+
...userShared
|
|
734
|
+
};
|
|
735
|
+
if (options?.includeRemoteComponentShared) {
|
|
736
|
+
Object.assign(result, self.__remote_component_shared__);
|
|
737
|
+
}
|
|
738
|
+
return result;
|
|
739
|
+
}
|
|
740
|
+
async function buildWebpackResolve(hostShared, remoteShared, bundle, reactModules, callerTag = "SharedModuleResolver") {
|
|
741
|
+
const resolve = {
|
|
742
|
+
...reactModules,
|
|
743
|
+
...Object.entries(remoteShared).reduce(
|
|
744
|
+
(acc, [key, value]) => {
|
|
745
|
+
if (typeof hostShared[value] !== "undefined") {
|
|
746
|
+
acc[key.replace(/^\(ssr\)\/(?<relative>\.\/)?/, "")] = hostShared[value];
|
|
747
|
+
} else {
|
|
748
|
+
logDebug(
|
|
749
|
+
callerTag,
|
|
750
|
+
`Remote requests "${value}" but host doesn't provide it`
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
return acc;
|
|
754
|
+
},
|
|
755
|
+
{}
|
|
756
|
+
)
|
|
757
|
+
};
|
|
758
|
+
await Promise.all(
|
|
759
|
+
Object.entries(resolve).map(async ([key, value]) => {
|
|
760
|
+
if (typeof value === "function") {
|
|
761
|
+
resolve[key] = await value(bundle);
|
|
762
|
+
}
|
|
763
|
+
return Promise.resolve(value);
|
|
764
|
+
})
|
|
765
|
+
);
|
|
766
|
+
return resolve;
|
|
632
767
|
}
|
|
633
768
|
|
|
634
|
-
// src/runtime/html/
|
|
635
|
-
var
|
|
769
|
+
// src/runtime/html/html-spec.ts
|
|
770
|
+
var ORIGIN_REWRITE_TAGS = [
|
|
636
771
|
"img",
|
|
637
772
|
"source",
|
|
638
773
|
"video",
|
|
@@ -643,10 +778,37 @@ var tagNames = [
|
|
|
643
778
|
"script",
|
|
644
779
|
"link"
|
|
645
780
|
];
|
|
781
|
+
var ID_SUFFIX_RSC = "_rsc";
|
|
782
|
+
var ID_SUFFIX_SSR = "_ssr";
|
|
783
|
+
var ID_SUFFIX_SHARED = "_shared";
|
|
784
|
+
var DATA_BUNDLE = "data-bundle";
|
|
785
|
+
var DATA_ROUTE = "data-route";
|
|
786
|
+
var DATA_RUNTIME = "data-runtime";
|
|
787
|
+
var DATA_TYPE = "data-type";
|
|
788
|
+
var DATA_SRC = "data-src";
|
|
789
|
+
var DATA_REMOTE_COMPONENTS_SHARED = "data-remote-components-shared";
|
|
790
|
+
var TAG_REMOTE_COMPONENT = "remote-component";
|
|
791
|
+
var NEXT_DATA_ID = "__NEXT_DATA__";
|
|
792
|
+
var REMOTE_NEXT_DATA_ID = "__REMOTE_NEXT_DATA__";
|
|
793
|
+
var NEXT_CONTAINER_ID = "__next";
|
|
794
|
+
|
|
795
|
+
// src/runtime/html/rewrite-srcset.ts
|
|
796
|
+
function rewriteSrcset(srcset, base, resolve) {
|
|
797
|
+
return srcset.split(",").map((entry) => {
|
|
798
|
+
const [url, descriptor] = entry.trim().split(/\s+/);
|
|
799
|
+
if (!url)
|
|
800
|
+
return entry;
|
|
801
|
+
const absoluteUrl = new URL(url, base).href;
|
|
802
|
+
const resolvedUrl = resolve ? resolve(absoluteUrl) : absoluteUrl;
|
|
803
|
+
return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
|
|
804
|
+
}).join(", ");
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
// src/runtime/html/apply-origin.ts
|
|
646
808
|
function applyOriginToNodes(doc, url, resolveClientUrl) {
|
|
647
809
|
if (url.origin !== location.origin) {
|
|
648
810
|
const nodes = doc.querySelectorAll(
|
|
649
|
-
|
|
811
|
+
ORIGIN_REWRITE_TAGS.map(
|
|
650
812
|
(type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
|
|
651
813
|
).join(",")
|
|
652
814
|
);
|
|
@@ -664,29 +826,17 @@ function applyOriginToNodes(doc, url, resolveClientUrl) {
|
|
|
664
826
|
);
|
|
665
827
|
}
|
|
666
828
|
if (node.hasAttribute("srcset")) {
|
|
667
|
-
const
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
const absoluteUrl = new URL(urlPart, url).href;
|
|
672
|
-
const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
|
|
673
|
-
return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
|
|
674
|
-
}).join(", ");
|
|
675
|
-
if (srcSet) {
|
|
676
|
-
node.setAttribute("srcset", srcSet);
|
|
829
|
+
const raw = node.getAttribute("srcset");
|
|
830
|
+
if (raw) {
|
|
831
|
+
const resolve = resolveClientUrl ? (abs) => resolveClientUrl(abs) ?? abs : void 0;
|
|
832
|
+
node.setAttribute("srcset", rewriteSrcset(raw, url, resolve));
|
|
677
833
|
}
|
|
678
834
|
}
|
|
679
835
|
if (node.hasAttribute("imagesrcset")) {
|
|
680
|
-
const
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
const absoluteUrl = new URL(urlPart, url).href;
|
|
685
|
-
const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
|
|
686
|
-
return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
|
|
687
|
-
}).join(", ");
|
|
688
|
-
if (srcSet) {
|
|
689
|
-
node.setAttribute("imagesrcset", srcSet);
|
|
836
|
+
const raw = node.getAttribute("imagesrcset");
|
|
837
|
+
if (raw) {
|
|
838
|
+
const resolve = resolveClientUrl ? (abs) => resolveClientUrl(abs) ?? abs : void 0;
|
|
839
|
+
node.setAttribute("imagesrcset", rewriteSrcset(raw, url, resolve));
|
|
690
840
|
}
|
|
691
841
|
}
|
|
692
842
|
});
|
|
@@ -727,26 +877,28 @@ function buildMetadata(attrs, url) {
|
|
|
727
877
|
|
|
728
878
|
// src/runtime/html/parse-remote-html.ts
|
|
729
879
|
function validateSingleComponent(doc, name, url) {
|
|
730
|
-
if (doc.querySelectorAll(
|
|
880
|
+
if (doc.querySelectorAll(`div[${DATA_BUNDLE}][${DATA_ROUTE}]`).length > 1 && !doc.querySelector(
|
|
881
|
+
`div[${DATA_BUNDLE}][${DATA_ROUTE}][id^="${name}"]`
|
|
882
|
+
) || doc.querySelectorAll(`${TAG_REMOTE_COMPONENT}:not([src])`).length > 1 && !doc.querySelector(`${TAG_REMOTE_COMPONENT}[name="${name}"]`)) {
|
|
731
883
|
throw multipleRemoteComponentsError(url);
|
|
732
884
|
}
|
|
733
885
|
}
|
|
734
886
|
function findComponentElement(doc, name) {
|
|
735
|
-
return doc.querySelector(`div[
|
|
887
|
+
return doc.querySelector(`div[${DATA_BUNDLE}][${DATA_ROUTE}][id^="${name}"]`) ?? doc.querySelector(`div[${DATA_BUNDLE}][${DATA_ROUTE}]`) ?? doc.querySelector(`div#${NEXT_CONTAINER_ID}`) ?? doc.querySelector(`${TAG_REMOTE_COMPONENT}[name="${name}"]:not([src])`) ?? doc.querySelector(`${TAG_REMOTE_COMPONENT}:not([src])`);
|
|
736
888
|
}
|
|
737
889
|
function parseNextData(doc) {
|
|
738
890
|
return JSON.parse(
|
|
739
|
-
(doc.querySelector(
|
|
891
|
+
(doc.querySelector(`#${NEXT_DATA_ID}`) ?? doc.querySelector(`#${REMOTE_NEXT_DATA_ID}`))?.textContent ?? "null"
|
|
740
892
|
);
|
|
741
893
|
}
|
|
742
894
|
function resolveComponentName(component, nextData, fallbackName) {
|
|
743
|
-
const isRemoteComponent = component?.tagName.toLowerCase() ===
|
|
744
|
-
const name = component?.getAttribute("id")?.replace(
|
|
895
|
+
const isRemoteComponent = component?.tagName.toLowerCase() === TAG_REMOTE_COMPONENT;
|
|
896
|
+
const name = component?.getAttribute("id")?.replace(new RegExp(`${ID_SUFFIX_SSR}$`), "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
|
|
745
897
|
return { name, isRemoteComponent };
|
|
746
898
|
}
|
|
747
899
|
function extractRemoteShared(doc, name, nextData) {
|
|
748
900
|
const remoteSharedEl = doc.querySelector(
|
|
749
|
-
`#${name}
|
|
901
|
+
`#${name}${ID_SUFFIX_SHARED}[${DATA_REMOTE_COMPONENTS_SHARED}]`
|
|
750
902
|
);
|
|
751
903
|
const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
|
|
752
904
|
remoteSharedEl?.remove();
|
|
@@ -767,7 +919,7 @@ function extractLinks(doc, component) {
|
|
|
767
919
|
function extractScripts(doc, component, isRemoteComponent) {
|
|
768
920
|
return Array.from(
|
|
769
921
|
(isRemoteComponent ? component : doc).querySelectorAll(
|
|
770
|
-
|
|
922
|
+
`script[src],script[${DATA_SRC}]`
|
|
771
923
|
)
|
|
772
924
|
);
|
|
773
925
|
}
|
|
@@ -780,15 +932,15 @@ function parseRemoteComponentDocument(doc, name, url) {
|
|
|
780
932
|
nextData,
|
|
781
933
|
name
|
|
782
934
|
);
|
|
783
|
-
const rsc = doc.querySelector(`#${resolvedName}
|
|
935
|
+
const rsc = doc.querySelector(`#${resolvedName}${ID_SUFFIX_RSC}`);
|
|
784
936
|
const metadata = buildMetadata(
|
|
785
937
|
{
|
|
786
938
|
name: resolvedName,
|
|
787
|
-
bundle: component?.getAttribute(
|
|
788
|
-
route: component?.getAttribute(
|
|
789
|
-
runtime: component?.getAttribute(
|
|
939
|
+
bundle: component?.getAttribute(DATA_BUNDLE) || nextData?.props.__REMOTE_COMPONENT__?.bundle,
|
|
940
|
+
route: component?.getAttribute(DATA_ROUTE) ?? nextData?.page,
|
|
941
|
+
runtime: component?.getAttribute(DATA_RUNTIME) ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? RUNTIME_SCRIPT,
|
|
790
942
|
id: component?.getAttribute("id"),
|
|
791
|
-
type: component?.getAttribute(
|
|
943
|
+
type: component?.getAttribute(DATA_TYPE)
|
|
792
944
|
},
|
|
793
945
|
url
|
|
794
946
|
);
|
|
@@ -816,48 +968,6 @@ function parseRemoteComponentDocument(doc, name, url) {
|
|
|
816
968
|
};
|
|
817
969
|
}
|
|
818
970
|
|
|
819
|
-
// src/runtime/html/set-attributes-from-props.ts
|
|
820
|
-
var DOMAttributeNames = {
|
|
821
|
-
acceptCharset: "accept-charset",
|
|
822
|
-
className: "class",
|
|
823
|
-
htmlFor: "for",
|
|
824
|
-
httpEquiv: "http-equiv",
|
|
825
|
-
noModule: "noModule"
|
|
826
|
-
};
|
|
827
|
-
var ignoreProps = [
|
|
828
|
-
"onLoad",
|
|
829
|
-
"onReady",
|
|
830
|
-
"dangerouslySetInnerHTML",
|
|
831
|
-
"children",
|
|
832
|
-
"onError",
|
|
833
|
-
"strategy",
|
|
834
|
-
"stylesheets"
|
|
835
|
-
];
|
|
836
|
-
function isBooleanScriptAttribute(attr) {
|
|
837
|
-
return ["async", "defer", "noModule"].includes(attr);
|
|
838
|
-
}
|
|
839
|
-
function setAttributesFromProps(el, props) {
|
|
840
|
-
for (const [p, value] of Object.entries(props)) {
|
|
841
|
-
if (!Object.hasOwn(props, p))
|
|
842
|
-
continue;
|
|
843
|
-
if (ignoreProps.includes(p))
|
|
844
|
-
continue;
|
|
845
|
-
if (value === void 0) {
|
|
846
|
-
continue;
|
|
847
|
-
}
|
|
848
|
-
const attr = DOMAttributeNames[p] || p.toLowerCase();
|
|
849
|
-
if (el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr)) {
|
|
850
|
-
el[attr] = Boolean(value);
|
|
851
|
-
} else {
|
|
852
|
-
el.setAttribute(attr, String(value));
|
|
853
|
-
}
|
|
854
|
-
if (value === false || el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr) && (!value || value === "false")) {
|
|
855
|
-
el.setAttribute(attr, "");
|
|
856
|
-
el.removeAttribute(attr);
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
|
|
861
971
|
// src/runtime/loaders/component-loader.ts
|
|
862
972
|
var React = __toESM(require("react"), 1);
|
|
863
973
|
var JSXDevRuntime = __toESM(require("react/jsx-dev-runtime"), 1);
|
|
@@ -877,13 +987,15 @@ function applySharedModules(bundle, resolve) {
|
|
|
877
987
|
`Shared modules to resolve: ${Object.keys(resolve)}`
|
|
878
988
|
);
|
|
879
989
|
const self = globalThis;
|
|
880
|
-
|
|
990
|
+
const scope = getScope(bundle);
|
|
991
|
+
const webpackBundle = scope?.webpackRequire ?? self.__remote_webpack_require__?.[bundle];
|
|
992
|
+
if (webpackBundle) {
|
|
881
993
|
const modulePaths = Object.keys(
|
|
882
|
-
self.__remote_webpack_module_map__?.[bundle] ??
|
|
994
|
+
self.__remote_webpack_module_map__?.[bundle] ?? webpackBundle.m ?? {}
|
|
883
995
|
);
|
|
884
996
|
logDebug(
|
|
885
997
|
"SharedModules",
|
|
886
|
-
`Available module paths
|
|
998
|
+
`Available module paths for bundle "${bundle}": ${modulePaths}`
|
|
887
999
|
);
|
|
888
1000
|
for (const [key, value] of Object.entries(resolve)) {
|
|
889
1001
|
const exactIds = modulePaths.filter((p) => p === key);
|
|
@@ -895,7 +1007,6 @@ function applySharedModules(bundle, resolve) {
|
|
|
895
1007
|
);
|
|
896
1008
|
}
|
|
897
1009
|
for (const id of ids) {
|
|
898
|
-
const webpackBundle = self.__remote_webpack_require__[bundle];
|
|
899
1010
|
if (webpackBundle.m) {
|
|
900
1011
|
const resolvedId = self.__remote_webpack_module_map__?.[bundle]?.[id] ? `${self.__remote_webpack_module_map__[bundle][id]}` : id;
|
|
901
1012
|
if (resolvedId !== id) {
|
|
@@ -993,10 +1104,8 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
|
993
1104
|
];
|
|
994
1105
|
const { default: Component } = componentLoader();
|
|
995
1106
|
const { default: App } = appLoader();
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
}
|
|
999
|
-
if (!self.__remote_next_css__[bundle]) {
|
|
1107
|
+
const cssCache = getNamespace().cssCache;
|
|
1108
|
+
if (!cssCache[bundle]) {
|
|
1000
1109
|
const cssRE = /\.s?css$/;
|
|
1001
1110
|
Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).filter((id) => cssRE.test(id)).forEach((id) => {
|
|
1002
1111
|
self.__remote_webpack_require__?.[bundle]?.(id);
|
|
@@ -1014,15 +1123,15 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
|
1014
1123
|
node.remove();
|
|
1015
1124
|
node = nextCss.previousSibling;
|
|
1016
1125
|
}
|
|
1017
|
-
|
|
1126
|
+
cssCache[bundle] = elements;
|
|
1018
1127
|
}
|
|
1019
1128
|
if (styleContainer) {
|
|
1020
|
-
const elements =
|
|
1129
|
+
const elements = cssCache[bundle];
|
|
1021
1130
|
elements.forEach((el) => {
|
|
1022
1131
|
styleContainer.appendChild(el.cloneNode(true));
|
|
1023
1132
|
});
|
|
1024
1133
|
} else {
|
|
1025
|
-
const elements =
|
|
1134
|
+
const elements = cssCache[bundle];
|
|
1026
1135
|
elements.forEach((el) => {
|
|
1027
1136
|
document.head.appendChild(el);
|
|
1028
1137
|
});
|
|
@@ -1059,6 +1168,18 @@ function fixPayload(payload) {
|
|
|
1059
1168
|
}
|
|
1060
1169
|
}
|
|
1061
1170
|
}
|
|
1171
|
+
function buildRSCChunks(rscName, data) {
|
|
1172
|
+
const chunks = [];
|
|
1173
|
+
for (const chunk of data) {
|
|
1174
|
+
for (const line of chunk.split("\n")) {
|
|
1175
|
+
const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
|
|
1176
|
+
if (match?.groups?.rsc) {
|
|
1177
|
+
chunks.push(JSON.parse(`"${match.groups.rsc}"`));
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
return chunks;
|
|
1182
|
+
}
|
|
1062
1183
|
function createRSCStream(rscName, data) {
|
|
1063
1184
|
return new import_web_streams_polyfill.ReadableStream({
|
|
1064
1185
|
type: "bytes",
|
|
@@ -1066,16 +1187,11 @@ function createRSCStream(rscName, data) {
|
|
|
1066
1187
|
const encoder = new TextEncoder();
|
|
1067
1188
|
const self = globalThis;
|
|
1068
1189
|
if (data.length > 0) {
|
|
1069
|
-
data
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
self[rscName] = self[rscName] ?? [];
|
|
1075
|
-
self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
});
|
|
1190
|
+
const parsed = buildRSCChunks(rscName, data);
|
|
1191
|
+
if (parsed.length > 0) {
|
|
1192
|
+
self[rscName] = self[rscName] ?? [];
|
|
1193
|
+
self[rscName].push(...parsed);
|
|
1194
|
+
}
|
|
1079
1195
|
}
|
|
1080
1196
|
const allChunks = (self[rscName] ?? [`0:[null]
|
|
1081
1197
|
`]).join("");
|
|
@@ -1105,12 +1221,38 @@ function createRSCStream(rscName, data) {
|
|
|
1105
1221
|
});
|
|
1106
1222
|
}
|
|
1107
1223
|
|
|
1224
|
+
// src/runtime/rsc-imports.ts
|
|
1225
|
+
async function importRSCClientBrowser() {
|
|
1226
|
+
try {
|
|
1227
|
+
return await import("next/dist/compiled/react-server-dom-webpack/client.browser");
|
|
1228
|
+
} catch {
|
|
1229
|
+
const mod = await import("react-server-dom-webpack/client.browser");
|
|
1230
|
+
return mod.default ?? mod;
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1108
1234
|
// src/runtime/turbopack/patterns.ts
|
|
1235
|
+
var MODULE_ID_PATTERN = '"[^"]+"|[0-9]+';
|
|
1236
|
+
function stripQuotes(value) {
|
|
1237
|
+
if (value.startsWith('"') && value.endsWith('"')) {
|
|
1238
|
+
return value.slice(1, -1);
|
|
1239
|
+
}
|
|
1240
|
+
return value;
|
|
1241
|
+
}
|
|
1242
|
+
function extractGroup(re, input, group) {
|
|
1243
|
+
const raw = re.exec(input)?.groups?.[group];
|
|
1244
|
+
return raw ? stripQuotes(raw) : void 0;
|
|
1245
|
+
}
|
|
1109
1246
|
var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
|
|
1110
|
-
var REMOTE_SHARED_ASSIGNMENT_RE =
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
var
|
|
1247
|
+
var REMOTE_SHARED_ASSIGNMENT_RE = new RegExp(
|
|
1248
|
+
`\\.TURBOPACK_REMOTE_SHARED\\s*=\\s*await (?:__turbopack_context__|[a-z])\\.A\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\)`
|
|
1249
|
+
);
|
|
1250
|
+
var ASYNC_MODULE_LOADER_RE = new RegExp(
|
|
1251
|
+
`(?:__turbopack_context__|[a-z])\\.A\\((?<asyncSharedModuleId>${MODULE_ID_PATTERN})\\)`
|
|
1252
|
+
);
|
|
1253
|
+
var ASYNC_MODULE_CALLBACK_RE = new RegExp(
|
|
1254
|
+
`(?:parentImport|[a-z])\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\)`
|
|
1255
|
+
);
|
|
1114
1256
|
var TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
|
|
1115
1257
|
|
|
1116
1258
|
// src/runtime/turbopack/chunk-loader.ts
|
|
@@ -1120,6 +1262,7 @@ function loadChunkWithScope(scope, chunkId) {
|
|
|
1120
1262
|
`loadChunkWithScope: "${chunkId}" (scope: "${scope.scopedName}")`
|
|
1121
1263
|
);
|
|
1122
1264
|
const self = globalThis;
|
|
1265
|
+
const ns = getNamespace();
|
|
1123
1266
|
const { bundle, path, prefix } = parseRemoteId(chunkId);
|
|
1124
1267
|
const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : scope.runtime;
|
|
1125
1268
|
if (remoteRuntime === RUNTIME_WEBPACK) {
|
|
@@ -1130,35 +1273,31 @@ function loadChunkWithScope(scope, chunkId) {
|
|
|
1130
1273
|
if (url.endsWith(".css")) {
|
|
1131
1274
|
return;
|
|
1132
1275
|
}
|
|
1133
|
-
if (
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {
|
|
1137
|
-
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
1276
|
+
if (ns.chunkCache[url]) {
|
|
1277
|
+
logDebug("ChunkLoader", `Cache hit for "${chunkId}" (url="${url}")`);
|
|
1278
|
+
return ns.chunkCache[url];
|
|
1138
1279
|
}
|
|
1139
1280
|
const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;
|
|
1140
1281
|
if (resolvedUrl !== url) {
|
|
1141
1282
|
logDebug("ChunkLoader", `Proxied chunk URL: "${url}" \u2192 "${resolvedUrl}"`);
|
|
1142
1283
|
}
|
|
1143
|
-
|
|
1144
|
-
(
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
);
|
|
1161
|
-
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
1284
|
+
ns.chunkCache[url] = new Promise((resolve, reject) => {
|
|
1285
|
+
fetch(resolvedUrl).then((res) => res.text()).then((code) => {
|
|
1286
|
+
const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);
|
|
1287
|
+
if (hasTurbopack) {
|
|
1288
|
+
return handleTurbopackChunk(code, scope, url);
|
|
1289
|
+
}
|
|
1290
|
+
}).then(resolve).catch((error) => {
|
|
1291
|
+
const isProxied = isProxiedUrl(resolvedUrl);
|
|
1292
|
+
if (isProxied) {
|
|
1293
|
+
reject(failedProxiedAssetError("chunk", url, resolvedUrl));
|
|
1294
|
+
} else {
|
|
1295
|
+
warnCrossOriginFetchError("ChunkLoader", url);
|
|
1296
|
+
reject(error);
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
});
|
|
1300
|
+
return ns.chunkCache[url];
|
|
1162
1301
|
}
|
|
1163
1302
|
function createChunkDispatcher() {
|
|
1164
1303
|
return function __chunk_dispatcher__(chunkId, scriptBundle) {
|
|
@@ -1207,19 +1346,39 @@ async function handleTurbopackChunk(code, scope, url) {
|
|
|
1207
1346
|
`//# sourceMappingURL=${new URL(".", new URL(url, scope.url)).href}$1$2.js.map`
|
|
1208
1347
|
);
|
|
1209
1348
|
if (!self[`TURBOPACK_${globalKey}`]) {
|
|
1210
|
-
const
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1349
|
+
const wrapPush = (target) => {
|
|
1350
|
+
const originalPush = target.push;
|
|
1351
|
+
if (typeof originalPush !== "function")
|
|
1352
|
+
return target;
|
|
1353
|
+
target.push = (...items) => {
|
|
1354
|
+
for (const item of items) {
|
|
1355
|
+
if (Array.isArray(item)) {
|
|
1356
|
+
for (const entry of item) {
|
|
1357
|
+
scope.turbopackModules.push(entry);
|
|
1358
|
+
}
|
|
1359
|
+
} else {
|
|
1360
|
+
scope.turbopackModules.push(item);
|
|
1361
|
+
}
|
|
1217
1362
|
}
|
|
1218
|
-
return
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1363
|
+
return originalPush.apply(target, items);
|
|
1364
|
+
};
|
|
1365
|
+
return target;
|
|
1221
1366
|
};
|
|
1222
|
-
|
|
1367
|
+
const globalProp = `TURBOPACK_${globalKey}`;
|
|
1368
|
+
let currentValue = wrapPush([]);
|
|
1369
|
+
Object.defineProperty(self, globalProp, {
|
|
1370
|
+
get() {
|
|
1371
|
+
return currentValue;
|
|
1372
|
+
},
|
|
1373
|
+
set(newValue) {
|
|
1374
|
+
if (newValue && typeof newValue === "object") {
|
|
1375
|
+
wrapPush(newValue);
|
|
1376
|
+
}
|
|
1377
|
+
currentValue = newValue;
|
|
1378
|
+
},
|
|
1379
|
+
configurable: true,
|
|
1380
|
+
enumerable: true
|
|
1381
|
+
});
|
|
1223
1382
|
}
|
|
1224
1383
|
await new Promise((scriptResolve, scriptReject) => {
|
|
1225
1384
|
const blob = new Blob([transformedCode], {
|
|
@@ -1271,13 +1430,13 @@ async function handleTurbopackChunk(code, scope, url) {
|
|
|
1271
1430
|
// src/runtime/turbopack/shared-modules.ts
|
|
1272
1431
|
var DEDUPLICATION_WARNING = "This module will not be deduplicated \u2014 the remote may load its own copy, which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).";
|
|
1273
1432
|
function getTurbopackModules(scope) {
|
|
1433
|
+
if (scope.turbopackModules.length > 0) {
|
|
1434
|
+
return scope.turbopackModules;
|
|
1435
|
+
}
|
|
1274
1436
|
const self = globalThis;
|
|
1275
1437
|
const raw = self[`TURBOPACK_${scope.globalKey}`];
|
|
1276
1438
|
if (!raw)
|
|
1277
1439
|
return void 0;
|
|
1278
|
-
if (typeof raw === "object" && "__chunks__" in raw) {
|
|
1279
|
-
return raw.__chunks__.flat();
|
|
1280
|
-
}
|
|
1281
1440
|
if (Array.isArray(raw)) {
|
|
1282
1441
|
return raw.flat();
|
|
1283
1442
|
}
|
|
@@ -1301,7 +1460,11 @@ async function initializeSharedModules(scope, hostShared = {}, remoteShared = {}
|
|
|
1301
1460
|
if (sharedModuleInitializerIndex > 0) {
|
|
1302
1461
|
const sharedModuleInitializerCode = allModules[sharedModuleInitializerIndex].toString();
|
|
1303
1462
|
const sharedModuleInitializerId = allModules[sharedModuleInitializerIndex - 1];
|
|
1304
|
-
const
|
|
1463
|
+
const sharedModuleId = extractGroup(
|
|
1464
|
+
REMOTE_SHARED_ASSIGNMENT_RE,
|
|
1465
|
+
sharedModuleInitializerCode,
|
|
1466
|
+
"sharedModuleId"
|
|
1467
|
+
);
|
|
1305
1468
|
if (sharedModuleId) {
|
|
1306
1469
|
const { default: sharedModuleInitializerInstance } = handleTurbopackModule(
|
|
1307
1470
|
scope,
|
|
@@ -1359,20 +1522,22 @@ async function initializeSharedModules(scope, hostShared = {}, remoteShared = {}
|
|
|
1359
1522
|
}
|
|
1360
1523
|
function extractSharedModuleIds(shared2, scope) {
|
|
1361
1524
|
return Object.entries(shared2).filter(([, value]) => typeof value === "function").reduce((acc, [key, value]) => {
|
|
1362
|
-
const
|
|
1525
|
+
const asyncSharedModuleId = extractGroup(
|
|
1526
|
+
ASYNC_MODULE_LOADER_RE,
|
|
1527
|
+
value.toString(),
|
|
1528
|
+
"asyncSharedModuleId"
|
|
1529
|
+
);
|
|
1363
1530
|
if (asyncSharedModuleId) {
|
|
1364
|
-
const
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
const asyncSharedModuleIdIndex = turbopackModules.indexOf(
|
|
1368
|
-
asyncSharedModuleIdNumber
|
|
1531
|
+
const asyncSharedModule = findModuleInit(
|
|
1532
|
+
getTurbopackModules(scope),
|
|
1533
|
+
asyncSharedModuleId
|
|
1369
1534
|
);
|
|
1370
|
-
if (asyncSharedModuleIdIndex !== -1 && typeof turbopackModules[asyncSharedModuleIdIndex + 1] === "function") {
|
|
1371
|
-
asyncSharedModule = turbopackModules[asyncSharedModuleIdIndex + 1];
|
|
1372
|
-
}
|
|
1373
1535
|
if (asyncSharedModule) {
|
|
1374
|
-
const
|
|
1375
|
-
|
|
1536
|
+
const sharedModuleId = extractGroup(
|
|
1537
|
+
ASYNC_MODULE_CALLBACK_RE,
|
|
1538
|
+
asyncSharedModule.toString(),
|
|
1539
|
+
"sharedModuleId"
|
|
1540
|
+
);
|
|
1376
1541
|
acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(
|
|
1377
1542
|
"__remote_shared_module_",
|
|
1378
1543
|
""
|
|
@@ -1463,9 +1628,17 @@ function findModuleInit(modules, moduleId) {
|
|
|
1463
1628
|
if (idx >= 0) {
|
|
1464
1629
|
return flat.slice(idx + 1).find((e) => typeof e === "function");
|
|
1465
1630
|
}
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1631
|
+
for (const entry of flat) {
|
|
1632
|
+
if (!entry || typeof entry !== "object")
|
|
1633
|
+
continue;
|
|
1634
|
+
const obj = entry;
|
|
1635
|
+
if (moduleId in obj)
|
|
1636
|
+
return obj[moduleId];
|
|
1637
|
+
const prefixKey = Object.keys(obj).find((k) => k.startsWith(moduleId));
|
|
1638
|
+
if (prefixKey)
|
|
1639
|
+
return obj[prefixKey];
|
|
1640
|
+
}
|
|
1641
|
+
return void 0;
|
|
1469
1642
|
}
|
|
1470
1643
|
function createTurbopackContext(scope, exports, moduleExports, modules, moduleInit, id) {
|
|
1471
1644
|
const scopedRequire = (moduleId) => requireModule(scope, moduleId, formatRemoteId(scope, String(moduleId)));
|
|
@@ -1544,7 +1717,10 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
|
|
|
1544
1717
|
}
|
|
1545
1718
|
if (typeof mod !== "object" || mod === null) {
|
|
1546
1719
|
mod = { default: mod };
|
|
1547
|
-
} else if (!("default" in mod) &&
|
|
1720
|
+
} else if (!("default" in mod) && // ES module namespace objects have a null prototype, so calling
|
|
1721
|
+
// mod.toString() directly throws. Use Object.prototype.toString
|
|
1722
|
+
// to safely detect them.
|
|
1723
|
+
Object.prototype.toString.call(mod) !== "[object Module]") {
|
|
1548
1724
|
try {
|
|
1549
1725
|
mod.default = mod;
|
|
1550
1726
|
} catch {
|
|
@@ -1608,21 +1784,38 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
|
|
|
1608
1784
|
};
|
|
1609
1785
|
}
|
|
1610
1786
|
|
|
1611
|
-
// src/runtime/turbopack/
|
|
1612
|
-
async function
|
|
1787
|
+
// src/runtime/turbopack/remote-scope-setup.ts
|
|
1788
|
+
async function setupRemoteScope(runtime, scripts = [], url = new URL(location.href), bundle, resolveClientUrl) {
|
|
1613
1789
|
const self = globalThis;
|
|
1790
|
+
const ns = getNamespace();
|
|
1614
1791
|
const bundleName = bundle ?? "default";
|
|
1792
|
+
const existingScope = getScope(bundleName);
|
|
1793
|
+
if (existingScope && existingScope.url.origin === url.origin) {
|
|
1794
|
+
logDebug(
|
|
1795
|
+
"WebpackRuntime",
|
|
1796
|
+
`Reusing scope "${existingScope.scopedName}" (turbopackModules=${existingScope.turbopackModules.length})`
|
|
1797
|
+
);
|
|
1798
|
+
existingScope.resolveClientUrl = resolveClientUrl;
|
|
1799
|
+
if (runtime === RUNTIME_TURBOPACK) {
|
|
1800
|
+
await Promise.allSettled(
|
|
1801
|
+
scripts.map(
|
|
1802
|
+
(script) => script.src ? loadChunkWithScope(existingScope, script.src) : Promise.resolve(void 0)
|
|
1803
|
+
)
|
|
1804
|
+
);
|
|
1805
|
+
}
|
|
1806
|
+
return existingScope;
|
|
1807
|
+
}
|
|
1615
1808
|
const scope = createScope(bundleName, url, runtime, resolveClientUrl);
|
|
1616
1809
|
registerScope(scope);
|
|
1617
|
-
if (
|
|
1618
|
-
|
|
1810
|
+
if (runtime === RUNTIME_WEBPACK && self.__remote_webpack_require__?.[bundleName]) {
|
|
1811
|
+
scope.webpackRequire = self.__remote_webpack_require__[bundleName];
|
|
1619
1812
|
}
|
|
1620
|
-
|
|
1813
|
+
ns.bundleUrls[bundleName] = url;
|
|
1621
1814
|
if (scope.scopedName !== bundleName) {
|
|
1622
|
-
|
|
1815
|
+
ns.bundleUrls[scope.scopedName] = url;
|
|
1623
1816
|
}
|
|
1624
1817
|
self.__webpack_get_script_filename__ = () => null;
|
|
1625
|
-
const willCreateDispatchers = typeof self.__webpack_require__ !== "function" ||
|
|
1818
|
+
const willCreateDispatchers = typeof self.__webpack_require__ !== "function" || ns.dispatcherRuntime !== "turbopack";
|
|
1626
1819
|
if (willCreateDispatchers) {
|
|
1627
1820
|
if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
|
|
1628
1821
|
self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
|
|
@@ -1630,6 +1823,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
1630
1823
|
}
|
|
1631
1824
|
self.__webpack_chunk_load__ = createChunkDispatcher();
|
|
1632
1825
|
self.__webpack_require__ = createModuleDispatcher(runtime);
|
|
1826
|
+
ns.dispatcherRuntime = runtime;
|
|
1633
1827
|
self.__webpack_require_type__ = runtime;
|
|
1634
1828
|
if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
|
|
1635
1829
|
self.__remote_webpack_require__[bundleName] = self.__webpack_require__;
|
|
@@ -1657,15 +1851,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
1657
1851
|
}
|
|
1658
1852
|
}
|
|
1659
1853
|
}
|
|
1660
|
-
|
|
1661
|
-
react: async () => (await import("react")).default,
|
|
1662
|
-
"react-dom": async () => (await import("react-dom")).default,
|
|
1663
|
-
"react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
|
|
1664
|
-
"react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
|
|
1665
|
-
"react-dom/client": async () => (await import("react-dom/client")).default,
|
|
1666
|
-
...shared2
|
|
1667
|
-
};
|
|
1668
|
-
await initializeSharedModules(scope, coreShared, remoteShared);
|
|
1854
|
+
return scope;
|
|
1669
1855
|
}
|
|
1670
1856
|
function createModuleDispatcher(runtime) {
|
|
1671
1857
|
return (id) => {
|
|
@@ -1682,6 +1868,9 @@ function createModuleDispatcher(runtime) {
|
|
|
1682
1868
|
);
|
|
1683
1869
|
try {
|
|
1684
1870
|
if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
|
|
1871
|
+
const scope2 = getScope(bundle);
|
|
1872
|
+
if (scope2?.webpackRequire)
|
|
1873
|
+
return scope2.webpackRequire(moduleId);
|
|
1685
1874
|
return self.__remote_webpack_require__?.[bundle]?.(moduleId);
|
|
1686
1875
|
}
|
|
1687
1876
|
const scope = getScope(bundleName);
|
|
@@ -1799,44 +1988,33 @@ async function loadRemoteComponent({
|
|
|
1799
1988
|
"ComponentLoader",
|
|
1800
1989
|
`Remote shared modules requested: ${JSON.stringify(remoteShared)}`
|
|
1801
1990
|
);
|
|
1802
|
-
await
|
|
1991
|
+
const scope = await setupRemoteScope(
|
|
1803
1992
|
runtime,
|
|
1804
1993
|
scripts,
|
|
1805
1994
|
url,
|
|
1806
1995
|
bundle,
|
|
1807
|
-
hostShared,
|
|
1808
|
-
remoteShared,
|
|
1809
1996
|
resolveClientUrl
|
|
1810
1997
|
);
|
|
1998
|
+
if (runtime === "turbopack") {
|
|
1999
|
+
await initializeSharedModules(
|
|
2000
|
+
scope,
|
|
2001
|
+
buildCoreShared(hostShared),
|
|
2002
|
+
remoteShared
|
|
2003
|
+
);
|
|
2004
|
+
}
|
|
1811
2005
|
if (bundle) {
|
|
1812
|
-
const resolve =
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
"ComponentLoader",
|
|
1825
|
-
`Remote requests "${value}" but host doesn't provide it`
|
|
1826
|
-
);
|
|
1827
|
-
}
|
|
1828
|
-
return acc;
|
|
1829
|
-
},
|
|
1830
|
-
{}
|
|
1831
|
-
)
|
|
1832
|
-
};
|
|
1833
|
-
await Promise.all(
|
|
1834
|
-
Object.entries(resolve).map(async ([key, value]) => {
|
|
1835
|
-
if (typeof value === "function") {
|
|
1836
|
-
resolve[key] = await value(bundle);
|
|
1837
|
-
}
|
|
1838
|
-
return Promise.resolve(value);
|
|
1839
|
-
})
|
|
2006
|
+
const resolve = await buildWebpackResolve(
|
|
2007
|
+
hostShared,
|
|
2008
|
+
remoteShared,
|
|
2009
|
+
bundle,
|
|
2010
|
+
{
|
|
2011
|
+
"/react/index.js": React,
|
|
2012
|
+
"/react/jsx-dev-runtime.js": JSXDevRuntime,
|
|
2013
|
+
"/react/jsx-runtime.js": JSXRuntime,
|
|
2014
|
+
"/react-dom/index.js": ReactDOM,
|
|
2015
|
+
"/react-dom/client.js": ReactDOMClient
|
|
2016
|
+
},
|
|
2017
|
+
"ComponentLoader"
|
|
1840
2018
|
);
|
|
1841
2019
|
applySharedModules(bundle, resolve);
|
|
1842
2020
|
} else {
|
|
@@ -1864,19 +2042,8 @@ async function loadRemoteComponent({
|
|
|
1864
2042
|
};
|
|
1865
2043
|
}
|
|
1866
2044
|
}
|
|
1867
|
-
async function importCreateFromReadableStream() {
|
|
1868
|
-
try {
|
|
1869
|
-
const { createFromReadableStream } = await import("next/dist/compiled/react-server-dom-webpack/client.browser");
|
|
1870
|
-
return createFromReadableStream;
|
|
1871
|
-
} catch {
|
|
1872
|
-
const {
|
|
1873
|
-
default: { createFromReadableStream }
|
|
1874
|
-
} = await import("react-server-dom-webpack/client.browser");
|
|
1875
|
-
return createFromReadableStream;
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
2045
|
async function loadRSCComponent(rscName, data) {
|
|
1879
|
-
const createFromReadableStream = await
|
|
2046
|
+
const { createFromReadableStream } = await importRSCClientBrowser();
|
|
1880
2047
|
if (typeof createFromReadableStream !== "function") {
|
|
1881
2048
|
throw new RemoteComponentsError(
|
|
1882
2049
|
'Failed to import "react-server-dom-webpack". Is Next.js installed correctly?'
|
|
@@ -1940,10 +2107,9 @@ async function importViaCallback(absoluteSrc, resolveClientUrl) {
|
|
|
1940
2107
|
URL.revokeObjectURL(moduleBlobUrl);
|
|
1941
2108
|
URL.revokeObjectURL(wrapperBlobUrl);
|
|
1942
2109
|
}
|
|
1943
|
-
const registry =
|
|
1944
|
-
const mod = registry
|
|
1945
|
-
|
|
1946
|
-
delete registry[absoluteSrc];
|
|
2110
|
+
const registry = getNamespace().moduleRegistry;
|
|
2111
|
+
const mod = registry[absoluteSrc] ?? {};
|
|
2112
|
+
delete registry[absoluteSrc];
|
|
1947
2113
|
return mod;
|
|
1948
2114
|
}
|
|
1949
2115
|
async function importDirectly(absoluteSrc) {
|
|
@@ -1973,12 +2139,12 @@ function resolveScriptSrc(script, url) {
|
|
|
1973
2139
|
return rawSrc;
|
|
1974
2140
|
}
|
|
1975
2141
|
async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
|
|
1976
|
-
const
|
|
1977
|
-
if (
|
|
1978
|
-
|
|
2142
|
+
const ns = getNamespace();
|
|
2143
|
+
if (ns.mountFns[url.href]) {
|
|
2144
|
+
ns.mountFns[url.href] = /* @__PURE__ */ new Set();
|
|
1979
2145
|
}
|
|
1980
|
-
if (
|
|
1981
|
-
|
|
2146
|
+
if (ns.unmountFns[url.href]) {
|
|
2147
|
+
ns.unmountFns[url.href] = /* @__PURE__ */ new Set();
|
|
1982
2148
|
}
|
|
1983
2149
|
const mountUnmountSets = await Promise.all(
|
|
1984
2150
|
scripts.map(async (script) => {
|
|
@@ -1990,25 +2156,19 @@ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
|
|
|
1990
2156
|
URL.revokeObjectURL(src);
|
|
1991
2157
|
}
|
|
1992
2158
|
if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
|
|
1993
|
-
if (!
|
|
1994
|
-
|
|
2159
|
+
if (!ns.mountFns[url.href]) {
|
|
2160
|
+
ns.mountFns[url.href] = /* @__PURE__ */ new Set();
|
|
1995
2161
|
}
|
|
1996
|
-
|
|
1997
|
-
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
1998
|
-
}
|
|
1999
|
-
self.__remote_script_entrypoint_mount__[url.href]?.add(
|
|
2162
|
+
ns.mountFns[url.href]?.add(
|
|
2000
2163
|
mod.mount || mod.default?.mount || (() => {
|
|
2001
2164
|
})
|
|
2002
2165
|
);
|
|
2003
2166
|
}
|
|
2004
2167
|
if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
|
|
2005
|
-
if (!
|
|
2006
|
-
|
|
2007
|
-
}
|
|
2008
|
-
if (!self.__remote_script_entrypoint_unmount__[url.href]) {
|
|
2009
|
-
self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
|
|
2168
|
+
if (!ns.unmountFns[url.href]) {
|
|
2169
|
+
ns.unmountFns[url.href] = /* @__PURE__ */ new Set();
|
|
2010
2170
|
}
|
|
2011
|
-
|
|
2171
|
+
ns.unmountFns[url.href]?.add(
|
|
2012
2172
|
mod.unmount || mod.default?.unmount || (() => {
|
|
2013
2173
|
})
|
|
2014
2174
|
);
|
|
@@ -2047,45 +2207,225 @@ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
|
|
|
2047
2207
|
);
|
|
2048
2208
|
}
|
|
2049
2209
|
|
|
2210
|
+
// src/host/shared/pipeline.ts
|
|
2211
|
+
function preparePipeline(input) {
|
|
2212
|
+
const parser = new DOMParser();
|
|
2213
|
+
const doc = parser.parseFromString(input.html, "text/html");
|
|
2214
|
+
const parsed = parseRemoteComponentDocument(doc, input.name, input.url);
|
|
2215
|
+
const remoteShared = input.remoteShared ?? parsed.remoteShared;
|
|
2216
|
+
if ("__remote_components_missing_shared__" in remoteShared) {
|
|
2217
|
+
throw new RemoteComponentsError(
|
|
2218
|
+
remoteShared.__remote_components_missing_shared__
|
|
2219
|
+
);
|
|
2220
|
+
}
|
|
2221
|
+
applyOriginToNodes(doc, input.url, input.resolveClientUrl);
|
|
2222
|
+
const scriptDescriptors = buildScriptDescriptors(parsed.scripts, input.url);
|
|
2223
|
+
return { doc, parsed, scriptDescriptors };
|
|
2224
|
+
}
|
|
2225
|
+
async function loadPrepared(input) {
|
|
2226
|
+
const { prepared, url, signal, resolveClientUrl, container, rscName } = input;
|
|
2227
|
+
const { doc, parsed, scriptDescriptors } = prepared;
|
|
2228
|
+
if (signal.aborted) {
|
|
2229
|
+
return { status: "aborted" };
|
|
2230
|
+
}
|
|
2231
|
+
const userShared = await input.shared;
|
|
2232
|
+
if (signal.aborted) {
|
|
2233
|
+
return { status: "aborted" };
|
|
2234
|
+
}
|
|
2235
|
+
if (parsed.isRemoteComponent) {
|
|
2236
|
+
return loadStaticPath({
|
|
2237
|
+
parsed,
|
|
2238
|
+
doc,
|
|
2239
|
+
url,
|
|
2240
|
+
resolveClientUrl
|
|
2241
|
+
});
|
|
2242
|
+
}
|
|
2243
|
+
return loadDynamicPath({
|
|
2244
|
+
parsed,
|
|
2245
|
+
doc,
|
|
2246
|
+
url,
|
|
2247
|
+
scriptDescriptors,
|
|
2248
|
+
shared: userShared,
|
|
2249
|
+
resolveClientUrl,
|
|
2250
|
+
container,
|
|
2251
|
+
rscName
|
|
2252
|
+
});
|
|
2253
|
+
}
|
|
2254
|
+
function buildScriptDescriptors(scripts, url) {
|
|
2255
|
+
return scripts.map((script) => {
|
|
2256
|
+
const scriptSrc = script.getAttribute("data-src") || script.getAttribute("src") || script.src;
|
|
2257
|
+
const { prefix, id: path } = REMOTE_COMPONENT_REGEX.exec(scriptSrc)?.groups ?? {
|
|
2258
|
+
prefix: void 0,
|
|
2259
|
+
id: scriptSrc
|
|
2260
|
+
};
|
|
2261
|
+
return {
|
|
2262
|
+
src: new URL(collapseDoubleSlashes(`${prefix ?? ""}${path}`), url).href
|
|
2263
|
+
};
|
|
2264
|
+
});
|
|
2265
|
+
}
|
|
2266
|
+
async function loadStaticPath(input) {
|
|
2267
|
+
const { parsed, doc, url, resolveClientUrl } = input;
|
|
2268
|
+
const scripts = Array.from(
|
|
2269
|
+
parsed.component.querySelectorAll("script")
|
|
2270
|
+
);
|
|
2271
|
+
const { mount, unmount } = await loadStaticRemoteComponent(
|
|
2272
|
+
scripts,
|
|
2273
|
+
url,
|
|
2274
|
+
resolveClientUrl
|
|
2275
|
+
);
|
|
2276
|
+
return {
|
|
2277
|
+
status: "static",
|
|
2278
|
+
mount,
|
|
2279
|
+
unmount,
|
|
2280
|
+
metadata: parsed.metadata,
|
|
2281
|
+
parsed,
|
|
2282
|
+
doc
|
|
2283
|
+
};
|
|
2284
|
+
}
|
|
2285
|
+
async function loadDynamicPath(input) {
|
|
2286
|
+
const {
|
|
2287
|
+
parsed,
|
|
2288
|
+
doc,
|
|
2289
|
+
url,
|
|
2290
|
+
scriptDescriptors,
|
|
2291
|
+
shared: shared2,
|
|
2292
|
+
resolveClientUrl,
|
|
2293
|
+
container
|
|
2294
|
+
} = input;
|
|
2295
|
+
const rscName = input.rscName ?? (parsed.rsc ? `__remote_component_rsc_${escapeString(url.href)}_${escapeString(parsed.name)}` : void 0);
|
|
2296
|
+
const rscData = parsed.rsc ? (parsed.rsc.textContent || "").split("\n").filter(Boolean) : [];
|
|
2297
|
+
const result = await loadRemoteComponent({
|
|
2298
|
+
url,
|
|
2299
|
+
name: parsed.name,
|
|
2300
|
+
rscName,
|
|
2301
|
+
bundle: parsed.metadata.bundle,
|
|
2302
|
+
route: parsed.metadata.route,
|
|
2303
|
+
runtime: parsed.metadata.runtime,
|
|
2304
|
+
data: rscData,
|
|
2305
|
+
nextData: parsed.nextData,
|
|
2306
|
+
scripts: scriptDescriptors,
|
|
2307
|
+
shared: buildHostShared(shared2, resolveClientUrl),
|
|
2308
|
+
remoteShared: parsed.remoteShared,
|
|
2309
|
+
container,
|
|
2310
|
+
resolveClientUrl
|
|
2311
|
+
});
|
|
2312
|
+
if (result.error) {
|
|
2313
|
+
return { status: "error", error: result.error };
|
|
2314
|
+
}
|
|
2315
|
+
return {
|
|
2316
|
+
status: "loaded",
|
|
2317
|
+
component: result.component,
|
|
2318
|
+
metadata: parsed.metadata,
|
|
2319
|
+
parsed,
|
|
2320
|
+
doc
|
|
2321
|
+
};
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
// src/host/shared/state.ts
|
|
2325
|
+
function createHostState() {
|
|
2326
|
+
return {
|
|
2327
|
+
stage: "idle",
|
|
2328
|
+
prevSrc: void 0,
|
|
2329
|
+
prevUrl: void 0,
|
|
2330
|
+
prevName: void 0,
|
|
2331
|
+
prevIsRemoteComponent: false,
|
|
2332
|
+
abortController: void 0
|
|
2333
|
+
};
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
// src/host/utils/resolve-name-from-src.ts
|
|
2337
|
+
function resolveNameFromSrc(src, defaultName) {
|
|
2338
|
+
if (!src) {
|
|
2339
|
+
return defaultName;
|
|
2340
|
+
}
|
|
2341
|
+
const hash = typeof src === "string" ? src : src.hash;
|
|
2342
|
+
const hashIndex = hash.indexOf("#");
|
|
2343
|
+
if (hashIndex < 0) {
|
|
2344
|
+
return defaultName;
|
|
2345
|
+
}
|
|
2346
|
+
const name = hash.slice(hashIndex + 1);
|
|
2347
|
+
return name || defaultName;
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
// src/runtime/html/set-attributes-from-props.ts
|
|
2351
|
+
var DOMAttributeNames = {
|
|
2352
|
+
acceptCharset: "accept-charset",
|
|
2353
|
+
className: "class",
|
|
2354
|
+
htmlFor: "for",
|
|
2355
|
+
httpEquiv: "http-equiv",
|
|
2356
|
+
noModule: "noModule"
|
|
2357
|
+
};
|
|
2358
|
+
var ignoreProps = [
|
|
2359
|
+
"onLoad",
|
|
2360
|
+
"onReady",
|
|
2361
|
+
"dangerouslySetInnerHTML",
|
|
2362
|
+
"children",
|
|
2363
|
+
"onError",
|
|
2364
|
+
"strategy",
|
|
2365
|
+
"stylesheets"
|
|
2366
|
+
];
|
|
2367
|
+
function isBooleanScriptAttribute(attr) {
|
|
2368
|
+
return ["async", "defer", "noModule"].includes(attr);
|
|
2369
|
+
}
|
|
2370
|
+
function setAttributesFromProps(el, props) {
|
|
2371
|
+
for (const [p, value] of Object.entries(props)) {
|
|
2372
|
+
if (!Object.hasOwn(props, p))
|
|
2373
|
+
continue;
|
|
2374
|
+
if (ignoreProps.includes(p))
|
|
2375
|
+
continue;
|
|
2376
|
+
if (value === void 0) {
|
|
2377
|
+
continue;
|
|
2378
|
+
}
|
|
2379
|
+
const attr = DOMAttributeNames[p] || p.toLowerCase();
|
|
2380
|
+
if (el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr)) {
|
|
2381
|
+
el[attr] = Boolean(value);
|
|
2382
|
+
} else {
|
|
2383
|
+
el.setAttribute(attr, String(value));
|
|
2384
|
+
}
|
|
2385
|
+
if (value === false || el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr) && (!value || value === "false")) {
|
|
2386
|
+
el.setAttribute(attr, "");
|
|
2387
|
+
el.removeAttribute(attr);
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2050
2392
|
// src/host/react/hooks/use-resolve-client-url.ts
|
|
2051
|
-
var
|
|
2393
|
+
var import_react2 = require("react");
|
|
2052
2394
|
var import_context = require("#internal/host/react/context");
|
|
2053
2395
|
function useResolveClientUrl(prop, urlHref) {
|
|
2054
2396
|
const { resolveClientUrl: contextValue } = (0, import_context.useRemoteComponentsContext)();
|
|
2055
2397
|
const raw = prop ?? contextValue;
|
|
2056
|
-
return (0,
|
|
2398
|
+
return (0, import_react2.useMemo)(() => bindResolveClientUrl(raw, urlHref), [raw, urlHref]);
|
|
2057
2399
|
}
|
|
2058
2400
|
|
|
2059
2401
|
// src/host/react/hooks/use-shadow-root.ts
|
|
2060
|
-
var
|
|
2402
|
+
var import_react3 = require("react");
|
|
2061
2403
|
function useShadowRoot({
|
|
2062
2404
|
isolate,
|
|
2063
2405
|
mode,
|
|
2064
2406
|
keySuffix
|
|
2065
2407
|
}) {
|
|
2066
|
-
const shadowRootContainerRef = (0,
|
|
2067
|
-
const [shadowRoot, setShadowRoot] = (0,
|
|
2068
|
-
const
|
|
2069
|
-
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
2408
|
+
const shadowRootContainerRef = (0, import_react3.useRef)(null);
|
|
2409
|
+
const [shadowRoot, setShadowRoot] = (0, import_react3.useState)(() => {
|
|
2410
|
+
const shadowRoots = getNamespace().shadowRoots;
|
|
2070
2411
|
const ssrShadowRoot = typeof document !== "undefined" ? document.querySelector(
|
|
2071
2412
|
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
2072
|
-
)?.shadowRoot ??
|
|
2073
|
-
|
|
2413
|
+
)?.shadowRoot ?? shadowRoots[keySuffix] ?? null : null;
|
|
2414
|
+
shadowRoots[keySuffix] = null;
|
|
2074
2415
|
return ssrShadowRoot;
|
|
2075
2416
|
});
|
|
2076
|
-
(0,
|
|
2417
|
+
(0, import_react3.useLayoutEffect)(() => {
|
|
2418
|
+
const shadowRoots = getNamespace().shadowRoots;
|
|
2077
2419
|
if (isolate !== false && typeof document !== "undefined" && (!shadowRoot || !shadowRoot.isConnected)) {
|
|
2078
|
-
const self = globalThis;
|
|
2079
|
-
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
2080
2420
|
let shadowRootElement = null;
|
|
2081
2421
|
const element = document.querySelector(
|
|
2082
2422
|
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
2083
2423
|
);
|
|
2084
|
-
shadowRootElement =
|
|
2424
|
+
shadowRootElement = shadowRoots[keySuffix] ?? element?.shadowRoot ?? null;
|
|
2085
2425
|
if (!shadowRootElement && element) {
|
|
2086
2426
|
try {
|
|
2087
2427
|
shadowRootElement = element.attachShadow({ mode });
|
|
2088
|
-
|
|
2428
|
+
shadowRoots[keySuffix] = shadowRootElement;
|
|
2089
2429
|
} catch {
|
|
2090
2430
|
}
|
|
2091
2431
|
}
|
|
@@ -2096,9 +2436,7 @@ function useShadowRoot({
|
|
|
2096
2436
|
setShadowRoot(shadowRootElement);
|
|
2097
2437
|
}
|
|
2098
2438
|
} else if (isolate === false && shadowRoot) {
|
|
2099
|
-
|
|
2100
|
-
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
2101
|
-
self[shadowRootKey] = null;
|
|
2439
|
+
shadowRoots[keySuffix] = null;
|
|
2102
2440
|
setShadowRoot(null);
|
|
2103
2441
|
}
|
|
2104
2442
|
}, [isolate, shadowRoot, mode, keySuffix]);
|
|
@@ -2132,7 +2470,7 @@ var import_jsx_runtime2 = (
|
|
|
2132
2470
|
// TODO: remove wrapper div by converting HTML to RSC or React tree
|
|
2133
2471
|
require("react/jsx-runtime")
|
|
2134
2472
|
);
|
|
2135
|
-
var
|
|
2473
|
+
var import_react5 = require("react");
|
|
2136
2474
|
function ConsumeRemoteComponent({
|
|
2137
2475
|
src,
|
|
2138
2476
|
isolate,
|
|
@@ -2150,36 +2488,40 @@ function ConsumeRemoteComponent({
|
|
|
2150
2488
|
onResponse,
|
|
2151
2489
|
resolveClientUrl: resolveClientUrlProp
|
|
2152
2490
|
}) {
|
|
2153
|
-
const instanceId = (0,
|
|
2491
|
+
const instanceId = (0, import_react4.useId)();
|
|
2154
2492
|
const { credentials: contextCredentials, shared: contextShared } = (0, import_context2.useRemoteComponentsContext)();
|
|
2155
2493
|
const credentials = credentialsProp ?? contextCredentials ?? "same-origin";
|
|
2156
2494
|
const shared2 = sharedProp ?? contextShared ?? {};
|
|
2157
|
-
const
|
|
2495
|
+
const emitter = (0, import_react4.useMemo)(
|
|
2496
|
+
() => makeReactEmitter({ onBeforeLoad, onLoad, onError, onChange }),
|
|
2497
|
+
[onBeforeLoad, onLoad, onError, onChange]
|
|
2498
|
+
);
|
|
2499
|
+
const name = (0, import_react4.useMemo)(
|
|
2158
2500
|
() => resolveNameFromSrc(src, nameProp),
|
|
2159
2501
|
[src, nameProp]
|
|
2160
2502
|
);
|
|
2161
|
-
const [data, setData] = (0,
|
|
2503
|
+
const [data, setData] = (0, import_react4.useState)(
|
|
2162
2504
|
null
|
|
2163
2505
|
);
|
|
2164
|
-
const url = (0,
|
|
2506
|
+
const url = (0, import_react4.useMemo)(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);
|
|
2165
2507
|
const resolveClientUrl = useResolveClientUrl(resolveClientUrlProp, url.href);
|
|
2166
2508
|
const id = url.origin === (typeof location !== "undefined" ? location.origin : DUMMY_FALLBACK) ? url.pathname : url.href;
|
|
2167
2509
|
const keySuffix = `${escapeString(id)}_${escapeString(
|
|
2168
2510
|
data?.name ?? name
|
|
2169
2511
|
)}_${escapeString(instanceId)}`;
|
|
2170
|
-
const [remoteComponent, setRemoteComponent] = (0,
|
|
2512
|
+
const [remoteComponent, setRemoteComponent] = (0, import_react4.useState)(null);
|
|
2171
2513
|
const { shadowRoot, shadowRootContainerRef } = useShadowRoot({
|
|
2172
2514
|
isolate,
|
|
2173
2515
|
mode,
|
|
2174
2516
|
keySuffix
|
|
2175
2517
|
});
|
|
2176
|
-
const htmlRef = (0,
|
|
2518
|
+
const htmlRef = (0, import_react4.useRef)(
|
|
2177
2519
|
typeof document !== "undefined" ? document.querySelector(
|
|
2178
2520
|
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
2179
2521
|
)?.shadowRoot?.innerHTML ?? document.getElementById(`__REMOTE_COMPONENT${name}`)?.innerHTML ?? document.querySelector(`div[data-bundle][data-route][id^="${name}"]`)?.innerHTML ?? document.querySelector("div[data-bundle][data-route]")?.innerHTML : null
|
|
2180
2522
|
);
|
|
2181
|
-
const endTemplateRef = (0,
|
|
2182
|
-
const childrenRef = (0,
|
|
2523
|
+
const endTemplateRef = (0, import_react4.useRef)(null);
|
|
2524
|
+
const childrenRef = (0, import_react4.useRef)(
|
|
2183
2525
|
typeof document !== "undefined" ? (() => {
|
|
2184
2526
|
let el = document.querySelector(`template[id="${name}_start"]`);
|
|
2185
2527
|
const elements = [];
|
|
@@ -2192,17 +2534,16 @@ function ConsumeRemoteComponent({
|
|
|
2192
2534
|
return elements;
|
|
2193
2535
|
})() : []
|
|
2194
2536
|
);
|
|
2195
|
-
const hostStateRef = (0,
|
|
2196
|
-
const componentHydrationHtml = (0,
|
|
2197
|
-
const prevRemoteComponentContainerRef = (0,
|
|
2198
|
-
const unmountRef = (0,
|
|
2199
|
-
(0,
|
|
2200
|
-
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
2537
|
+
const hostStateRef = (0, import_react4.useRef)(createHostState());
|
|
2538
|
+
const componentHydrationHtml = (0, import_react4.useRef)(null);
|
|
2539
|
+
const prevRemoteComponentContainerRef = (0, import_react4.useRef)(null);
|
|
2540
|
+
const unmountRef = (0, import_react4.useRef)(null);
|
|
2541
|
+
(0, import_react4.useLayoutEffect)(() => {
|
|
2201
2542
|
return () => {
|
|
2202
|
-
delete
|
|
2543
|
+
delete getNamespace().shadowRoots[keySuffix];
|
|
2203
2544
|
};
|
|
2204
2545
|
}, [keySuffix]);
|
|
2205
|
-
(0,
|
|
2546
|
+
(0, import_react4.useLayoutEffect)(() => {
|
|
2206
2547
|
if (childrenRef.current.length > 0 && remoteComponent) {
|
|
2207
2548
|
childrenRef.current.forEach((el) => {
|
|
2208
2549
|
el.remove();
|
|
@@ -2210,7 +2551,7 @@ function ConsumeRemoteComponent({
|
|
|
2210
2551
|
childrenRef.current = [];
|
|
2211
2552
|
}
|
|
2212
2553
|
}, [remoteComponent]);
|
|
2213
|
-
(0,
|
|
2554
|
+
(0, import_react4.useLayoutEffect)(() => {
|
|
2214
2555
|
if (shadowRoot && remoteComponent) {
|
|
2215
2556
|
const resetStyles = shadowRoot.querySelectorAll(
|
|
2216
2557
|
"style[data-remote-components-reset]"
|
|
@@ -2233,7 +2574,7 @@ function ConsumeRemoteComponent({
|
|
|
2233
2574
|
}
|
|
2234
2575
|
}
|
|
2235
2576
|
}, [shadowRoot, remoteComponent, name]);
|
|
2236
|
-
(0,
|
|
2577
|
+
(0, import_react4.useEffect)(() => {
|
|
2237
2578
|
if (src && src !== hostStateRef.current.prevSrc) {
|
|
2238
2579
|
const previousSrc = hostStateRef.current.prevSrc;
|
|
2239
2580
|
const previousName = hostStateRef.current.prevName;
|
|
@@ -2244,9 +2585,9 @@ function ConsumeRemoteComponent({
|
|
|
2244
2585
|
hostStateRef.current.abortController?.abort();
|
|
2245
2586
|
hostStateRef.current.abortController = new AbortController();
|
|
2246
2587
|
const { signal } = hostStateRef.current.abortController;
|
|
2247
|
-
|
|
2588
|
+
emitter.beforeLoad(src);
|
|
2248
2589
|
hostStateRef.current.stage = "loading";
|
|
2249
|
-
(0,
|
|
2590
|
+
(0, import_react4.startTransition)(async () => {
|
|
2250
2591
|
try {
|
|
2251
2592
|
let html = getRemoteComponentHtml(
|
|
2252
2593
|
htmlRef.current ?? (endTemplateRef.current?.previousElementSibling?.tagName === "div" ? endTemplateRef.current.previousElementSibling.innerHTML : "")
|
|
@@ -2275,26 +2616,32 @@ function ConsumeRemoteComponent({
|
|
|
2275
2616
|
}
|
|
2276
2617
|
if (signal.aborted)
|
|
2277
2618
|
return;
|
|
2278
|
-
const
|
|
2279
|
-
|
|
2619
|
+
const userShared = await shared2;
|
|
2620
|
+
if (signal.aborted)
|
|
2621
|
+
return;
|
|
2622
|
+
const prepared = preparePipeline({
|
|
2623
|
+
html,
|
|
2624
|
+
name,
|
|
2625
|
+
url,
|
|
2626
|
+
shared: userShared,
|
|
2627
|
+
resolveClientUrl
|
|
2628
|
+
});
|
|
2629
|
+
const { doc, parsed } = prepared;
|
|
2280
2630
|
const {
|
|
2281
2631
|
component,
|
|
2282
2632
|
name: remoteName,
|
|
2283
2633
|
isRemoteComponent,
|
|
2284
2634
|
metadata,
|
|
2285
|
-
nextData,
|
|
2286
2635
|
rsc,
|
|
2287
2636
|
remoteShared,
|
|
2288
|
-
links: linkElements
|
|
2289
|
-
|
|
2290
|
-
} = parseRemoteComponentDocument(doc, name, url);
|
|
2637
|
+
links: linkElements
|
|
2638
|
+
} = parsed;
|
|
2291
2639
|
if (hostStateRef.current.prevIsRemoteComponent) {
|
|
2292
2640
|
if (shadowRoot) {
|
|
2293
2641
|
shadowRoot.innerHTML = "";
|
|
2294
2642
|
}
|
|
2295
|
-
const self = globalThis;
|
|
2296
2643
|
const prevUrl = hostStateRef.current.prevUrl;
|
|
2297
|
-
if (prevUrl &&
|
|
2644
|
+
if (prevUrl && getNamespace().unmountFns[prevUrl.href]) {
|
|
2298
2645
|
const unmountPromises = Promise.all(
|
|
2299
2646
|
Array.from(unmountRef.current ?? []).map(
|
|
2300
2647
|
async (unmount) => unmount(
|
|
@@ -2309,7 +2656,6 @@ function ConsumeRemoteComponent({
|
|
|
2309
2656
|
hostStateRef.current.prevIsRemoteComponent = isRemoteComponent;
|
|
2310
2657
|
hostStateRef.current.prevUrl = url;
|
|
2311
2658
|
hostStateRef.current.prevName = remoteName;
|
|
2312
|
-
applyOriginToNodes(doc, url, resolveClientUrl);
|
|
2313
2659
|
const links = linkElements.map((link) => ({
|
|
2314
2660
|
href: new URL(link.getAttribute("href") ?? link.href, url).href,
|
|
2315
2661
|
...link.getAttributeNames().reduce((acc, key) => {
|
|
@@ -2319,7 +2665,6 @@ function ConsumeRemoteComponent({
|
|
|
2319
2665
|
return acc;
|
|
2320
2666
|
}, {})
|
|
2321
2667
|
}));
|
|
2322
|
-
const scripts = scriptElements;
|
|
2323
2668
|
const inlineScripts = (isRemoteComponent ? component : doc).querySelectorAll(
|
|
2324
2669
|
"script:not([src]):not([data-src]):not([id*='_rsc']):not([id='__NEXT_DATA__']):not([id='__REMOTE_NEXT_DATA__'])"
|
|
2325
2670
|
);
|
|
@@ -2398,20 +2743,10 @@ function ConsumeRemoteComponent({
|
|
|
2398
2743
|
componentHydrationHtml.current = `${Array.from(
|
|
2399
2744
|
doc.querySelectorAll("link,style")
|
|
2400
2745
|
).map((link) => link.outerHTML).join("")}${reset ? `<style data-remote-components-reset="">:host { all: initial; }</style>` : ""}${component.innerHTML}`;
|
|
2401
|
-
const userShared = await shared2;
|
|
2402
|
-
if ("__remote_components_missing_shared__" in userShared) {
|
|
2403
|
-
userShared.__remote_components_missing_shared__().catch((e) => {
|
|
2404
|
-
throw e;
|
|
2405
|
-
});
|
|
2406
|
-
} else if ("__remote_components_missing_shared__" in remoteShared) {
|
|
2407
|
-
throw new RemoteComponentsError(
|
|
2408
|
-
remoteShared.__remote_components_missing_shared__
|
|
2409
|
-
);
|
|
2410
|
-
}
|
|
2411
2746
|
if (isRemoteComponent) {
|
|
2412
2747
|
if (previousSrc !== void 0) {
|
|
2413
|
-
|
|
2414
|
-
previousSrc,
|
|
2748
|
+
emitter.change({
|
|
2749
|
+
previousSrc: previousSrc ?? null,
|
|
2415
2750
|
nextSrc: src,
|
|
2416
2751
|
previousName,
|
|
2417
2752
|
nextName: remoteName
|
|
@@ -2432,7 +2767,7 @@ function ConsumeRemoteComponent({
|
|
|
2432
2767
|
await Promise.all(
|
|
2433
2768
|
Array.from(mount).map((mountFn) => mountFn(shadowRoot))
|
|
2434
2769
|
);
|
|
2435
|
-
|
|
2770
|
+
emitter.load(src);
|
|
2436
2771
|
} else if (isolate === false) {
|
|
2437
2772
|
setRemoteComponent(
|
|
2438
2773
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
@@ -2455,62 +2790,42 @@ function ConsumeRemoteComponent({
|
|
|
2455
2790
|
(mountFn) => mountFn(prevRemoteComponentContainerRef.current)
|
|
2456
2791
|
)
|
|
2457
2792
|
);
|
|
2458
|
-
|
|
2793
|
+
emitter.load(src);
|
|
2459
2794
|
}
|
|
2460
2795
|
hostStateRef.current.stage = "loaded";
|
|
2461
2796
|
} else {
|
|
2462
|
-
const result = await
|
|
2797
|
+
const result = await loadPrepared({
|
|
2798
|
+
prepared,
|
|
2463
2799
|
url,
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
route: metadata.route,
|
|
2468
|
-
runtime: metadata.runtime,
|
|
2469
|
-
data: newData.data,
|
|
2470
|
-
nextData,
|
|
2471
|
-
scripts: Array.from(scripts).map((script) => {
|
|
2472
|
-
const scriptSrc = script.getAttribute("data-src") || script.getAttribute("src") || script.src;
|
|
2473
|
-
const { prefix, id: path } = REMOTE_COMPONENT_REGEX.exec(
|
|
2474
|
-
scriptSrc
|
|
2475
|
-
)?.groups ?? {
|
|
2476
|
-
prefix: void 0,
|
|
2477
|
-
id: scriptSrc
|
|
2478
|
-
};
|
|
2479
|
-
return {
|
|
2480
|
-
src: new URL(
|
|
2481
|
-
collapseDoubleSlashes(`${prefix ?? ""}${path}`),
|
|
2482
|
-
url
|
|
2483
|
-
).href
|
|
2484
|
-
};
|
|
2485
|
-
}),
|
|
2486
|
-
shared: {
|
|
2487
|
-
...sharedPolyfills(userShared, resolveClientUrl),
|
|
2488
|
-
...userShared
|
|
2489
|
-
},
|
|
2490
|
-
remoteShared,
|
|
2800
|
+
signal,
|
|
2801
|
+
shared: userShared,
|
|
2802
|
+
resolveClientUrl,
|
|
2491
2803
|
container: shadowRoot,
|
|
2492
|
-
|
|
2804
|
+
rscName
|
|
2493
2805
|
});
|
|
2494
2806
|
if (rsc) {
|
|
2495
2807
|
rsc.remove();
|
|
2496
2808
|
}
|
|
2497
2809
|
setData(newData);
|
|
2498
2810
|
if (previousSrc !== void 0) {
|
|
2499
|
-
|
|
2500
|
-
previousSrc,
|
|
2811
|
+
emitter.change({
|
|
2812
|
+
previousSrc: previousSrc ?? null,
|
|
2501
2813
|
nextSrc: src,
|
|
2502
2814
|
previousName,
|
|
2503
2815
|
nextName: remoteName
|
|
2504
2816
|
});
|
|
2505
2817
|
}
|
|
2506
|
-
if (result.
|
|
2818
|
+
if (result.status === "aborted") {
|
|
2819
|
+
return;
|
|
2820
|
+
}
|
|
2821
|
+
if (result.status === "error") {
|
|
2507
2822
|
hostStateRef.current.stage = "error";
|
|
2508
2823
|
setRemoteComponent(result.error);
|
|
2509
|
-
|
|
2510
|
-
} else {
|
|
2824
|
+
emitter.error(result.error);
|
|
2825
|
+
} else if (result.status === "loaded") {
|
|
2511
2826
|
hostStateRef.current.stage = "loaded";
|
|
2512
2827
|
setRemoteComponent(result.component);
|
|
2513
|
-
|
|
2828
|
+
emitter.load(src);
|
|
2514
2829
|
}
|
|
2515
2830
|
}
|
|
2516
2831
|
} catch (error) {
|
|
@@ -2520,7 +2835,7 @@ function ConsumeRemoteComponent({
|
|
|
2520
2835
|
}
|
|
2521
2836
|
hostStateRef.current.stage = "error";
|
|
2522
2837
|
setRemoteComponent(error);
|
|
2523
|
-
|
|
2838
|
+
emitter.error(error);
|
|
2524
2839
|
}
|
|
2525
2840
|
});
|
|
2526
2841
|
}
|
|
@@ -2534,10 +2849,10 @@ function ConsumeRemoteComponent({
|
|
|
2534
2849
|
shadowRoot,
|
|
2535
2850
|
reset,
|
|
2536
2851
|
id,
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2852
|
+
emitter.beforeLoad,
|
|
2853
|
+
emitter.load,
|
|
2854
|
+
emitter.error,
|
|
2855
|
+
emitter.change,
|
|
2541
2856
|
onRequest,
|
|
2542
2857
|
onResponse,
|
|
2543
2858
|
resolveClientUrl
|
|
@@ -2552,7 +2867,7 @@ function ConsumeRemoteComponent({
|
|
|
2552
2867
|
runtime: hostStateRef.current.prevIsRemoteComponent ? RUNTIME_SCRIPT : data?.runtime || RUNTIME_WEBPACK
|
|
2553
2868
|
}) });
|
|
2554
2869
|
const resetStyle = reset ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { "data-remote-components-reset": "react", children: `:host { all: initial; }` }) : null;
|
|
2555
|
-
const linksToRender = data?.links?.map((link) => /* @__PURE__ */ (0,
|
|
2870
|
+
const linksToRender = data?.links?.map((link) => /* @__PURE__ */ (0, import_react5.createElement)(
|
|
2556
2871
|
"link",
|
|
2557
2872
|
{
|
|
2558
2873
|
...link,
|
|
@@ -2579,7 +2894,7 @@ function ConsumeRemoteComponent({
|
|
|
2579
2894
|
);
|
|
2580
2895
|
}).then(() => {
|
|
2581
2896
|
if (src) {
|
|
2582
|
-
|
|
2897
|
+
emitter.load(src);
|
|
2583
2898
|
}
|
|
2584
2899
|
}).catch((e) => {
|
|
2585
2900
|
const error = new RemoteComponentsError(
|
|
@@ -2589,7 +2904,7 @@ function ConsumeRemoteComponent({
|
|
|
2589
2904
|
}
|
|
2590
2905
|
);
|
|
2591
2906
|
setRemoteComponent(error);
|
|
2592
|
-
|
|
2907
|
+
emitter.error(error);
|
|
2593
2908
|
});
|
|
2594
2909
|
}
|
|
2595
2910
|
}
|
|
@@ -2618,8 +2933,10 @@ function ConsumeRemoteComponent({
|
|
|
2618
2933
|
alt="" decoding="async" style="display:none"
|
|
2619
2934
|
src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="
|
|
2620
2935
|
onload="(function(el){
|
|
2936
|
+
// Capture the shadow root during SSR hydration so the client-side
|
|
2937
|
+
// useShadowRoot hook can find it.
|
|
2621
2938
|
const root = el.getRootNode();
|
|
2622
|
-
globalThis.__remote_components_shadowroot_${keySuffix}
|
|
2939
|
+
globalThis.__remote_components_shadowroot_${keySuffix}=root;
|
|
2623
2940
|
el.parentElement.remove();
|
|
2624
2941
|
})(this)"
|
|
2625
2942
|
/>`
|
|
@@ -2740,7 +3057,7 @@ function RemoteComponentsClientProvider({
|
|
|
2740
3057
|
children,
|
|
2741
3058
|
...props
|
|
2742
3059
|
}) {
|
|
2743
|
-
const mergedShared = (0,
|
|
3060
|
+
const mergedShared = (0, import_react6.useMemo)(
|
|
2744
3061
|
() => sharedModules(shared2, resolveClientUrl),
|
|
2745
3062
|
[shared2, resolveClientUrl]
|
|
2746
3063
|
);
|