remote-components 0.0.34 → 0.0.36

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 (66) hide show
  1. package/dist/html/host.cjs +127 -117
  2. package/dist/html/host.cjs.map +1 -1
  3. package/dist/html/host.js +127 -117
  4. package/dist/html/host.js.map +1 -1
  5. package/dist/html/remote.cjs +4 -3
  6. package/dist/html/remote.cjs.map +1 -1
  7. package/dist/html/remote.js +4 -3
  8. package/dist/html/remote.js.map +1 -1
  9. package/dist/internal/next/host/app-router-client.cjs +4 -15
  10. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  11. package/dist/internal/next/host/app-router-client.js +10 -21
  12. package/dist/internal/next/host/app-router-client.js.map +1 -1
  13. package/dist/internal/next/host/app-router-compat.cjs.map +1 -1
  14. package/dist/internal/next/host/app-router-compat.d.ts +1 -1
  15. package/dist/internal/next/host/app-router-compat.js.map +1 -1
  16. package/dist/internal/next/remote/render-server.cjs +1 -1
  17. package/dist/internal/next/remote/render-server.cjs.map +1 -1
  18. package/dist/internal/next/remote/render-server.js +1 -1
  19. package/dist/internal/next/remote/render-server.js.map +1 -1
  20. package/dist/internal/shared/client/polyfill.cjs.map +1 -1
  21. package/dist/internal/shared/client/polyfill.js.map +1 -1
  22. package/dist/internal/shared/client/remote-component.cjs +179 -174
  23. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  24. package/dist/internal/shared/client/remote-component.d.ts +23 -23
  25. package/dist/internal/shared/client/remote-component.js +179 -174
  26. package/dist/internal/shared/client/remote-component.js.map +1 -1
  27. package/dist/internal/shared/error.cjs +1 -1
  28. package/dist/internal/shared/error.cjs.map +1 -1
  29. package/dist/internal/shared/error.js +1 -1
  30. package/dist/internal/shared/error.js.map +1 -1
  31. package/dist/internal/shared/ssr/dom-flight.cjs +7 -3
  32. package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
  33. package/dist/internal/shared/ssr/dom-flight.js +7 -3
  34. package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
  35. package/dist/internal/shared/ssr/fetch-remote-component.cjs +4 -4
  36. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  37. package/dist/internal/shared/ssr/fetch-remote-component.js +5 -5
  38. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  39. package/dist/next/config.cjs +100 -86
  40. package/dist/next/config.cjs.map +1 -1
  41. package/dist/next/config.js +100 -86
  42. package/dist/next/config.js.map +1 -1
  43. package/dist/next/host/app-router-server.cjs.map +1 -1
  44. package/dist/next/host/app-router-server.js +1 -1
  45. package/dist/next/host/app-router-server.js.map +1 -1
  46. package/dist/next/host/client/index.cjs +723 -718
  47. package/dist/next/host/client/index.cjs.map +1 -1
  48. package/dist/next/host/client/index.js +727 -722
  49. package/dist/next/host/client/index.js.map +1 -1
  50. package/dist/next/host/pages-router-server.cjs +4 -4
  51. package/dist/next/host/pages-router-server.cjs.map +1 -1
  52. package/dist/next/host/pages-router-server.js +4 -4
  53. package/dist/next/host/pages-router-server.js.map +1 -1
  54. package/dist/next/{middleware.cjs → proxy.cjs} +24 -14
  55. package/dist/next/proxy.cjs.map +1 -0
  56. package/dist/next/proxy.d.ts +29 -0
  57. package/dist/next/{middleware.js → proxy.js} +21 -11
  58. package/dist/next/proxy.js.map +1 -0
  59. package/dist/react/index.cjs +4 -4
  60. package/dist/react/index.cjs.map +1 -1
  61. package/dist/react/index.js +11 -11
  62. package/dist/react/index.js.map +1 -1
  63. package/package.json +15 -9
  64. package/dist/next/middleware.cjs.map +0 -1
  65. package/dist/next/middleware.d.ts +0 -29
  66. package/dist/next/middleware.js.map +0 -1
@@ -40,215 +40,562 @@ var Image = __toESM(require("next/image"), 1);
40
40
  var import_react = require("react");
41
41
  var import_react_dom = require("react-dom");
42
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 ?? {}
43
+ // src/shared/client/apply-origin.ts
44
+ var tagNames = [
45
+ "img",
46
+ "source",
47
+ "video",
48
+ "audio",
49
+ "track",
50
+ "iframe",
51
+ "embed",
52
+ "script",
53
+ "link"
54
+ ];
55
+ function applyOriginToNodes(doc, url) {
56
+ if (url.origin !== location.origin) {
57
+ const nodes = doc.querySelectorAll(
58
+ tagNames.map(
59
+ (type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
60
+ ).join(",")
56
61
  );
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));
62
+ nodes.forEach((node) => {
63
+ if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
64
+ node.src = new URL(node.getAttribute("src") ?? "/", url).href;
61
65
  }
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
- };
66
+ if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
67
+ node.setAttribute(
68
+ "href",
69
+ new URL(node.getAttribute("href") ?? "/", url).href
70
+ );
71
+ }
72
+ if (node.hasAttribute("srcset")) {
73
+ const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
74
+ const [urlPart, descriptor] = entry.trim().split(/\s+/);
75
+ if (!urlPart)
76
+ return entry;
77
+ const absoluteUrl = new URL(urlPart, url).href;
78
+ return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
79
+ }).join(", ");
80
+ if (srcSet) {
81
+ node.setAttribute("srcset", srcSet);
71
82
  }
72
83
  }
73
- }
74
- }
75
- }
76
-
77
- // src/shared/error.ts
78
- var RemoteComponentsError = class extends Error {
79
- constructor(message, options) {
80
- super(message, options);
81
- this.code = "REMOTE_COMPONENTS_ERROR";
82
- this.name = "RemoteComponentsError";
83
- }
84
- };
85
- function multipleRemoteComponentsError(url) {
86
- return new Error(
87
- `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.`
88
- );
89
- }
90
- function failedToFetchRemoteComponentError(url, error) {
91
- return new RemoteComponentsError(
92
- `Failed to fetch Remote Component from "${url}". Is the URL correct and accessible?`,
93
- { cause: error instanceof Error ? error : new Error(String(error)) }
94
- );
95
- }
96
-
97
- // src/shared/webpack/next-client-pages-loader.ts
98
- function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
99
- const self = globalThis;
100
- const nextCssOriginal = document.querySelector(
101
- `[id="__next_css__DO_NOT_USE__"]:not([data-bundle="${bundle}"][data-route="${route}"])`
102
- );
103
- if (nextCssOriginal) {
104
- nextCssOriginal.parentNode?.removeChild(nextCssOriginal);
105
- }
106
- const nextCss = document.createElement("noscript");
107
- nextCss.id = "__next_css__DO_NOT_USE__";
108
- nextCss.setAttribute("data-bundle", bundle);
109
- nextCss.setAttribute("data-route", route);
110
- const nextCssEnd = document.createElement("noscript");
111
- nextCssEnd.id = "__next_css__DO_NOT_USE_END__";
112
- nextCssEnd.setAttribute("data-bundle", bundle);
113
- nextCssEnd.setAttribute("data-route", route);
114
- document.head.appendChild(nextCssEnd);
115
- document.head.appendChild(nextCss);
116
- const componentLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
117
- (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
118
- ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
119
- (key) => key.includes("/next/dist/client/page-loader.js")
120
- ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
121
- (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
122
- ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
123
- (key) => key.includes("/next/dist/client/page-loader.js")
124
- ) ?? ""] ?? -1;
125
- const appLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
126
- (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
127
- ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
128
- (key) => key.includes("/next/dist/client/page-loader.js")
129
- ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
130
- (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
131
- ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
132
- (key) => key.includes("/next/dist/client/page-loader.js")
133
- ) ?? ""] ?? -1;
134
- if (!(componentLoaderChunk && appLoaderChunk)) {
135
- throw new RemoteComponentsError(
136
- `Next.js client pages loader not found in bundle "${bundle}".`
137
- );
138
- }
139
- const __NEXT_P_ORIGINAL = self.__NEXT_P;
140
- const selfOriginal = self;
141
- delete selfOriginal.__NEXT_P;
142
- self.__remote_webpack_require__?.[bundle]?.(
143
- self.__remote_webpack_require__[bundle].type !== "turbopack" ? componentLoaderChunk : `[${bundle}] ${componentLoaderChunk}`
144
- );
145
- if (typeof appLoaderChunk === "string" || typeof appLoaderChunk === "number" && appLoaderChunk !== -1) {
146
- self.__remote_webpack_require__?.[bundle]?.(
147
- self.__remote_webpack_require__[bundle].type !== "turbopack" ? appLoaderChunk : `[${bundle}] ${appLoaderChunk}`
148
- );
149
- }
150
- if (self.__NEXT_P) {
151
- const [, componentLoader] = self.__NEXT_P[0] ?? [
152
- void 0,
153
- () => ({ default: null })
154
- ];
155
- const [, appLoader] = self.__NEXT_P[2] ?? [
156
- void 0,
157
- () => ({
158
- default: null
159
- })
160
- ];
161
- const { default: Component } = componentLoader();
162
- const { default: App } = appLoader();
163
- if (!self.__remote_next_css__) {
164
- self.__remote_next_css__ = {};
165
- }
166
- if (!self.__remote_next_css__[bundle]) {
167
- const cssRE = /\.s?css$/;
168
- Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).filter((id) => cssRE.test(id)).forEach((id) => {
169
- self.__remote_webpack_require__?.[bundle]?.(id);
170
- });
171
- Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {}).filter((path) => cssRE.test(path)).forEach((path) => {
172
- const id = self.__remote_webpack_module_map__?.[bundle]?.[path];
173
- if (id) {
174
- self.__remote_webpack_require__?.[bundle]?.(id);
84
+ if (node.hasAttribute("imagesrcset")) {
85
+ const srcSet = node.getAttribute("imagesrcset")?.split(",").map((entry) => {
86
+ const [urlPart, descriptor] = entry.trim().split(/\s+/);
87
+ if (!urlPart)
88
+ return entry;
89
+ const absoluteUrl = new URL(urlPart, url).href;
90
+ return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
91
+ }).join(", ");
92
+ if (srcSet) {
93
+ node.setAttribute("imagesrcset", srcSet);
175
94
  }
176
- });
177
- const elements = [];
178
- let node = nextCss.previousSibling;
179
- while (node && node !== nextCssEnd) {
180
- elements.push(node);
181
- node.remove();
182
- node = nextCss.previousSibling;
183
95
  }
184
- self.__remote_next_css__[bundle] = elements;
185
- }
186
- if (styleContainer) {
187
- const elements = self.__remote_next_css__[bundle];
188
- elements.forEach((el) => {
189
- styleContainer.appendChild(el.cloneNode(true));
190
- });
191
- } else {
192
- const elements = self.__remote_next_css__[bundle];
193
- elements.forEach((el) => {
194
- document.head.appendChild(el);
195
- });
196
- }
197
- delete self.__NEXT_P;
198
- self.__NEXT_P = __NEXT_P_ORIGINAL;
199
- if (nextCssOriginal) {
200
- nextCssOriginal.parentNode?.appendChild(nextCssOriginal);
201
- }
202
- nextCss.remove();
203
- nextCssEnd.remove();
204
- return { Component, App };
96
+ });
205
97
  }
206
- return { Component: null, App: null };
207
- }
208
-
209
- // src/shared/utils/index.ts
210
- function escapeString(str) {
211
- return str.replace(/[^a-z0-9]/g, "_");
212
- }
213
- var attrToProp = {
214
- fetchpriority: "fetchPriority",
215
- crossorigin: "crossOrigin",
216
- imagesrcset: "imageSrcSet",
217
- imagesizes: "imageSizes",
218
- srcset: "srcSet"
219
- };
220
-
221
- // src/shared/client/const.ts
222
- var DEFAULT_ROUTE = "/";
223
- var RUNTIME_WEBPACK = "webpack";
224
- var RUNTIME_TURBOPACK = "turbopack";
225
- var RUNTIME_SCRIPT = "script";
226
- var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
227
- function getBundleKey(bundle) {
228
- return escapeString(bundle);
229
98
  }
230
99
 
231
- // src/shared/client/webpack-adapter.ts
232
- async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}) {
100
+ // src/shared/client/polyfill.tsx
101
+ var import_jsx_runtime = (
102
+ // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
103
+ require("react/jsx-runtime")
104
+ );
105
+ function applyBundleUrlToSrc(bundle, src) {
233
106
  const self = globalThis;
234
- if (!self.__remote_bundle_url__) {
235
- self.__remote_bundle_url__ = {};
107
+ if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {
108
+ return src;
236
109
  }
237
- self.__remote_bundle_url__[bundle ?? "default"] = url;
238
- self.__webpack_get_script_filename__ = () => null;
239
- if (typeof self.__webpack_require__ !== "function" || self.__webpack_require_type__ !== "turbopack") {
240
- if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
241
- self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
242
- self.__original_webpack_require__ = self.__webpack_require__;
243
- }
244
- self.__webpack_chunk_load__ = createChunkLoader(runtime);
245
- self.__webpack_require__ = createModuleRequire(runtime);
246
- self.__webpack_require_type__ = runtime;
247
- if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
248
- const remoteBundle = bundle ?? "default";
249
- self.__remote_webpack_require__[remoteBundle] = self.__webpack_require__;
250
- self.__remote_webpack_require__[remoteBundle].type = "turbopack";
251
- }
110
+ const { assetPrefix, path } = /^(?<assetPrefix>.*?)\/_next\/(?<path>.*)/.exec(src)?.groups ?? {};
111
+ if (!path) {
112
+ return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;
113
+ }
114
+ return `${self.__remote_bundle_url__?.[bundle]?.origin ?? ""}${assetPrefix}/_next/${path}`;
115
+ }
116
+ function applyBundleUrlToImagePropsSrc(bundle, src) {
117
+ if (typeof src === "string") {
118
+ return applyBundleUrlToSrc(bundle, src);
119
+ }
120
+ const propSrc = src;
121
+ return applyBundleUrlToSrc(bundle, propSrc.src);
122
+ }
123
+ var imageImpl = (bundle) => function RemoteImage({
124
+ fill: _fill,
125
+ loader: _loader,
126
+ quality: _quality,
127
+ priority: _priority,
128
+ loading: _loading,
129
+ placeholder: _placeholder,
130
+ blurDataURL: _blurDataURL,
131
+ unoptimized: _unoptimized,
132
+ overrideSrc: _overrideSrc,
133
+ src,
134
+ ...props
135
+ }) {
136
+ const newSrc = applyBundleUrlToImagePropsSrc(
137
+ bundle,
138
+ typeof src === "string" ? src : src.src
139
+ );
140
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
141
+ "img",
142
+ {
143
+ decoding: "async",
144
+ style: { color: "transparent" },
145
+ ...props,
146
+ src: newSrc,
147
+ suppressHydrationWarning: true
148
+ }
149
+ );
150
+ };
151
+ function sharedPolyfills(shared) {
152
+ const self = globalThis;
153
+ const polyfill = {
154
+ "next/dist/client/components/navigation": self.__remote_component_host_shared_modules__?.["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
155
+ useRouter() {
156
+ return {
157
+ push: (routerUrl) => {
158
+ history.pushState({}, "", routerUrl);
159
+ },
160
+ replace: (routerUrl) => {
161
+ history.replaceState({}, "", routerUrl);
162
+ },
163
+ back: () => {
164
+ history.back();
165
+ }
166
+ };
167
+ },
168
+ usePathname() {
169
+ return location.pathname;
170
+ },
171
+ useParams() {
172
+ return {};
173
+ },
174
+ useSearchParams() {
175
+ return new URLSearchParams(location.search);
176
+ },
177
+ useSelectedLayoutSegment() {
178
+ return null;
179
+ },
180
+ useSelectedLayoutSegments() {
181
+ return [];
182
+ },
183
+ __esModule: true
184
+ })),
185
+ "next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
186
+ default: ({
187
+ scroll: _,
188
+ replace,
189
+ prefetch,
190
+ onNavigate,
191
+ children,
192
+ ...props
193
+ }) => {
194
+ if (prefetch) {
195
+ console.warn(
196
+ "Next.js Link prefetch is not supported in remote components"
197
+ );
198
+ }
199
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
200
+ "a",
201
+ {
202
+ ...props,
203
+ href: props.href,
204
+ onClick: (e) => {
205
+ e.preventDefault();
206
+ let preventDefaulted = false;
207
+ e.preventDefault = () => {
208
+ preventDefaulted = true;
209
+ e.defaultPrevented = true;
210
+ };
211
+ if (typeof props.onClick === "function") {
212
+ props.onClick(e);
213
+ }
214
+ onNavigate?.(e);
215
+ if (preventDefaulted) {
216
+ return;
217
+ }
218
+ if (replace) {
219
+ history.replaceState({}, "", props.href);
220
+ } else {
221
+ history.pushState({}, "", props.href);
222
+ }
223
+ },
224
+ suppressHydrationWarning: true,
225
+ children: children ?? null
226
+ }
227
+ );
228
+ },
229
+ useLinkStatus() {
230
+ return { pending: false };
231
+ },
232
+ __esModule: true
233
+ })),
234
+ "next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
235
+ default: () => {
236
+ throw new Error("Next.js <Form> component not implemented");
237
+ },
238
+ __esModule: true
239
+ })),
240
+ "next/dist/client/image-component": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
241
+ Image: imageImpl(bundle),
242
+ __esModule: true
243
+ })),
244
+ "next/image": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
245
+ default: imageImpl(bundle),
246
+ getImageProps: (_imgProps) => {
247
+ throw new Error(
248
+ "Next.js getImageProps() is not implemented in remote components"
249
+ );
250
+ },
251
+ __esModule: true
252
+ })),
253
+ "next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
254
+ // TODO: implement <Script> component for non-Next.js host applications
255
+ // do not throw an error for now
256
+ default: () => null,
257
+ __esModule: true
258
+ })),
259
+ "next/router": self.__remote_component_host_shared_modules__?.["next/router"] ?? shared?.["next/router"] ?? (() => (
260
+ // TODO: incomplete implementation
261
+ Promise.resolve({
262
+ useRouter() {
263
+ return {
264
+ push: (routerUrl) => {
265
+ history.pushState({}, "", routerUrl);
266
+ },
267
+ replace: (routerUrl) => {
268
+ history.replaceState({}, "", routerUrl);
269
+ },
270
+ back: () => {
271
+ history.back();
272
+ }
273
+ };
274
+ },
275
+ __esModule: true
276
+ })
277
+ )),
278
+ "next/dist/build/polyfills/process": () => Promise.resolve({
279
+ default: {
280
+ env: {
281
+ NODE_ENV: "production"
282
+ }
283
+ },
284
+ __esModule: true
285
+ })
286
+ };
287
+ polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
288
+ polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
289
+ polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
290
+ polyfill["next/dist/api/image"] = polyfill["next/dist/client/image-component"];
291
+ polyfill["next/script"] = polyfill["next/dist/client/script"];
292
+ return polyfill;
293
+ }
294
+
295
+ // src/shared/error.ts
296
+ var RemoteComponentsError = class extends Error {
297
+ code = "REMOTE_COMPONENTS_ERROR";
298
+ constructor(message, options) {
299
+ super(message, options);
300
+ this.name = "RemoteComponentsError";
301
+ }
302
+ };
303
+ function multipleRemoteComponentsError(url) {
304
+ return new Error(
305
+ `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.`
306
+ );
307
+ }
308
+ function failedToFetchRemoteComponentError(url, error) {
309
+ return new RemoteComponentsError(
310
+ `Failed to fetch Remote Component from "${url}". Is the URL correct and accessible?`,
311
+ { cause: error instanceof Error ? error : new Error(String(error)) }
312
+ );
313
+ }
314
+
315
+ // src/shared/client/component-loader.ts
316
+ var React = __toESM(require("react"), 1);
317
+ var JSXDevRuntime = __toESM(require("react/jsx-dev-runtime"), 1);
318
+ var JSXRuntime = __toESM(require("react/jsx-runtime"), 1);
319
+ var ReactDOM = __toESM(require("react-dom"), 1);
320
+ var ReactDOMClient = __toESM(require("react-dom/client"), 1);
321
+
322
+ // src/shared/webpack/next-client-pages-loader.ts
323
+ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
324
+ const self = globalThis;
325
+ const nextCssOriginal = document.querySelector(
326
+ `[id="__next_css__DO_NOT_USE__"]:not([data-bundle="${bundle}"][data-route="${route}"])`
327
+ );
328
+ if (nextCssOriginal) {
329
+ nextCssOriginal.parentNode?.removeChild(nextCssOriginal);
330
+ }
331
+ const nextCss = document.createElement("noscript");
332
+ nextCss.id = "__next_css__DO_NOT_USE__";
333
+ nextCss.setAttribute("data-bundle", bundle);
334
+ nextCss.setAttribute("data-route", route);
335
+ const nextCssEnd = document.createElement("noscript");
336
+ nextCssEnd.id = "__next_css__DO_NOT_USE_END__";
337
+ nextCssEnd.setAttribute("data-bundle", bundle);
338
+ nextCssEnd.setAttribute("data-route", route);
339
+ document.head.appendChild(nextCssEnd);
340
+ document.head.appendChild(nextCss);
341
+ const componentLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
342
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
343
+ ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
344
+ (key) => key.includes("/next/dist/client/page-loader.js")
345
+ ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
346
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
347
+ ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
348
+ (key) => key.includes("/next/dist/client/page-loader.js")
349
+ ) ?? ""] ?? -1;
350
+ const appLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
351
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
352
+ ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
353
+ (key) => key.includes("/next/dist/client/page-loader.js")
354
+ ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
355
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
356
+ ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
357
+ (key) => key.includes("/next/dist/client/page-loader.js")
358
+ ) ?? ""] ?? -1;
359
+ if (!(componentLoaderChunk && appLoaderChunk)) {
360
+ throw new RemoteComponentsError(
361
+ `Next.js client pages loader not found in bundle "${bundle}".`
362
+ );
363
+ }
364
+ const __NEXT_P_ORIGINAL = self.__NEXT_P;
365
+ const selfOriginal = self;
366
+ delete selfOriginal.__NEXT_P;
367
+ self.__remote_webpack_require__?.[bundle]?.(
368
+ self.__remote_webpack_require__[bundle].type !== "turbopack" ? componentLoaderChunk : `[${bundle}] ${componentLoaderChunk}`
369
+ );
370
+ if (typeof appLoaderChunk === "string" || typeof appLoaderChunk === "number" && appLoaderChunk !== -1) {
371
+ self.__remote_webpack_require__?.[bundle]?.(
372
+ self.__remote_webpack_require__[bundle].type !== "turbopack" ? appLoaderChunk : `[${bundle}] ${appLoaderChunk}`
373
+ );
374
+ }
375
+ if (self.__NEXT_P) {
376
+ const [, componentLoader] = self.__NEXT_P[0] ?? [
377
+ void 0,
378
+ () => ({ default: null })
379
+ ];
380
+ const [, appLoader] = self.__NEXT_P[2] ?? [
381
+ void 0,
382
+ () => ({
383
+ default: null
384
+ })
385
+ ];
386
+ const { default: Component } = componentLoader();
387
+ const { default: App } = appLoader();
388
+ if (!self.__remote_next_css__) {
389
+ self.__remote_next_css__ = {};
390
+ }
391
+ if (!self.__remote_next_css__[bundle]) {
392
+ const cssRE = /\.s?css$/;
393
+ Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).filter((id) => cssRE.test(id)).forEach((id) => {
394
+ self.__remote_webpack_require__?.[bundle]?.(id);
395
+ });
396
+ Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {}).filter((path) => cssRE.test(path)).forEach((path) => {
397
+ const id = self.__remote_webpack_module_map__?.[bundle]?.[path];
398
+ if (id) {
399
+ self.__remote_webpack_require__?.[bundle]?.(id);
400
+ }
401
+ });
402
+ const elements = [];
403
+ let node = nextCss.previousSibling;
404
+ while (node && node !== nextCssEnd) {
405
+ elements.push(node);
406
+ node.remove();
407
+ node = nextCss.previousSibling;
408
+ }
409
+ self.__remote_next_css__[bundle] = elements;
410
+ }
411
+ if (styleContainer) {
412
+ const elements = self.__remote_next_css__[bundle];
413
+ elements.forEach((el) => {
414
+ styleContainer.appendChild(el.cloneNode(true));
415
+ });
416
+ } else {
417
+ const elements = self.__remote_next_css__[bundle];
418
+ elements.forEach((el) => {
419
+ document.head.appendChild(el);
420
+ });
421
+ }
422
+ delete self.__NEXT_P;
423
+ self.__NEXT_P = __NEXT_P_ORIGINAL;
424
+ if (nextCssOriginal) {
425
+ nextCssOriginal.parentNode?.appendChild(nextCssOriginal);
426
+ }
427
+ nextCss.remove();
428
+ nextCssEnd.remove();
429
+ return { Component, App };
430
+ }
431
+ return { Component: null, App: null };
432
+ }
433
+
434
+ // src/shared/webpack/shared-modules.ts
435
+ function applySharedModules(bundle, resolve) {
436
+ const self = globalThis;
437
+ if (self.__remote_webpack_require__?.[bundle]) {
438
+ const modulePaths = Object.keys(
439
+ self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
440
+ );
441
+ for (const [key, value] of Object.entries(resolve)) {
442
+ let ids = modulePaths.filter((p) => p === key);
443
+ if (ids.length === 0) {
444
+ ids = modulePaths.filter((p) => p.includes(key));
445
+ }
446
+ for (let id of ids) {
447
+ const webpackBundle = self.__remote_webpack_require__[bundle];
448
+ if (webpackBundle.m) {
449
+ if (self.__remote_webpack_module_map__?.[bundle]?.[id]) {
450
+ id = `${self.__remote_webpack_module_map__[bundle][id]}`;
451
+ }
452
+ webpackBundle.m[id] = (module2) => {
453
+ module2.exports = value;
454
+ };
455
+ }
456
+ }
457
+ }
458
+ }
459
+ }
460
+
461
+ // src/shared/client/rsc.ts
462
+ var import_web_streams_polyfill = require("web-streams-polyfill");
463
+ function fixPayload(payload) {
464
+ if (Array.isArray(payload)) {
465
+ if (payload[0] === "$") {
466
+ fixPayload(payload[3]);
467
+ if (payload.length === 4) {
468
+ payload.push(null, null, 1);
469
+ }
470
+ } else {
471
+ for (const item of payload) {
472
+ fixPayload(item);
473
+ }
474
+ }
475
+ } else if (typeof payload === "object" && payload !== null) {
476
+ for (const key in payload) {
477
+ fixPayload(payload[key]);
478
+ }
479
+ }
480
+ }
481
+ function createRSCStream(rscName, data) {
482
+ return new import_web_streams_polyfill.ReadableStream({
483
+ type: "bytes",
484
+ start(controller) {
485
+ const encoder = new TextEncoder();
486
+ const self = globalThis;
487
+ if (data.length > 0) {
488
+ data.forEach((chunk) => {
489
+ const lines = chunk.split("\n");
490
+ for (const line of lines) {
491
+ const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
492
+ if (match?.groups?.rsc) {
493
+ self[rscName] = self[rscName] ?? [];
494
+ self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
495
+ }
496
+ }
497
+ });
498
+ }
499
+ const allChunks = (self[rscName] ?? [`0:[null]
500
+ `]).join("");
501
+ self[rscName] = null;
502
+ allChunks.split("\n").forEach((chunk) => {
503
+ if (chunk.length > 0) {
504
+ const { before, id, prefix, payload } = /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
505
+ chunk
506
+ )?.groups ?? {};
507
+ if (payload) {
508
+ const jsonPayload = JSON.parse(payload);
509
+ fixPayload(jsonPayload);
510
+ const reconstruct = `${before ?? ""}${id}:${prefix ?? ""}${JSON.stringify(jsonPayload)}`;
511
+ controller.enqueue(encoder.encode(`${reconstruct}
512
+ `));
513
+ } else {
514
+ controller.enqueue(encoder.encode(`${chunk}
515
+ `));
516
+ }
517
+ } else {
518
+ controller.enqueue(encoder.encode(`${chunk}
519
+ `));
520
+ }
521
+ });
522
+ controller.close();
523
+ }
524
+ });
525
+ }
526
+
527
+ // src/shared/client/script-loader.ts
528
+ async function loadScripts(scripts) {
529
+ await Promise.all(
530
+ scripts.map((script) => {
531
+ return new Promise((resolve, reject) => {
532
+ const newSrc = new URL(
533
+ // remove the remote component bundle name identifier from the script src
534
+ script.src.replace(/\/_next\/\[.+\](?<whitespace>%20| )/, "/_next/"),
535
+ location.origin
536
+ ).href;
537
+ const newScript = document.createElement("script");
538
+ newScript.onload = () => {
539
+ resolve();
540
+ };
541
+ newScript.onerror = () => {
542
+ reject(
543
+ new RemoteComponentsError(
544
+ `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
545
+ )
546
+ );
547
+ };
548
+ newScript.src = newSrc;
549
+ newScript.async = true;
550
+ document.head.appendChild(newScript);
551
+ });
552
+ })
553
+ );
554
+ }
555
+
556
+ // src/shared/utils/index.ts
557
+ function escapeString(str) {
558
+ return str.replace(/[^a-z0-9]/g, "_");
559
+ }
560
+ var attrToProp = {
561
+ fetchpriority: "fetchPriority",
562
+ crossorigin: "crossOrigin",
563
+ imagesrcset: "imageSrcSet",
564
+ imagesizes: "imageSizes",
565
+ srcset: "srcSet"
566
+ };
567
+
568
+ // src/shared/client/const.ts
569
+ var DEFAULT_ROUTE = "/";
570
+ var RUNTIME_WEBPACK = "webpack";
571
+ var RUNTIME_TURBOPACK = "turbopack";
572
+ var RUNTIME_SCRIPT = "script";
573
+ var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
574
+ function getBundleKey(bundle) {
575
+ return escapeString(bundle);
576
+ }
577
+
578
+ // src/shared/client/webpack-adapter.ts
579
+ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}) {
580
+ const self = globalThis;
581
+ if (!self.__remote_bundle_url__) {
582
+ self.__remote_bundle_url__ = {};
583
+ }
584
+ self.__remote_bundle_url__[bundle ?? "default"] = url;
585
+ self.__webpack_get_script_filename__ = () => null;
586
+ if (typeof self.__webpack_require__ !== "function" || self.__webpack_require_type__ !== "turbopack") {
587
+ if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
588
+ self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
589
+ self.__original_webpack_require__ = self.__webpack_require__;
590
+ }
591
+ self.__webpack_chunk_load__ = createChunkLoader(runtime);
592
+ self.__webpack_require__ = createModuleRequire(runtime);
593
+ self.__webpack_require_type__ = runtime;
594
+ if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
595
+ const remoteBundle = bundle ?? "default";
596
+ self.__remote_webpack_require__[remoteBundle] = self.__webpack_require__;
597
+ self.__remote_webpack_require__[remoteBundle].type = "turbopack";
598
+ }
252
599
  }
253
600
  if (runtime === RUNTIME_TURBOPACK) {
254
601
  await Promise.all(
@@ -391,7 +738,10 @@ async function handleTurbopackChunk(code, bundle, url) {
391
738
  function createModuleRequire(runtime) {
392
739
  return (id) => {
393
740
  const self = globalThis;
394
- const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? { bundle: "default", id };
741
+ const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? {
742
+ bundle: "default",
743
+ id
744
+ };
395
745
  const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
396
746
  try {
397
747
  if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
@@ -634,192 +984,97 @@ function handleTurbopackModule(bundle, moduleId, id) {
634
984
  let mod;
635
985
  if (typeof importId === "string") {
636
986
  const { exportSource, exportName } = /\s+<export (?<exportSource>.*?) as (?<exportName>.*?)>$/.exec(
637
- importId
638
- )?.groups ?? {};
639
- const normalizedId = importId.replace(
640
- /\s+<export(?<specifier>.*)>$/,
641
- ""
642
- );
643
- mod = self.__webpack_require__?.(
644
- `[${bundle}] ${normalizedId}`
645
- );
646
- if (exportSource && exportName && (exportSource === "*" || typeof mod[exportSource] !== "undefined") && typeof mod[exportName] === "undefined") {
647
- if (exportSource === "*") {
648
- mod[exportName] = mod;
649
- } else {
650
- mod[exportName] = mod[exportSource];
651
- }
652
- }
653
- } else {
654
- mod = self.__webpack_require__?.(`[${bundle}] ${importId}`);
655
- }
656
- if (typeof mod !== "object") {
657
- mod = { default: mod };
658
- } else if (!("default" in mod) && // eslint-disable-next-line @typescript-eslint/no-base-to-string
659
- mod.toString() !== "[object Module]") {
660
- try {
661
- mod.default = mod;
662
- } catch {
663
- }
664
- }
665
- return mod;
666
- },
667
- // require
668
- r(requireId) {
669
- return self.__webpack_require__?.(`[${bundle}] ${requireId}`);
670
- },
671
- // value exports
672
- v(value) {
673
- if (typeof value === "function") {
674
- exports.default = value((vid) => {
675
- return self.__webpack_require__?.(`[${bundle}] ${vid}`);
676
- });
677
- } else {
678
- moduleExports.exports = value;
679
- }
680
- },
681
- // async module initializer
682
- async a(mod) {
683
- let result;
684
- await mod(
685
- () => {
686
- },
687
- (value) => result = value
688
- );
689
- exports.default = result;
690
- },
691
- // async module loader
692
- async A(Aid) {
693
- const mod = self.__webpack_require__?.(`[${bundle}] ${Aid}`);
694
- return mod.default(
695
- (parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
696
- );
697
- },
698
- // chunk loader
699
- l(url) {
700
- const moduleInitIndex = allModules.indexOf(moduleInit);
701
- if (moduleInitIndex !== -1) {
702
- const scriptIndex = allModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
703
- if (scriptIndex !== -1) {
704
- const script = allModules[scriptIndex];
705
- const scriptSrc = script.getAttribute("data-turbopack-src") || "";
706
- const nextIndex = scriptSrc.indexOf("/_next");
707
- const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
708
- const bundleUrl = `[${bundle}] ${baseUrl}/_next/${url}`;
709
- return self.__webpack_chunk_load__?.(bundleUrl, bundle);
710
- }
711
- }
712
- throw new Error(
713
- `Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
714
- );
715
- },
716
- // global
717
- g: self.__remote_components_turbopack_global__[bundle],
718
- m: moduleExports,
719
- e: exports
720
- },
721
- moduleExports,
722
- exports
723
- );
724
- if (self.__remote_components_turbopack_modules__[bundle][moduleId] !== moduleExports.exports) {
725
- self.__remote_components_turbopack_modules__[bundle][moduleId] = moduleExports.exports;
726
- }
727
- return moduleExports.exports;
728
- }
729
-
730
- // src/shared/client/script-loader.ts
731
- async function loadScripts(scripts) {
732
- await Promise.all(
733
- scripts.map((script) => {
734
- return new Promise((resolve, reject) => {
735
- const newSrc = new URL(
736
- // remove the remote component bundle name identifier from the script src
737
- script.src.replace(/\/_next\/\[.+\](?<whitespace>%20| )/, "/_next/"),
738
- location.origin
739
- ).href;
740
- const newScript = document.createElement("script");
741
- newScript.onload = () => {
742
- resolve();
743
- };
744
- newScript.onerror = () => {
745
- reject(
746
- new RemoteComponentsError(
747
- `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
748
- )
749
- );
750
- };
751
- newScript.src = newSrc;
752
- newScript.async = true;
753
- document.head.appendChild(newScript);
754
- });
755
- })
756
- );
757
- }
758
-
759
- // src/shared/client/rsc.ts
760
- var import_web_streams_polyfill = require("web-streams-polyfill");
761
- function fixPayload(payload) {
762
- if (Array.isArray(payload)) {
763
- if (payload[0] === "$") {
764
- fixPayload(payload[3]);
765
- if (payload.length === 4) {
766
- payload.push(null, null, 1);
767
- }
768
- } else {
769
- for (const item of payload) {
770
- fixPayload(item);
771
- }
772
- }
773
- } else if (typeof payload === "object" && payload !== null) {
774
- for (const key in payload) {
775
- fixPayload(payload[key]);
776
- }
777
- }
778
- }
779
- function createRSCStream(rscName, data) {
780
- return new import_web_streams_polyfill.ReadableStream({
781
- type: "bytes",
782
- start(controller) {
783
- const encoder = new TextEncoder();
784
- const self = globalThis;
785
- if (data.length > 0) {
786
- data.forEach((chunk) => {
787
- const lines = chunk.split("\n");
788
- for (const line of lines) {
789
- const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
790
- if (match?.groups?.rsc) {
791
- self[rscName] = self[rscName] ?? [];
792
- self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
793
- }
794
- }
795
- });
796
- }
797
- const allChunks = (self[rscName] ?? [`0:[null]
798
- `]).join("");
799
- self[rscName] = null;
800
- allChunks.split("\n").forEach((chunk) => {
801
- if (chunk.length > 0) {
802
- const { before, id, prefix, payload } = /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
803
- chunk
804
- )?.groups ?? {};
805
- if (payload) {
806
- const jsonPayload = JSON.parse(payload);
807
- fixPayload(jsonPayload);
808
- const reconstruct = `${before ?? ""}${id}:${prefix ?? ""}${JSON.stringify(jsonPayload)}`;
809
- controller.enqueue(encoder.encode(`${reconstruct}
810
- `));
811
- } else {
812
- controller.enqueue(encoder.encode(`${chunk}
813
- `));
987
+ importId
988
+ )?.groups ?? {};
989
+ const normalizedId = importId.replace(
990
+ /\s+<export(?<specifier>.*)>$/,
991
+ ""
992
+ );
993
+ mod = self.__webpack_require__?.(
994
+ `[${bundle}] ${normalizedId}`
995
+ );
996
+ if (exportSource && exportName && (exportSource === "*" || typeof mod[exportSource] !== "undefined") && typeof mod[exportName] === "undefined") {
997
+ if (exportSource === "*") {
998
+ mod[exportName] = mod;
999
+ } else {
1000
+ mod[exportName] = mod[exportSource];
1001
+ }
814
1002
  }
815
1003
  } else {
816
- controller.enqueue(encoder.encode(`${chunk}
817
- `));
1004
+ mod = self.__webpack_require__?.(`[${bundle}] ${importId}`);
818
1005
  }
819
- });
820
- controller.close();
821
- }
822
- });
1006
+ if (typeof mod !== "object") {
1007
+ mod = { default: mod };
1008
+ } else if (!("default" in mod) && // eslint-disable-next-line @typescript-eslint/no-base-to-string
1009
+ mod.toString() !== "[object Module]") {
1010
+ try {
1011
+ mod.default = mod;
1012
+ } catch {
1013
+ }
1014
+ }
1015
+ return mod;
1016
+ },
1017
+ // require
1018
+ r(requireId) {
1019
+ return self.__webpack_require__?.(`[${bundle}] ${requireId}`);
1020
+ },
1021
+ // value exports
1022
+ v(value) {
1023
+ if (typeof value === "function") {
1024
+ exports.default = value((vid) => {
1025
+ return self.__webpack_require__?.(`[${bundle}] ${vid}`);
1026
+ });
1027
+ } else {
1028
+ moduleExports.exports = value;
1029
+ }
1030
+ },
1031
+ // async module initializer
1032
+ async a(mod) {
1033
+ let result;
1034
+ await mod(
1035
+ () => {
1036
+ },
1037
+ (value) => result = value
1038
+ );
1039
+ exports.default = result;
1040
+ },
1041
+ // async module loader
1042
+ async A(Aid) {
1043
+ const mod = self.__webpack_require__?.(`[${bundle}] ${Aid}`);
1044
+ return mod.default(
1045
+ (parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
1046
+ );
1047
+ },
1048
+ // chunk loader
1049
+ l(url) {
1050
+ const moduleInitIndex = allModules.indexOf(moduleInit);
1051
+ if (moduleInitIndex !== -1) {
1052
+ const scriptIndex = allModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
1053
+ if (scriptIndex !== -1) {
1054
+ const script = allModules[scriptIndex];
1055
+ const scriptSrc = script.getAttribute("data-turbopack-src") || "";
1056
+ const nextIndex = scriptSrc.indexOf("/_next");
1057
+ const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
1058
+ const bundleUrl = `[${bundle}] ${baseUrl}/_next/${url}`;
1059
+ return self.__webpack_chunk_load__?.(bundleUrl, bundle);
1060
+ }
1061
+ }
1062
+ throw new Error(
1063
+ `Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
1064
+ );
1065
+ },
1066
+ // global
1067
+ g: self.__remote_components_turbopack_global__[bundle],
1068
+ m: moduleExports,
1069
+ e: exports
1070
+ },
1071
+ moduleExports,
1072
+ exports
1073
+ );
1074
+ if (self.__remote_components_turbopack_modules__[bundle][moduleId] !== moduleExports.exports) {
1075
+ self.__remote_components_turbopack_modules__[bundle][moduleId] = moduleExports.exports;
1076
+ }
1077
+ return moduleExports.exports;
823
1078
  }
824
1079
 
825
1080
  // src/shared/client/component-loader.ts
@@ -894,7 +1149,9 @@ async function loadRemoteComponent({
894
1149
  component: null,
895
1150
  error: new RemoteComponentsError(
896
1151
  `Failed to load remote component "${name}".`,
897
- { cause: error instanceof Error ? error : new Error(String(error)) }
1152
+ {
1153
+ cause: error instanceof Error ? error : new Error(String(error))
1154
+ }
898
1155
  )
899
1156
  };
900
1157
  }
@@ -930,100 +1187,6 @@ function loadNextPagesComponent(bundle, route, nextData, name, container) {
930
1187
  return { component };
931
1188
  }
932
1189
 
933
- // src/shared/client/static-loader.ts
934
- async function loadStaticRemoteComponent(scripts, url) {
935
- const self = globalThis;
936
- if (self.__remote_script_entrypoint_mount__?.[url.href]) {
937
- self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
938
- }
939
- if (self.__remote_script_entrypoint_unmount__?.[url.href]) {
940
- self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
941
- }
942
- const mountUnmountSets = await Promise.all(
943
- scripts.map(async (script) => {
944
- try {
945
- let src = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
946
- if (!src && script.textContent) {
947
- const blob = new Blob(
948
- [
949
- script.textContent.replace(
950
- /import\.meta\.url/g,
951
- JSON.stringify(url)
952
- )
953
- ],
954
- {
955
- type: "text/javascript"
956
- }
957
- );
958
- src = URL.createObjectURL(blob);
959
- }
960
- const mod = await import(
961
- /* @vite-ignore */
962
- /* webpackIgnore: true */
963
- new URL(src, url).href
964
- );
965
- if (src.startsWith("blob:")) {
966
- URL.revokeObjectURL(src);
967
- }
968
- if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
969
- if (!self.__remote_script_entrypoint_mount__) {
970
- self.__remote_script_entrypoint_mount__ = {};
971
- }
972
- if (!self.__remote_script_entrypoint_mount__[url.href]) {
973
- self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
974
- }
975
- self.__remote_script_entrypoint_mount__[url.href]?.add(
976
- mod.mount || mod.default?.mount || (() => {
977
- })
978
- );
979
- }
980
- if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
981
- if (!self.__remote_script_entrypoint_unmount__) {
982
- self.__remote_script_entrypoint_unmount__ = {};
983
- }
984
- if (!self.__remote_script_entrypoint_unmount__[url.href]) {
985
- self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
986
- }
987
- self.__remote_script_entrypoint_unmount__[url.href]?.add(
988
- mod.unmount || mod.default?.unmount || (() => {
989
- })
990
- );
991
- }
992
- return {
993
- mount: mod.mount || mod.default?.mount,
994
- unmount: mod.unmount || mod.default?.unmount
995
- };
996
- } catch (e) {
997
- console.error(
998
- new RemoteComponentsError(
999
- `Error loading remote component script from "${script.src || url.href}".`,
1000
- { cause: e }
1001
- )
1002
- );
1003
- return {
1004
- mount: void 0,
1005
- unmount: void 0
1006
- };
1007
- }
1008
- })
1009
- );
1010
- return mountUnmountSets.reduce(
1011
- (acc, { mount, unmount }) => {
1012
- if (typeof mount === "function") {
1013
- acc.mount.add(mount);
1014
- }
1015
- if (typeof unmount === "function") {
1016
- acc.unmount.add(unmount);
1017
- }
1018
- return acc;
1019
- },
1020
- {
1021
- mount: /* @__PURE__ */ new Set(),
1022
- unmount: /* @__PURE__ */ new Set()
1023
- }
1024
- );
1025
- }
1026
-
1027
1190
  // src/shared/client/set-attributes-from-props.ts
1028
1191
  var DOMAttributeNames = {
1029
1192
  acceptCharset: "accept-charset",
@@ -1046,7 +1209,7 @@ function isBooleanScriptAttribute(attr) {
1046
1209
  }
1047
1210
  function setAttributesFromProps(el, props) {
1048
1211
  for (const [p, value] of Object.entries(props)) {
1049
- if (!Object.prototype.hasOwnProperty.call(props, p))
1212
+ if (!Object.hasOwn(props, p))
1050
1213
  continue;
1051
1214
  if (ignoreProps.includes(p))
1052
1215
  continue;
@@ -1066,256 +1229,98 @@ function setAttributesFromProps(el, props) {
1066
1229
  }
1067
1230
  }
1068
1231
 
1069
- // src/shared/client/polyfill.tsx
1070
- var import_jsx_runtime = (
1071
- // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
1072
- require("react/jsx-runtime")
1073
- );
1074
- function applyBundleUrlToSrc(bundle, src) {
1075
- const self = globalThis;
1076
- if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {
1077
- return src;
1078
- }
1079
- const { assetPrefix, path } = /^(?<assetPrefix>.*?)\/_next\/(?<path>.*)/.exec(src)?.groups ?? {};
1080
- if (!path) {
1081
- return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;
1082
- }
1083
- return `${self.__remote_bundle_url__?.[bundle]?.origin ?? ""}${assetPrefix}/_next/${path}`;
1084
- }
1085
- function applyBundleUrlToImagePropsSrc(bundle, src) {
1086
- if (typeof src === "string") {
1087
- return applyBundleUrlToSrc(bundle, src);
1088
- }
1089
- const propSrc = src;
1090
- return applyBundleUrlToSrc(bundle, propSrc.src);
1091
- }
1092
- var imageImpl = (bundle) => function RemoteImage({
1093
- fill: _fill,
1094
- loader: _loader,
1095
- quality: _quality,
1096
- priority: _priority,
1097
- loading: _loading,
1098
- placeholder: _placeholder,
1099
- blurDataURL: _blurDataURL,
1100
- unoptimized: _unoptimized,
1101
- overrideSrc: _overrideSrc,
1102
- src,
1103
- ...props
1104
- }) {
1105
- const newSrc = applyBundleUrlToImagePropsSrc(
1106
- bundle,
1107
- typeof src === "string" ? src : src.src
1108
- );
1109
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1110
- "img",
1111
- {
1112
- decoding: "async",
1113
- style: { color: "transparent" },
1114
- ...props,
1115
- src: newSrc,
1116
- suppressHydrationWarning: true
1117
- }
1118
- );
1119
- };
1120
- function sharedPolyfills(shared) {
1232
+ // src/shared/client/static-loader.ts
1233
+ async function loadStaticRemoteComponent(scripts, url) {
1121
1234
  const self = globalThis;
1122
- const polyfill = {
1123
- "next/dist/client/components/navigation": self.__remote_component_host_shared_modules__?.["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
1124
- useRouter() {
1125
- return {
1126
- push: (routerUrl) => {
1127
- history.pushState({}, "", routerUrl);
1128
- },
1129
- replace: (routerUrl) => {
1130
- history.replaceState({}, "", routerUrl);
1131
- },
1132
- back: () => {
1133
- history.back();
1235
+ if (self.__remote_script_entrypoint_mount__?.[url.href]) {
1236
+ self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
1237
+ }
1238
+ if (self.__remote_script_entrypoint_unmount__?.[url.href]) {
1239
+ self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
1240
+ }
1241
+ const mountUnmountSets = await Promise.all(
1242
+ scripts.map(async (script) => {
1243
+ try {
1244
+ let src = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
1245
+ if (!src && script.textContent) {
1246
+ const blob = new Blob(
1247
+ [
1248
+ script.textContent.replace(
1249
+ /import\.meta\.url/g,
1250
+ JSON.stringify(url)
1251
+ )
1252
+ ],
1253
+ {
1254
+ type: "text/javascript"
1255
+ }
1256
+ );
1257
+ src = URL.createObjectURL(blob);
1258
+ }
1259
+ const mod = await import(
1260
+ /* @vite-ignore */
1261
+ /* webpackIgnore: true */
1262
+ new URL(src, url).href
1263
+ );
1264
+ if (src.startsWith("blob:")) {
1265
+ URL.revokeObjectURL(src);
1266
+ }
1267
+ if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
1268
+ if (!self.__remote_script_entrypoint_mount__) {
1269
+ self.__remote_script_entrypoint_mount__ = {};
1134
1270
  }
1135
- };
1136
- },
1137
- usePathname() {
1138
- return location.pathname;
1139
- },
1140
- useParams() {
1141
- return {};
1142
- },
1143
- useSearchParams() {
1144
- return new URLSearchParams(location.search);
1145
- },
1146
- useSelectedLayoutSegment() {
1147
- return null;
1148
- },
1149
- useSelectedLayoutSegments() {
1150
- return [];
1151
- },
1152
- __esModule: true
1153
- })),
1154
- "next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
1155
- default: ({
1156
- scroll: _,
1157
- replace,
1158
- prefetch,
1159
- onNavigate,
1160
- children,
1161
- ...props
1162
- }) => {
1163
- if (prefetch) {
1164
- console.warn(
1165
- "Next.js Link prefetch is not supported in remote components"
1271
+ if (!self.__remote_script_entrypoint_mount__[url.href]) {
1272
+ self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
1273
+ }
1274
+ self.__remote_script_entrypoint_mount__[url.href]?.add(
1275
+ mod.mount || mod.default?.mount || (() => {
1276
+ })
1166
1277
  );
1167
1278
  }
1168
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1169
- "a",
1170
- {
1171
- ...props,
1172
- href: props.href,
1173
- onClick: (e) => {
1174
- e.preventDefault();
1175
- let preventDefaulted = false;
1176
- e.preventDefault = () => {
1177
- preventDefaulted = true;
1178
- e.defaultPrevented = true;
1179
- };
1180
- if (typeof props.onClick === "function") {
1181
- props.onClick(e);
1182
- }
1183
- onNavigate?.(e);
1184
- if (preventDefaulted) {
1185
- return;
1186
- }
1187
- if (replace) {
1188
- history.replaceState({}, "", props.href);
1189
- } else {
1190
- history.pushState({}, "", props.href);
1191
- }
1192
- },
1193
- suppressHydrationWarning: true,
1194
- children: children ?? null
1279
+ if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
1280
+ if (!self.__remote_script_entrypoint_unmount__) {
1281
+ self.__remote_script_entrypoint_unmount__ = {};
1195
1282
  }
1196
- );
1197
- },
1198
- useLinkStatus() {
1199
- return { pending: false };
1200
- },
1201
- __esModule: true
1202
- })),
1203
- "next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
1204
- default: () => {
1205
- throw new Error("Next.js <Form> component not implemented");
1206
- },
1207
- __esModule: true
1208
- })),
1209
- "next/dist/client/image-component": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
1210
- Image: imageImpl(bundle),
1211
- __esModule: true
1212
- })),
1213
- "next/image": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
1214
- default: imageImpl(bundle),
1215
- getImageProps: (_imgProps) => {
1216
- throw new Error(
1217
- "Next.js getImageProps() is not implemented in remote components"
1218
- );
1219
- },
1220
- __esModule: true
1221
- })),
1222
- "next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
1223
- // TODO: implement <Script> component for non-Next.js host applications
1224
- // do not throw an error for now
1225
- default: () => null,
1226
- __esModule: true
1227
- })),
1228
- "next/router": self.__remote_component_host_shared_modules__?.["next/router"] ?? shared?.["next/router"] ?? (() => (
1229
- // TODO: incomplete implementation
1230
- Promise.resolve({
1231
- useRouter() {
1232
- return {
1233
- push: (routerUrl) => {
1234
- history.pushState({}, "", routerUrl);
1235
- },
1236
- replace: (routerUrl) => {
1237
- history.replaceState({}, "", routerUrl);
1238
- },
1239
- back: () => {
1240
- history.back();
1241
- }
1242
- };
1243
- },
1244
- __esModule: true
1245
- })
1246
- )),
1247
- "next/dist/build/polyfills/process": () => Promise.resolve({
1248
- default: {
1249
- env: {
1250
- NODE_ENV: "production"
1283
+ if (!self.__remote_script_entrypoint_unmount__[url.href]) {
1284
+ self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
1285
+ }
1286
+ self.__remote_script_entrypoint_unmount__[url.href]?.add(
1287
+ mod.unmount || mod.default?.unmount || (() => {
1288
+ })
1289
+ );
1251
1290
  }
1252
- },
1253
- __esModule: true
1254
- })
1255
- };
1256
- polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
1257
- polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
1258
- polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
1259
- polyfill["next/dist/api/image"] = polyfill["next/dist/client/image-component"];
1260
- polyfill["next/script"] = polyfill["next/dist/client/script"];
1261
- return polyfill;
1262
- }
1263
-
1264
- // src/shared/client/apply-origin.ts
1265
- var tagNames = [
1266
- "img",
1267
- "source",
1268
- "video",
1269
- "audio",
1270
- "track",
1271
- "iframe",
1272
- "embed",
1273
- "script",
1274
- "link"
1275
- ];
1276
- function applyOriginToNodes(doc, url) {
1277
- if (url.origin !== location.origin) {
1278
- const nodes = doc.querySelectorAll(
1279
- tagNames.map(
1280
- (type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
1281
- ).join(",")
1282
- );
1283
- nodes.forEach((node) => {
1284
- if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
1285
- node.src = new URL(node.getAttribute("src") ?? "/", url).href;
1286
- }
1287
- if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
1288
- node.setAttribute(
1289
- "href",
1290
- new URL(node.getAttribute("href") ?? "/", url).href
1291
+ return {
1292
+ mount: mod.mount || mod.default?.mount,
1293
+ unmount: mod.unmount || mod.default?.unmount
1294
+ };
1295
+ } catch (e) {
1296
+ console.error(
1297
+ new RemoteComponentsError(
1298
+ `Error loading remote component script from "${script.src || url.href}".`,
1299
+ { cause: e }
1300
+ )
1291
1301
  );
1302
+ return {
1303
+ mount: void 0,
1304
+ unmount: void 0
1305
+ };
1292
1306
  }
1293
- if (node.hasAttribute("srcset")) {
1294
- const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
1295
- const [urlPart, descriptor] = entry.trim().split(/\s+/);
1296
- if (!urlPart)
1297
- return entry;
1298
- const absoluteUrl = new URL(urlPart, url).href;
1299
- return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
1300
- }).join(", ");
1301
- if (srcSet) {
1302
- node.setAttribute("srcset", srcSet);
1303
- }
1307
+ })
1308
+ );
1309
+ return mountUnmountSets.reduce(
1310
+ (acc, { mount, unmount }) => {
1311
+ if (typeof mount === "function") {
1312
+ acc.mount.add(mount);
1304
1313
  }
1305
- if (node.hasAttribute("imagesrcset")) {
1306
- const srcSet = node.getAttribute("imagesrcset")?.split(",").map((entry) => {
1307
- const [urlPart, descriptor] = entry.trim().split(/\s+/);
1308
- if (!urlPart)
1309
- return entry;
1310
- const absoluteUrl = new URL(urlPart, url).href;
1311
- return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
1312
- }).join(", ");
1313
- if (srcSet) {
1314
- node.setAttribute("imagesrcset", srcSet);
1315
- }
1314
+ if (typeof unmount === "function") {
1315
+ acc.unmount.add(unmount);
1316
1316
  }
1317
- });
1318
- }
1317
+ return acc;
1318
+ },
1319
+ {
1320
+ mount: /* @__PURE__ */ new Set(),
1321
+ unmount: /* @__PURE__ */ new Set()
1322
+ }
1323
+ );
1319
1324
  }
1320
1325
 
1321
1326
  // src/shared/ssr/fetch-headers.ts