remote-components 0.0.42 → 0.0.43
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 +30 -0
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +30 -0
- package/dist/html/host.js.map +1 -1
- package/dist/internal/next/host/app-router-client.d.ts +30 -3
- package/dist/internal/shared/client/remote-component.cjs +29 -0
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.js +29 -0
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/next/host/client/index.cjs +120 -60
- package/dist/next/host/client/index.cjs.map +1 -1
- package/dist/next/host/client/index.d.ts +2 -49
- package/dist/next/host/client/index.js +115 -54
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/react/index.cjs +1559 -82
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -10
- package/dist/react/index.js +1536 -81
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/types-235b68a5.d.ts +0 -32
package/dist/react/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,26 +17,1515 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/react/index.tsx
|
|
19
31
|
var react_exports = {};
|
|
20
32
|
__export(react_exports, {
|
|
21
33
|
RemoteComponent: () => RemoteComponent
|
|
22
34
|
});
|
|
23
35
|
module.exports = __toCommonJS(react_exports);
|
|
36
|
+
var import_react2 = require("react");
|
|
37
|
+
var import_react_dom = require("react-dom");
|
|
38
|
+
|
|
39
|
+
// src/shared/client/apply-origin.ts
|
|
40
|
+
var tagNames = [
|
|
41
|
+
"img",
|
|
42
|
+
"source",
|
|
43
|
+
"video",
|
|
44
|
+
"audio",
|
|
45
|
+
"track",
|
|
46
|
+
"iframe",
|
|
47
|
+
"embed",
|
|
48
|
+
"script",
|
|
49
|
+
"link"
|
|
50
|
+
];
|
|
51
|
+
function applyOriginToNodes(doc, url) {
|
|
52
|
+
if (url.origin !== location.origin) {
|
|
53
|
+
const nodes = doc.querySelectorAll(
|
|
54
|
+
tagNames.map(
|
|
55
|
+
(type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
|
|
56
|
+
).join(",")
|
|
57
|
+
);
|
|
58
|
+
nodes.forEach((node) => {
|
|
59
|
+
if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
|
|
60
|
+
node.src = new URL(node.getAttribute("src") ?? "/", url).href;
|
|
61
|
+
}
|
|
62
|
+
if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
|
|
63
|
+
node.setAttribute(
|
|
64
|
+
"href",
|
|
65
|
+
new URL(node.getAttribute("href") ?? "/", url).href
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (node.hasAttribute("srcset")) {
|
|
69
|
+
const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
|
|
70
|
+
const [urlPart, descriptor] = entry.trim().split(/\s+/);
|
|
71
|
+
if (!urlPart)
|
|
72
|
+
return entry;
|
|
73
|
+
const absoluteUrl = new URL(urlPart, url).href;
|
|
74
|
+
return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
|
|
75
|
+
}).join(", ");
|
|
76
|
+
if (srcSet) {
|
|
77
|
+
node.setAttribute("srcset", srcSet);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (node.hasAttribute("imagesrcset")) {
|
|
81
|
+
const srcSet = node.getAttribute("imagesrcset")?.split(",").map((entry) => {
|
|
82
|
+
const [urlPart, descriptor] = entry.trim().split(/\s+/);
|
|
83
|
+
if (!urlPart)
|
|
84
|
+
return entry;
|
|
85
|
+
const absoluteUrl = new URL(urlPart, url).href;
|
|
86
|
+
return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
|
|
87
|
+
}).join(", ");
|
|
88
|
+
if (srcSet) {
|
|
89
|
+
node.setAttribute("imagesrcset", srcSet);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/shared/client/polyfill.tsx
|
|
24
97
|
var import_jsx_runtime = (
|
|
25
|
-
//
|
|
98
|
+
// eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
|
|
26
99
|
require("react/jsx-runtime")
|
|
27
100
|
);
|
|
101
|
+
function applyBundleUrlToSrc(bundle, src) {
|
|
102
|
+
const self = globalThis;
|
|
103
|
+
if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {
|
|
104
|
+
return src;
|
|
105
|
+
}
|
|
106
|
+
const { assetPrefix, path } = /^(?<assetPrefix>.*?)\/_next\/(?<path>.*)/.exec(src)?.groups ?? {};
|
|
107
|
+
if (!path) {
|
|
108
|
+
return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;
|
|
109
|
+
}
|
|
110
|
+
return `${self.__remote_bundle_url__?.[bundle]?.origin ?? ""}${assetPrefix}/_next/${path}`;
|
|
111
|
+
}
|
|
112
|
+
function applyBundleUrlToImagePropsSrc(bundle, src) {
|
|
113
|
+
if (typeof src === "string") {
|
|
114
|
+
return applyBundleUrlToSrc(bundle, src);
|
|
115
|
+
}
|
|
116
|
+
const propSrc = src;
|
|
117
|
+
return applyBundleUrlToSrc(bundle, propSrc.src);
|
|
118
|
+
}
|
|
119
|
+
var imageImpl = (bundle) => function RemoteImage({
|
|
120
|
+
fill: _fill,
|
|
121
|
+
loader: _loader,
|
|
122
|
+
quality: _quality,
|
|
123
|
+
priority: _priority,
|
|
124
|
+
loading: _loading,
|
|
125
|
+
placeholder: _placeholder,
|
|
126
|
+
blurDataURL: _blurDataURL,
|
|
127
|
+
unoptimized: _unoptimized,
|
|
128
|
+
overrideSrc: _overrideSrc,
|
|
129
|
+
src,
|
|
130
|
+
...props
|
|
131
|
+
}) {
|
|
132
|
+
const newSrc = applyBundleUrlToImagePropsSrc(
|
|
133
|
+
bundle,
|
|
134
|
+
typeof src === "string" ? src : src.src
|
|
135
|
+
);
|
|
136
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
137
|
+
"img",
|
|
138
|
+
{
|
|
139
|
+
decoding: "async",
|
|
140
|
+
style: { color: "transparent" },
|
|
141
|
+
...props,
|
|
142
|
+
src: newSrc,
|
|
143
|
+
suppressHydrationWarning: true
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
function sharedPolyfills(shared) {
|
|
148
|
+
const self = globalThis;
|
|
149
|
+
const polyfill = {
|
|
150
|
+
"next/dist/client/components/navigation": self.__remote_component_host_shared_modules__?.["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
|
|
151
|
+
useRouter() {
|
|
152
|
+
return {
|
|
153
|
+
push: (routerUrl) => {
|
|
154
|
+
history.pushState({}, "", routerUrl);
|
|
155
|
+
},
|
|
156
|
+
replace: (routerUrl) => {
|
|
157
|
+
history.replaceState({}, "", routerUrl);
|
|
158
|
+
},
|
|
159
|
+
back: () => {
|
|
160
|
+
history.back();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
usePathname() {
|
|
165
|
+
return location.pathname;
|
|
166
|
+
},
|
|
167
|
+
useParams() {
|
|
168
|
+
return {};
|
|
169
|
+
},
|
|
170
|
+
useSearchParams() {
|
|
171
|
+
return new URLSearchParams(location.search);
|
|
172
|
+
},
|
|
173
|
+
useSelectedLayoutSegment() {
|
|
174
|
+
return null;
|
|
175
|
+
},
|
|
176
|
+
useSelectedLayoutSegments() {
|
|
177
|
+
return [];
|
|
178
|
+
},
|
|
179
|
+
__esModule: true
|
|
180
|
+
})),
|
|
181
|
+
"next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
|
|
182
|
+
default: ({
|
|
183
|
+
scroll: _,
|
|
184
|
+
replace,
|
|
185
|
+
prefetch,
|
|
186
|
+
onNavigate,
|
|
187
|
+
children,
|
|
188
|
+
...props
|
|
189
|
+
}) => {
|
|
190
|
+
if (prefetch) {
|
|
191
|
+
console.warn(
|
|
192
|
+
"Next.js Link prefetch is not supported in remote components"
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
196
|
+
"a",
|
|
197
|
+
{
|
|
198
|
+
...props,
|
|
199
|
+
href: props.href,
|
|
200
|
+
onClick: (e) => {
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
let preventDefaulted = false;
|
|
203
|
+
e.preventDefault = () => {
|
|
204
|
+
preventDefaulted = true;
|
|
205
|
+
e.defaultPrevented = true;
|
|
206
|
+
};
|
|
207
|
+
if (typeof props.onClick === "function") {
|
|
208
|
+
props.onClick(e);
|
|
209
|
+
}
|
|
210
|
+
onNavigate?.(e);
|
|
211
|
+
if (preventDefaulted) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (replace) {
|
|
215
|
+
history.replaceState({}, "", props.href);
|
|
216
|
+
} else {
|
|
217
|
+
history.pushState({}, "", props.href);
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
suppressHydrationWarning: true,
|
|
221
|
+
children: children ?? null
|
|
222
|
+
}
|
|
223
|
+
);
|
|
224
|
+
},
|
|
225
|
+
useLinkStatus() {
|
|
226
|
+
return { pending: false };
|
|
227
|
+
},
|
|
228
|
+
__esModule: true
|
|
229
|
+
})),
|
|
230
|
+
"next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
|
|
231
|
+
default: () => {
|
|
232
|
+
throw new Error("Next.js <Form> component not implemented");
|
|
233
|
+
},
|
|
234
|
+
__esModule: true
|
|
235
|
+
})),
|
|
236
|
+
"next/dist/client/image-component": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
|
|
237
|
+
Image: imageImpl(bundle),
|
|
238
|
+
__esModule: true
|
|
239
|
+
})),
|
|
240
|
+
"next/image": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
|
|
241
|
+
default: imageImpl(bundle),
|
|
242
|
+
getImageProps: (_imgProps) => {
|
|
243
|
+
throw new Error(
|
|
244
|
+
"Next.js getImageProps() is not implemented in remote components"
|
|
245
|
+
);
|
|
246
|
+
},
|
|
247
|
+
__esModule: true
|
|
248
|
+
})),
|
|
249
|
+
"next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
|
|
250
|
+
// TODO: implement <Script> component for non-Next.js host applications
|
|
251
|
+
// do not throw an error for now
|
|
252
|
+
default: () => null,
|
|
253
|
+
__esModule: true
|
|
254
|
+
})),
|
|
255
|
+
"next/router": self.__remote_component_host_shared_modules__?.["next/router"] ?? shared?.["next/router"] ?? (() => (
|
|
256
|
+
// TODO: incomplete implementation
|
|
257
|
+
Promise.resolve({
|
|
258
|
+
useRouter() {
|
|
259
|
+
return {
|
|
260
|
+
push: (routerUrl) => {
|
|
261
|
+
history.pushState({}, "", routerUrl);
|
|
262
|
+
},
|
|
263
|
+
replace: (routerUrl) => {
|
|
264
|
+
history.replaceState({}, "", routerUrl);
|
|
265
|
+
},
|
|
266
|
+
back: () => {
|
|
267
|
+
history.back();
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
},
|
|
271
|
+
__esModule: true
|
|
272
|
+
})
|
|
273
|
+
)),
|
|
274
|
+
"next/dist/build/polyfills/process": () => Promise.resolve({
|
|
275
|
+
default: {
|
|
276
|
+
env: {
|
|
277
|
+
NODE_ENV: "production"
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
__esModule: true
|
|
281
|
+
})
|
|
282
|
+
};
|
|
283
|
+
polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
|
|
284
|
+
polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
|
|
285
|
+
polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
|
|
286
|
+
polyfill["next/dist/api/image"] = polyfill["next/dist/client/image-component"];
|
|
287
|
+
polyfill["next/script"] = polyfill["next/dist/client/script"];
|
|
288
|
+
return polyfill;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// src/shared/error.ts
|
|
292
|
+
var RemoteComponentsError = class extends Error {
|
|
293
|
+
code = "REMOTE_COMPONENTS_ERROR";
|
|
294
|
+
constructor(message, options) {
|
|
295
|
+
super(message, options);
|
|
296
|
+
this.name = "RemoteComponentsError";
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
function multipleRemoteComponentsError(url) {
|
|
300
|
+
return new RemoteComponentsError(
|
|
301
|
+
`Multiple Remote Components found at "${url}". When a page exposes multiple Remote Components you must specify the "name" prop to select which one to load.`
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
function failedToFetchRemoteComponentError(url, { status, statusText }, help = "Is the URL correct and accessible?") {
|
|
305
|
+
return new RemoteComponentsError(
|
|
306
|
+
`Failed to fetch Remote Component from "${url}". ${help}`,
|
|
307
|
+
{ cause: new Error(`${status} ${statusText}`) }
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// src/shared/client/component-loader.ts
|
|
312
|
+
var React = __toESM(require("react"), 1);
|
|
313
|
+
var JSXDevRuntime = __toESM(require("react/jsx-dev-runtime"), 1);
|
|
314
|
+
var JSXRuntime = __toESM(require("react/jsx-runtime"), 1);
|
|
315
|
+
var ReactDOM = __toESM(require("react-dom"), 1);
|
|
316
|
+
var ReactDOMClient = __toESM(require("react-dom/client"), 1);
|
|
317
|
+
|
|
318
|
+
// src/shared/utils/logger.ts
|
|
319
|
+
var PREFIX = "remote-components";
|
|
320
|
+
var DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
|
|
321
|
+
function logDebug(location2, message) {
|
|
322
|
+
if (DEBUG) {
|
|
323
|
+
console.debug(`[${PREFIX}:${location2}]: ${message}`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function logWarn(location2, message) {
|
|
327
|
+
console.warn(`[${PREFIX}:${location2}]: ${message}`);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// src/shared/webpack/next-client-pages-loader.ts
|
|
331
|
+
function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
332
|
+
const self = globalThis;
|
|
333
|
+
const nextCssOriginal = document.querySelector(
|
|
334
|
+
`[id="__next_css__DO_NOT_USE__"]:not([data-bundle="${bundle}"][data-route="${route}"])`
|
|
335
|
+
);
|
|
336
|
+
if (nextCssOriginal) {
|
|
337
|
+
nextCssOriginal.parentNode?.removeChild(nextCssOriginal);
|
|
338
|
+
}
|
|
339
|
+
const nextCss = document.createElement("noscript");
|
|
340
|
+
nextCss.id = "__next_css__DO_NOT_USE__";
|
|
341
|
+
nextCss.setAttribute("data-bundle", bundle);
|
|
342
|
+
nextCss.setAttribute("data-route", route);
|
|
343
|
+
const nextCssEnd = document.createElement("noscript");
|
|
344
|
+
nextCssEnd.id = "__next_css__DO_NOT_USE_END__";
|
|
345
|
+
nextCssEnd.setAttribute("data-bundle", bundle);
|
|
346
|
+
nextCssEnd.setAttribute("data-route", route);
|
|
347
|
+
document.head.appendChild(nextCssEnd);
|
|
348
|
+
document.head.appendChild(nextCss);
|
|
349
|
+
const componentLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
|
|
350
|
+
(key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
|
|
351
|
+
) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
|
|
352
|
+
(key) => key.includes("/next/dist/client/page-loader.js")
|
|
353
|
+
) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
|
|
354
|
+
(key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
|
|
355
|
+
) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
|
|
356
|
+
(key) => key.includes("/next/dist/client/page-loader.js")
|
|
357
|
+
) ?? ""] ?? -1;
|
|
358
|
+
const appLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
|
|
359
|
+
(key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
|
|
360
|
+
) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
|
|
361
|
+
(key) => key.includes("/next/dist/client/page-loader.js")
|
|
362
|
+
) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
|
|
363
|
+
(key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
|
|
364
|
+
) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
|
|
365
|
+
(key) => key.includes("/next/dist/client/page-loader.js")
|
|
366
|
+
) ?? ""] ?? -1;
|
|
367
|
+
if (!(componentLoaderChunk && appLoaderChunk)) {
|
|
368
|
+
throw new RemoteComponentsError(
|
|
369
|
+
`Next.js client pages loader not found in bundle "${bundle}".`
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
const __NEXT_P_ORIGINAL = self.__NEXT_P;
|
|
373
|
+
const selfOriginal = self;
|
|
374
|
+
delete selfOriginal.__NEXT_P;
|
|
375
|
+
self.__remote_webpack_require__?.[bundle]?.(
|
|
376
|
+
self.__remote_webpack_require__[bundle].type !== "turbopack" ? componentLoaderChunk : `[${bundle}] ${componentLoaderChunk}`
|
|
377
|
+
);
|
|
378
|
+
if (typeof appLoaderChunk === "string" || typeof appLoaderChunk === "number" && appLoaderChunk !== -1) {
|
|
379
|
+
self.__remote_webpack_require__?.[bundle]?.(
|
|
380
|
+
self.__remote_webpack_require__[bundle].type !== "turbopack" ? appLoaderChunk : `[${bundle}] ${appLoaderChunk}`
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
if (self.__NEXT_P) {
|
|
384
|
+
const [, componentLoader] = self.__NEXT_P[0] ?? [
|
|
385
|
+
void 0,
|
|
386
|
+
() => ({ default: null })
|
|
387
|
+
];
|
|
388
|
+
const [, appLoader] = self.__NEXT_P[2] ?? [
|
|
389
|
+
void 0,
|
|
390
|
+
() => ({
|
|
391
|
+
default: null
|
|
392
|
+
})
|
|
393
|
+
];
|
|
394
|
+
const { default: Component } = componentLoader();
|
|
395
|
+
const { default: App } = appLoader();
|
|
396
|
+
if (!self.__remote_next_css__) {
|
|
397
|
+
self.__remote_next_css__ = {};
|
|
398
|
+
}
|
|
399
|
+
if (!self.__remote_next_css__[bundle]) {
|
|
400
|
+
const cssRE = /\.s?css$/;
|
|
401
|
+
Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).filter((id) => cssRE.test(id)).forEach((id) => {
|
|
402
|
+
self.__remote_webpack_require__?.[bundle]?.(id);
|
|
403
|
+
});
|
|
404
|
+
Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {}).filter((path) => cssRE.test(path)).forEach((path) => {
|
|
405
|
+
const id = self.__remote_webpack_module_map__?.[bundle]?.[path];
|
|
406
|
+
if (id) {
|
|
407
|
+
self.__remote_webpack_require__?.[bundle]?.(id);
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
const elements = [];
|
|
411
|
+
let node = nextCss.previousSibling;
|
|
412
|
+
while (node && node !== nextCssEnd) {
|
|
413
|
+
elements.push(node);
|
|
414
|
+
node.remove();
|
|
415
|
+
node = nextCss.previousSibling;
|
|
416
|
+
}
|
|
417
|
+
self.__remote_next_css__[bundle] = elements;
|
|
418
|
+
}
|
|
419
|
+
if (styleContainer) {
|
|
420
|
+
const elements = self.__remote_next_css__[bundle];
|
|
421
|
+
elements.forEach((el) => {
|
|
422
|
+
styleContainer.appendChild(el.cloneNode(true));
|
|
423
|
+
});
|
|
424
|
+
} else {
|
|
425
|
+
const elements = self.__remote_next_css__[bundle];
|
|
426
|
+
elements.forEach((el) => {
|
|
427
|
+
document.head.appendChild(el);
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
delete self.__NEXT_P;
|
|
431
|
+
self.__NEXT_P = __NEXT_P_ORIGINAL;
|
|
432
|
+
if (nextCssOriginal) {
|
|
433
|
+
nextCssOriginal.parentNode?.appendChild(nextCssOriginal);
|
|
434
|
+
}
|
|
435
|
+
nextCss.remove();
|
|
436
|
+
nextCssEnd.remove();
|
|
437
|
+
return { Component, App };
|
|
438
|
+
}
|
|
439
|
+
return { Component: null, App: null };
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// src/shared/webpack/shared-modules.ts
|
|
443
|
+
function applySharedModules(bundle, resolve) {
|
|
444
|
+
logDebug(
|
|
445
|
+
"SharedModules",
|
|
446
|
+
`applySharedModules called for bundle: "${bundle}"`
|
|
447
|
+
);
|
|
448
|
+
logDebug(
|
|
449
|
+
"SharedModules",
|
|
450
|
+
`Shared modules to resolve: ${Object.keys(resolve)}`
|
|
451
|
+
);
|
|
452
|
+
const self = globalThis;
|
|
453
|
+
if (self.__remote_webpack_require__?.[bundle]) {
|
|
454
|
+
const modulePaths = Object.keys(
|
|
455
|
+
self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
|
|
456
|
+
);
|
|
457
|
+
logDebug(
|
|
458
|
+
"SharedModules",
|
|
459
|
+
`Available module paths in __remote_webpack_require__[${bundle}]: ${modulePaths}`
|
|
460
|
+
);
|
|
461
|
+
for (const [key, value] of Object.entries(resolve)) {
|
|
462
|
+
let ids = modulePaths.filter((p) => p === key);
|
|
463
|
+
if (ids.length === 0) {
|
|
464
|
+
ids = modulePaths.filter((p) => p.includes(key));
|
|
465
|
+
}
|
|
466
|
+
if (ids.length === 0) {
|
|
467
|
+
logDebug(
|
|
468
|
+
"SharedModules",
|
|
469
|
+
`No matching module path found for shared module "${key}"`
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
for (let id of ids) {
|
|
473
|
+
const webpackBundle = self.__remote_webpack_require__[bundle];
|
|
474
|
+
if (webpackBundle.m) {
|
|
475
|
+
if (self.__remote_webpack_module_map__?.[bundle]?.[id]) {
|
|
476
|
+
const mappedId = `${self.__remote_webpack_module_map__[bundle][id]}`;
|
|
477
|
+
logDebug(
|
|
478
|
+
"SharedModules",
|
|
479
|
+
`Mapped module id: "${id}" -> "${mappedId}"`
|
|
480
|
+
);
|
|
481
|
+
id = mappedId;
|
|
482
|
+
}
|
|
483
|
+
webpackBundle.m[id] = (module2) => {
|
|
484
|
+
module2.exports = value;
|
|
485
|
+
};
|
|
486
|
+
} else {
|
|
487
|
+
logWarn(
|
|
488
|
+
"SharedModules",
|
|
489
|
+
`webpackBundle.m is not available for bundle "${bundle}"`
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
} else {
|
|
495
|
+
logWarn("SharedModules", `No webpack require found for bundle "${bundle}"`);
|
|
496
|
+
logDebug(
|
|
497
|
+
"SharedModules",
|
|
498
|
+
`Available bundles: ${Object.keys(self.__remote_webpack_require__ ?? {})}`
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// src/shared/client/rsc.ts
|
|
504
|
+
var import_web_streams_polyfill = require("web-streams-polyfill");
|
|
505
|
+
function fixPayload(payload) {
|
|
506
|
+
if (Array.isArray(payload)) {
|
|
507
|
+
if (payload[0] === "$") {
|
|
508
|
+
fixPayload(payload[3]);
|
|
509
|
+
if (payload.length === 4) {
|
|
510
|
+
payload.push(null, null, 1);
|
|
511
|
+
}
|
|
512
|
+
} else {
|
|
513
|
+
for (const item of payload) {
|
|
514
|
+
fixPayload(item);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
} else if (typeof payload === "object" && payload !== null) {
|
|
518
|
+
for (const key in payload) {
|
|
519
|
+
fixPayload(payload[key]);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
function createRSCStream(rscName, data) {
|
|
524
|
+
return new import_web_streams_polyfill.ReadableStream({
|
|
525
|
+
type: "bytes",
|
|
526
|
+
start(controller) {
|
|
527
|
+
const encoder = new TextEncoder();
|
|
528
|
+
const self = globalThis;
|
|
529
|
+
if (data.length > 0) {
|
|
530
|
+
data.forEach((chunk) => {
|
|
531
|
+
const lines = chunk.split("\n");
|
|
532
|
+
for (const line of lines) {
|
|
533
|
+
const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
|
|
534
|
+
if (match?.groups?.rsc) {
|
|
535
|
+
self[rscName] = self[rscName] ?? [];
|
|
536
|
+
self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
const allChunks = (self[rscName] ?? [`0:[null]
|
|
542
|
+
`]).join("");
|
|
543
|
+
self[rscName] = null;
|
|
544
|
+
allChunks.split("\n").forEach((chunk) => {
|
|
545
|
+
if (chunk.length > 0) {
|
|
546
|
+
const { before, id, prefix, payload } = /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
|
|
547
|
+
chunk
|
|
548
|
+
)?.groups ?? {};
|
|
549
|
+
if (payload) {
|
|
550
|
+
const jsonPayload = JSON.parse(payload);
|
|
551
|
+
fixPayload(jsonPayload);
|
|
552
|
+
const reconstruct = `${before ?? ""}${id}:${prefix ?? ""}${JSON.stringify(jsonPayload)}`;
|
|
553
|
+
controller.enqueue(encoder.encode(`${reconstruct}
|
|
554
|
+
`));
|
|
555
|
+
} else {
|
|
556
|
+
controller.enqueue(encoder.encode(`${chunk}
|
|
557
|
+
`));
|
|
558
|
+
}
|
|
559
|
+
} else {
|
|
560
|
+
controller.enqueue(encoder.encode(`${chunk}
|
|
561
|
+
`));
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
controller.close();
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// src/shared/client/script-loader.ts
|
|
570
|
+
async function loadScripts(scripts) {
|
|
571
|
+
await Promise.all(
|
|
572
|
+
scripts.map((script) => {
|
|
573
|
+
return new Promise((resolve, reject) => {
|
|
574
|
+
const newSrc = new URL(
|
|
575
|
+
// remove the remote component bundle name identifier from the script src
|
|
576
|
+
script.src.replace(/\/_next\/\[.+\](?<whitespace>%20| )/, "/_next/"),
|
|
577
|
+
location.origin
|
|
578
|
+
).href;
|
|
579
|
+
const newScript = document.createElement("script");
|
|
580
|
+
newScript.onload = () => {
|
|
581
|
+
resolve();
|
|
582
|
+
};
|
|
583
|
+
newScript.onerror = () => {
|
|
584
|
+
reject(
|
|
585
|
+
new RemoteComponentsError(
|
|
586
|
+
`Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
|
|
587
|
+
)
|
|
588
|
+
);
|
|
589
|
+
};
|
|
590
|
+
newScript.src = newSrc;
|
|
591
|
+
newScript.async = true;
|
|
592
|
+
document.head.appendChild(newScript);
|
|
593
|
+
});
|
|
594
|
+
})
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// src/shared/utils/index.ts
|
|
599
|
+
function escapeString(str) {
|
|
600
|
+
return str.replace(/[^a-z0-9]/g, "_");
|
|
601
|
+
}
|
|
602
|
+
var attrToProp = {
|
|
603
|
+
fetchpriority: "fetchPriority",
|
|
604
|
+
crossorigin: "crossOrigin",
|
|
605
|
+
imagesrcset: "imageSrcSet",
|
|
606
|
+
imagesizes: "imageSizes",
|
|
607
|
+
srcset: "srcSet"
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
// src/shared/client/const.ts
|
|
611
|
+
var DEFAULT_ROUTE = "/";
|
|
612
|
+
var RUNTIME_WEBPACK = "webpack";
|
|
613
|
+
var RUNTIME_TURBOPACK = "turbopack";
|
|
614
|
+
var RUNTIME_SCRIPT = "script";
|
|
615
|
+
var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
616
|
+
function getBundleKey(bundle) {
|
|
617
|
+
return escapeString(bundle);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// src/shared/client/chunk-loader.ts
|
|
621
|
+
function createChunkLoader(runtime) {
|
|
622
|
+
return function __turbopack_chunk_load__(chunkId, scriptBundle) {
|
|
623
|
+
logDebug("ChunkLoader", `Loading chunk: "${chunkId}"`);
|
|
624
|
+
const self = globalThis;
|
|
625
|
+
const {
|
|
626
|
+
bundle,
|
|
627
|
+
id: path,
|
|
628
|
+
prefix
|
|
629
|
+
} = REMOTE_COMPONENT_REGEX.exec(chunkId)?.groups ?? {
|
|
630
|
+
bundle: scriptBundle ?? "",
|
|
631
|
+
id: chunkId
|
|
632
|
+
};
|
|
633
|
+
logDebug(
|
|
634
|
+
"ChunkLoader",
|
|
635
|
+
`Parsed chunk - bundle: "${bundle}", path: "${path}", prefix: "${prefix}"`
|
|
636
|
+
);
|
|
637
|
+
const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
|
|
638
|
+
logDebug("ChunkLoader", `Remote runtime: "${remoteRuntime}"`);
|
|
639
|
+
if (remoteRuntime === RUNTIME_WEBPACK) {
|
|
640
|
+
logDebug("ChunkLoader", "Skipping chunk load - webpack runtime detected");
|
|
641
|
+
return Promise.resolve(void 0);
|
|
642
|
+
}
|
|
643
|
+
const url = new URL(
|
|
644
|
+
path ? `${prefix ?? ""}${path}`.replace(
|
|
645
|
+
/(?<char>[^:])(?<double>\/\/)/g,
|
|
646
|
+
"$1/"
|
|
647
|
+
) : "/",
|
|
648
|
+
self.__remote_bundle_url__?.[bundle ?? "default"] ?? new URL(location.origin)
|
|
649
|
+
).href;
|
|
650
|
+
if (url.endsWith(".css")) {
|
|
651
|
+
logDebug("ChunkLoader", `Skipping CSS file: "${url}"`);
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
if (!self.__remote_components_turbopack_chunk_loader_promise__) {
|
|
655
|
+
self.__remote_components_turbopack_chunk_loader_promise__ = {};
|
|
656
|
+
}
|
|
657
|
+
if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {
|
|
658
|
+
logDebug("ChunkLoader", `Returning cached promise for: "${url}"`);
|
|
659
|
+
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
660
|
+
}
|
|
661
|
+
logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
|
|
662
|
+
self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
|
|
663
|
+
fetch(url).then((res) => res.text()).then((code) => {
|
|
664
|
+
if (code.includes("globalThis.TURBOPACK")) {
|
|
665
|
+
return handleTurbopackChunk(code, bundle ?? "", url);
|
|
666
|
+
}
|
|
667
|
+
}).then(resolve).catch(reject);
|
|
668
|
+
});
|
|
669
|
+
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
async function handleTurbopackChunk(code, bundle, url) {
|
|
673
|
+
logDebug(
|
|
674
|
+
"ChunkLoader",
|
|
675
|
+
`Handling Turbopack chunk - bundle: "${bundle}", url: "${url}"`
|
|
676
|
+
);
|
|
677
|
+
if (/importScripts\(\.\.\.self.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {
|
|
678
|
+
logDebug("ChunkLoader", `Skipping worker chunk: "${url}"`);
|
|
679
|
+
const preloadLinks = document.querySelectorAll(
|
|
680
|
+
`link[rel="preload"][href="${new URL(url).pathname}"]`
|
|
681
|
+
);
|
|
682
|
+
preloadLinks.forEach((preloadLink) => preloadLink.remove());
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
const self = globalThis;
|
|
686
|
+
const bundleKey = getBundleKey(bundle);
|
|
687
|
+
logDebug("ChunkLoader", `Bundle key: "${bundleKey}"`);
|
|
688
|
+
const transformedCode = code.replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(
|
|
689
|
+
/TURBOPACK_WORKER_LOCATION/g,
|
|
690
|
+
`TURBOPACK_WORKER_LOCATION_${bundleKey}`
|
|
691
|
+
).replace(
|
|
692
|
+
/TURBOPACK_NEXT_CHUNK_URLS/g,
|
|
693
|
+
`TURBOPACK_NEXT_CHUNK_URLS_${bundleKey}`
|
|
694
|
+
).replace(
|
|
695
|
+
/TURBOPACK_CHUNK_UPDATE_LISTENERS/g,
|
|
696
|
+
`TURBOPACK_CHUNK_UPDATE_LISTENERS_${bundleKey}`
|
|
697
|
+
).replace(/__next_require__/g, `__${bundleKey}_next_require__`).replace(
|
|
698
|
+
/\/\/# sourceMappingURL=(?<name>.+)(?<optional>\._)?\.js\.map/g,
|
|
699
|
+
`//# sourceMappingURL=${new URL(
|
|
700
|
+
".",
|
|
701
|
+
new URL(
|
|
702
|
+
url,
|
|
703
|
+
self.__remote_bundle_url__?.[bundle] ?? new URL(location.origin)
|
|
704
|
+
)
|
|
705
|
+
).href}$1$2.js.map`
|
|
706
|
+
);
|
|
707
|
+
logDebug("ChunkLoader", `Creating blob script for: "${url}"`);
|
|
708
|
+
await new Promise((scriptResolve, scriptReject) => {
|
|
709
|
+
const blob = new Blob([transformedCode], {
|
|
710
|
+
type: "application/javascript; charset=UTF-8"
|
|
711
|
+
});
|
|
712
|
+
const scriptUrl = URL.createObjectURL(blob);
|
|
713
|
+
const script = document.createElement("script");
|
|
714
|
+
script.setAttribute("data-turbopack-src", url);
|
|
715
|
+
script.src = scriptUrl;
|
|
716
|
+
script.async = true;
|
|
717
|
+
script.onload = () => {
|
|
718
|
+
URL.revokeObjectURL(scriptUrl);
|
|
719
|
+
scriptResolve(void 0);
|
|
720
|
+
script.remove();
|
|
721
|
+
};
|
|
722
|
+
script.onerror = () => {
|
|
723
|
+
URL.revokeObjectURL(scriptUrl);
|
|
724
|
+
scriptReject(
|
|
725
|
+
new RemoteComponentsError(
|
|
726
|
+
`Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
|
|
727
|
+
)
|
|
728
|
+
);
|
|
729
|
+
script.remove();
|
|
730
|
+
};
|
|
731
|
+
document.head.appendChild(script);
|
|
732
|
+
});
|
|
733
|
+
const chunkLists = self[`TURBOPACK_${bundleKey}_CHUNK_LISTS`];
|
|
734
|
+
logDebug(
|
|
735
|
+
"ChunkLoader",
|
|
736
|
+
`Processing chunk lists for bundle "${bundle}": ${chunkLists?.length ?? 0} lists`
|
|
737
|
+
);
|
|
738
|
+
const loadChunkLists = [];
|
|
739
|
+
while (chunkLists?.length) {
|
|
740
|
+
const { chunks } = chunkLists.shift() ?? { chunks: [] };
|
|
741
|
+
if (chunks.length > 0) {
|
|
742
|
+
logDebug(
|
|
743
|
+
"ChunkLoader",
|
|
744
|
+
`Loading ${chunks.length} additional chunks for bundle "${bundle}": [${chunks.join(", ")}]`
|
|
745
|
+
);
|
|
746
|
+
chunks.forEach((id) => {
|
|
747
|
+
const chunkLoadResult = self.__webpack_chunk_load__?.(
|
|
748
|
+
`[${bundle}] ${url.slice(0, url.indexOf("/_next"))}/_next/${id}`
|
|
749
|
+
);
|
|
750
|
+
if (chunkLoadResult) {
|
|
751
|
+
loadChunkLists.push(chunkLoadResult);
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
if (loadChunkLists.length > 0) {
|
|
757
|
+
logDebug(
|
|
758
|
+
"ChunkLoader",
|
|
759
|
+
`Waiting for ${loadChunkLists.length} additional chunks to load`
|
|
760
|
+
);
|
|
761
|
+
await Promise.all(loadChunkLists);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// src/shared/client/turbopack-module.ts
|
|
766
|
+
function handleTurbopackModule(bundle, moduleId, id) {
|
|
767
|
+
const self = globalThis;
|
|
768
|
+
const bundleKey = getBundleKey(bundle);
|
|
769
|
+
const modules = self[`TURBOPACK_${bundleKey}`];
|
|
770
|
+
const moduleInit = findModuleInit(modules, moduleId);
|
|
771
|
+
const exports = {};
|
|
772
|
+
const moduleExports = { exports };
|
|
773
|
+
if (!self.__remote_components_turbopack_modules__) {
|
|
774
|
+
self.__remote_components_turbopack_modules__ = {};
|
|
775
|
+
}
|
|
776
|
+
if (!self.__remote_components_turbopack_modules__[bundle]) {
|
|
777
|
+
self.__remote_components_turbopack_modules__[bundle] = {};
|
|
778
|
+
}
|
|
779
|
+
if (self.__remote_components_turbopack_modules__[bundle][moduleId]) {
|
|
780
|
+
return self.__remote_components_turbopack_modules__[bundle][moduleId];
|
|
781
|
+
}
|
|
782
|
+
if (typeof moduleInit !== "function") {
|
|
783
|
+
throw new Error(
|
|
784
|
+
`Module ${id} not found in bundle ${bundle} with id ${moduleId}`
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
self.__remote_components_turbopack_modules__[bundle][moduleId] = moduleExports.exports;
|
|
788
|
+
if (!self.__remote_components_turbopack_global__) {
|
|
789
|
+
self.__remote_components_turbopack_global__ = {};
|
|
790
|
+
}
|
|
791
|
+
if (!self.__remote_components_turbopack_global__[bundle]) {
|
|
792
|
+
self.__remote_components_turbopack_global__[bundle] = {};
|
|
793
|
+
}
|
|
794
|
+
const allModules = modules?.flat() ?? [];
|
|
795
|
+
moduleInit(
|
|
796
|
+
createTurbopackContext(
|
|
797
|
+
bundle,
|
|
798
|
+
exports,
|
|
799
|
+
moduleExports,
|
|
800
|
+
allModules,
|
|
801
|
+
moduleInit,
|
|
802
|
+
id,
|
|
803
|
+
self
|
|
804
|
+
),
|
|
805
|
+
moduleExports,
|
|
806
|
+
exports
|
|
807
|
+
);
|
|
808
|
+
if (self.__remote_components_turbopack_modules__[bundle][moduleId] !== moduleExports.exports) {
|
|
809
|
+
self.__remote_components_turbopack_modules__[bundle][moduleId] = moduleExports.exports;
|
|
810
|
+
}
|
|
811
|
+
return moduleExports.exports;
|
|
812
|
+
}
|
|
813
|
+
function findModuleInit(modules, moduleId) {
|
|
814
|
+
const allModules = modules?.flat() ?? [];
|
|
815
|
+
if (typeof allModules[1] === "string" || typeof allModules[1] === "number") {
|
|
816
|
+
const normalizedId = /^[0-9]+$/.test(moduleId) ? Number(moduleId) : moduleId;
|
|
817
|
+
let moduleIdIndex = allModules.indexOf(normalizedId);
|
|
818
|
+
if (moduleIdIndex === -1) {
|
|
819
|
+
moduleIdIndex = allModules.findIndex(
|
|
820
|
+
(bundleEntry) => typeof bundleEntry === "string" && bundleEntry.startsWith(moduleId) || bundleEntry === normalizedId
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
if (moduleIdIndex !== -1) {
|
|
824
|
+
while (typeof allModules[moduleIdIndex] !== "function" && moduleIdIndex < allModules.length) {
|
|
825
|
+
moduleIdIndex++;
|
|
826
|
+
}
|
|
827
|
+
return allModules[moduleIdIndex];
|
|
828
|
+
}
|
|
829
|
+
} else {
|
|
830
|
+
return allModules.find(
|
|
831
|
+
(bundleEntry) => typeof bundleEntry === "object" && bundleEntry !== null && moduleId in bundleEntry
|
|
832
|
+
)?.[moduleId];
|
|
833
|
+
}
|
|
834
|
+
return void 0;
|
|
835
|
+
}
|
|
836
|
+
function createTurbopackContext(bundle, exports, moduleExports, allModules, moduleInit, id, self) {
|
|
837
|
+
return {
|
|
838
|
+
// HMR not implemented for Remote Components
|
|
839
|
+
k: {
|
|
840
|
+
register() {
|
|
841
|
+
},
|
|
842
|
+
registerExports() {
|
|
843
|
+
},
|
|
844
|
+
signature() {
|
|
845
|
+
return (fn) => fn;
|
|
846
|
+
}
|
|
847
|
+
},
|
|
848
|
+
// ESM exports setup
|
|
849
|
+
s(bindings, esmId) {
|
|
850
|
+
let mod = exports;
|
|
851
|
+
if (typeof esmId === "string" || typeof esmId === "number") {
|
|
852
|
+
if (!self.__remote_components_turbopack_modules__) {
|
|
853
|
+
self.__remote_components_turbopack_modules__ = {};
|
|
854
|
+
}
|
|
855
|
+
if (!self.__remote_components_turbopack_modules__[bundle]) {
|
|
856
|
+
self.__remote_components_turbopack_modules__[bundle] = {};
|
|
857
|
+
}
|
|
858
|
+
if (!self.__remote_components_turbopack_modules__[bundle][esmId]) {
|
|
859
|
+
self.__remote_components_turbopack_modules__[bundle][esmId] = {};
|
|
860
|
+
}
|
|
861
|
+
mod = self.__remote_components_turbopack_modules__[bundle][esmId];
|
|
862
|
+
}
|
|
863
|
+
Object.defineProperty(mod, "__esModule", { value: true });
|
|
864
|
+
if (Array.isArray(bindings)) {
|
|
865
|
+
let i = 0;
|
|
866
|
+
while (i < bindings.length) {
|
|
867
|
+
const propName = bindings[i++];
|
|
868
|
+
const tagOrFunc = bindings[i++];
|
|
869
|
+
if (typeof tagOrFunc === "number") {
|
|
870
|
+
Object.defineProperty(mod, propName, {
|
|
871
|
+
value: bindings[i++],
|
|
872
|
+
enumerable: true,
|
|
873
|
+
writable: false
|
|
874
|
+
});
|
|
875
|
+
} else {
|
|
876
|
+
const getterFn = tagOrFunc;
|
|
877
|
+
if (typeof bindings[i] === "function") {
|
|
878
|
+
const setterFn = bindings[i++];
|
|
879
|
+
Object.defineProperty(mod, propName, {
|
|
880
|
+
get: getterFn,
|
|
881
|
+
set: setterFn,
|
|
882
|
+
enumerable: true
|
|
883
|
+
});
|
|
884
|
+
} else {
|
|
885
|
+
Object.defineProperty(mod, propName, {
|
|
886
|
+
get: getterFn,
|
|
887
|
+
enumerable: true
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
},
|
|
894
|
+
// import
|
|
895
|
+
i(importId) {
|
|
896
|
+
let mod;
|
|
897
|
+
if (typeof importId === "string") {
|
|
898
|
+
const { exportSource, exportName } = /\s+<export (?<exportSource>.*?) as (?<exportName>.*?)>$/.exec(
|
|
899
|
+
importId
|
|
900
|
+
)?.groups ?? {};
|
|
901
|
+
const normalizedId = importId.replace(
|
|
902
|
+
/\s+<export(?<specifier>.*)>$/,
|
|
903
|
+
""
|
|
904
|
+
);
|
|
905
|
+
mod = self.__webpack_require__?.(`[${bundle}] ${normalizedId}`);
|
|
906
|
+
if (mod && exportSource && exportName && (exportSource === "*" || typeof mod[exportSource] !== "undefined") && typeof mod[exportName] === "undefined") {
|
|
907
|
+
if (exportSource === "*") {
|
|
908
|
+
mod[exportName] = mod;
|
|
909
|
+
} else {
|
|
910
|
+
mod[exportName] = mod[exportSource];
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
} else {
|
|
914
|
+
mod = self.__webpack_require__?.(`[${bundle}] ${importId}`);
|
|
915
|
+
}
|
|
916
|
+
if (typeof mod !== "object" || mod === null) {
|
|
917
|
+
mod = { default: mod };
|
|
918
|
+
} else if (!("default" in mod) && mod.toString() !== "[object Module]") {
|
|
919
|
+
try {
|
|
920
|
+
mod.default = mod;
|
|
921
|
+
} catch {
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
return mod;
|
|
925
|
+
},
|
|
926
|
+
// require
|
|
927
|
+
r(requireId) {
|
|
928
|
+
return self.__webpack_require__?.(`[${bundle}] ${requireId}`);
|
|
929
|
+
},
|
|
930
|
+
// value exports
|
|
931
|
+
v(value) {
|
|
932
|
+
if (typeof value === "function") {
|
|
933
|
+
exports.default = value((vid) => {
|
|
934
|
+
return self.__webpack_require__?.(`[${bundle}] ${vid}`);
|
|
935
|
+
});
|
|
936
|
+
} else {
|
|
937
|
+
moduleExports.exports = value;
|
|
938
|
+
}
|
|
939
|
+
},
|
|
940
|
+
// async module initializer
|
|
941
|
+
async a(mod) {
|
|
942
|
+
let result;
|
|
943
|
+
await mod(
|
|
944
|
+
() => {
|
|
945
|
+
},
|
|
946
|
+
(value) => result = value
|
|
947
|
+
);
|
|
948
|
+
exports.default = result;
|
|
949
|
+
},
|
|
950
|
+
// async module loader
|
|
951
|
+
async A(Aid) {
|
|
952
|
+
const mod = self.__webpack_require__?.(`[${bundle}] ${Aid}`);
|
|
953
|
+
return mod.default(
|
|
954
|
+
(parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
|
|
955
|
+
);
|
|
956
|
+
},
|
|
957
|
+
// chunk loader
|
|
958
|
+
l(url) {
|
|
959
|
+
const moduleInitIndex = allModules.indexOf(moduleInit);
|
|
960
|
+
if (moduleInitIndex !== -1) {
|
|
961
|
+
const scriptIndex = allModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
|
|
962
|
+
if (scriptIndex !== -1) {
|
|
963
|
+
const script = allModules[scriptIndex];
|
|
964
|
+
const scriptSrc = script.getAttribute("data-turbopack-src") || "";
|
|
965
|
+
const nextIndex = scriptSrc.indexOf("/_next");
|
|
966
|
+
const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
|
|
967
|
+
const bundleUrl = `[${bundle}] ${baseUrl}/_next/${url}`;
|
|
968
|
+
return self.__webpack_chunk_load__?.(bundleUrl, bundle);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
throw new Error(
|
|
972
|
+
`Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
|
|
973
|
+
);
|
|
974
|
+
},
|
|
975
|
+
// global object for this bundle
|
|
976
|
+
g: self.__remote_components_turbopack_global__?.[bundle],
|
|
977
|
+
m: moduleExports,
|
|
978
|
+
e: exports
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
// src/shared/client/turbopack-patterns.ts
|
|
983
|
+
var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
|
|
984
|
+
var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
|
|
985
|
+
var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
|
|
986
|
+
var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
|
|
987
|
+
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]+)\)\)\)\}/;
|
|
988
|
+
|
|
989
|
+
// src/shared/client/shared-modules.ts
|
|
990
|
+
async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {}) {
|
|
991
|
+
const self = globalThis;
|
|
992
|
+
self.__remote_shared_modules__ = self.__remote_shared_modules__ ?? {};
|
|
993
|
+
if (!self.__remote_shared_modules__[bundle]) {
|
|
994
|
+
self.__remote_shared_modules__[bundle] = {};
|
|
995
|
+
}
|
|
996
|
+
const bundleKey = getBundleKey(bundle);
|
|
997
|
+
const modules = self[`TURBOPACK_${bundleKey}`];
|
|
998
|
+
let sharedModuleInitializer = null;
|
|
999
|
+
if (modules && Array.isArray(modules)) {
|
|
1000
|
+
const allModules = modules.flat();
|
|
1001
|
+
const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {
|
|
1002
|
+
if (typeof idOrFunc !== "function") {
|
|
1003
|
+
return false;
|
|
1004
|
+
}
|
|
1005
|
+
const funcCode = idOrFunc.toString();
|
|
1006
|
+
return REMOTE_SHARED_MARKER_RE.test(funcCode);
|
|
1007
|
+
});
|
|
1008
|
+
if (sharedModuleInitializerIndex > 0) {
|
|
1009
|
+
const sharedModuleInitializerCode = allModules[sharedModuleInitializerIndex].toString();
|
|
1010
|
+
const sharedModuleInitializerId = allModules[sharedModuleInitializerIndex - 1];
|
|
1011
|
+
const { sharedModuleId } = REMOTE_SHARED_ASSIGNMENT_RE.exec(sharedModuleInitializerCode)?.groups ?? {};
|
|
1012
|
+
if (sharedModuleId) {
|
|
1013
|
+
const { default: sharedModuleInitializerInstance } = handleTurbopackModule(
|
|
1014
|
+
bundle,
|
|
1015
|
+
sharedModuleId,
|
|
1016
|
+
`[${bundle}] ${sharedModuleInitializerId}`
|
|
1017
|
+
);
|
|
1018
|
+
sharedModuleInitializer = sharedModuleInitializerInstance;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
if (sharedModuleInitializer) {
|
|
1022
|
+
const { shared } = await sharedModuleInitializer;
|
|
1023
|
+
const sharedModuleIds = extractSharedModuleIds(
|
|
1024
|
+
shared,
|
|
1025
|
+
bundleKey,
|
|
1026
|
+
self
|
|
1027
|
+
);
|
|
1028
|
+
return Promise.all(
|
|
1029
|
+
Object.entries(sharedModuleIds).map(async ([id, module2]) => {
|
|
1030
|
+
if (self.__remote_shared_modules__?.[bundle]) {
|
|
1031
|
+
if (hostShared[module2]) {
|
|
1032
|
+
self.__remote_shared_modules__[bundle][id] = await hostShared[module2](bundle);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
})
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
return Promise.all(
|
|
1040
|
+
Object.entries(remoteShared).map(async ([id, module2]) => {
|
|
1041
|
+
if (self.__remote_shared_modules__?.[bundle]) {
|
|
1042
|
+
if (hostShared[module2]) {
|
|
1043
|
+
self.__remote_shared_modules__[bundle][id.replace("[app-ssr]", "[app-client]")] = await hostShared[module2](bundle);
|
|
1044
|
+
} else {
|
|
1045
|
+
console.error(`Shared module "${module2}" not found for "${bundle}".`);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
})
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
function extractSharedModuleIds(shared, bundleKey, self) {
|
|
1052
|
+
return Object.entries(shared).filter(([, value]) => typeof value === "function").reduce((acc, [key, value]) => {
|
|
1053
|
+
const { asyncSharedModuleId } = ASYNC_MODULE_LOADER_RE.exec(value.toString())?.groups ?? {};
|
|
1054
|
+
if (asyncSharedModuleId) {
|
|
1055
|
+
const asyncSharedModuleIdNumber = Number(asyncSharedModuleId);
|
|
1056
|
+
let asyncSharedModule;
|
|
1057
|
+
const newAllModules = self[`TURBOPACK_${bundleKey}`]?.flat() ?? [];
|
|
1058
|
+
const asyncSharedModuleIdIndex = newAllModules.indexOf(
|
|
1059
|
+
asyncSharedModuleIdNumber
|
|
1060
|
+
);
|
|
1061
|
+
if (asyncSharedModuleIdIndex !== -1 && typeof newAllModules[asyncSharedModuleIdIndex + 1] === "function") {
|
|
1062
|
+
asyncSharedModule = newAllModules[asyncSharedModuleIdIndex + 1];
|
|
1063
|
+
}
|
|
1064
|
+
if (asyncSharedModule) {
|
|
1065
|
+
const asyncSharedModuleCode = asyncSharedModule.toString();
|
|
1066
|
+
const { sharedModuleId } = ASYNC_MODULE_RESOLVE_RE.exec(asyncSharedModuleCode)?.groups ?? ASYNC_MODULE_ALL_RE.exec(asyncSharedModuleCode)?.groups ?? {};
|
|
1067
|
+
acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(
|
|
1068
|
+
"__remote_shared_module_",
|
|
1069
|
+
""
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
return acc;
|
|
1074
|
+
}, {});
|
|
1075
|
+
}
|
|
1076
|
+
function getSharedModule(bundle, id) {
|
|
1077
|
+
const self = globalThis;
|
|
1078
|
+
for (const [key, value] of Object.entries(
|
|
1079
|
+
self.__remote_shared_modules__?.[bundle] ?? {}
|
|
1080
|
+
)) {
|
|
1081
|
+
if (typeof value !== "undefined" && (typeof id === "string" && id.includes(key) || id === key)) {
|
|
1082
|
+
return value;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
return null;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// src/shared/client/webpack-adapter.ts
|
|
1089
|
+
async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}) {
|
|
1090
|
+
const self = globalThis;
|
|
1091
|
+
if (!self.__remote_bundle_url__) {
|
|
1092
|
+
self.__remote_bundle_url__ = {};
|
|
1093
|
+
}
|
|
1094
|
+
self.__remote_bundle_url__[bundle ?? "default"] = url;
|
|
1095
|
+
self.__webpack_get_script_filename__ = () => null;
|
|
1096
|
+
if (typeof self.__webpack_require__ !== "function" || self.__webpack_require_type__ !== "turbopack") {
|
|
1097
|
+
if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
|
|
1098
|
+
self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
|
|
1099
|
+
self.__original_webpack_require__ = self.__webpack_require__;
|
|
1100
|
+
}
|
|
1101
|
+
self.__webpack_chunk_load__ = createChunkLoader(runtime);
|
|
1102
|
+
self.__webpack_require__ = createModuleRequire(runtime);
|
|
1103
|
+
self.__webpack_require_type__ = runtime;
|
|
1104
|
+
if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
|
|
1105
|
+
const remoteBundle = bundle ?? "default";
|
|
1106
|
+
self.__remote_webpack_require__[remoteBundle] = self.__webpack_require__;
|
|
1107
|
+
self.__remote_webpack_require__[remoteBundle].type = "turbopack";
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
if (runtime === RUNTIME_TURBOPACK) {
|
|
1111
|
+
await Promise.all(
|
|
1112
|
+
scripts.map((script) => {
|
|
1113
|
+
if (script.src) {
|
|
1114
|
+
return self.__webpack_chunk_load__?.(script.src, bundle);
|
|
1115
|
+
}
|
|
1116
|
+
return Promise.resolve(void 0);
|
|
1117
|
+
})
|
|
1118
|
+
);
|
|
1119
|
+
}
|
|
1120
|
+
const coreShared = {
|
|
1121
|
+
react: async () => (await import("react")).default,
|
|
1122
|
+
"react-dom": async () => (await import("react-dom")).default,
|
|
1123
|
+
"react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
|
|
1124
|
+
"react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
|
|
1125
|
+
"react-dom/client": async () => (await import("react-dom/client")).default,
|
|
1126
|
+
...shared
|
|
1127
|
+
};
|
|
1128
|
+
await initializeSharedModules(
|
|
1129
|
+
bundle ?? "default",
|
|
1130
|
+
// include all core modules as shared
|
|
1131
|
+
coreShared,
|
|
1132
|
+
remoteShared
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
function createModuleRequire(runtime) {
|
|
1136
|
+
return (id) => {
|
|
1137
|
+
const self = globalThis;
|
|
1138
|
+
const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? {
|
|
1139
|
+
bundle: "default",
|
|
1140
|
+
id
|
|
1141
|
+
};
|
|
1142
|
+
const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
|
|
1143
|
+
logDebug("WebpackAdapter", `remoteRuntime: "${remoteRuntime}"`);
|
|
1144
|
+
try {
|
|
1145
|
+
if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
|
|
1146
|
+
return self.__remote_webpack_require__?.[bundle]?.(moduleId);
|
|
1147
|
+
}
|
|
1148
|
+
const sharedModuleId = moduleId ?? id;
|
|
1149
|
+
const sharedModule = getSharedModule(bundle ?? "default", sharedModuleId);
|
|
1150
|
+
if (sharedModule) {
|
|
1151
|
+
return sharedModule;
|
|
1152
|
+
}
|
|
1153
|
+
if (bundle && moduleId) {
|
|
1154
|
+
return handleTurbopackModule(bundle, moduleId, id);
|
|
1155
|
+
}
|
|
1156
|
+
throw new Error(`Module "${id}" not found.`);
|
|
1157
|
+
} catch (requireError) {
|
|
1158
|
+
logWarn(
|
|
1159
|
+
"WebpackAdapter",
|
|
1160
|
+
`Module require failed: ${String(requireError)}`
|
|
1161
|
+
);
|
|
1162
|
+
if (typeof self.__original_webpack_require__ !== "function") {
|
|
1163
|
+
throw new RemoteComponentsError(
|
|
1164
|
+
`Module "${id}" not found in remote component bundle "${bundle}".`,
|
|
1165
|
+
{
|
|
1166
|
+
cause: requireError instanceof Error ? requireError : void 0
|
|
1167
|
+
}
|
|
1168
|
+
);
|
|
1169
|
+
}
|
|
1170
|
+
try {
|
|
1171
|
+
logDebug("WebpackAdapter", "Falling back to original webpack require");
|
|
1172
|
+
return self.__original_webpack_require__(id);
|
|
1173
|
+
} catch (originalError) {
|
|
1174
|
+
throw new RemoteComponentsError(
|
|
1175
|
+
`Module "${id}" not found in remote component bundle "${bundle}".`,
|
|
1176
|
+
{ cause: originalError instanceof Error ? originalError : void 0 }
|
|
1177
|
+
);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
// src/shared/client/component-loader.ts
|
|
1184
|
+
async function loadRemoteComponent({
|
|
1185
|
+
url,
|
|
1186
|
+
name,
|
|
1187
|
+
rscName,
|
|
1188
|
+
bundle,
|
|
1189
|
+
route = "/",
|
|
1190
|
+
runtime = "webpack",
|
|
1191
|
+
data,
|
|
1192
|
+
nextData,
|
|
1193
|
+
scripts = [],
|
|
1194
|
+
shared = Promise.resolve({}),
|
|
1195
|
+
remoteShared = {},
|
|
1196
|
+
container
|
|
1197
|
+
}) {
|
|
1198
|
+
try {
|
|
1199
|
+
if (runtime === "webpack") {
|
|
1200
|
+
const self = globalThis;
|
|
1201
|
+
if (!self.__DISABLE_WEBPACK_EXEC__) {
|
|
1202
|
+
self.__DISABLE_WEBPACK_EXEC__ = {};
|
|
1203
|
+
}
|
|
1204
|
+
self.__DISABLE_WEBPACK_EXEC__[bundle] = true;
|
|
1205
|
+
await loadScripts(scripts);
|
|
1206
|
+
}
|
|
1207
|
+
const hostShared = await shared;
|
|
1208
|
+
logDebug(
|
|
1209
|
+
"ComponentLoader",
|
|
1210
|
+
`loadRemoteComponent: bundle="${bundle}", name="${name}"`
|
|
1211
|
+
);
|
|
1212
|
+
logDebug(
|
|
1213
|
+
"ComponentLoader",
|
|
1214
|
+
`Host shared modules available: ${Object.keys(hostShared)}`
|
|
1215
|
+
);
|
|
1216
|
+
logDebug(
|
|
1217
|
+
"ComponentLoader",
|
|
1218
|
+
`Remote shared modules requested: ${JSON.stringify(remoteShared)}`
|
|
1219
|
+
);
|
|
1220
|
+
await setupWebpackRuntime(
|
|
1221
|
+
runtime,
|
|
1222
|
+
scripts,
|
|
1223
|
+
url,
|
|
1224
|
+
bundle,
|
|
1225
|
+
hostShared,
|
|
1226
|
+
remoteShared
|
|
1227
|
+
);
|
|
1228
|
+
if (bundle) {
|
|
1229
|
+
const resolve = {
|
|
1230
|
+
"/react/index.js": React,
|
|
1231
|
+
"/react/jsx-dev-runtime.js": JSXDevRuntime,
|
|
1232
|
+
"/react/jsx-runtime.js": JSXRuntime,
|
|
1233
|
+
"/react-dom/index.js": ReactDOM,
|
|
1234
|
+
"/react-dom/client.js": ReactDOMClient,
|
|
1235
|
+
...Object.entries(remoteShared).reduce(
|
|
1236
|
+
(acc, [key, value]) => {
|
|
1237
|
+
if (typeof hostShared[value] !== "undefined") {
|
|
1238
|
+
acc[key.replace(/^\(ssr\)\/(?<relative>\.\/)?/, "")] = hostShared[value];
|
|
1239
|
+
} else {
|
|
1240
|
+
logDebug(
|
|
1241
|
+
"ComponentLoader",
|
|
1242
|
+
`Remote requests "${value}" but host doesn't provide it`
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
return acc;
|
|
1246
|
+
},
|
|
1247
|
+
{}
|
|
1248
|
+
)
|
|
1249
|
+
};
|
|
1250
|
+
await Promise.all(
|
|
1251
|
+
Object.entries(resolve).map(async ([key, value]) => {
|
|
1252
|
+
if (typeof value === "function") {
|
|
1253
|
+
resolve[key] = await value(bundle);
|
|
1254
|
+
}
|
|
1255
|
+
return Promise.resolve(value);
|
|
1256
|
+
})
|
|
1257
|
+
);
|
|
1258
|
+
applySharedModules(bundle, resolve);
|
|
1259
|
+
} else {
|
|
1260
|
+
logWarn(
|
|
1261
|
+
"ComponentLoader",
|
|
1262
|
+
"No bundle specified, skipping shared module setup"
|
|
1263
|
+
);
|
|
1264
|
+
}
|
|
1265
|
+
if (data.length > 0) {
|
|
1266
|
+
return await loadRSCComponent(rscName ?? name, data);
|
|
1267
|
+
} else if (nextData) {
|
|
1268
|
+
return loadNextPagesComponent(bundle, route, nextData, name, container);
|
|
1269
|
+
}
|
|
1270
|
+
return loadRSCComponent(rscName ?? name, [`0:[null]
|
|
1271
|
+
`]);
|
|
1272
|
+
} catch (error) {
|
|
1273
|
+
return {
|
|
1274
|
+
component: null,
|
|
1275
|
+
error: new RemoteComponentsError(
|
|
1276
|
+
`Failed to load remote component "${name}".`,
|
|
1277
|
+
{
|
|
1278
|
+
cause: error instanceof Error ? error : new Error(String(error))
|
|
1279
|
+
}
|
|
1280
|
+
)
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
async function loadRSCComponent(rscName, data) {
|
|
1285
|
+
let createFromReadableStream;
|
|
1286
|
+
try {
|
|
1287
|
+
const { createFromReadableStream: _createFromReadableStream } = await import("next/dist/compiled/react-server-dom-webpack/client.browser");
|
|
1288
|
+
createFromReadableStream = _createFromReadableStream;
|
|
1289
|
+
} catch {
|
|
1290
|
+
const {
|
|
1291
|
+
default: { createFromReadableStream: _createFromReadableStream }
|
|
1292
|
+
} = await import("react-server-dom-webpack/client.browser");
|
|
1293
|
+
createFromReadableStream = _createFromReadableStream;
|
|
1294
|
+
}
|
|
1295
|
+
if (typeof createFromReadableStream !== "function") {
|
|
1296
|
+
throw new RemoteComponentsError(
|
|
1297
|
+
'Failed to import "react-server-dom-webpack". Is Next.js installed correctly?'
|
|
1298
|
+
);
|
|
1299
|
+
}
|
|
1300
|
+
const stream = createRSCStream(rscName, data);
|
|
1301
|
+
const component = createFromReadableStream(stream);
|
|
1302
|
+
return { component };
|
|
1303
|
+
}
|
|
1304
|
+
function loadNextPagesComponent(bundle, route, nextData, name, container) {
|
|
1305
|
+
const { Component, App } = nextClientPagesLoader(bundle, route, container);
|
|
1306
|
+
if (!Component) {
|
|
1307
|
+
throw new RemoteComponentsError(
|
|
1308
|
+
`Remote Component "${name}" is trying to load the component for route "${route}" but it is not available.`
|
|
1309
|
+
);
|
|
1310
|
+
}
|
|
1311
|
+
const component = App ? React.createElement(App, { Component, ...nextData.props }) : React.createElement(Component, nextData.props);
|
|
1312
|
+
return { component };
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
// src/shared/client/set-attributes-from-props.ts
|
|
1316
|
+
var DOMAttributeNames = {
|
|
1317
|
+
acceptCharset: "accept-charset",
|
|
1318
|
+
className: "class",
|
|
1319
|
+
htmlFor: "for",
|
|
1320
|
+
httpEquiv: "http-equiv",
|
|
1321
|
+
noModule: "noModule"
|
|
1322
|
+
};
|
|
1323
|
+
var ignoreProps = [
|
|
1324
|
+
"onLoad",
|
|
1325
|
+
"onReady",
|
|
1326
|
+
"dangerouslySetInnerHTML",
|
|
1327
|
+
"children",
|
|
1328
|
+
"onError",
|
|
1329
|
+
"strategy",
|
|
1330
|
+
"stylesheets"
|
|
1331
|
+
];
|
|
1332
|
+
function isBooleanScriptAttribute(attr) {
|
|
1333
|
+
return ["async", "defer", "noModule"].includes(attr);
|
|
1334
|
+
}
|
|
1335
|
+
function setAttributesFromProps(el, props) {
|
|
1336
|
+
for (const [p, value] of Object.entries(props)) {
|
|
1337
|
+
if (!Object.hasOwn(props, p))
|
|
1338
|
+
continue;
|
|
1339
|
+
if (ignoreProps.includes(p))
|
|
1340
|
+
continue;
|
|
1341
|
+
if (value === void 0) {
|
|
1342
|
+
continue;
|
|
1343
|
+
}
|
|
1344
|
+
const attr = DOMAttributeNames[p] || p.toLowerCase();
|
|
1345
|
+
if (el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr)) {
|
|
1346
|
+
el[attr] = Boolean(value);
|
|
1347
|
+
} else {
|
|
1348
|
+
el.setAttribute(attr, String(value));
|
|
1349
|
+
}
|
|
1350
|
+
if (value === false || el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr) && (!value || value === "false")) {
|
|
1351
|
+
el.setAttribute(attr, "");
|
|
1352
|
+
el.removeAttribute(attr);
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
// src/shared/client/static-loader.ts
|
|
1358
|
+
async function loadStaticRemoteComponent(scripts, url) {
|
|
1359
|
+
const self = globalThis;
|
|
1360
|
+
if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
1361
|
+
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
1362
|
+
}
|
|
1363
|
+
if (self.__remote_script_entrypoint_unmount__?.[url.href]) {
|
|
1364
|
+
self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
|
|
1365
|
+
}
|
|
1366
|
+
const mountUnmountSets = await Promise.all(
|
|
1367
|
+
scripts.map(async (script) => {
|
|
1368
|
+
try {
|
|
1369
|
+
let src = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
|
|
1370
|
+
if (!src && script.textContent) {
|
|
1371
|
+
const blob = new Blob(
|
|
1372
|
+
[
|
|
1373
|
+
script.textContent.replace(
|
|
1374
|
+
/import\.meta\.url/g,
|
|
1375
|
+
JSON.stringify(url)
|
|
1376
|
+
)
|
|
1377
|
+
],
|
|
1378
|
+
{
|
|
1379
|
+
type: "text/javascript"
|
|
1380
|
+
}
|
|
1381
|
+
);
|
|
1382
|
+
src = URL.createObjectURL(blob);
|
|
1383
|
+
}
|
|
1384
|
+
const mod = await import(
|
|
1385
|
+
/* @vite-ignore */
|
|
1386
|
+
/* webpackIgnore: true */
|
|
1387
|
+
new URL(src, url).href
|
|
1388
|
+
);
|
|
1389
|
+
if (src.startsWith("blob:")) {
|
|
1390
|
+
URL.revokeObjectURL(src);
|
|
1391
|
+
}
|
|
1392
|
+
if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
|
|
1393
|
+
if (!self.__remote_script_entrypoint_mount__) {
|
|
1394
|
+
self.__remote_script_entrypoint_mount__ = {};
|
|
1395
|
+
}
|
|
1396
|
+
if (!self.__remote_script_entrypoint_mount__[url.href]) {
|
|
1397
|
+
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
1398
|
+
}
|
|
1399
|
+
self.__remote_script_entrypoint_mount__[url.href]?.add(
|
|
1400
|
+
mod.mount || mod.default?.mount || (() => {
|
|
1401
|
+
})
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1404
|
+
if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
|
|
1405
|
+
if (!self.__remote_script_entrypoint_unmount__) {
|
|
1406
|
+
self.__remote_script_entrypoint_unmount__ = {};
|
|
1407
|
+
}
|
|
1408
|
+
if (!self.__remote_script_entrypoint_unmount__[url.href]) {
|
|
1409
|
+
self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
|
|
1410
|
+
}
|
|
1411
|
+
self.__remote_script_entrypoint_unmount__[url.href]?.add(
|
|
1412
|
+
mod.unmount || mod.default?.unmount || (() => {
|
|
1413
|
+
})
|
|
1414
|
+
);
|
|
1415
|
+
}
|
|
1416
|
+
return {
|
|
1417
|
+
mount: mod.mount || mod.default?.mount,
|
|
1418
|
+
unmount: mod.unmount || mod.default?.unmount
|
|
1419
|
+
};
|
|
1420
|
+
} catch (e) {
|
|
1421
|
+
console.error(
|
|
1422
|
+
new RemoteComponentsError(
|
|
1423
|
+
`Error loading remote component script from "${script.src || url.href}".`,
|
|
1424
|
+
{ cause: e }
|
|
1425
|
+
)
|
|
1426
|
+
);
|
|
1427
|
+
return {
|
|
1428
|
+
mount: void 0,
|
|
1429
|
+
unmount: void 0
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
})
|
|
1433
|
+
);
|
|
1434
|
+
return mountUnmountSets.reduce(
|
|
1435
|
+
(acc, { mount, unmount }) => {
|
|
1436
|
+
if (typeof mount === "function") {
|
|
1437
|
+
acc.mount.add(mount);
|
|
1438
|
+
}
|
|
1439
|
+
if (typeof unmount === "function") {
|
|
1440
|
+
acc.unmount.add(unmount);
|
|
1441
|
+
}
|
|
1442
|
+
return acc;
|
|
1443
|
+
},
|
|
1444
|
+
{
|
|
1445
|
+
mount: /* @__PURE__ */ new Set(),
|
|
1446
|
+
unmount: /* @__PURE__ */ new Set()
|
|
1447
|
+
}
|
|
1448
|
+
);
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
// src/shared/ssr/fetch-headers.ts
|
|
1452
|
+
function remoteFetchHeaders(additionalHeaders) {
|
|
1453
|
+
return {
|
|
1454
|
+
/**
|
|
1455
|
+
* Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
|
|
1456
|
+
* Ensure the automation bypass secret is the same on the client and host.
|
|
1457
|
+
* Otherwise, manually specify x-vercel-protection-bypass for the remote in the `additionalHeaders` parameter.
|
|
1458
|
+
*/
|
|
1459
|
+
...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
|
|
1460
|
+
"x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
|
|
1461
|
+
} : {},
|
|
1462
|
+
...Object.fromEntries(
|
|
1463
|
+
additionalHeaders instanceof Headers ? additionalHeaders.entries() : Object.entries(additionalHeaders ?? {})
|
|
1464
|
+
),
|
|
1465
|
+
Accept: "text/html"
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
// src/shared/ssr/get-client-or-server-url.ts
|
|
1470
|
+
function getClientOrServerUrl(src, serverFallback) {
|
|
1471
|
+
const fallback = typeof location !== "undefined" ? location.href : serverFallback;
|
|
1472
|
+
if (!src) {
|
|
1473
|
+
return new URL(fallback);
|
|
1474
|
+
}
|
|
1475
|
+
return typeof src === "string" ? new URL(src, fallback) : src;
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
// src/react/hooks/use-shadow-root.ts
|
|
28
1479
|
var import_react = require("react");
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
1480
|
+
function useShadowRoot({
|
|
1481
|
+
isolate,
|
|
1482
|
+
mode,
|
|
1483
|
+
keySuffix
|
|
1484
|
+
}) {
|
|
1485
|
+
const shadowRootContainerRef = (0, import_react.useRef)(null);
|
|
1486
|
+
const [shadowRoot, setShadowRoot] = (0, import_react.useState)(() => {
|
|
1487
|
+
const self = globalThis;
|
|
1488
|
+
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
1489
|
+
const ssrShadowRoot = typeof document !== "undefined" ? document.querySelector(
|
|
1490
|
+
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
1491
|
+
)?.shadowRoot ?? self[shadowRootKey] ?? null : null;
|
|
1492
|
+
self[shadowRootKey] = null;
|
|
1493
|
+
return ssrShadowRoot;
|
|
1494
|
+
});
|
|
1495
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
1496
|
+
if (isolate !== false && typeof document !== "undefined" && (!shadowRoot || !shadowRoot.isConnected)) {
|
|
1497
|
+
const self = globalThis;
|
|
1498
|
+
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
1499
|
+
let shadowRootElement = null;
|
|
1500
|
+
const element = document.querySelector(
|
|
1501
|
+
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
1502
|
+
);
|
|
1503
|
+
shadowRootElement = self[shadowRootKey] ?? element?.shadowRoot ?? null;
|
|
1504
|
+
if (!shadowRootElement && element) {
|
|
1505
|
+
try {
|
|
1506
|
+
shadowRootElement = element.attachShadow({ mode });
|
|
1507
|
+
self[shadowRootKey] = shadowRootElement;
|
|
1508
|
+
} catch {
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
if (shadowRootElement) {
|
|
1512
|
+
shadowRootElement.querySelectorAll("*:not(link)").forEach((node) => {
|
|
1513
|
+
node.remove();
|
|
1514
|
+
});
|
|
1515
|
+
setShadowRoot(shadowRootElement);
|
|
1516
|
+
}
|
|
1517
|
+
} else if (isolate === false && shadowRoot) {
|
|
1518
|
+
const self = globalThis;
|
|
1519
|
+
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
1520
|
+
self[shadowRootKey] = null;
|
|
1521
|
+
setShadowRoot(null);
|
|
1522
|
+
}
|
|
1523
|
+
}, [isolate, shadowRoot, mode, keySuffix]);
|
|
1524
|
+
return { shadowRoot, shadowRootContainerRef };
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
// src/react/utils/parse-remote-html.ts
|
|
1528
|
+
var DUMMY_FALLBACK = "http://remote-components-dummy-fallback";
|
|
38
1529
|
function getRemoteComponentHtml(html) {
|
|
39
1530
|
if (typeof document === "undefined")
|
|
40
1531
|
return html;
|
|
@@ -54,7 +1545,13 @@ function getRemoteComponentHtml(html) {
|
|
|
54
1545
|
}
|
|
55
1546
|
return "";
|
|
56
1547
|
}
|
|
57
|
-
|
|
1548
|
+
|
|
1549
|
+
// src/react/index.tsx
|
|
1550
|
+
var import_jsx_runtime2 = (
|
|
1551
|
+
// TODO: remove wrapper div by converting HTML to RSC or React tree
|
|
1552
|
+
require("react/jsx-runtime")
|
|
1553
|
+
);
|
|
1554
|
+
var import_react3 = require("react");
|
|
58
1555
|
function RemoteComponent({
|
|
59
1556
|
src,
|
|
60
1557
|
isolate,
|
|
@@ -70,6 +1567,7 @@ function RemoteComponent({
|
|
|
70
1567
|
onError,
|
|
71
1568
|
onChange
|
|
72
1569
|
}) {
|
|
1570
|
+
const instanceId = (0, import_react2.useId)();
|
|
73
1571
|
const name = (0, import_react2.useMemo)(() => {
|
|
74
1572
|
if (typeof src === "string") {
|
|
75
1573
|
const url2 = new URL(
|
|
@@ -85,19 +1583,14 @@ function RemoteComponent({
|
|
|
85
1583
|
return nameProp;
|
|
86
1584
|
}, [src, nameProp]);
|
|
87
1585
|
const [data, setData] = (0, import_react2.useState)(null);
|
|
88
|
-
const url = (0, import_react2.useMemo)(() =>
|
|
1586
|
+
const url = (0, import_react2.useMemo)(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);
|
|
89
1587
|
const id = url.origin === (typeof location !== "undefined" ? location.origin : DUMMY_FALLBACK) ? url.pathname : url.href;
|
|
90
|
-
const keySuffix = `${
|
|
1588
|
+
const keySuffix = `${escapeString(id)}_${escapeString(data?.name ?? name)}_${escapeString(instanceId)}`;
|
|
91
1589
|
const [remoteComponent, setRemoteComponent] = (0, import_react2.useState)(null);
|
|
92
|
-
const shadowRootContainerRef = (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const ssrShadowRoot = typeof document !== "undefined" ? document.querySelector(
|
|
97
|
-
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
98
|
-
)?.shadowRoot ?? self[shadowRootKey] ?? null : null;
|
|
99
|
-
self[shadowRootKey] = null;
|
|
100
|
-
return ssrShadowRoot;
|
|
1590
|
+
const { shadowRoot, shadowRootContainerRef } = useShadowRoot({
|
|
1591
|
+
isolate,
|
|
1592
|
+
mode,
|
|
1593
|
+
keySuffix
|
|
101
1594
|
});
|
|
102
1595
|
const htmlRef = (0, import_react2.useRef)(
|
|
103
1596
|
typeof document !== "undefined" ? document.querySelector(
|
|
@@ -125,6 +1618,12 @@ function RemoteComponent({
|
|
|
125
1618
|
const prevRemoteComponentContainerRef = (0, import_react2.useRef)(null);
|
|
126
1619
|
const unmountRef = (0, import_react2.useRef)(null);
|
|
127
1620
|
const prevNameRef = (0, import_react2.useRef)(void 0);
|
|
1621
|
+
(0, import_react2.useLayoutEffect)(() => {
|
|
1622
|
+
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
1623
|
+
return () => {
|
|
1624
|
+
delete globalThis[shadowRootKey];
|
|
1625
|
+
};
|
|
1626
|
+
}, [keySuffix]);
|
|
128
1627
|
(0, import_react2.useLayoutEffect)(() => {
|
|
129
1628
|
if (childrenRef.current.length > 0 && remoteComponent) {
|
|
130
1629
|
childrenRef.current.forEach((el) => {
|
|
@@ -132,29 +1631,7 @@ function RemoteComponent({
|
|
|
132
1631
|
});
|
|
133
1632
|
childrenRef.current = [];
|
|
134
1633
|
}
|
|
135
|
-
|
|
136
|
-
const self = globalThis;
|
|
137
|
-
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
138
|
-
let shadowRootElement = null;
|
|
139
|
-
const element = document.querySelector(
|
|
140
|
-
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
141
|
-
);
|
|
142
|
-
shadowRootElement = self[shadowRootKey] ?? element?.shadowRoot ?? null;
|
|
143
|
-
if (!shadowRootElement && element) {
|
|
144
|
-
try {
|
|
145
|
-
shadowRootElement = element.attachShadow({ mode });
|
|
146
|
-
self[shadowRootKey] = shadowRootElement;
|
|
147
|
-
} catch {
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (shadowRootElement) {
|
|
151
|
-
shadowRootElement.querySelectorAll("*:not(link)").forEach((node) => {
|
|
152
|
-
node.remove();
|
|
153
|
-
});
|
|
154
|
-
setShadowRoot(shadowRootElement);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}, [isolate, shadowRoot, remoteComponent, mode, keySuffix]);
|
|
1634
|
+
}, [remoteComponent]);
|
|
158
1635
|
(0, import_react2.useLayoutEffect)(() => {
|
|
159
1636
|
if (shadowRoot && remoteComponent) {
|
|
160
1637
|
const resetStyles = shadowRoot.querySelectorAll(
|
|
@@ -192,12 +1669,12 @@ function RemoteComponent({
|
|
|
192
1669
|
if (!html && src) {
|
|
193
1670
|
const fetchInit = {
|
|
194
1671
|
method: "GET",
|
|
195
|
-
headers:
|
|
1672
|
+
headers: remoteFetchHeaders(additionalHeaders),
|
|
196
1673
|
credentials
|
|
197
1674
|
};
|
|
198
1675
|
const res = await fetch(url, fetchInit);
|
|
199
1676
|
if (!res.ok) {
|
|
200
|
-
let error =
|
|
1677
|
+
let error = failedToFetchRemoteComponentError(
|
|
201
1678
|
url.href,
|
|
202
1679
|
res
|
|
203
1680
|
);
|
|
@@ -215,7 +1692,7 @@ function RemoteComponent({
|
|
|
215
1692
|
"data-next-error-stack"
|
|
216
1693
|
);
|
|
217
1694
|
if (errorMessage) {
|
|
218
|
-
error = new
|
|
1695
|
+
error = new RemoteComponentsError(errorMessage);
|
|
219
1696
|
if (errorStack) {
|
|
220
1697
|
error.stack = errorStack;
|
|
221
1698
|
}
|
|
@@ -233,7 +1710,7 @@ function RemoteComponent({
|
|
|
233
1710
|
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(
|
|
234
1711
|
`div[data-bundle][data-route][id^="${name}"]`
|
|
235
1712
|
) || doc.querySelectorAll("remote-component:not([src])").length > 1 && !doc.querySelector(`remote-component[name="${name}"]`)) {
|
|
236
|
-
throw
|
|
1713
|
+
throw multipleRemoteComponentsError(url.href);
|
|
237
1714
|
}
|
|
238
1715
|
const component = doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) ?? // fallback to the first element with the data-bundle and data-route attributes when not using a named remote component
|
|
239
1716
|
doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
|
|
@@ -249,8 +1726,8 @@ function RemoteComponent({
|
|
|
249
1726
|
const metadata = {
|
|
250
1727
|
name: remoteName,
|
|
251
1728
|
bundle,
|
|
252
|
-
route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname ||
|
|
253
|
-
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime ||
|
|
1729
|
+
route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
|
|
1730
|
+
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
|
|
254
1731
|
};
|
|
255
1732
|
const remoteSharedEl = doc.querySelector(
|
|
256
1733
|
`#${remoteName}_shared[data-remote-components-shared]`
|
|
@@ -258,7 +1735,7 @@ function RemoteComponent({
|
|
|
258
1735
|
const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
|
|
259
1736
|
remoteSharedEl?.remove();
|
|
260
1737
|
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
261
|
-
throw new
|
|
1738
|
+
throw new RemoteComponentsError(
|
|
262
1739
|
`Remote Component not found on ${url.href}.${remoteName !== "__vercel_remote_component" ? `The name for the <RemoteComponent> is "${remoteName}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
|
|
263
1740
|
);
|
|
264
1741
|
}
|
|
@@ -283,7 +1760,7 @@ function RemoteComponent({
|
|
|
283
1760
|
prevIsRemoteComponentRef.current = isRemoteComponent;
|
|
284
1761
|
prevUrlRef.current = url;
|
|
285
1762
|
prevNameRef.current = remoteName;
|
|
286
|
-
|
|
1763
|
+
applyOriginToNodes(doc, url);
|
|
287
1764
|
const links = Array.from(
|
|
288
1765
|
doc.querySelectorAll("link[href]")
|
|
289
1766
|
).filter((link) => {
|
|
@@ -292,7 +1769,7 @@ function RemoteComponent({
|
|
|
292
1769
|
href: new URL(link.getAttribute("href") ?? link.href, url).href,
|
|
293
1770
|
...link.getAttributeNames().reduce((acc, key) => {
|
|
294
1771
|
if (key !== "href") {
|
|
295
|
-
acc[
|
|
1772
|
+
acc[attrToProp[key] ?? key] = link.getAttribute(key) ?? "";
|
|
296
1773
|
}
|
|
297
1774
|
return acc;
|
|
298
1775
|
}, {})
|
|
@@ -350,16 +1827,16 @@ function RemoteComponent({
|
|
|
350
1827
|
if (typeof props.children === "string") {
|
|
351
1828
|
script.textContent = props.children;
|
|
352
1829
|
}
|
|
353
|
-
|
|
1830
|
+
setAttributesFromProps(script, props);
|
|
354
1831
|
document.head.appendChild(script);
|
|
355
1832
|
});
|
|
356
1833
|
self.__next_s = prevNextScripts;
|
|
357
1834
|
}
|
|
358
1835
|
let rscName;
|
|
359
1836
|
if (rsc) {
|
|
360
|
-
rscName = `__remote_component_rsc_${
|
|
1837
|
+
rscName = `__remote_component_rsc_${escapeString(
|
|
361
1838
|
id
|
|
362
|
-
)}_${
|
|
1839
|
+
)}_${escapeString(remoteName)}`;
|
|
363
1840
|
rsc.textContent = rsc.textContent?.replace(
|
|
364
1841
|
new RegExp(`self\\["${remoteName}"\\]`, "g"),
|
|
365
1842
|
`self["${rscName}"]`
|
|
@@ -383,7 +1860,7 @@ function RemoteComponent({
|
|
|
383
1860
|
throw e;
|
|
384
1861
|
});
|
|
385
1862
|
} else if ("__remote_components_missing_shared__" in remoteShared) {
|
|
386
|
-
throw new
|
|
1863
|
+
throw new RemoteComponentsError(
|
|
387
1864
|
remoteShared.__remote_components_missing_shared__
|
|
388
1865
|
);
|
|
389
1866
|
}
|
|
@@ -404,7 +1881,7 @@ function RemoteComponent({
|
|
|
404
1881
|
}
|
|
405
1882
|
shadowRoot.innerHTML = shadowRootHtml;
|
|
406
1883
|
setRemoteComponent(null);
|
|
407
|
-
const { mount, unmount } = await
|
|
1884
|
+
const { mount, unmount } = await loadStaticRemoteComponent(
|
|
408
1885
|
Array.from(shadowRoot.querySelectorAll("script")),
|
|
409
1886
|
url
|
|
410
1887
|
);
|
|
@@ -415,7 +1892,7 @@ function RemoteComponent({
|
|
|
415
1892
|
onLoad?.(src);
|
|
416
1893
|
} else if (isolate === false) {
|
|
417
1894
|
setRemoteComponent(
|
|
418
|
-
/* @__PURE__ */ (0,
|
|
1895
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
419
1896
|
"div",
|
|
420
1897
|
{
|
|
421
1898
|
dangerouslySetInnerHTML: { __html: component.innerHTML },
|
|
@@ -423,7 +1900,7 @@ function RemoteComponent({
|
|
|
423
1900
|
}
|
|
424
1901
|
)
|
|
425
1902
|
);
|
|
426
|
-
const { mount, unmount } = await
|
|
1903
|
+
const { mount, unmount } = await loadStaticRemoteComponent(
|
|
427
1904
|
Array.from(component.querySelectorAll("script")),
|
|
428
1905
|
url
|
|
429
1906
|
);
|
|
@@ -436,7 +1913,7 @@ function RemoteComponent({
|
|
|
436
1913
|
onLoad?.(src);
|
|
437
1914
|
}
|
|
438
1915
|
} else {
|
|
439
|
-
const result = await
|
|
1916
|
+
const result = await loadRemoteComponent({
|
|
440
1917
|
url,
|
|
441
1918
|
name: remoteName,
|
|
442
1919
|
rscName,
|
|
@@ -447,7 +1924,7 @@ function RemoteComponent({
|
|
|
447
1924
|
nextData,
|
|
448
1925
|
scripts: Array.from(scripts).map((script) => {
|
|
449
1926
|
const scriptSrc = script.getAttribute("data-src") || script.getAttribute("src") || script.src;
|
|
450
|
-
const { prefix, id: path } =
|
|
1927
|
+
const { prefix, id: path } = REMOTE_COMPONENT_REGEX.exec(
|
|
451
1928
|
scriptSrc
|
|
452
1929
|
)?.groups ?? {
|
|
453
1930
|
prefix: void 0,
|
|
@@ -464,7 +1941,7 @@ function RemoteComponent({
|
|
|
464
1941
|
};
|
|
465
1942
|
}),
|
|
466
1943
|
shared: {
|
|
467
|
-
...
|
|
1944
|
+
...sharedPolyfills(userShared),
|
|
468
1945
|
...userShared
|
|
469
1946
|
},
|
|
470
1947
|
remoteShared,
|
|
@@ -515,14 +1992,14 @@ function RemoteComponent({
|
|
|
515
1992
|
if (remoteComponent instanceof Error) {
|
|
516
1993
|
throw remoteComponent;
|
|
517
1994
|
}
|
|
518
|
-
const metadataJson = /* @__PURE__ */ (0,
|
|
1995
|
+
const metadataJson = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
|
|
519
1996
|
name: data?.name || name,
|
|
520
1997
|
bundle: data?.bundle || "default",
|
|
521
|
-
route: data?.route ||
|
|
522
|
-
runtime: prevIsRemoteComponentRef.current ?
|
|
1998
|
+
route: data?.route || DEFAULT_ROUTE,
|
|
1999
|
+
runtime: prevIsRemoteComponentRef.current ? RUNTIME_SCRIPT : data?.runtime || RUNTIME_WEBPACK
|
|
523
2000
|
}) });
|
|
524
|
-
const resetStyle = reset ? /* @__PURE__ */ (0,
|
|
525
|
-
const linksToRender = data?.links?.map((link) => /* @__PURE__ */ (0,
|
|
2001
|
+
const resetStyle = reset ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { "data-remote-components-reset": "react", children: `:host { all: initial; }` }) : null;
|
|
2002
|
+
const linksToRender = data?.links?.map((link) => /* @__PURE__ */ (0, import_react3.createElement)(
|
|
526
2003
|
"link",
|
|
527
2004
|
{
|
|
528
2005
|
...link,
|
|
@@ -530,7 +2007,7 @@ function RemoteComponent({
|
|
|
530
2007
|
key: JSON.stringify(link)
|
|
531
2008
|
}
|
|
532
2009
|
)) || null;
|
|
533
|
-
const componentToRender = /* @__PURE__ */ (0,
|
|
2010
|
+
const componentToRender = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
534
2011
|
resetStyle,
|
|
535
2012
|
linksToRender,
|
|
536
2013
|
remoteComponent ?? children
|
|
@@ -539,7 +2016,7 @@ function RemoteComponent({
|
|
|
539
2016
|
shadowRoot.innerHTML = componentHydrationHtml.current;
|
|
540
2017
|
componentHydrationHtml.current = null;
|
|
541
2018
|
if (prevIsRemoteComponentRef.current) {
|
|
542
|
-
|
|
2019
|
+
loadStaticRemoteComponent(
|
|
543
2020
|
Array.from(shadowRoot.querySelectorAll("script")),
|
|
544
2021
|
url
|
|
545
2022
|
).then(({ mount }) => {
|
|
@@ -551,7 +2028,7 @@ function RemoteComponent({
|
|
|
551
2028
|
onLoad?.(src);
|
|
552
2029
|
}
|
|
553
2030
|
}).catch((e) => {
|
|
554
|
-
const error = new
|
|
2031
|
+
const error = new RemoteComponentsError(
|
|
555
2032
|
`Error mounting remote component from "${url.href}"`,
|
|
556
2033
|
{
|
|
557
2034
|
cause: e
|
|
@@ -567,9 +2044,9 @@ function RemoteComponent({
|
|
|
567
2044
|
if (shadowRemoteComponentHtml) {
|
|
568
2045
|
shadowRemoteComponentHtml.remove();
|
|
569
2046
|
}
|
|
570
|
-
return /* @__PURE__ */ (0,
|
|
2047
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
571
2048
|
metadataJson,
|
|
572
|
-
/* @__PURE__ */ (0,
|
|
2049
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
573
2050
|
"div",
|
|
574
2051
|
{
|
|
575
2052
|
"data-remote-component-id": `shadowroot_${keySuffix}`,
|
|
@@ -578,8 +2055,8 @@ function RemoteComponent({
|
|
|
578
2055
|
children: [
|
|
579
2056
|
typeof document === "undefined" ? (
|
|
580
2057
|
// eslint-disable-next-line react/no-unknown-property
|
|
581
|
-
/* @__PURE__ */ (0,
|
|
582
|
-
typeof document === "undefined" ? /* @__PURE__ */ (0,
|
|
2058
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("template", { shadowrootmode: mode, children: [
|
|
2059
|
+
typeof document === "undefined" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
583
2060
|
"div",
|
|
584
2061
|
{
|
|
585
2062
|
dangerouslySetInnerHTML: {
|
|
@@ -601,12 +2078,12 @@ function RemoteComponent({
|
|
|
601
2078
|
] })
|
|
602
2079
|
) : null,
|
|
603
2080
|
shadowRoot && remoteComponent ? (0, import_react_dom.createPortal)(
|
|
604
|
-
/* @__PURE__ */ (0,
|
|
605
|
-
/* @__PURE__ */ (0,
|
|
2081
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2082
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("template", { id: `${name}_start` }),
|
|
606
2083
|
resetStyle,
|
|
607
2084
|
linksToRender,
|
|
608
2085
|
remoteComponent,
|
|
609
|
-
/* @__PURE__ */ (0,
|
|
2086
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("template", { id: `${name}_end`, ref: endTemplateRef })
|
|
610
2087
|
] }),
|
|
611
2088
|
shadowRoot
|
|
612
2089
|
) : null
|
|
@@ -616,11 +2093,11 @@ function RemoteComponent({
|
|
|
616
2093
|
] });
|
|
617
2094
|
}
|
|
618
2095
|
htmlRef.current = null;
|
|
619
|
-
return /* @__PURE__ */ (0,
|
|
620
|
-
/* @__PURE__ */ (0,
|
|
2096
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2097
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("template", { id: `${name}_start` }),
|
|
621
2098
|
metadataJson,
|
|
622
2099
|
componentToRender,
|
|
623
|
-
/* @__PURE__ */ (0,
|
|
2100
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("template", { id: `${name}_end`, ref: endTemplateRef })
|
|
624
2101
|
] });
|
|
625
2102
|
}
|
|
626
2103
|
// Annotate the CommonJS export names for ESM import in node:
|