remote-components 0.0.29 → 0.0.31

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