remote-components 0.3.5 → 0.3.7

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 (142) hide show
  1. package/dist/app-63L5THIQ.js +12 -0
  2. package/dist/app-63L5THIQ.js.map +1 -0
  3. package/dist/app-A5QE7XRH.cjs +12 -0
  4. package/dist/app-A5QE7XRH.cjs.map +1 -0
  5. package/dist/chunk-52BJ7VFA.js +202 -0
  6. package/dist/chunk-52BJ7VFA.js.map +1 -0
  7. package/dist/chunk-AWWWK2ZY.cjs +670 -0
  8. package/dist/chunk-AWWWK2ZY.cjs.map +1 -0
  9. package/dist/chunk-CTUJSWCM.js +215 -0
  10. package/dist/chunk-CTUJSWCM.js.map +1 -0
  11. package/dist/chunk-D5GNZB6O.js +61 -0
  12. package/dist/chunk-D5GNZB6O.js.map +1 -0
  13. package/dist/chunk-ENYGL5CO.js +11 -0
  14. package/dist/chunk-ENYGL5CO.js.map +1 -0
  15. package/dist/chunk-GAXJTFBV.js +20 -0
  16. package/dist/chunk-GAXJTFBV.js.map +1 -0
  17. package/dist/chunk-GBFUPMMI.js +670 -0
  18. package/dist/chunk-GBFUPMMI.js.map +1 -0
  19. package/dist/chunk-I47KE3EC.cjs +703 -0
  20. package/dist/chunk-I47KE3EC.cjs.map +1 -0
  21. package/dist/chunk-KE7QPAQ4.cjs +21 -0
  22. package/dist/chunk-KE7QPAQ4.cjs.map +1 -0
  23. package/dist/chunk-LCXO7BUY.cjs +57 -0
  24. package/dist/chunk-LCXO7BUY.cjs.map +1 -0
  25. package/dist/chunk-LQ7VQ74E.js +155 -0
  26. package/dist/chunk-LQ7VQ74E.js.map +1 -0
  27. package/dist/chunk-N5VQR2PW.cjs +215 -0
  28. package/dist/chunk-N5VQR2PW.cjs.map +1 -0
  29. package/dist/chunk-NZAB7REE.js +703 -0
  30. package/dist/chunk-NZAB7REE.js.map +1 -0
  31. package/dist/chunk-QKB74MLO.js +709 -0
  32. package/dist/chunk-QKB74MLO.js.map +1 -0
  33. package/dist/chunk-RJW3EZJP.cjs +709 -0
  34. package/dist/chunk-RJW3EZJP.cjs.map +1 -0
  35. package/dist/chunk-RUWR74XQ.cjs +152 -0
  36. package/dist/chunk-RUWR74XQ.cjs.map +1 -0
  37. package/dist/chunk-S2A4TFLS.js +152 -0
  38. package/dist/chunk-S2A4TFLS.js.map +1 -0
  39. package/dist/chunk-SHFJ5OQA.cjs +11 -0
  40. package/dist/chunk-SHFJ5OQA.cjs.map +1 -0
  41. package/dist/chunk-SJM7AAGU.js +358 -0
  42. package/dist/chunk-SJM7AAGU.js.map +1 -0
  43. package/dist/chunk-SZFCBE54.js +57 -0
  44. package/dist/chunk-SZFCBE54.js.map +1 -0
  45. package/dist/chunk-T64P7BAG.cjs +202 -0
  46. package/dist/chunk-T64P7BAG.cjs.map +1 -0
  47. package/dist/chunk-TCFLEBQM.cjs +20 -0
  48. package/dist/chunk-TCFLEBQM.cjs.map +1 -0
  49. package/dist/chunk-TZT7DLO5.cjs +155 -0
  50. package/dist/chunk-TZT7DLO5.cjs.map +1 -0
  51. package/dist/chunk-X6W464D6.cjs +358 -0
  52. package/dist/chunk-X6W464D6.cjs.map +1 -0
  53. package/dist/chunk-X6YKUJKH.js +21 -0
  54. package/dist/chunk-X6YKUJKH.js.map +1 -0
  55. package/dist/chunk-Z2SLBFQL.cjs +61 -0
  56. package/dist/chunk-Z2SLBFQL.cjs.map +1 -0
  57. package/dist/config/nextjs.cjs +74 -355
  58. package/dist/config/nextjs.cjs.map +1 -1
  59. package/dist/config/nextjs.js +25 -271
  60. package/dist/config/nextjs.js.map +1 -1
  61. package/dist/config/webpack.cjs +12 -240
  62. package/dist/config/webpack.cjs.map +1 -1
  63. package/dist/config/webpack.js +6 -207
  64. package/dist/config/webpack.js.map +1 -1
  65. package/dist/host/html.cjs +128 -2494
  66. package/dist/host/html.cjs.map +1 -1
  67. package/dist/host/html.js +45 -2382
  68. package/dist/host/html.js.map +1 -1
  69. package/dist/host/nextjs/app/client-only.cjs +53 -2939
  70. package/dist/host/nextjs/app/client-only.cjs.map +1 -1
  71. package/dist/host/nextjs/app/client-only.js +31 -2894
  72. package/dist/host/nextjs/app/client-only.js.map +1 -1
  73. package/dist/host/proxy/client.cjs +8 -38
  74. package/dist/host/proxy/client.cjs.map +1 -1
  75. package/dist/host/proxy/client.js +4 -7
  76. package/dist/host/proxy/client.js.map +1 -1
  77. package/dist/host/proxy.cjs +19 -56
  78. package/dist/host/proxy.cjs.map +1 -1
  79. package/dist/host/proxy.js +8 -20
  80. package/dist/host/proxy.js.map +1 -1
  81. package/dist/host/react.cjs +17 -2870
  82. package/dist/host/react.cjs.map +1 -1
  83. package/dist/host/react.js +13 -2837
  84. package/dist/host/react.js.map +1 -1
  85. package/dist/internal/config/webpack/next-client-pages-loader.cjs +27 -15
  86. package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
  87. package/dist/internal/config/webpack/next-client-pages-loader.d.ts +3 -5
  88. package/dist/internal/config/webpack/next-client-pages-loader.js +27 -15
  89. package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
  90. package/dist/internal/host/nextjs/app-client.d.ts +1 -1
  91. package/dist/internal/host/react/context.d.ts +2 -2
  92. package/dist/internal/host/server/fetch-remote-component.cjs +1 -18
  93. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
  94. package/dist/internal/host/server/fetch-remote-component.js +1 -18
  95. package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
  96. package/dist/internal/host/shared/pipeline.d.ts +2 -2
  97. package/dist/internal/runtime/loaders/component-loader.cjs +5 -2
  98. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
  99. package/dist/internal/runtime/loaders/component-loader.d.ts +2 -2
  100. package/dist/internal/runtime/loaders/component-loader.js +5 -2
  101. package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
  102. package/dist/internal/runtime/loaders/static-loader.d.ts +2 -1
  103. package/dist/internal/runtime/namespace.cjs +1 -0
  104. package/dist/internal/runtime/namespace.cjs.map +1 -1
  105. package/dist/internal/runtime/namespace.d.ts +2 -1
  106. package/dist/internal/runtime/namespace.js +1 -0
  107. package/dist/internal/runtime/namespace.js.map +1 -1
  108. package/dist/internal/runtime/turbopack/remote-scope.cjs +1 -5
  109. package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
  110. package/dist/internal/runtime/turbopack/remote-scope.js +1 -5
  111. package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
  112. package/dist/internal/runtime/types.d.ts +2 -1
  113. package/dist/internal/utils.cjs +1 -1
  114. package/dist/internal/utils.cjs.map +1 -1
  115. package/dist/internal/utils.d.ts +5 -5
  116. package/dist/internal/utils.js +1 -1
  117. package/dist/internal/utils.js.map +1 -1
  118. package/dist/remote/html.cjs +15 -314
  119. package/dist/remote/html.cjs.map +1 -1
  120. package/dist/remote/html.js +7 -305
  121. package/dist/remote/html.js.map +1 -1
  122. package/dist/remote/middleware.cjs +16 -41
  123. package/dist/remote/middleware.cjs.map +1 -1
  124. package/dist/script-D5AD7HLV.cjs +26 -0
  125. package/dist/script-D5AD7HLV.cjs.map +1 -0
  126. package/dist/script-VPOI7ARP.js +26 -0
  127. package/dist/script-VPOI7ARP.js.map +1 -0
  128. package/dist/{server-handoff-ce13bebc.d.ts → server-handoff-8c89b856.d.ts} +2 -2
  129. package/dist/static-loader-OHSAUD62.js +11 -0
  130. package/dist/static-loader-OHSAUD62.js.map +1 -0
  131. package/dist/static-loader-UDIXK5MV.cjs +11 -0
  132. package/dist/static-loader-UDIXK5MV.cjs.map +1 -0
  133. package/dist/turbopack-5LW6V6IT.js +55 -0
  134. package/dist/turbopack-5LW6V6IT.js.map +1 -0
  135. package/dist/turbopack-KRKECGY2.cjs +55 -0
  136. package/dist/turbopack-KRKECGY2.cjs.map +1 -0
  137. package/dist/{types-59251814.d.ts → types-8b0edd78.d.ts} +7 -0
  138. package/dist/webpack-NPZNXRNL.js +92 -0
  139. package/dist/webpack-NPZNXRNL.js.map +1 -0
  140. package/dist/webpack-TTZDARNY.cjs +92 -0
  141. package/dist/webpack-TTZDARNY.cjs.map +1 -0
  142. package/package.json +9 -2
@@ -1,2404 +1,40 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
- };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
-
33
- // src/utils/constants.ts
34
- var RC_PROTECTED_REMOTE_FETCH_PATHNAME, CORS_DOCS_URL;
35
- var init_constants = __esm({
36
- "src/utils/constants.ts"() {
37
- "use strict";
38
- RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
39
- CORS_DOCS_URL = "https://vercel.com/docs/remote-components/concepts/cors-external-urls#accessing-cross-site-protected-remote-components";
40
- }
41
- });
42
-
43
- // src/runtime/url/protected-rc-fallback.ts
44
- function isProxiedUrl(url) {
45
- try {
46
- return new URL(url, location.href).pathname === RC_PROTECTED_REMOTE_FETCH_PATHNAME;
47
- } catch {
48
- return false;
49
- }
50
- }
51
- var init_protected_rc_fallback = __esm({
52
- "src/runtime/url/protected-rc-fallback.ts"() {
53
- "use strict";
54
- init_constants();
55
- }
56
- });
57
-
58
- // src/utils/abort.ts
59
- function isAbortError(error) {
60
- if (error instanceof DOMException && error.name === "AbortError") {
61
- return true;
62
- }
63
- if (error !== null && typeof error === "object" && "name" in error && error.name === "AbortError" && "message" in error && typeof error.message === "string") {
64
- const e = error;
65
- return typeof e.code === "number" || e.constructor?.name === "DOMException";
66
- }
67
- return false;
68
- }
69
- var init_abort = __esm({
70
- "src/utils/abort.ts"() {
71
- "use strict";
72
- }
73
- });
74
-
75
- // src/utils/error.ts
76
- function multipleRemoteComponentsError(url) {
77
- return new RemoteComponentsError(
78
- `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.`
79
- );
80
- }
81
- function failedToFetchRemoteComponentError(url, { status, statusText }, help = "Is the URL correct and accessible?") {
82
- return new RemoteComponentsError(
83
- `Failed to fetch Remote Component from "${url}". ${help}`,
84
- { cause: new Error(`${status} ${statusText}`) }
85
- );
86
- }
87
- async function errorFromFailedFetch(originalUrl, resolvedUrl, res) {
88
- const isProxied = isProxiedUrl(resolvedUrl.href);
89
- if (isProxied && res) {
90
- const body = await res.text().catch(() => "");
91
- return failedProxyFetchError(
92
- originalUrl,
93
- resolvedUrl.href,
94
- res.status,
95
- body
96
- );
97
- }
98
- const fallback = failedToFetchRemoteComponentError(
99
- originalUrl,
100
- res ?? { status: 0, statusText: "No Response" }
101
- );
102
- if (!res)
103
- return fallback;
104
- try {
105
- const body = await res.text();
106
- const parser = new DOMParser();
107
- const doc = parser.parseFromString(body, "text/html");
108
- const errorTemplate = doc.querySelector(
109
- "template[data-next-error-message]"
110
- );
111
- const errorMessage = errorTemplate?.getAttribute("data-next-error-message");
112
- if (errorMessage) {
113
- const error = new RemoteComponentsError(errorMessage);
114
- const errorStack = errorTemplate?.getAttribute("data-next-error-stack");
115
- if (errorStack) {
116
- error.stack = errorStack;
117
- }
118
- return error;
119
- }
120
- } catch (parseError) {
121
- if (isAbortError(parseError))
122
- throw parseError;
123
- }
124
- return fallback;
125
- }
126
- function failedProxiedAssetError(kind, url, resolvedUrl) {
127
- return new RemoteComponentsError(
128
- `Failed to load ${kind} "${url}" via proxy "${resolvedUrl}". Ensure withRemoteComponentsHostProxy middleware is configured, "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" is in the matcher, and the remote URL is included in allowedProxyUrls. See: ${CORS_DOCS_URL}`
129
- );
130
- }
131
- function failedProxyFetchError(originalUrl, proxyUrl, status, responseBody) {
132
- if (status === 404) {
133
- return new RemoteComponentsError(
134
- `Could not proxy the request to "${originalUrl}" \u2014 the proxy endpoint "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" returned 404.
135
-
136
- The host server needs middleware or a route that handles "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}".
137
-
138
- Proxying requires two pieces:
139
- 1. resolveClientUrl={routeThroughHostProxy} on <RemoteComponent>
140
- 2. Middleware or a route for "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" on the host server
141
-
142
- Docs: ${CORS_DOCS_URL}`
143
- );
144
- }
145
- if (status === 403) {
146
- const detail = responseBody ? ` ${responseBody}` : "";
147
- return new RemoteComponentsError(
148
- `Proxied request to "${proxyUrl}" was forbidden.${detail} See: ${CORS_DOCS_URL}`
149
- );
150
- }
151
- return new RemoteComponentsError(
152
- `Proxied request for "${originalUrl}" via "${proxyUrl}" failed with status ${status}. See: ${CORS_DOCS_URL}`
153
- );
154
- }
155
- var RemoteComponentsError;
156
- var init_error = __esm({
157
- "src/utils/error.ts"() {
158
- "use strict";
159
- init_protected_rc_fallback();
160
- init_abort();
161
- init_constants();
162
- RemoteComponentsError = class extends Error {
163
- code = "REMOTE_COMPONENTS_ERROR";
164
- constructor(message, options) {
165
- super(message, options);
166
- this.name = "RemoteComponentsError";
167
- }
168
- };
169
- }
170
- });
171
-
172
- // src/utils/logger.ts
173
- function logDebug(location2, message) {
174
- if (DEBUG) {
175
- console.debug(`[${PREFIX}:${location2}]: ${message}`);
176
- }
177
- }
178
- function logWarn(location2, message) {
179
- console.warn(`[${PREFIX}:${location2}]: ${message}`);
180
- }
181
- function logError(location2, message, cause) {
182
- console.error(
183
- new RemoteComponentsError(`[${PREFIX}:${location2}]: ${message}`, {
184
- cause
185
- })
186
- );
187
- }
188
- function warnCrossOriginFetchError(logLocation, url) {
189
- try {
190
- const parsed = typeof url === "string" ? new URL(url) : url;
191
- if (typeof location === "undefined" || parsed.origin === location.origin) {
192
- return;
193
- }
194
- logWarn(
195
- logLocation,
196
- `Failed to fetch cross-origin resource "${parsed.href}". To load assets from a protected deployment, two steps are required: (1) configure withRemoteComponentsHostProxy middleware in your host with the remote URL in allowedProxyUrls, and (2) provide a resolveClientUrl prop that rewrites cross-origin asset URLs to go through the proxy. See: ${CORS_DOCS_URL}`
197
- );
198
- } catch {
199
- }
200
- }
201
- var PREFIX, DEBUG;
202
- var init_logger = __esm({
203
- "src/utils/logger.ts"() {
204
- "use strict";
205
- init_constants();
206
- init_error();
207
- PREFIX = "remote-components";
208
- DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true" || typeof process !== "undefined" && process.env.RC_DEBUG === "true";
209
- }
210
- });
211
-
212
- // src/utils/index.ts
213
- function escapeString(str) {
214
- return str.replace(/[^a-z0-9]/g, "_");
215
- }
216
- function computeScopedName(name, options) {
217
- return options.isCrossOrigin ? `${name}_${escapeString(options.remoteHost.toLowerCase())}` : name;
218
- }
219
- var init_utils = __esm({
220
- "src/utils/index.ts"() {
221
- "use strict";
222
- }
223
- });
224
-
225
- // src/runtime/constants.ts
226
- function getBundleKey(bundle) {
227
- return escapeString(bundle);
228
- }
229
- var DEFAULT_BUNDLE_NAME, DEFAULT_COMPONENT_NAME, DEFAULT_ROUTE, RUNTIME_WEBPACK, RUNTIME_TURBOPACK, RUNTIME_SCRIPT;
230
- var init_constants2 = __esm({
231
- "src/runtime/constants.ts"() {
232
- "use strict";
233
- init_utils();
234
- DEFAULT_BUNDLE_NAME = "__vercel_remote_bundle";
235
- DEFAULT_COMPONENT_NAME = "__vercel_remote_component";
236
- DEFAULT_ROUTE = "/";
237
- RUNTIME_WEBPACK = "webpack";
238
- RUNTIME_TURBOPACK = "turbopack";
239
- RUNTIME_SCRIPT = "script";
240
- }
241
- });
242
-
243
- // src/runtime/namespace.ts
244
- function getNamespace() {
245
- const g = globalThis;
246
- const existing = g.__remote_components__;
247
- if (existing) {
248
- return existing;
249
- }
250
- const ns = {
251
- scopes: /* @__PURE__ */ new Map(),
252
- chunkCache: {},
253
- mountFns: {},
254
- unmountFns: {},
255
- bundleUrls: {},
256
- moduleRegistry: {},
257
- dispatcherRuntime: void 0,
258
- hostSharedModules: {},
259
- cssCache: {},
260
- shadowRoots: {}
261
- };
262
- const nsRecord = ns;
263
- for (const { global, prop } of LEGACY_ALIASES) {
264
- const legacyValue = g[global];
265
- if (legacyValue != null) {
266
- nsRecord[prop] = legacyValue;
267
- }
268
- g[global] = ns[prop];
269
- }
270
- const gRecord = g;
271
- for (const key of Object.keys(gRecord)) {
272
- if (key.startsWith(SHADOW_ROOT_PREFIX)) {
273
- const suffix = key.slice(SHADOW_ROOT_PREFIX.length);
274
- ns.shadowRoots[suffix] = gRecord[key];
275
- delete gRecord[key];
276
- }
277
- }
278
- g.__remote_components__ = ns;
279
- return ns;
280
- }
281
- var SHADOW_ROOT_PREFIX, LEGACY_ALIASES;
282
- var init_namespace = __esm({
283
- "src/runtime/namespace.ts"() {
284
- "use strict";
285
- SHADOW_ROOT_PREFIX = "__remote_components_shadowroot_";
286
- LEGACY_ALIASES = [
287
- { global: "__remote_component_scopes__", prop: "scopes" },
288
- {
289
- global: "__remote_components_turbopack_chunk_loader_promise__",
290
- prop: "chunkCache"
291
- },
292
- { global: "__remote_script_entrypoint_mount__", prop: "mountFns" },
293
- { global: "__remote_script_entrypoint_unmount__", prop: "unmountFns" },
294
- { global: "__remote_bundle_url__", prop: "bundleUrls" },
295
- { global: "__rc_module_registry__", prop: "moduleRegistry" },
296
- {
297
- global: "__remote_component_host_shared_modules__",
298
- prop: "hostSharedModules"
299
- },
300
- { global: "__remote_next_css__", prop: "cssCache" }
301
- ];
302
- }
303
- });
304
-
305
- // src/runtime/patterns.ts
306
- function collapseDoubleSlashes(path) {
307
- return path.replace(DOUBLE_SLASH_RE, "/");
308
- }
309
- var REMOTE_COMPONENT_REGEX, NEXT_BUNDLE_PATH_RE, DOUBLE_SLASH_RE;
310
- var init_patterns = __esm({
311
- "src/runtime/patterns.ts"() {
312
- "use strict";
313
- REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
314
- NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
315
- DOUBLE_SLASH_RE = /(?<!:)\/\//g;
316
- }
317
- });
318
-
319
- // src/runtime/turbopack/remote-scope.ts
320
- function getRegistry() {
321
- return getNamespace().scopes;
322
- }
323
- function createScope(name, url, runtime, resolveClientUrl) {
324
- const isCrossOrigin = url.origin !== location.origin;
325
- const scopedName = computeScopedName(name, {
326
- remoteHost: url.host,
327
- isCrossOrigin
328
- });
329
- const globalKey = getBundleKey(scopedName);
330
- return {
331
- name,
332
- scopedName,
333
- globalKey,
334
- url,
335
- runtime,
336
- resolveClientUrl,
337
- moduleCache: {},
338
- sharedModules: {},
339
- moduleGlobal: {},
340
- turbopackModules: []
341
- };
342
- }
343
- function registerScope(scope) {
344
- const registry = getRegistry();
345
- registry.set(scope.scopedName, scope);
346
- if (scope.scopedName !== scope.name) {
347
- const existing = registry.get(scope.name);
348
- if (existing && existing.scopedName !== scope.scopedName) {
349
- logWarn(
350
- "RemoteScope",
351
- `Plain name "${scope.name}" already registered by scope "${existing.scopedName}" \u2014 overwriting with "${scope.scopedName}". Static hosts will only resolve the latest one.`
352
- );
353
- }
354
- registry.set(scope.name, scope);
355
- }
356
- logDebug(
357
- "RemoteScope",
358
- `Registered scope "${scope.scopedName}" (${registry.size} total)`
359
- );
360
- }
361
- function getScope(name) {
362
- return getRegistry().get(name);
363
- }
364
- function formatRemoteId(scope, path) {
365
- return `[${scope.scopedName}] ${path}`;
366
- }
367
- function parseRemoteId(id) {
368
- const groups = REMOTE_COMPONENT_REGEX.exec(id)?.groups;
369
- if (groups?.bundle && groups.id) {
370
- return {
371
- bundle: groups.bundle,
372
- path: groups.id,
373
- prefix: groups.prefix ?? ""
374
- };
375
- }
376
- return { bundle: "default", path: id, prefix: "" };
377
- }
378
- var init_remote_scope = __esm({
379
- "src/runtime/turbopack/remote-scope.ts"() {
380
- "use strict";
381
- init_constants2();
382
- init_namespace();
383
- init_patterns();
384
- init_utils();
385
- init_logger();
386
- }
387
- });
388
-
389
- // src/host/shared/remote-image-loader.ts
390
- function createRemoteImageLoader(bundle, resolveClientUrl) {
391
- const loader = Object.assign(
392
- ({
393
- config,
394
- src,
395
- width,
396
- quality
397
- }) => {
398
- const q = quality ?? 75;
399
- const remoteOrigin = getScope(bundle)?.url.origin ?? "";
400
- const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;
401
- const basePath = isCrossOrigin ? `${remoteOrigin}${config.path ?? "/_next/image"}` : config.path ?? `${remoteOrigin}/_next/image`;
402
- const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;
403
- return resolveClientUrl?.(url) ?? url;
404
- },
405
- // Signals to getImgProps that this is a default loader (not a user-defined
406
- // one), enabling srcSet generation with device/image sizes from the config.
407
- { __next_img_default: true }
408
- );
409
- return loader;
410
- }
411
- var init_remote_image_loader = __esm({
412
- "src/host/shared/remote-image-loader.ts"() {
413
- "use strict";
414
- init_remote_scope();
415
- }
416
- });
417
-
418
- // src/host/shared/polyfill.tsx
419
- function sharedPolyfills(shared, resolveClientUrl) {
420
- const hostShared = getNamespace().hostSharedModules;
421
- const polyfill = {
422
- "next/dist/client/components/navigation": hostShared["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
423
- useRouter() {
424
- return {
425
- push: (routerUrl) => {
426
- history.pushState({}, "", routerUrl);
427
- },
428
- replace: (routerUrl) => {
429
- history.replaceState({}, "", routerUrl);
430
- },
431
- back: () => {
432
- history.back();
433
- }
434
- };
435
- },
436
- usePathname() {
437
- return location.pathname;
438
- },
439
- useParams() {
440
- return {};
441
- },
442
- useSearchParams() {
443
- return new URLSearchParams(location.search);
444
- },
445
- useSelectedLayoutSegment() {
446
- return null;
447
- },
448
- useSelectedLayoutSegments() {
449
- return [];
450
- },
451
- __esModule: true
452
- })),
453
- "next/dist/client/app-dir/link": hostShared["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
454
- default: ({
455
- scroll: _,
456
- replace,
457
- prefetch,
458
- onNavigate,
459
- children,
460
- ...props
461
- }) => {
462
- if (prefetch) {
463
- logWarn(
464
- "Polyfill",
465
- "Next.js Link prefetch is not supported in remote components"
466
- );
467
- }
468
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
469
- "a",
470
- {
471
- ...props,
472
- href: props.href,
473
- onClick: (e) => {
474
- e.preventDefault();
475
- let preventDefaulted = false;
476
- e.preventDefault = () => {
477
- preventDefaulted = true;
478
- e.defaultPrevented = true;
479
- };
480
- if (typeof props.onClick === "function") {
481
- props.onClick(e);
482
- }
483
- onNavigate?.(e);
484
- if (preventDefaulted) {
485
- return;
486
- }
487
- if (replace) {
488
- history.replaceState({}, "", props.href);
489
- } else {
490
- history.pushState({}, "", props.href);
491
- }
492
- },
493
- suppressHydrationWarning: true,
494
- children: children ?? null
495
- }
496
- );
497
- },
498
- useLinkStatus() {
499
- return { pending: false };
500
- },
501
- __esModule: true
502
- })),
503
- "next/dist/client/app-dir/form": hostShared["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
504
- default: () => {
505
- throw new Error("Next.js <Form> component not implemented");
506
- },
507
- __esModule: true
508
- })),
509
- // Instead of replacing next/image entirely, we let the real Next.js Image
510
- // component load from the remote bundle and only replace its default loader.
511
- // This gives us full next/image fidelity (fill, priority, srcSet, blur
512
- // placeholders, error handling) while routing image optimization through the
513
- // remote app's /_next/image endpoint.
514
- "next/dist/shared/lib/image-loader": hostShared["next/dist/shared/lib/image-loader"] ?? shared?.["next/dist/shared/lib/image-loader"] ?? ((bundle) => Promise.resolve({
515
- default: createRemoteImageLoader(bundle, resolveClientUrl),
516
- __esModule: true
517
- })),
518
- "next/dist/client/script": hostShared["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
519
- // TODO: implement <Script> component for non-Next.js host applications
520
- // do not throw an error for now
521
- default: () => null,
522
- __esModule: true
523
- })),
524
- "next/router": hostShared["next/router"] ?? shared?.["next/router"] ?? (() => (
525
- // TODO: incomplete implementation
526
- Promise.resolve({
527
- useRouter() {
528
- return {
529
- push: (routerUrl) => {
530
- history.pushState({}, "", routerUrl);
531
- },
532
- replace: (routerUrl) => {
533
- history.replaceState({}, "", routerUrl);
534
- },
535
- back: () => {
536
- history.back();
537
- }
538
- };
539
- },
540
- __esModule: true
541
- })
542
- )),
543
- "next/dist/build/polyfills/process": () => Promise.resolve({
544
- default: {
545
- env: {
546
- NODE_ENV: "production"
547
- }
548
- },
549
- __esModule: true
550
- })
551
- };
552
- polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
553
- polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
554
- polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
555
- polyfill["next/dist/esm/shared/lib/image-loader"] = polyfill["next/dist/shared/lib/image-loader"];
556
- polyfill["next/script"] = polyfill["next/dist/client/script"];
557
- return polyfill;
558
- }
559
- var import_jsx_runtime;
560
- var init_polyfill = __esm({
561
- "src/host/shared/polyfill.tsx"() {
562
- "use strict";
563
- init_remote_image_loader();
564
- init_namespace();
565
- init_logger();
566
- import_jsx_runtime = require("react/jsx-runtime");
567
- }
568
- });
569
-
570
- // src/host/shared/shared-module-resolver.ts
571
- function buildCoreShared(userShared) {
572
- return {
573
- react: async () => (await import("react")).default,
574
- "react-dom": async () => (await import("react-dom")).default,
575
- "react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
576
- "react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
577
- "react-dom/client": async () => (await import("react-dom/client")).default,
578
- ...userShared
579
- };
580
- }
581
- function buildHostShared(userShared, resolveClientUrl, options) {
582
- const self = globalThis;
583
- const result = {
584
- ...sharedPolyfills(userShared, resolveClientUrl),
585
- ...self.__remote_component_host_shared_modules__,
586
- ...userShared
587
- };
588
- if (options?.includeRemoteComponentShared) {
589
- Object.assign(result, self.__remote_component_shared__);
590
- }
591
- return result;
592
- }
593
- async function buildWebpackResolve(hostShared, remoteShared, bundle, reactModules, callerTag = "SharedModuleResolver") {
594
- const resolve = {
595
- ...reactModules,
596
- ...Object.entries(remoteShared).reduce(
597
- (acc, [key, value]) => {
598
- if (typeof hostShared[value] !== "undefined") {
599
- acc[key.replace(/^\(ssr\)\/(?<relative>\.\/)?/, "")] = hostShared[value];
600
- } else {
601
- logDebug(
602
- callerTag,
603
- `Remote requests "${value}" but host doesn't provide it`
604
- );
605
- }
606
- return acc;
607
- },
608
- {}
609
- )
610
- };
611
- await Promise.all(
612
- Object.entries(resolve).map(async ([key, value]) => {
613
- if (typeof value === "function") {
614
- resolve[key] = await value(bundle);
615
- }
616
- return Promise.resolve(value);
617
- })
618
- );
619
- return resolve;
620
- }
621
- var CORE_REACT_PATH_MAP, VENDOR_SHARED;
622
- var init_shared_module_resolver = __esm({
623
- "src/host/shared/shared-module-resolver.ts"() {
624
- "use strict";
625
- init_polyfill();
626
- init_logger();
627
- CORE_REACT_PATH_MAP = {
628
- react: "/react/index.js",
629
- "react/jsx-dev-runtime": "/react/jsx-dev-runtime.js",
630
- "react/jsx-runtime": "/react/jsx-runtime.js",
631
- "react-dom": "/react-dom/index.js",
632
- "react-dom/client": "/react-dom/client.js"
633
- };
634
- VENDOR_SHARED = Object.fromEntries(
635
- Object.entries(CORE_REACT_PATH_MAP).filter(([key]) => key !== "react-dom/client").map(([key, path]) => [key, `'${path}'`])
636
- );
637
- }
638
- });
639
-
640
- // src/config/webpack/apply-shared-modules.ts
641
- function applySharedModules(bundle, resolve) {
642
- logDebug(
643
- "SharedModules",
644
- `applySharedModules called for bundle: "${bundle}"`
645
- );
646
- logDebug(
647
- "SharedModules",
648
- `Shared modules to resolve: ${Object.keys(resolve)}`
649
- );
650
- const self = globalThis;
651
- const scope = getScope(bundle);
652
- const webpackBundle = scope?.webpackRequire ?? self.__remote_webpack_require__?.[bundle];
653
- if (webpackBundle) {
654
- const modulePaths = Object.keys(
655
- self.__remote_webpack_module_map__?.[bundle] ?? webpackBundle.m ?? {}
656
- );
657
- logDebug(
658
- "SharedModules",
659
- `Available module paths for bundle "${bundle}": ${modulePaths}`
660
- );
661
- for (const [key, value] of Object.entries(resolve)) {
662
- const exactIds = modulePaths.filter((p) => p === key);
663
- const ids = exactIds.length > 0 ? exactIds : modulePaths.filter((p) => p.includes(key));
664
- if (ids.length === 0) {
665
- logDebug(
666
- "SharedModules",
667
- `No matching module path found for shared module "${key}"`
668
- );
669
- }
670
- for (const id of ids) {
671
- if (webpackBundle.m) {
672
- const resolvedId = self.__remote_webpack_module_map__?.[bundle]?.[id] ? `${self.__remote_webpack_module_map__[bundle][id]}` : id;
673
- if (resolvedId !== id) {
674
- logDebug(
675
- "SharedModules",
676
- `Mapped module id: "${id}" -> "${resolvedId}"`
677
- );
678
- }
679
- webpackBundle.m[resolvedId] = (module2) => {
680
- module2.exports = value;
681
- };
682
- } else {
683
- logWarn(
684
- "SharedModules",
685
- `webpackBundle.m is not available for bundle "${bundle}" \u2014 ${DEDUPLICATION_SKIPPED}`
686
- );
687
- }
688
- }
689
- }
690
- } else {
691
- logWarn(
692
- "SharedModules",
693
- `No webpack require found for bundle "${bundle}" \u2014 ${DEDUPLICATION_SKIPPED}`
694
- );
695
- logDebug(
696
- "SharedModules",
697
- `Available bundles: ${Object.keys(self.__remote_webpack_require__ ?? {})}`
698
- );
699
- }
700
- }
701
- var DEDUPLICATION_SKIPPED;
702
- var init_apply_shared_modules = __esm({
703
- "src/config/webpack/apply-shared-modules.ts"() {
704
- "use strict";
705
- init_remote_scope();
706
- init_logger();
707
- DEDUPLICATION_SKIPPED = "shared module deduplication skipped. The remote may load its own copy of shared dependencies.";
708
- }
709
- });
710
-
711
- // src/config/webpack/next-client-pages-loader.ts
712
- function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
713
- const self = globalThis;
714
- const nextCssOriginal = document.querySelector(
715
- `[id="__next_css__DO_NOT_USE__"]:not([data-bundle="${bundle}"][data-route="${route}"])`
716
- );
717
- if (nextCssOriginal) {
718
- nextCssOriginal.parentNode?.removeChild(nextCssOriginal);
719
- }
720
- const nextCss = document.createElement("noscript");
721
- nextCss.id = "__next_css__DO_NOT_USE__";
722
- nextCss.setAttribute("data-bundle", bundle);
723
- nextCss.setAttribute("data-route", route);
724
- const nextCssEnd = document.createElement("noscript");
725
- nextCssEnd.id = "__next_css__DO_NOT_USE_END__";
726
- nextCssEnd.setAttribute("data-bundle", bundle);
727
- nextCssEnd.setAttribute("data-route", route);
728
- document.head.appendChild(nextCssEnd);
729
- document.head.appendChild(nextCss);
730
- const componentLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
731
- (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
732
- ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
733
- (key) => key.includes("/next/dist/client/page-loader.js")
734
- ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
735
- (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
736
- ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
737
- (key) => key.includes("/next/dist/client/page-loader.js")
738
- ) ?? ""] ?? -1;
739
- const appLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
740
- (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
741
- ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
742
- (key) => key.includes("/next/dist/client/page-loader.js")
743
- ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
744
- (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
745
- ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
746
- (key) => key.includes("/next/dist/client/page-loader.js")
747
- ) ?? ""] ?? -1;
748
- if (!(componentLoaderChunk && appLoaderChunk)) {
749
- throw new RemoteComponentsError(
750
- `Next.js client pages loader not found in bundle "${bundle}".`
751
- );
752
- }
753
- const __NEXT_P_ORIGINAL = self.__NEXT_P;
754
- const selfOriginal = self;
755
- delete selfOriginal.__NEXT_P;
756
- self.__remote_webpack_require__?.[bundle]?.(
757
- self.__remote_webpack_require__[bundle].type !== "turbopack" ? componentLoaderChunk : `[${bundle}] ${componentLoaderChunk}`
758
- );
759
- if (typeof appLoaderChunk === "string" || typeof appLoaderChunk === "number" && appLoaderChunk !== -1) {
760
- self.__remote_webpack_require__?.[bundle]?.(
761
- self.__remote_webpack_require__[bundle].type !== "turbopack" ? appLoaderChunk : `[${bundle}] ${appLoaderChunk}`
762
- );
763
- }
764
- if (self.__NEXT_P) {
765
- const [, componentLoader] = self.__NEXT_P[0] ?? [
766
- void 0,
767
- () => ({ default: null })
768
- ];
769
- const [, appLoader] = self.__NEXT_P[2] ?? [
770
- void 0,
771
- () => ({
772
- default: null
773
- })
774
- ];
775
- const { default: Component } = componentLoader();
776
- const { default: App } = appLoader();
777
- const cssCache = getNamespace().cssCache;
778
- if (!cssCache[bundle]) {
779
- const cssRE = /\.s?css$/;
780
- Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).filter((id) => cssRE.test(id)).forEach((id) => {
781
- self.__remote_webpack_require__?.[bundle]?.(id);
782
- });
783
- Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {}).filter((path) => cssRE.test(path)).forEach((path) => {
784
- const id = self.__remote_webpack_module_map__?.[bundle]?.[path];
785
- if (id) {
786
- self.__remote_webpack_require__?.[bundle]?.(id);
787
- }
788
- });
789
- const elements = [];
790
- let node = nextCss.previousSibling;
791
- while (node && node !== nextCssEnd) {
792
- elements.push(node);
793
- node.remove();
794
- node = nextCss.previousSibling;
795
- }
796
- cssCache[bundle] = elements;
797
- }
798
- if (styleContainer) {
799
- const elements = cssCache[bundle];
800
- elements.forEach((el) => {
801
- styleContainer.appendChild(el.cloneNode(true));
802
- });
803
- } else {
804
- const elements = cssCache[bundle];
805
- elements.forEach((el) => {
806
- document.head.appendChild(el);
807
- });
808
- }
809
- delete self.__NEXT_P;
810
- self.__NEXT_P = __NEXT_P_ORIGINAL;
811
- if (nextCssOriginal) {
812
- nextCssOriginal.parentNode?.appendChild(nextCssOriginal);
813
- }
814
- nextCss.remove();
815
- nextCssEnd.remove();
816
- return { Component, App };
817
- }
818
- return { Component: null, App: null };
819
- }
820
- var init_next_client_pages_loader = __esm({
821
- "src/config/webpack/next-client-pages-loader.ts"() {
822
- "use strict";
823
- init_namespace();
824
- init_error();
825
- }
826
- });
827
-
828
- // src/runtime/turbopack/patterns.ts
829
- function stripQuotes(value) {
830
- if (value.startsWith('"') && value.endsWith('"')) {
831
- return value.slice(1, -1);
832
- }
833
- return value;
834
- }
835
- function extractGroup(re, input, group) {
836
- const raw = re.exec(input)?.groups?.[group];
837
- return raw ? stripQuotes(raw) : void 0;
838
- }
839
- var MODULE_ID_PATTERN, REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_CALLBACK_RE, TURBOPACK_GLOBAL_RE;
840
- var init_patterns2 = __esm({
841
- "src/runtime/turbopack/patterns.ts"() {
842
- "use strict";
843
- MODULE_ID_PATTERN = '"[^"]+"|[0-9]+';
844
- REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
845
- REMOTE_SHARED_ASSIGNMENT_RE = new RegExp(
846
- `\\.TURBOPACK_REMOTE_SHARED\\s*=\\s*await (?:__turbopack_context__|[a-z])\\.A\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\)`
847
- );
848
- ASYNC_MODULE_LOADER_RE = new RegExp(
849
- `(?:__turbopack_context__|[a-z])\\.A\\((?<asyncSharedModuleId>${MODULE_ID_PATTERN})\\)`
850
- );
851
- ASYNC_MODULE_CALLBACK_RE = new RegExp(
852
- `(?:parentImport|[a-z])\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\)`
853
- );
854
- TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
855
- }
856
- });
857
-
858
- // src/runtime/turbopack/chunk-loader.ts
859
- function loadChunkWithScope(scope, chunkId) {
860
- logDebug(
861
- "ChunkLoader",
862
- `loadChunkWithScope: "${chunkId}" (scope: "${scope.scopedName}")`
863
- );
864
- const self = globalThis;
865
- const ns = getNamespace();
866
- const { bundle, path, prefix } = parseRemoteId(chunkId);
867
- const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : scope.runtime;
868
- if (remoteRuntime === RUNTIME_WEBPACK) {
869
- return Promise.resolve(void 0);
870
- }
871
- const rawPath = path ? collapseDoubleSlashes(`${prefix}${path}`) : "/";
872
- const url = new URL(rawPath, scope.url).href;
873
- if (url.endsWith(".css")) {
874
- return;
875
- }
876
- if (ns.chunkCache[url]) {
877
- logDebug("ChunkLoader", `Cache hit for "${chunkId}" (url="${url}")`);
878
- return ns.chunkCache[url];
879
- }
880
- const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;
881
- if (resolvedUrl !== url) {
882
- logDebug("ChunkLoader", `Proxied chunk URL: "${url}" \u2192 "${resolvedUrl}"`);
883
- }
884
- ns.chunkCache[url] = new Promise((resolve, reject) => {
885
- fetch(resolvedUrl).then((res) => res.text()).then((code) => {
886
- const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);
887
- if (hasTurbopack) {
888
- return handleTurbopackChunk(code, scope, url);
889
- }
890
- }).then(resolve).catch((error) => {
891
- const isProxied = isProxiedUrl(resolvedUrl);
892
- if (isProxied) {
893
- reject(failedProxiedAssetError("chunk", url, resolvedUrl));
894
- } else {
895
- warnCrossOriginFetchError("ChunkLoader", url);
896
- reject(error);
897
- }
898
- });
899
- });
900
- return ns.chunkCache[url];
901
- }
902
- function createChunkDispatcher() {
903
- return function __chunk_dispatcher__(chunkId, scriptBundle) {
904
- logDebug("ChunkDispatcher", `Dispatching chunk: "${chunkId}"`);
905
- const { bundle } = parseRemoteId(chunkId);
906
- const bundleName = bundle || scriptBundle || "default";
907
- const scope = getScope(bundleName);
908
- logDebug(
909
- "ChunkDispatcher",
910
- `Scope resolution: bundle="${bundleName}", scope=${scope?.scopedName ?? "null"}`
911
- );
912
- if (!scope) {
913
- logWarn("ChunkDispatcher", `No scope found for bundle "${bundleName}"`);
914
- return Promise.resolve(void 0);
915
- }
916
- return loadChunkWithScope(scope, chunkId);
917
- };
918
- }
919
- async function handleTurbopackChunk(code, scope, url) {
920
- if (/importScripts\(\.\.\.self.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {
921
- const preloadLinks = document.querySelectorAll(
922
- `link[rel="preload"][href="${new URL(url).pathname}"]`
923
- );
924
- preloadLinks.forEach((preloadLink) => preloadLink.remove());
925
- return;
926
- }
927
- const self = globalThis;
928
- const { globalKey } = scope;
929
- const transformedCode = code.replace(
930
- /globalThis\[\s*["']TURBOPACK["']\s*\]/g,
931
- `globalThis["TURBOPACK_${globalKey}"]`
932
- ).replace(
933
- /self\[\s*["']TURBOPACK["']\s*\]/g,
934
- `self["TURBOPACK_${globalKey}"]`
935
- ).replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${globalKey}`).replace(/self\.TURBOPACK(?!_)/g, `self.TURBOPACK_${globalKey}`).replace(
936
- /TURBOPACK_WORKER_LOCATION/g,
937
- `TURBOPACK_WORKER_LOCATION_${globalKey}`
938
- ).replace(
939
- /TURBOPACK_NEXT_CHUNK_URLS/g,
940
- `TURBOPACK_NEXT_CHUNK_URLS_${globalKey}`
941
- ).replace(
942
- /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,
943
- `TURBOPACK_CHUNK_UPDATE_LISTENERS_${globalKey}`
944
- ).replace(/__next_require__/g, `__${globalKey}_next_require__`).replace(
945
- /\/\/# sourceMappingURL=(?<name>.+)(?<optional>\._)?\.js\.map/g,
946
- `//# sourceMappingURL=${new URL(".", new URL(url, scope.url)).href}$1$2.js.map`
947
- );
948
- if (!self[`TURBOPACK_${globalKey}`]) {
949
- const wrapPush = (target) => {
950
- const originalPush = target.push;
951
- if (typeof originalPush !== "function")
952
- return target;
953
- target.push = (...items) => {
954
- for (const item of items) {
955
- if (Array.isArray(item)) {
956
- for (const entry of item) {
957
- scope.turbopackModules.push(entry);
958
- }
959
- } else {
960
- scope.turbopackModules.push(item);
961
- }
962
- }
963
- return originalPush.apply(target, items);
964
- };
965
- return target;
966
- };
967
- const globalProp = `TURBOPACK_${globalKey}`;
968
- let currentValue = wrapPush([]);
969
- Object.defineProperty(self, globalProp, {
970
- get() {
971
- return currentValue;
972
- },
973
- set(newValue) {
974
- if (newValue && typeof newValue === "object") {
975
- wrapPush(newValue);
976
- }
977
- currentValue = newValue;
978
- },
979
- configurable: true,
980
- enumerable: true
981
- });
982
- }
983
- await new Promise((scriptResolve, scriptReject) => {
984
- const blob = new Blob([transformedCode], {
985
- type: "application/javascript; charset=UTF-8"
986
- });
987
- const scriptUrl = URL.createObjectURL(blob);
988
- const script = document.createElement("script");
989
- script.setAttribute("data-turbopack-src", url);
990
- script.src = scriptUrl;
991
- script.async = true;
992
- script.onload = () => {
993
- URL.revokeObjectURL(scriptUrl);
994
- scriptResolve(void 0);
995
- script.remove();
996
- };
997
- script.onerror = () => {
998
- URL.revokeObjectURL(scriptUrl);
999
- scriptReject(
1000
- new RemoteComponentsError(
1001
- `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
1002
- )
1003
- );
1004
- script.remove();
1005
- };
1006
- document.head.appendChild(script);
1007
- });
1008
- const chunkLists = self[`TURBOPACK_${globalKey}_CHUNK_LISTS`];
1009
- const loadChunkPromises = [];
1010
- while (chunkLists?.length) {
1011
- const { chunks } = chunkLists.shift() ?? { chunks: [] };
1012
- if (chunks.length > 0) {
1013
- for (const id of chunks) {
1014
- const baseUrl = url.slice(0, url.indexOf("/_next"));
1015
- const chunkLoadResult = loadChunkWithScope(
1016
- scope,
1017
- formatRemoteId(scope, `${baseUrl}/_next/${id}`)
1018
- );
1019
- if (chunkLoadResult) {
1020
- loadChunkPromises.push(chunkLoadResult);
1021
- }
1022
- }
1023
- }
1024
- }
1025
- if (loadChunkPromises.length > 0) {
1026
- await Promise.all(loadChunkPromises);
1027
- }
1028
- }
1029
- var init_chunk_loader = __esm({
1030
- "src/runtime/turbopack/chunk-loader.ts"() {
1031
- "use strict";
1032
- init_constants2();
1033
- init_namespace();
1034
- init_patterns();
1035
- init_protected_rc_fallback();
1036
- init_error();
1037
- init_logger();
1038
- init_patterns2();
1039
- init_remote_scope();
1040
- }
1041
- });
1042
-
1043
- // src/runtime/turbopack/shared-modules.ts
1044
- function getTurbopackModules(scope) {
1045
- if (scope.turbopackModules.length > 0) {
1046
- return scope.turbopackModules;
1047
- }
1048
- const self = globalThis;
1049
- const raw = self[`TURBOPACK_${scope.globalKey}`];
1050
- if (!raw)
1051
- return void 0;
1052
- if (Array.isArray(raw)) {
1053
- return raw.flat();
1054
- }
1055
- return Object.entries(raw).flat();
1056
- }
1057
- async function initializeSharedModules(scope, hostShared = {}, remoteShared = {}) {
1058
- const allModules = getTurbopackModules(scope);
1059
- logDebug(
1060
- "SharedModules",
1061
- `initializeSharedModules: scope="${scope.scopedName}", allModules=${allModules ? allModules.length : "null"}, hostShared=[${Object.keys(hostShared).join(", ")}], remoteShared=${JSON.stringify(remoteShared)}`
1062
- );
1063
- let sharedModuleInitializer = null;
1064
- if (allModules) {
1065
- const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {
1066
- if (typeof idOrFunc !== "function") {
1067
- return false;
1068
- }
1069
- const funcCode = idOrFunc.toString();
1070
- return REMOTE_SHARED_MARKER_RE.test(funcCode);
1071
- });
1072
- if (sharedModuleInitializerIndex > 0) {
1073
- const sharedModuleInitializerCode = allModules[sharedModuleInitializerIndex].toString();
1074
- const sharedModuleInitializerId = allModules[sharedModuleInitializerIndex - 1];
1075
- const sharedModuleId = extractGroup(
1076
- REMOTE_SHARED_ASSIGNMENT_RE,
1077
- sharedModuleInitializerCode,
1078
- "sharedModuleId"
1079
- );
1080
- if (sharedModuleId) {
1081
- const { default: sharedModuleInitializerInstance } = handleTurbopackModule(
1082
- scope,
1083
- sharedModuleId,
1084
- formatRemoteId(scope, String(sharedModuleInitializerId))
1085
- );
1086
- sharedModuleInitializer = sharedModuleInitializerInstance;
1087
- }
1088
- }
1089
- if (sharedModuleInitializer) {
1090
- const { shared } = await sharedModuleInitializer;
1091
- const sharedModuleIds = extractSharedModuleIds(shared, scope);
1092
- logDebug(
1093
- "SharedModules",
1094
- `Resolved shared modules for scope="${scope.scopedName}": ${JSON.stringify(sharedModuleIds)}`
1095
- );
1096
- return Promise.all(
1097
- Object.entries(sharedModuleIds).map(async ([id, module2]) => {
1098
- if (hostShared[module2]) {
1099
- scope.sharedModules[id] = await hostShared[module2](scope.name);
1100
- } else {
1101
- logError(
1102
- "SharedModules",
1103
- `Host shared module "${module2}" not found for ID ${id}. ${DEDUPLICATION_WARNING}`
1104
- );
1105
- }
1106
- })
1107
- );
1108
- }
1109
- logWarn(
1110
- "SharedModules",
1111
- `No shared module initializer found in bundle for scope="${scope.scopedName}" \u2014 falling back to remoteShared mapping`
1112
- );
1113
- } else {
1114
- logWarn(
1115
- "SharedModules",
1116
- `No TURBOPACK modules found for scope="${scope.scopedName}" (TURBOPACK_${scope.globalKey} is empty)`
1117
- );
1118
- }
1119
- return Promise.all(
1120
- Object.entries(remoteShared).map(async ([id, module2]) => {
1121
- if (hostShared[module2]) {
1122
- const normalizedId = id.replace("[app-ssr]", "[app-client]");
1123
- scope.sharedModules[normalizedId] = await hostShared[module2](
1124
- scope.name
1125
- );
1126
- } else {
1127
- logError(
1128
- "SharedModules",
1129
- `Shared module "${module2}" not found for "${scope.name}". ${DEDUPLICATION_WARNING}`
1130
- );
1131
- }
1132
- })
1133
- );
1134
- }
1135
- function extractSharedModuleIds(shared, scope) {
1136
- return Object.entries(shared).filter(([, value]) => typeof value === "function").reduce((acc, [key, value]) => {
1137
- const asyncSharedModuleId = extractGroup(
1138
- ASYNC_MODULE_LOADER_RE,
1139
- value.toString(),
1140
- "asyncSharedModuleId"
1141
- );
1142
- if (asyncSharedModuleId) {
1143
- const asyncSharedModule = findModuleInit(
1144
- getTurbopackModules(scope),
1145
- asyncSharedModuleId
1146
- );
1147
- if (asyncSharedModule) {
1148
- const sharedModuleId = extractGroup(
1149
- ASYNC_MODULE_CALLBACK_RE,
1150
- asyncSharedModule.toString(),
1151
- "sharedModuleId"
1152
- );
1153
- acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(
1154
- "__remote_shared_module_",
1155
- ""
1156
- );
1157
- }
1158
- }
1159
- return acc;
1160
- }, {});
1161
- }
1162
- function getSharedModule(scope, id) {
1163
- const idStr = String(id);
1164
- if (scope.sharedModules[idStr] !== void 0) {
1165
- return scope.sharedModules[idStr];
1166
- }
1167
- for (const [key, value] of Object.entries(scope.sharedModules)) {
1168
- if (typeof value !== "undefined" && idStr !== key && idStr.endsWith(key)) {
1169
- return value;
1170
- }
1171
- }
1172
- return null;
1173
- }
1174
- var DEDUPLICATION_WARNING;
1175
- var init_shared_modules = __esm({
1176
- "src/runtime/turbopack/shared-modules.ts"() {
1177
- "use strict";
1178
- init_logger();
1179
- init_module();
1180
- init_patterns2();
1181
- init_remote_scope();
1182
- DEDUPLICATION_WARNING = "This module will not be deduplicated \u2014 the remote may load its own copy, which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).";
1183
- }
1184
- });
1185
-
1186
- // src/runtime/turbopack/module.ts
1187
- function requireModule(scope, moduleId, fullId) {
1188
- const idStr = String(moduleId);
1189
- if (scope.moduleCache[idStr])
1190
- return scope.moduleCache[idStr];
1191
- const sharedModule = getSharedModule(scope, moduleId);
1192
- if (sharedModule)
1193
- return sharedModule;
1194
- return handleTurbopackModule(
1195
- scope,
1196
- idStr,
1197
- fullId ?? formatRemoteId(scope, idStr)
1198
- );
1199
- }
1200
- function handleTurbopackModule(scope, moduleId, id) {
1201
- if (scope.moduleCache[moduleId]) {
1202
- return scope.moduleCache[moduleId];
1203
- }
1204
- const modules = getTurbopackModules(scope);
1205
- if (!modules) {
1206
- logError(
1207
- "TurbopackModule",
1208
- `TURBOPACK_${scope.globalKey} is undefined (scope: "${scope.scopedName}")`
1209
- );
1210
- }
1211
- const moduleInit = findModuleInit(modules, moduleId);
1212
- const exports = {};
1213
- const moduleExports = { exports };
1214
- if (typeof moduleInit !== "function") {
1215
- throw new Error(
1216
- `Module ${id} not found in bundle ${scope.name} with id ${moduleId}`
1217
- );
1218
- }
1219
- scope.moduleCache[moduleId] = moduleExports.exports;
1220
- moduleInit(
1221
- createTurbopackContext(
1222
- scope,
1223
- exports,
1224
- moduleExports,
1225
- modules,
1226
- moduleInit,
1227
- id
1228
- ),
1229
- moduleExports,
1230
- exports
1231
- );
1232
- if (scope.moduleCache[moduleId] !== moduleExports.exports) {
1233
- scope.moduleCache[moduleId] = moduleExports.exports;
1234
- }
1235
- return moduleExports.exports;
1236
- }
1237
- function findModuleInit(modules, moduleId) {
1238
- if (!modules || typeof modules !== "object")
1239
- return;
1240
- if (!Array.isArray(modules)) {
1241
- const key = moduleId in modules ? moduleId : Object.keys(modules).find((k) => k.startsWith(moduleId));
1242
- return key !== void 0 ? modules[key] : void 0;
1243
- }
1244
- const flat = modules.flat();
1245
- let idx = flat.findIndex((e) => String(e) === String(moduleId));
1246
- if (idx < 0) {
1247
- idx = flat.findIndex(
1248
- (e) => typeof e === "string" && e.startsWith(moduleId)
1249
- );
1250
- }
1251
- if (idx >= 0) {
1252
- return flat.slice(idx + 1).find((e) => typeof e === "function");
1253
- }
1254
- for (const entry of flat) {
1255
- if (!entry || typeof entry !== "object")
1256
- continue;
1257
- const obj = entry;
1258
- if (moduleId in obj)
1259
- return obj[moduleId];
1260
- const prefixKey = Object.keys(obj).find((k) => k.startsWith(moduleId));
1261
- if (prefixKey)
1262
- return obj[prefixKey];
1263
- }
1264
- return void 0;
1265
- }
1266
- function createTurbopackContext(scope, exports, moduleExports, modules, moduleInit, id) {
1267
- const scopedRequire = (moduleId) => requireModule(scope, moduleId, formatRemoteId(scope, String(moduleId)));
1268
- return {
1269
- // HMR not implemented for Remote Components
1270
- k: {
1271
- register() {
1272
- },
1273
- registerExports() {
1274
- },
1275
- signature() {
1276
- return (fn) => fn;
1277
- }
1278
- },
1279
- // ESM exports setup
1280
- s(bindings, esmId) {
1281
- let mod = exports;
1282
- if (typeof esmId === "string" || typeof esmId === "number") {
1283
- if (!scope.moduleCache[esmId]) {
1284
- scope.moduleCache[esmId] = {};
1285
- }
1286
- mod = scope.moduleCache[esmId];
1287
- }
1288
- Object.defineProperty(mod, "__esModule", { value: true });
1289
- if (Array.isArray(bindings)) {
1290
- let i = 0;
1291
- while (i < bindings.length) {
1292
- const propName = bindings[i++];
1293
- const tagOrFunc = bindings[i++];
1294
- if (typeof tagOrFunc === "number") {
1295
- Object.defineProperty(mod, propName, {
1296
- value: bindings[i++],
1297
- enumerable: true,
1298
- writable: false
1299
- });
1300
- } else {
1301
- const getterFn = tagOrFunc;
1302
- if (typeof bindings[i] === "function") {
1303
- const setterFn = bindings[i++];
1304
- Object.defineProperty(mod, propName, {
1305
- get: getterFn,
1306
- set: setterFn,
1307
- enumerable: true
1308
- });
1309
- } else {
1310
- Object.defineProperty(mod, propName, {
1311
- get: getterFn,
1312
- enumerable: true
1313
- });
1314
- }
1315
- }
1316
- }
1317
- }
1318
- },
1319
- // import — resolves directly via scope, no global dispatch
1320
- i(importId) {
1321
- let mod;
1322
- if (typeof importId === "string") {
1323
- const { exportSource, exportName } = /\s+<export (?<exportSource>.*?) as (?<exportName>.*?)>$/.exec(
1324
- importId
1325
- )?.groups ?? {};
1326
- const normalizedId = importId.replace(
1327
- /\s+<export(?<specifier>.*)>$/,
1328
- ""
1329
- );
1330
- mod = scopedRequire(normalizedId);
1331
- if (mod && exportSource && exportName && (exportSource === "*" || typeof mod[exportSource] !== "undefined") && typeof mod[exportName] === "undefined") {
1332
- if (exportSource === "*") {
1333
- mod[exportName] = mod;
1334
- } else {
1335
- mod[exportName] = mod[exportSource];
1336
- }
1337
- }
1338
- } else {
1339
- mod = scopedRequire(importId);
1340
- }
1341
- if (typeof mod !== "object" || mod === null) {
1342
- mod = { default: mod };
1343
- } else if (!("default" in mod) && // ES module namespace objects have a null prototype, so calling
1344
- // mod.toString() directly throws. Use Object.prototype.toString
1345
- // to safely detect them.
1346
- Object.prototype.toString.call(mod) !== "[object Module]") {
1347
- try {
1348
- mod.default = mod;
1349
- } catch {
1350
- }
1351
- }
1352
- return mod;
1353
- },
1354
- // require — resolves directly via scope
1355
- r(requireId) {
1356
- return scopedRequire(requireId);
1357
- },
1358
- // value exports
1359
- v(value) {
1360
- if (typeof value === "function") {
1361
- exports.default = value((vid) => scopedRequire(vid));
1362
- } else {
1363
- moduleExports.exports = value;
1364
- }
1365
- },
1366
- // async module initializer
1367
- async a(mod) {
1368
- let result;
1369
- await mod(
1370
- () => {
1371
- },
1372
- (value) => result = value
1373
- );
1374
- exports.default = result;
1375
- },
1376
- // async module loader — resolves directly via scope
1377
- async A(Aid) {
1378
- const mod = scopedRequire(Aid);
1379
- return mod.default((parentId) => scopedRequire(parentId));
1380
- },
1381
- // dynamic import tracking — no-op for remote components
1382
- j() {
1383
- },
1384
- // chunk loader — loads directly via scope, no global dispatch
1385
- l(url) {
1386
- const flatModules = Array.isArray(modules) ? modules : [];
1387
- const moduleInitIndex = flatModules.indexOf(moduleInit);
1388
- if (moduleInitIndex !== -1) {
1389
- const scriptIndex = flatModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
1390
- if (scriptIndex !== -1) {
1391
- const script = flatModules[scriptIndex];
1392
- const scriptSrc = script.getAttribute("data-turbopack-src") || "";
1393
- const nextIndex = scriptSrc.indexOf("/_next");
1394
- const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
1395
- const chunkUrl = `${baseUrl}/_next/${url}`;
1396
- return loadChunkWithScope(scope, formatRemoteId(scope, chunkUrl));
1397
- }
1398
- }
1399
- throw new Error(
1400
- `Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
1401
- );
1402
- },
1403
- // globalThis substitute shared across all modules in this scope
1404
- g: scope.moduleGlobal,
1405
- m: moduleExports,
1406
- e: exports
1407
- };
1408
- }
1409
- var init_module = __esm({
1410
- "src/runtime/turbopack/module.ts"() {
1411
- "use strict";
1412
- init_logger();
1413
- init_chunk_loader();
1414
- init_remote_scope();
1415
- init_shared_modules();
1416
- }
1417
- });
1418
-
1419
- // src/runtime/turbopack/remote-scope-setup.ts
1420
- async function setupRemoteScope(runtime, scripts = [], url = new URL(location.href), bundle, resolveClientUrl) {
1421
- const self = globalThis;
1422
- const ns = getNamespace();
1423
- const bundleName = bundle ?? "default";
1424
- const existingScope = getScope(bundleName);
1425
- if (existingScope && existingScope.url.origin === url.origin) {
1426
- logDebug(
1427
- "WebpackRuntime",
1428
- `Reusing scope "${existingScope.scopedName}" (turbopackModules=${existingScope.turbopackModules.length})`
1429
- );
1430
- existingScope.resolveClientUrl = resolveClientUrl;
1431
- if (runtime === RUNTIME_TURBOPACK) {
1432
- await Promise.allSettled(
1433
- scripts.map(
1434
- (script) => script.src ? loadChunkWithScope(existingScope, script.src) : Promise.resolve(void 0)
1435
- )
1436
- );
1437
- }
1438
- return existingScope;
1439
- }
1440
- const scope = createScope(bundleName, url, runtime, resolveClientUrl);
1441
- registerScope(scope);
1442
- if (runtime === RUNTIME_WEBPACK && self.__remote_webpack_require__?.[bundleName]) {
1443
- scope.webpackRequire = self.__remote_webpack_require__[bundleName];
1444
- }
1445
- ns.bundleUrls[bundleName] = url;
1446
- if (scope.scopedName !== bundleName) {
1447
- ns.bundleUrls[scope.scopedName] = url;
1448
- }
1449
- self.__webpack_get_script_filename__ = () => null;
1450
- const willCreateDispatchers = typeof self.__webpack_require__ !== "function" || ns.dispatcherRuntime !== "turbopack";
1451
- if (willCreateDispatchers) {
1452
- if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
1453
- self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
1454
- self.__original_webpack_require__ = self.__webpack_require__;
1455
- }
1456
- self.__webpack_chunk_load__ = createChunkDispatcher();
1457
- self.__webpack_require__ = createModuleDispatcher(runtime);
1458
- ns.dispatcherRuntime = runtime;
1459
- self.__webpack_require_type__ = runtime;
1460
- if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
1461
- self.__remote_webpack_require__[bundleName] = self.__webpack_require__;
1462
- self.__remote_webpack_require__[bundleName].type = "turbopack";
1463
- }
1464
- }
1465
- if (self.__remote_webpack_require__?.[bundleName] && scope.scopedName !== bundleName) {
1466
- self.__remote_webpack_require__[scope.scopedName] = self.__remote_webpack_require__[bundleName];
1467
- }
1468
- if (runtime === RUNTIME_TURBOPACK) {
1469
- const results = await Promise.allSettled(
1470
- scripts.map((script) => {
1471
- if (script.src) {
1472
- return loadChunkWithScope(scope, script.src);
1473
- }
1474
- return Promise.resolve(void 0);
1475
- })
1476
- );
1477
- for (const result of results) {
1478
- if (result.status === "rejected") {
1479
- logWarn(
1480
- "WebpackRuntime",
1481
- `Initial chunk load failed: ${String(result.reason)}`
1482
- );
1483
- }
1484
- }
1485
- }
1486
- return scope;
1487
- }
1488
- function createModuleDispatcher(runtime) {
1489
- return (id) => {
1490
- const self = globalThis;
1491
- const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? {
1492
- bundle: "default",
1493
- id
1494
- };
1495
- const bundleName = bundle ?? "default";
1496
- const remoteRuntime = self.__remote_webpack_require__?.[bundleName] ? self.__remote_webpack_require__[bundleName]?.type || "webpack" : runtime;
1497
- logDebug(
1498
- "ModuleDispatcher",
1499
- `Resolving "${id}" (bundle: "${bundleName}", runtime: "${remoteRuntime}")`
1500
- );
1501
- try {
1502
- if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
1503
- const scope2 = getScope(bundle);
1504
- if (scope2?.webpackRequire)
1505
- return scope2.webpackRequire(moduleId);
1506
- return self.__remote_webpack_require__?.[bundle]?.(moduleId);
1507
- }
1508
- const scope = getScope(bundleName);
1509
- if (scope) {
1510
- return requireModule(scope, moduleId ?? id, id);
1511
- }
1512
- throw new Error(
1513
- `Module "${id}" not found \u2014 no scope for bundle "${bundleName}".`
1514
- );
1515
- } catch (requireError) {
1516
- logWarn(
1517
- "ModuleDispatcher",
1518
- `Module require failed: ${String(requireError)}`
1519
- );
1520
- if (typeof self.__original_webpack_require__ !== "function") {
1521
- throw new RemoteComponentsError(
1522
- `Module "${id}" not found in remote component bundle "${bundleName}".`,
1523
- {
1524
- cause: requireError instanceof Error ? requireError : void 0
1525
- }
1526
- );
1527
- }
1528
- try {
1529
- logDebug(
1530
- "ModuleDispatcher",
1531
- "Falling back to original webpack require"
1532
- );
1533
- return self.__original_webpack_require__(id);
1534
- } catch (originalError) {
1535
- throw new RemoteComponentsError(
1536
- `Module "${id}" not found in remote component bundle "${bundleName}".`,
1537
- { cause: originalError instanceof Error ? originalError : void 0 }
1538
- );
1539
- }
1540
- }
1541
- };
1542
- }
1543
- var init_remote_scope_setup = __esm({
1544
- "src/runtime/turbopack/remote-scope-setup.ts"() {
1545
- "use strict";
1546
- init_constants2();
1547
- init_namespace();
1548
- init_patterns();
1549
- init_error();
1550
- init_logger();
1551
- init_chunk_loader();
1552
- init_module();
1553
- init_remote_scope();
1554
- }
1555
- });
1556
-
1557
- // src/runtime/loaders/script-loader.ts
1558
- async function loadScripts(scripts, resolveClientUrl) {
1559
- await Promise.all(
1560
- scripts.map((script) => {
1561
- return new Promise((resolve, reject) => {
1562
- const newSrc = new URL(
1563
- // remove the remote component bundle name identifier from the script src
1564
- script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
1565
- location.origin
1566
- ).href;
1567
- const resolvedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
1568
- const alreadyLoaded = Array.from(
1569
- document.querySelectorAll("script[src]")
1570
- ).some((s) => s.src === resolvedSrc);
1571
- if (alreadyLoaded) {
1572
- resolve();
1573
- return;
1574
- }
1575
- const newScript = document.createElement("script");
1576
- newScript.onload = () => resolve();
1577
- newScript.onerror = () => {
1578
- const isProxied = isProxiedUrl(resolvedSrc);
1579
- if (isProxied) {
1580
- reject(failedProxiedAssetError("script", newSrc, resolvedSrc));
1581
- } else {
1582
- warnCrossOriginFetchError("ScriptLoader", newSrc);
1583
- reject(
1584
- new RemoteComponentsError(
1585
- `Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
1586
- )
1587
- );
1588
- }
1589
- };
1590
- newScript.src = resolvedSrc;
1591
- newScript.async = true;
1592
- document.head.appendChild(newScript);
1593
- });
1594
- })
1595
- );
1596
- }
1597
- var init_script_loader = __esm({
1598
- "src/runtime/loaders/script-loader.ts"() {
1599
- "use strict";
1600
- init_patterns();
1601
- init_protected_rc_fallback();
1602
- init_error();
1603
- init_logger();
1604
- }
1605
- });
1606
-
1607
- // src/runtime/loaders/static-loader.ts
1608
- async function importViaCallback(absoluteSrc, resolveClientUrl) {
1609
- const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;
1610
- const fetchUrl = new URL(resolvedUrl, location.href).href;
1611
- const response = await fetch(fetchUrl);
1612
- if (!response.ok)
1613
- throw new Error(`Proxied fetch failed: ${response.status}`);
1614
- const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
1615
- /\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
1616
- (_, keyword, quote, relativePath) => {
1617
- const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
1618
- const resolvedImportUrl = new URL(
1619
- resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,
1620
- location.href
1621
- ).href;
1622
- return `${keyword} ${quote}${resolvedImportUrl}${quote}`;
1623
- }
1624
- );
1625
- const moduleBlobUrl = URL.createObjectURL(
1626
- new Blob([content], { type: "text/javascript" })
1627
- );
1628
- const wrapperContent = [
1629
- `import*as m from${JSON.stringify(moduleBlobUrl)};`,
1630
- `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
1631
- `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
1632
- ].join("");
1633
- const wrapperBlobUrl = URL.createObjectURL(
1634
- new Blob([wrapperContent], { type: "text/javascript" })
1635
- );
1636
- const scriptEl = document.createElement("script");
1637
- scriptEl.type = "module";
1638
- scriptEl.src = wrapperBlobUrl;
1639
- try {
1640
- await new Promise((resolve, reject) => {
1641
- scriptEl.onload = () => resolve();
1642
- scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
1643
- document.head.appendChild(scriptEl);
1644
- });
1645
- } finally {
1646
- scriptEl.remove();
1647
- URL.revokeObjectURL(moduleBlobUrl);
1648
- URL.revokeObjectURL(wrapperBlobUrl);
1649
- }
1650
- const registry = getNamespace().moduleRegistry;
1651
- const mod = registry[absoluteSrc] ?? {};
1652
- delete registry[absoluteSrc];
1653
- return mod;
1654
- }
1655
- async function importDirectly(absoluteSrc) {
1656
- try {
1657
- return await import(
1658
- /* @vite-ignore */
1659
- /* webpackIgnore: true */
1660
- absoluteSrc
1661
- );
1662
- } catch (importError) {
1663
- if (!absoluteSrc.startsWith("blob:")) {
1664
- warnCrossOriginFetchError("StaticLoader", absoluteSrc);
1665
- }
1666
- throw importError;
1667
- }
1668
- }
1669
- function resolveScriptSrc(script, url) {
1670
- const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
1671
- if (!rawSrc && script.textContent) {
1672
- return URL.createObjectURL(
1673
- new Blob(
1674
- [script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
1675
- { type: "text/javascript" }
1676
- )
1677
- );
1678
- }
1679
- return rawSrc;
1680
- }
1681
- async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
1682
- const ns = getNamespace();
1683
- if (ns.mountFns[url.href]) {
1684
- ns.mountFns[url.href] = /* @__PURE__ */ new Set();
1685
- }
1686
- if (ns.unmountFns[url.href]) {
1687
- ns.unmountFns[url.href] = /* @__PURE__ */ new Set();
1688
- }
1689
- const mountUnmountSets = await Promise.all(
1690
- scripts.map(async (script) => {
1691
- try {
1692
- const src = resolveScriptSrc(script, url);
1693
- const absoluteSrc = new URL(src, url).href;
1694
- const mod = resolveClientUrl ? await importViaCallback(absoluteSrc, resolveClientUrl) : await importDirectly(absoluteSrc);
1695
- if (src.startsWith("blob:")) {
1696
- URL.revokeObjectURL(src);
1697
- }
1698
- if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
1699
- if (!ns.mountFns[url.href]) {
1700
- ns.mountFns[url.href] = /* @__PURE__ */ new Set();
1701
- }
1702
- ns.mountFns[url.href]?.add(
1703
- mod.mount || mod.default?.mount || (() => {
1704
- })
1705
- );
1706
- }
1707
- if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
1708
- if (!ns.unmountFns[url.href]) {
1709
- ns.unmountFns[url.href] = /* @__PURE__ */ new Set();
1710
- }
1711
- ns.unmountFns[url.href]?.add(
1712
- mod.unmount || mod.default?.unmount || (() => {
1713
- })
1714
- );
1715
- }
1716
- return {
1717
- mount: mod.mount || mod.default?.mount,
1718
- unmount: mod.unmount || mod.default?.unmount
1719
- };
1720
- } catch (e) {
1721
- logError(
1722
- "StaticLoader",
1723
- `Error loading remote component script from "${script.src || url.href}".`,
1724
- e
1725
- );
1726
- return {
1727
- mount: void 0,
1728
- unmount: void 0
1729
- };
1730
- }
1731
- })
1732
- );
1733
- return mountUnmountSets.reduce(
1734
- (acc, { mount, unmount }) => {
1735
- if (typeof mount === "function") {
1736
- acc.mount.add(mount);
1737
- }
1738
- if (typeof unmount === "function") {
1739
- acc.unmount.add(unmount);
1740
- }
1741
- return acc;
1742
- },
1743
- {
1744
- mount: /* @__PURE__ */ new Set(),
1745
- unmount: /* @__PURE__ */ new Set()
1746
- }
1747
- );
1748
- }
1749
- var init_static_loader = __esm({
1750
- "src/runtime/loaders/static-loader.ts"() {
1751
- "use strict";
1752
- init_namespace();
1753
- init_logger();
1754
- }
1755
- });
1756
-
1757
- // src/host/html/runtime/webpack.ts
1758
- var webpack_exports = {};
1759
- __export(webpack_exports, {
1760
- webpackRuntime: () => webpackRuntime
1761
- });
1762
- async function webpackRuntime(bundle, shared, remoteShared, resolveClientUrl) {
1763
- const self = globalThis;
1764
- if (!self.__DISABLE_WEBPACK_EXEC__) {
1765
- self.__DISABLE_WEBPACK_EXEC__ = {};
1766
- }
1767
- self.__DISABLE_WEBPACK_EXEC__[bundle] = true;
1768
- if (typeof self.__webpack_require__ !== "function" && self.__webpack_require_type__ !== "turbopack") {
1769
- self.__webpack_require__ = (remoteId) => {
1770
- const re = /\[(?<bundle>[^\]]+)\] (?<id>.*)/;
1771
- const match = re.exec(remoteId);
1772
- const remoteBundle = match?.groups?.bundle;
1773
- const id = match?.groups?.id;
1774
- if (!(id && remoteBundle)) {
1775
- throw new RemoteComponentsError(
1776
- `Remote Component module "${remoteId}" not found. Did you forget to wrap the Next.js config with \`withRemoteComponentsConfig\` on both host and remote?`
1777
- );
1778
- }
1779
- if (typeof self.__remote_webpack_require__?.[remoteBundle] !== "function") {
1780
- throw new RemoteComponentsError(
1781
- `Remote Components are not available in "${remoteBundle}". Did you forget to wrap the Next.js config with \`withRemoteComponentsConfig\` on both host and remote?`
1782
- );
1783
- }
1784
- return self.__remote_webpack_require__[remoteBundle](id);
1785
- };
1786
- self.__webpack_chunk_load__ = () => {
1787
- return Promise.resolve([]);
1788
- };
1789
- }
1790
- const {
1791
- default: { createFromReadableStream }
1792
- } = await import("react-server-dom-webpack/client.browser");
1793
- async function preloadScripts(scripts, url, remoteBundle, _) {
1794
- const scriptSrcs = scripts.flatMap((script) => {
1795
- const scriptSrc = script.getAttribute("src") || script.getAttribute("data-src");
1796
- script.parentElement?.removeChild(script);
1797
- if (!scriptSrc)
1798
- return [];
1799
- return [
1800
- {
1801
- src: new URL(scriptSrc.replace(NEXT_BUNDLE_PATH_RE, "/_next/"), url).href
1802
- }
1803
- ];
1804
- });
1805
- await loadScripts(scriptSrcs, resolveClientUrl);
1806
- const hostShared = buildHostShared(shared, resolveClientUrl);
1807
- const resolve = await buildWebpackResolve(
1808
- hostShared,
1809
- remoteShared ?? {},
1810
- remoteBundle,
1811
- {
1812
- "/react/index.js": (await import("react")).default,
1813
- "/react/jsx-dev-runtime.js": (await import("react/jsx-dev-runtime")).default,
1814
- "/react/jsx-runtime.js": (await import("react/jsx-runtime")).default,
1815
- "/react-dom/index.js": (await import("react-dom")).default,
1816
- "/react-dom/client.js": (await import("react-dom/client")).default
1817
- },
1818
- "WebpackRuntime"
1819
- );
1820
- applySharedModules(remoteBundle, resolve);
1821
- }
1822
- return {
1823
- self,
1824
- createFromReadableStream,
1825
- applySharedModules,
1826
- nextClientPagesLoader,
1827
- preloadScripts
1828
- };
1829
- }
1830
- var init_webpack = __esm({
1831
- "src/host/html/runtime/webpack.ts"() {
1832
- "use strict";
1833
- init_apply_shared_modules();
1834
- init_next_client_pages_loader();
1835
- init_shared_module_resolver();
1836
- init_script_loader();
1837
- init_patterns();
1838
- init_error();
1839
- }
1840
- });
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1841
2
 
1842
- // src/host/html/runtime/turbopack.ts
1843
- var turbopack_exports = {};
1844
- __export(turbopack_exports, {
1845
- turbopackRuntime: () => turbopackRuntime
1846
- });
1847
- async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClientUrl) {
1848
- const self = globalThis;
1849
- const hostShared = buildHostShared(shared, resolveClientUrl, {
1850
- includeRemoteComponentShared: true
1851
- });
1852
- await setupRemoteScope("turbopack", [], url, bundle, resolveClientUrl);
1853
- const {
1854
- default: { createFromReadableStream }
1855
- } = await import("react-server-dom-webpack/client.browser");
1856
- async function preloadScripts(scripts, __) {
1857
- const scope = await setupRemoteScope(
1858
- "turbopack",
1859
- scripts.map((script) => ({
1860
- src: script.getAttribute("src") || script.getAttribute("data-src") || script.src
1861
- })),
1862
- url,
1863
- bundle,
1864
- resolveClientUrl
1865
- );
1866
- await initializeSharedModules(
1867
- scope,
1868
- buildCoreShared(hostShared),
1869
- remoteShared ?? {}
1870
- );
1871
- }
1872
- return {
1873
- self,
1874
- createFromReadableStream,
1875
- applySharedModules,
1876
- nextClientPagesLoader,
1877
- preloadScripts
1878
- };
1879
- }
1880
- var init_turbopack = __esm({
1881
- "src/host/html/runtime/turbopack.ts"() {
1882
- "use strict";
1883
- init_apply_shared_modules();
1884
- init_next_client_pages_loader();
1885
- init_shared_module_resolver();
1886
- init_remote_scope_setup();
1887
- init_shared_modules();
1888
- }
1889
- });
1890
3
 
1891
- // src/host/html/runtime/script.ts
1892
- var script_exports = {};
1893
- __export(script_exports, {
1894
- scriptRuntime: () => scriptRuntime
1895
- });
1896
- function scriptRuntime(resolveClientUrl) {
1897
- const self = globalThis;
1898
- return {
1899
- self,
1900
- createFromReadableStream: () => Promise.resolve(null),
1901
- applySharedModules: () => Promise.resolve(),
1902
- nextClientPagesLoader: () => ({
1903
- Component: null,
1904
- App: null
1905
- }),
1906
- preloadScripts: (scripts, url) => loadStaticRemoteComponent(scripts, url, resolveClientUrl)
1907
- };
1908
- }
1909
- var init_script = __esm({
1910
- "src/host/html/runtime/script.ts"() {
1911
- "use strict";
1912
- init_static_loader();
1913
- }
1914
- });
1915
4
 
1916
- // src/host/html/index.tsx
1917
- var html_exports = {};
1918
- __export(html_exports, {
1919
- registerSharedModules: () => registerSharedModules
1920
- });
1921
- module.exports = __toCommonJS(html_exports);
1922
- var import_react = require("react");
1923
- var import_client = require("react-dom/client");
1924
5
 
1925
- // src/host/server/fetch-with-hooks.ts
1926
- init_logger();
1927
6
 
1928
- // src/host/server/fetch-headers.ts
1929
- function remoteFetchHeaders() {
1930
- return {
1931
- /**
1932
- * Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
1933
- * If the remote component uses vercel deployment protection, ensure the host and remote vercel
1934
- * projects share a common automation bypass secret, and the shared secret is used as the
1935
- * VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
1936
- */
1937
- ...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
1938
- "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
1939
- } : {},
1940
- Accept: "text/html"
1941
- };
1942
- }
1943
7
 
1944
- // src/host/server/fetch-with-hooks.ts
1945
- async function fetchWithWarning(url, init) {
1946
- try {
1947
- return await fetch(url, init);
1948
- } catch (error) {
1949
- warnCrossOriginFetchError("FetchRemoteComponent", url);
1950
- throw error;
1951
- }
1952
- }
1953
- async function fetchWithHooks(url, additionalInit, options = {}) {
1954
- const {
1955
- onRequest,
1956
- onResponse,
1957
- abortController = new AbortController()
1958
- } = options;
1959
- const signal = abortController.signal;
1960
- const hookOptions = {
1961
- signal,
1962
- abort: (reason) => abortController.abort(reason)
1963
- };
1964
- const init = {
1965
- method: "GET",
1966
- headers: remoteFetchHeaders(),
1967
- signal,
1968
- ...additionalInit
1969
- };
1970
- const res = await onRequest?.(url, init, hookOptions) ?? await fetchWithWarning(url, init);
1971
- return await onResponse?.(url, res, hookOptions) ?? res;
1972
- }
1973
8
 
1974
- // src/host/server/get-client-or-server-url.ts
1975
- function getClientOrServerUrl(src, serverFallback) {
1976
- const fallback = typeof location !== "undefined" ? location.href : serverFallback;
1977
- if (!src) {
1978
- return new URL(fallback);
1979
- }
1980
- return typeof src === "string" ? new URL(src, fallback) : src;
1981
- }
1982
9
 
1983
- // src/host/shared/lifecycle.ts
1984
- function makeEventEmitter(element) {
1985
- function dispatch(type, detail) {
1986
- const event = new Event(type, { bubbles: true, composed: true });
1987
- if (detail) {
1988
- Object.assign(event, detail);
1989
- }
1990
- element.dispatchEvent(event);
1991
- }
1992
- return {
1993
- beforeLoad(src) {
1994
- dispatch("beforeload", { src });
1995
- },
1996
- load(src) {
1997
- dispatch("load", { src });
1998
- },
1999
- error(error, src) {
2000
- dispatch("error", src != null ? { error, src } : { error });
2001
- },
2002
- change(info) {
2003
- dispatch("change", info);
2004
- }
2005
- };
2006
- }
10
+ var _chunkI47KE3ECcjs = require('../chunk-I47KE3EC.cjs');
11
+ require('../chunk-LCXO7BUY.cjs');
12
+ require('../chunk-RJW3EZJP.cjs');
13
+ require('../chunk-T64P7BAG.cjs');
14
+ require('../chunk-TZT7DLO5.cjs');
2007
15
 
2008
- // src/host/shared/pipeline.ts
2009
- init_shared_module_resolver();
2010
16
 
2011
- // src/runtime/html/html-spec.ts
2012
- var ORIGIN_REWRITE_TAGS = [
2013
- "img",
2014
- "source",
2015
- "video",
2016
- "audio",
2017
- "track",
2018
- "iframe",
2019
- "embed",
2020
- "script",
2021
- "link"
2022
- ];
2023
- var ID_SUFFIX_RSC = "_rsc";
2024
- var ID_SUFFIX_SSR = "_ssr";
2025
- var ID_SUFFIX_SHARED = "_shared";
2026
- var DATA_BUNDLE = "data-bundle";
2027
- var DATA_ROUTE = "data-route";
2028
- var DATA_RUNTIME = "data-runtime";
2029
- var DATA_TYPE = "data-type";
2030
- var DATA_SRC = "data-src";
2031
- var DATA_REMOTE_COMPONENTS_SHARED = "data-remote-components-shared";
2032
- var TAG_REMOTE_COMPONENT = "remote-component";
2033
- var NEXT_DATA_ID = "__NEXT_DATA__";
2034
- var REMOTE_NEXT_DATA_ID = "__REMOTE_NEXT_DATA__";
2035
- var NEXT_CONTAINER_ID = "__next";
2036
17
 
2037
- // src/runtime/html/rewrite-srcset.ts
2038
- function rewriteSrcset(srcset, base, resolve) {
2039
- return srcset.split(",").map((entry) => {
2040
- const [url, descriptor] = entry.trim().split(/\s+/);
2041
- if (!url)
2042
- return entry;
2043
- const absoluteUrl = new URL(url, base).href;
2044
- const resolvedUrl = resolve ? resolve(absoluteUrl) : absoluteUrl;
2045
- return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
2046
- }).join(", ");
2047
- }
2048
18
 
2049
- // src/runtime/html/apply-origin.ts
2050
- function applyOriginToNodes(doc, url, resolveClientUrl) {
2051
- if (url.origin !== location.origin) {
2052
- const nodes = doc.querySelectorAll(
2053
- ORIGIN_REWRITE_TAGS.map(
2054
- (type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
2055
- ).join(",")
2056
- );
2057
- nodes.forEach((node) => {
2058
- if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
2059
- const absoluteSrc = new URL(node.getAttribute("src") ?? "/", url).href;
2060
- const isScript = node.tagName.toLowerCase() === "script";
2061
- node.src = isScript ? absoluteSrc : resolveClientUrl?.(absoluteSrc) ?? absoluteSrc;
2062
- }
2063
- if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
2064
- const absoluteHref = new URL(node.getAttribute("href") ?? "/", url).href;
2065
- node.setAttribute(
2066
- "href",
2067
- resolveClientUrl?.(absoluteHref) ?? absoluteHref
2068
- );
2069
- }
2070
- if (node.hasAttribute("srcset")) {
2071
- const raw = node.getAttribute("srcset");
2072
- if (raw) {
2073
- const resolve = resolveClientUrl ? (abs) => resolveClientUrl(abs) ?? abs : void 0;
2074
- node.setAttribute("srcset", rewriteSrcset(raw, url, resolve));
2075
- }
2076
- }
2077
- if (node.hasAttribute("imagesrcset")) {
2078
- const raw = node.getAttribute("imagesrcset");
2079
- if (raw) {
2080
- const resolve = resolveClientUrl ? (abs) => resolveClientUrl(abs) ?? abs : void 0;
2081
- node.setAttribute("imagesrcset", rewriteSrcset(raw, url, resolve));
2082
- }
2083
- }
2084
- });
2085
- }
2086
- }
19
+ var _chunkX6W464D6cjs = require('../chunk-X6W464D6.cjs');
2087
20
 
2088
- // src/runtime/html/parse-remote-html.ts
2089
- init_constants2();
2090
21
 
2091
- // src/runtime/metadata.ts
2092
- init_constants2();
2093
- var VALID_RUNTIMES = /* @__PURE__ */ new Set(["webpack", "turbopack", "script"]);
2094
- var VALID_TYPES = /* @__PURE__ */ new Set([
2095
- "nextjs",
2096
- "remote-component",
2097
- "unknown"
2098
- ]);
2099
- function isRuntime(value) {
2100
- return VALID_RUNTIMES.has(value);
2101
- }
2102
- function isComponentType(value) {
2103
- return VALID_TYPES.has(value);
2104
- }
2105
- function toRuntime(value) {
2106
- return value && isRuntime(value) ? value : "webpack";
2107
- }
2108
- function toComponentType(value) {
2109
- return value && isComponentType(value) ? value : "unknown";
2110
- }
2111
- function buildMetadata(attrs, url) {
2112
- const id = attrs.id || DEFAULT_COMPONENT_NAME;
2113
- const bundle = attrs.bundle || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || DEFAULT_BUNDLE_NAME;
2114
- return {
2115
- name: attrs.name || id.replace(/_ssr$/, ""),
2116
- bundle,
2117
- route: attrs.route || url.pathname || DEFAULT_ROUTE,
2118
- runtime: toRuntime(attrs.runtime),
2119
- id,
2120
- type: toComponentType(attrs.type)
2121
- };
2122
- }
22
+ var _chunkZ2SLBFQLcjs = require('../chunk-Z2SLBFQL.cjs');
2123
23
 
2124
- // src/runtime/html/parse-remote-html.ts
2125
- init_error();
2126
- function validateSingleComponent(doc, name, url) {
2127
- if (doc.querySelectorAll(`div[${DATA_BUNDLE}][${DATA_ROUTE}]`).length > 1 && !doc.querySelector(
2128
- `div[${DATA_BUNDLE}][${DATA_ROUTE}][id^="${name}"]`
2129
- ) || doc.querySelectorAll(`${TAG_REMOTE_COMPONENT}:not([src])`).length > 1 && !doc.querySelector(`${TAG_REMOTE_COMPONENT}[name="${name}"]`)) {
2130
- throw multipleRemoteComponentsError(url);
2131
- }
2132
- }
2133
- function findComponentElement(doc, name) {
2134
- return doc.querySelector(`div[${DATA_BUNDLE}][${DATA_ROUTE}][id^="${name}"]`) ?? doc.querySelector(`div[${DATA_BUNDLE}][${DATA_ROUTE}]`) ?? doc.querySelector(`div#${NEXT_CONTAINER_ID}`) ?? doc.querySelector(`${TAG_REMOTE_COMPONENT}[name="${name}"]:not([src])`) ?? doc.querySelector(`${TAG_REMOTE_COMPONENT}:not([src])`);
2135
- }
2136
- function parseNextData(doc) {
2137
- return JSON.parse(
2138
- (doc.querySelector(`#${NEXT_DATA_ID}`) ?? doc.querySelector(`#${REMOTE_NEXT_DATA_ID}`))?.textContent ?? "null"
2139
- );
2140
- }
2141
- function resolveComponentName(component, nextData, fallbackName) {
2142
- const isRemoteComponent = component?.tagName.toLowerCase() === TAG_REMOTE_COMPONENT;
2143
- const name = component?.getAttribute("id")?.replace(new RegExp(`${ID_SUFFIX_SSR}$`), "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
2144
- return { name, isRemoteComponent };
2145
- }
2146
- function extractRemoteShared(doc, name, nextData) {
2147
- const remoteSharedEl = doc.querySelector(
2148
- `#${name}${ID_SUFFIX_SHARED}[${DATA_REMOTE_COMPONENTS_SHARED}]`
2149
- );
2150
- const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
2151
- remoteSharedEl?.remove();
2152
- return remoteShared;
2153
- }
2154
- function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
2155
- if (!component || !(rsc || nextData || isRemoteComponent)) {
2156
- throw new RemoteComponentsError(
2157
- `Remote Component not found on ${url}.${name !== DEFAULT_COMPONENT_NAME ? ` The name for the <RemoteComponent> is "${name}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
2158
- );
2159
- }
2160
- }
2161
- function extractLinks(doc, component) {
2162
- return Array.from(doc.querySelectorAll("link[href]")).filter(
2163
- (link) => !component.contains(link)
2164
- );
2165
- }
2166
- function extractScripts(doc, component, isRemoteComponent) {
2167
- return Array.from(
2168
- (isRemoteComponent ? component : doc).querySelectorAll(
2169
- `script[src],script[${DATA_SRC}]`
2170
- )
2171
- );
2172
- }
2173
- function parseRemoteComponentDocument(doc, name, url) {
2174
- validateSingleComponent(doc, name, url.href);
2175
- const component = findComponentElement(doc, name);
2176
- const nextData = parseNextData(doc);
2177
- const { name: resolvedName, isRemoteComponent } = resolveComponentName(
2178
- component,
2179
- nextData,
2180
- name
2181
- );
2182
- const rsc = doc.querySelector(`#${resolvedName}${ID_SUFFIX_RSC}`);
2183
- const metadata = buildMetadata(
2184
- {
2185
- name: resolvedName,
2186
- bundle: component?.getAttribute(DATA_BUNDLE) || nextData?.props.__REMOTE_COMPONENT__?.bundle,
2187
- route: component?.getAttribute(DATA_ROUTE) ?? nextData?.page,
2188
- runtime: component?.getAttribute(DATA_RUNTIME) ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? RUNTIME_SCRIPT,
2189
- id: component?.getAttribute("id"),
2190
- type: component?.getAttribute(DATA_TYPE)
2191
- },
2192
- url
2193
- );
2194
- const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
2195
- validateComponentFound(
2196
- component,
2197
- rsc,
2198
- nextData,
2199
- isRemoteComponent,
2200
- url.href,
2201
- resolvedName
2202
- );
2203
- const links = extractLinks(doc, component);
2204
- const scripts = extractScripts(doc, component, isRemoteComponent);
2205
- return {
2206
- component,
2207
- name: resolvedName,
2208
- isRemoteComponent,
2209
- metadata,
2210
- nextData,
2211
- rsc,
2212
- remoteShared,
2213
- links,
2214
- scripts
2215
- };
2216
- }
2217
24
 
2218
- // src/runtime/loaders/component-loader.ts
2219
- var React = __toESM(require("react"), 1);
2220
- var JSXDevRuntime = __toESM(require("react/jsx-dev-runtime"), 1);
2221
- var JSXRuntime = __toESM(require("react/jsx-runtime"), 1);
2222
- var ReactDOM = __toESM(require("react-dom"), 1);
2223
- var ReactDOMClient = __toESM(require("react-dom/client"), 1);
2224
- init_apply_shared_modules();
2225
- init_next_client_pages_loader();
2226
- init_shared_module_resolver();
2227
25
 
2228
- // src/runtime/rsc.ts
2229
- var import_web_streams_polyfill = require("web-streams-polyfill");
2230
- function fixPayload(payload) {
2231
- if (Array.isArray(payload)) {
2232
- if (payload[0] === "$") {
2233
- fixPayload(payload[3]);
2234
- if (payload.length === 4) {
2235
- payload.push(null, null, 1);
2236
- }
2237
- } else {
2238
- for (const item of payload) {
2239
- fixPayload(item);
2240
- }
2241
- }
2242
- } else if (typeof payload === "object" && payload !== null) {
2243
- for (const key in payload) {
2244
- fixPayload(payload[key]);
2245
- }
2246
- }
2247
- }
2248
- function buildRSCChunks(rscName, data) {
2249
- const chunks = [];
2250
- for (const chunk of data) {
2251
- for (const line of chunk.split("\n")) {
2252
- const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
2253
- if (match?.groups?.rsc) {
2254
- chunks.push(JSON.parse(`"${match.groups.rsc}"`));
2255
- }
2256
- }
2257
- }
2258
- return chunks;
2259
- }
2260
- function createRSCStream(rscName, data) {
2261
- return new import_web_streams_polyfill.ReadableStream({
2262
- type: "bytes",
2263
- start(controller) {
2264
- const encoder = new TextEncoder();
2265
- const self = globalThis;
2266
- if (data.length > 0) {
2267
- const parsed = buildRSCChunks(rscName, data);
2268
- if (parsed.length > 0) {
2269
- self[rscName] = self[rscName] ?? [];
2270
- self[rscName].push(...parsed);
2271
- }
2272
- }
2273
- const allChunks = (self[rscName] ?? [`0:[null]
2274
- `]).join("");
2275
- self[rscName] = null;
2276
- allChunks.split("\n").forEach((chunk) => {
2277
- if (chunk.length > 0) {
2278
- const { before, id, prefix, payload } = /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
2279
- chunk
2280
- )?.groups ?? {};
2281
- if (payload) {
2282
- const jsonPayload = JSON.parse(payload);
2283
- fixPayload(jsonPayload);
2284
- const reconstruct = `${before ?? ""}${id}:${prefix ?? ""}${JSON.stringify(jsonPayload)}`;
2285
- controller.enqueue(encoder.encode(`${reconstruct}
2286
- `));
2287
- } else {
2288
- controller.enqueue(encoder.encode(`${chunk}
2289
- `));
2290
- }
2291
- } else {
2292
- controller.enqueue(encoder.encode(`${chunk}
2293
- `));
2294
- }
2295
- });
2296
- controller.close();
2297
- }
2298
- });
2299
- }
2300
26
 
2301
- // src/runtime/loaders/component-loader.ts
2302
- init_remote_scope_setup();
2303
- init_shared_modules();
2304
- init_error();
2305
- init_logger();
2306
- init_script_loader();
2307
-
2308
- // src/host/shared/pipeline.ts
2309
- init_static_loader();
2310
- init_patterns();
2311
- init_utils();
2312
- init_error();
2313
- function preparePipeline(input) {
2314
- const parser = new DOMParser();
2315
- const doc = parser.parseFromString(input.html, "text/html");
2316
- const parsed = parseRemoteComponentDocument(doc, input.name, input.url);
2317
- const remoteShared = input.remoteShared ?? parsed.remoteShared;
2318
- if ("__remote_components_missing_shared__" in remoteShared) {
2319
- throw new RemoteComponentsError(
2320
- remoteShared.__remote_components_missing_shared__
2321
- );
2322
- }
2323
- applyOriginToNodes(doc, input.url, input.resolveClientUrl);
2324
- const scriptDescriptors = buildScriptDescriptors(parsed.scripts, input.url);
2325
- return { doc, parsed, scriptDescriptors };
2326
- }
2327
- function buildScriptDescriptors(scripts, url) {
2328
- return scripts.map((script) => {
2329
- const scriptSrc = script.getAttribute("data-src") || script.getAttribute("src") || script.src;
2330
- const { prefix, id: path } = REMOTE_COMPONENT_REGEX.exec(scriptSrc)?.groups ?? {
2331
- prefix: void 0,
2332
- id: scriptSrc
2333
- };
2334
- return {
2335
- src: new URL(collapseDoubleSlashes(`${prefix ?? ""}${path}`), url).href
2336
- };
2337
- });
2338
- }
2339
27
 
2340
- // src/host/shared/state.ts
2341
- function createHostState() {
2342
- return {
2343
- stage: "idle",
2344
- prevSrc: void 0,
2345
- prevUrl: void 0,
2346
- prevName: void 0,
2347
- prevIsRemoteComponent: false,
2348
- abortController: void 0
2349
- };
2350
- }
2351
-
2352
- // src/host/utils/resolve-name-from-src.ts
2353
- function resolveNameFromSrc(src, defaultName) {
2354
- if (!src) {
2355
- return defaultName;
2356
- }
2357
- const hash = typeof src === "string" ? src : src.hash;
2358
- const hashIndex = hash.indexOf("#");
2359
- if (hashIndex < 0) {
2360
- return defaultName;
2361
- }
2362
- const name = hash.slice(hashIndex + 1);
2363
- return name || defaultName;
2364
- }
28
+ var _chunkRUWR74XQcjs = require('../chunk-RUWR74XQ.cjs');
29
+ require('../chunk-TCFLEBQM.cjs');
30
+ require('../chunk-KE7QPAQ4.cjs');
31
+ require('../chunk-SHFJ5OQA.cjs');
2365
32
 
2366
33
  // src/host/html/index.tsx
2367
- init_constants2();
2368
- init_namespace();
2369
-
2370
- // src/runtime/url/resolve-client-url.ts
2371
- function withRemoteSrc(resolveClientUrl, remoteSrc) {
2372
- const remoteOrigin = parseOrigin(remoteSrc);
2373
- return (url) => {
2374
- const urlOrigin = parseOrigin(url);
2375
- if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
2376
- return void 0;
2377
- }
2378
- return resolveClientUrl(remoteSrc, url);
2379
- };
2380
- }
2381
- function parseOrigin(url) {
2382
- try {
2383
- return new URL(url).origin;
2384
- } catch {
2385
- return void 0;
2386
- }
2387
- }
2388
-
2389
- // src/runtime/url/default-resolve-client-url.ts
2390
- function bindResolveClientUrl(prop, remoteSrc) {
2391
- return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
2392
- }
2393
-
2394
- // src/host/html/index.tsx
2395
- init_utils();
2396
- init_abort();
2397
- init_error();
2398
- init_logger();
34
+ var _react = require('react');
35
+ var _client = require('react-dom/client');
2399
36
 
2400
37
  // src/host/html/attach-styles.ts
2401
- init_error();
2402
38
  async function attachStyles({
2403
39
  doc,
2404
40
  component,
@@ -2420,9 +56,9 @@ async function attachStyles({
2420
56
  link.onerror = null;
2421
57
  link.remove();
2422
58
  }
2423
- abortReject?.(new DOMException("Aborted", "AbortError"));
59
+ _optionalChain([abortReject, 'optionalCall', _2 => _2(new DOMException("Aborted", "AbortError"))]);
2424
60
  };
2425
- signal?.addEventListener("abort", abortHandler, { once: true });
61
+ _optionalChain([signal, 'optionalAccess', _3 => _3.addEventListener, 'call', _4 => _4("abort", abortHandler, { once: true })]);
2426
62
  try {
2427
63
  await Promise.all(
2428
64
  Array.from(links).filter((link) => !component.contains(link)).map((link) => {
@@ -2432,7 +68,7 @@ async function attachStyles({
2432
68
  if (link.rel === "stylesheet") {
2433
69
  newLink.onload = () => resolve();
2434
70
  newLink.onerror = () => reject(
2435
- new RemoteComponentsError(
71
+ new (0, _chunkRUWR74XQcjs.RemoteComponentsError)(
2436
72
  `Failed to load <link href="${link.href}"> for Remote Component. Check the URL is correct.`
2437
73
  )
2438
74
  );
@@ -2444,11 +80,11 @@ async function attachStyles({
2444
80
  if (attr.name === "href") {
2445
81
  const absoluteHref = new URL(
2446
82
  attr.value,
2447
- baseUrl ?? location.origin
83
+ _nullishCoalesce(baseUrl, () => ( location.origin))
2448
84
  ).href;
2449
85
  newLink.setAttribute(
2450
86
  attr.name,
2451
- resolveClientUrl?.(absoluteHref) ?? absoluteHref
87
+ _nullishCoalesce(_optionalChain([resolveClientUrl, 'optionalCall', _5 => _5(absoluteHref)]), () => ( absoluteHref))
2452
88
  );
2453
89
  } else {
2454
90
  newLink.setAttribute(attr.name, attr.value);
@@ -2460,28 +96,27 @@ async function attachStyles({
2460
96
  remoteComponentSrc
2461
97
  );
2462
98
  }
2463
- root?.appendChild(newLink);
99
+ _optionalChain([root, 'optionalAccess', _6 => _6.appendChild, 'call', _7 => _7(newLink)]);
2464
100
  return Promise.race([loadPromise, abortPromise]);
2465
101
  })
2466
102
  );
2467
103
  } finally {
2468
- signal?.removeEventListener("abort", abortHandler);
104
+ _optionalChain([signal, 'optionalAccess', _8 => _8.removeEventListener, 'call', _9 => _9("abort", abortHandler)]);
2469
105
  }
2470
106
  const styles = doc.querySelectorAll("style");
2471
107
  for (const style of styles) {
2472
- if (style.parentElement?.tagName.toLowerCase() === "head") {
108
+ if (_optionalChain([style, 'access', _10 => _10.parentElement, 'optionalAccess', _11 => _11.tagName, 'access', _12 => _12.toLowerCase, 'call', _13 => _13()]) === "head") {
2473
109
  const newStyle = document.createElement("style");
2474
110
  newStyle.textContent = style.textContent;
2475
111
  if (remoteComponentSrc) {
2476
112
  newStyle.setAttribute("data-remote-component-src", remoteComponentSrc);
2477
113
  }
2478
- root?.appendChild(newStyle);
114
+ _optionalChain([root, 'optionalAccess', _14 => _14.appendChild, 'call', _15 => _15(newStyle)]);
2479
115
  }
2480
116
  }
2481
117
  }
2482
118
 
2483
119
  // src/host/html/runtime/index.ts
2484
- init_error();
2485
120
  async function getRuntime(type, url, bundle, shared, remoteShared, resolveClientUrl) {
2486
121
  if (typeof globalThis.process === "undefined") {
2487
122
  globalThis.process = {
@@ -2489,11 +124,11 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
2489
124
  };
2490
125
  }
2491
126
  if (type === "webpack") {
2492
- const { webpackRuntime: webpackRuntime2 } = await Promise.resolve().then(() => (init_webpack(), webpack_exports));
2493
- return webpackRuntime2(bundle, shared, remoteShared, resolveClientUrl);
127
+ const { webpackRuntime } = await Promise.resolve().then(() => _interopRequireWildcard(require("../webpack-TTZDARNY.cjs")));
128
+ return webpackRuntime(bundle, shared, remoteShared, resolveClientUrl);
2494
129
  } else if (type === "turbopack") {
2495
- const { turbopackRuntime: turbopackRuntime2 } = await Promise.resolve().then(() => (init_turbopack(), turbopack_exports));
2496
- return turbopackRuntime2(
130
+ const { turbopackRuntime } = await Promise.resolve().then(() => _interopRequireWildcard(require("../turbopack-KRKECGY2.cjs")));
131
+ return turbopackRuntime(
2497
132
  url,
2498
133
  bundle,
2499
134
  shared,
@@ -2501,33 +136,33 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
2501
136
  resolveClientUrl
2502
137
  );
2503
138
  } else if (type === "script") {
2504
- const { scriptRuntime: scriptRuntime2 } = await Promise.resolve().then(() => (init_script(), script_exports));
2505
- return scriptRuntime2(resolveClientUrl);
139
+ const { scriptRuntime } = await Promise.resolve().then(() => _interopRequireWildcard(require("../script-D5AD7HLV.cjs")));
140
+ return scriptRuntime(resolveClientUrl);
2506
141
  }
2507
- throw new RemoteComponentsError(
142
+ throw new (0, _chunkRUWR74XQcjs.RemoteComponentsError)(
2508
143
  `Remote Components runtime "${type}" is not supported. Supported runtimes are "webpack", "turbopack", and "script".`
2509
144
  );
2510
145
  }
2511
146
 
2512
147
  // src/host/html/index.tsx
2513
- var import_jsx_runtime2 = require("react/jsx-runtime");
148
+ var _jsxruntime = require('react/jsx-runtime');
2514
149
  if (typeof HTMLElement !== "undefined") {
2515
- class RemoteComponent extends HTMLElement {
2516
- name = DEFAULT_COMPONENT_NAME;
2517
- bundle = DEFAULT_BUNDLE_NAME;
2518
- fallbackSlot;
2519
- __next = null;
2520
- fouc = null;
2521
- hostState = createHostState();
2522
- root = null;
2523
- reactRoot;
2524
- emitter = makeEventEmitter(this);
2525
- onRequest;
2526
- onResponse;
2527
- resolveClientUrl;
150
+ class RemoteComponent extends HTMLElement {constructor(...args) { super(...args); RemoteComponent.prototype.__init.call(this);RemoteComponent.prototype.__init2.call(this);RemoteComponent.prototype.__init3.call(this);RemoteComponent.prototype.__init4.call(this);RemoteComponent.prototype.__init5.call(this);RemoteComponent.prototype.__init6.call(this);RemoteComponent.prototype.__init7.call(this); }
151
+ __init() {this.name = _chunkX6W464D6cjs.DEFAULT_COMPONENT_NAME}
152
+ __init2() {this.bundle = _chunkX6W464D6cjs.DEFAULT_BUNDLE_NAME}
153
+
154
+ __init3() {this.__next = null}
155
+ __init4() {this.fouc = null}
156
+ __init5() {this.hostState = _chunkI47KE3ECcjs.createHostState.call(void 0, )}
157
+ __init6() {this.root = null}
158
+
159
+ __init7() {this.emitter = _chunkI47KE3ECcjs.makeEventEmitter.call(void 0, this)}
160
+
161
+
162
+
2528
163
  // -- ConsumeServerConfig property accessors (attribute-reflected) --
2529
164
  get src() {
2530
- return this.getAttribute("src") ?? void 0;
165
+ return _nullishCoalesce(this.getAttribute("src"), () => ( void 0));
2531
166
  }
2532
167
  set src(value) {
2533
168
  if (value == null) {
@@ -2576,10 +211,10 @@ if (typeof HTMLElement !== "undefined") {
2576
211
  if ((name === "src" || name === "name") && oldValue !== newValue) {
2577
212
  if (this.src) {
2578
213
  this.load().catch((e) => {
2579
- if (isAbortError(e)) {
214
+ if (_chunkRUWR74XQcjs.isAbortError.call(void 0, e)) {
2580
215
  return;
2581
216
  }
2582
- logError("HtmlHost", "Error loading remote component.", e);
217
+ _chunkRUWR74XQcjs.logError.call(void 0, "HtmlHost", "Error loading remote component.", e);
2583
218
  this.emitter.error(e, this.src);
2584
219
  this.hostState.stage = "error";
2585
220
  });
@@ -2593,10 +228,10 @@ if (typeof HTMLElement !== "undefined") {
2593
228
  });
2594
229
  this.root = newRoot;
2595
230
  this.load().catch((e) => {
2596
- if (isAbortError(e)) {
231
+ if (_chunkRUWR74XQcjs.isAbortError.call(void 0, e)) {
2597
232
  return;
2598
233
  }
2599
- logError("HtmlHost", "Error reloading remote component.", e);
234
+ _chunkRUWR74XQcjs.logError.call(void 0, "HtmlHost", "Error reloading remote component.", e);
2600
235
  this.emitter.error(e, this.src);
2601
236
  });
2602
237
  }
@@ -2608,7 +243,7 @@ if (typeof HTMLElement !== "undefined") {
2608
243
  });
2609
244
  });
2610
245
  if (this.hostState.stage === "loading") {
2611
- this.hostState.abortController?.abort();
246
+ _optionalChain([this, 'access', _16 => _16.hostState, 'access', _17 => _17.abortController, 'optionalAccess', _18 => _18.abort, 'call', _19 => _19()]);
2612
247
  this.hostState.stage = "idle";
2613
248
  if (this.root && !this.reactRoot) {
2614
249
  this.root.innerHTML = "";
@@ -2631,50 +266,50 @@ if (typeof HTMLElement !== "undefined") {
2631
266
  const signal = this.hostState.abortController.signal;
2632
267
  const isCurrentLoad = () => !signal.aborted && this.src === src;
2633
268
  const abandonLoad = () => {
2634
- if (this.hostState.abortController?.signal === signal && this.hostState.stage === "loading") {
269
+ if (_optionalChain([this, 'access', _20 => _20.hostState, 'access', _21 => _21.abortController, 'optionalAccess', _22 => _22.signal]) === signal && this.hostState.stage === "loading") {
2635
270
  this.hostState.stage = "idle";
2636
271
  }
2637
272
  };
2638
- this.emitter.beforeLoad(src ?? "");
273
+ this.emitter.beforeLoad(_nullishCoalesce(src, () => ( "")));
2639
274
  const remoteComponentChild = this.querySelector("div#__REMOTE_COMPONENT__") || this.querySelector("div[data-bundle][data-route]");
2640
275
  if (!src && !remoteComponentChild) {
2641
- throw new RemoteComponentsError('"src" attribute is required');
276
+ throw new (0, _chunkRUWR74XQcjs.RemoteComponentsError)('"src" attribute is required');
2642
277
  }
2643
278
  let url = null;
2644
279
  let html = this.innerHTML;
2645
280
  if (src) {
2646
- url = getClientOrServerUrl(src, window.location.href);
2647
- this.name = resolveNameFromSrc(src, this.name);
281
+ url = _chunkI47KE3ECcjs.getClientOrServerUrl.call(void 0, src, window.location.href);
282
+ this.name = _chunkI47KE3ECcjs.resolveNameFromSrc.call(void 0, src, this.name);
2648
283
  }
2649
- const resolveClientUrl = url ? bindResolveClientUrl(this.resolveClientUrl, url.href) : void 0;
284
+ const resolveClientUrl = url ? _chunkI47KE3ECcjs.bindResolveClientUrl.call(void 0, this.resolveClientUrl, url.href) : void 0;
2650
285
  if (!remoteComponentChild && url) {
2651
286
  const fetchInit = {
2652
287
  credentials: this.credentials || "same-origin"
2653
288
  };
2654
289
  const resolvedUrl = new URL(
2655
- resolveClientUrl?.(url.href) ?? url.href,
290
+ _nullishCoalesce(_optionalChain([resolveClientUrl, 'optionalCall', _23 => _23(url.href)]), () => ( url.href)),
2656
291
  window.location.href
2657
292
  );
2658
293
  let res;
2659
294
  try {
2660
- res = await fetchWithHooks(resolvedUrl, fetchInit, {
295
+ res = await _chunkI47KE3ECcjs.fetchWithHooks.call(void 0, resolvedUrl, fetchInit, {
2661
296
  onRequest: this.onRequest,
2662
297
  onResponse: this.onResponse,
2663
298
  abortController: this.hostState.abortController
2664
299
  });
2665
300
  } catch (e) {
2666
- if (isAbortError(e)) {
301
+ if (_chunkRUWR74XQcjs.isAbortError.call(void 0, e)) {
2667
302
  return abandonLoad();
2668
303
  }
2669
304
  throw e;
2670
305
  }
2671
306
  if (!res || !res.ok) {
2672
- throw await errorFromFailedFetch(url.href, resolvedUrl, res);
307
+ throw await _chunkRUWR74XQcjs.errorFromFailedFetch.call(void 0, url.href, resolvedUrl, res);
2673
308
  }
2674
309
  try {
2675
310
  html = await res.text();
2676
311
  } catch (e) {
2677
- if (isAbortError(e)) {
312
+ if (_chunkRUWR74XQcjs.isAbortError.call(void 0, e)) {
2678
313
  return abandonLoad();
2679
314
  }
2680
315
  throw e;
@@ -2683,8 +318,8 @@ if (typeof HTMLElement !== "undefined") {
2683
318
  return abandonLoad();
2684
319
  }
2685
320
  }
2686
- const effectiveUrl = url ?? new URL(window.location.href);
2687
- const { doc, parsed } = preparePipeline({
321
+ const effectiveUrl = _nullishCoalesce(url, () => ( new URL(window.location.href)));
322
+ const { doc, parsed } = _chunkI47KE3ECcjs.preparePipeline.call(void 0, {
2688
323
  html,
2689
324
  name: this.name,
2690
325
  url: effectiveUrl,
@@ -2708,7 +343,7 @@ if (typeof HTMLElement !== "undefined") {
2708
343
  this.name = resolvedName;
2709
344
  this.bundle = parsedMetadata.bundle;
2710
345
  if (url) {
2711
- getNamespace().bundleUrls[this.bundle] = url;
346
+ _chunkZ2SLBFQLcjs.getNamespace.call(void 0, ).bundleUrls[this.bundle] = url;
2712
347
  }
2713
348
  const metadataEl = document.createElement("script");
2714
349
  metadataEl.type = "application/json";
@@ -2720,22 +355,22 @@ if (typeof HTMLElement !== "undefined") {
2720
355
  runtime: parsedMetadata.runtime
2721
356
  };
2722
357
  metadataEl.textContent = JSON.stringify(metadataObj);
2723
- if (this.previousElementSibling?.getAttribute("data-remote-component") !== null) {
2724
- this.previousElementSibling?.remove();
358
+ if (_optionalChain([this, 'access', _24 => _24.previousElementSibling, 'optionalAccess', _25 => _25.getAttribute, 'call', _26 => _26("data-remote-component")]) !== null) {
359
+ _optionalChain([this, 'access', _27 => _27.previousElementSibling, 'optionalAccess', _28 => _28.remove, 'call', _29 => _29()]);
2725
360
  }
2726
- this.parentElement?.insertBefore(metadataEl, this);
361
+ _optionalChain([this, 'access', _30 => _30.parentElement, 'optionalAccess', _31 => _31.insertBefore, 'call', _32 => _32(metadataEl, this)]);
2727
362
  if (this.hostState.prevIsRemoteComponent) {
2728
363
  if (this.hostState.prevUrl) {
2729
364
  const prevUrl = this.hostState.prevUrl;
2730
- const nsUnmount = getNamespace();
365
+ const nsUnmount = _chunkZ2SLBFQLcjs.getNamespace.call(void 0, );
2731
366
  if (nsUnmount.unmountFns[prevUrl.href]) {
2732
367
  await Promise.all(
2733
- Array.from(nsUnmount.unmountFns[prevUrl.href] ?? []).map(
368
+ Array.from(_nullishCoalesce(nsUnmount.unmountFns[prevUrl.href], () => ( []))).map(
2734
369
  async (unmount) => {
2735
370
  try {
2736
371
  await unmount(this.root);
2737
372
  } catch (e) {
2738
- logError(
373
+ _chunkRUWR74XQcjs.logError.call(void 0,
2739
374
  "HtmlHost",
2740
375
  `Error while calling unmount() for Remote Component from ${prevUrl.href}.`,
2741
376
  e
@@ -2753,8 +388,8 @@ if (typeof HTMLElement !== "undefined") {
2753
388
  }
2754
389
  if (this.hostState.prevSrc !== void 0) {
2755
390
  this.emitter.change({
2756
- previousSrc: this.hostState.prevSrc ?? null,
2757
- nextSrc: src ?? null,
391
+ previousSrc: _nullishCoalesce(this.hostState.prevSrc, () => ( null)),
392
+ nextSrc: _nullishCoalesce(src, () => ( null)),
2758
393
  previousName: this.hostState.prevName,
2759
394
  nextName: this.name
2760
395
  });
@@ -2772,9 +407,9 @@ if (typeof HTMLElement !== "undefined") {
2772
407
  links,
2773
408
  signal: void 0,
2774
409
  // Effects run after load, no abort needed
2775
- baseUrl: url?.href,
410
+ baseUrl: _optionalChain([url, 'optionalAccess', _33 => _33.href]),
2776
411
  remoteComponentSrc,
2777
- root: this.root ?? null,
412
+ root: _nullishCoalesce(this.root, () => ( null)),
2778
413
  resolveClientUrl
2779
414
  });
2780
415
  if (!this.reactRoot) {
@@ -2783,7 +418,7 @@ if (typeof HTMLElement !== "undefined") {
2783
418
  component,
2784
419
  links,
2785
420
  signal,
2786
- baseUrl: url?.href,
421
+ baseUrl: _optionalChain([url, 'optionalAccess', _34 => _34.href]),
2787
422
  remoteComponentSrc,
2788
423
  root: this.root,
2789
424
  resolveClientUrl
@@ -2800,11 +435,11 @@ if (typeof HTMLElement !== "undefined") {
2800
435
  if (attr.name === "src") {
2801
436
  const absoluteSrc = new URL(
2802
437
  attr.value,
2803
- url ?? window.location.origin
438
+ _nullishCoalesce(url, () => ( window.location.origin))
2804
439
  ).href;
2805
440
  newScript.setAttribute(
2806
441
  attr.name,
2807
- resolveClientUrl?.(absoluteSrc) ?? absoluteSrc
442
+ _nullishCoalesce(_optionalChain([resolveClientUrl, 'optionalCall', _35 => _35(absoluteSrc)]), () => ( absoluteSrc))
2808
443
  );
2809
444
  } else {
2810
445
  newScript.setAttribute(attr.name, attr.value);
@@ -2817,7 +452,7 @@ if (typeof HTMLElement !== "undefined") {
2817
452
  remoteComponentSrc
2818
453
  );
2819
454
  }
2820
- this.root?.appendChild(newScript);
455
+ _optionalChain([this, 'access', _36 => _36.root, 'optionalAccess', _37 => _37.appendChild, 'call', _38 => _38(newScript)]);
2821
456
  } else {
2822
457
  const newEl = el.cloneNode(true);
2823
458
  for (const attr of el.attributes) {
@@ -2825,16 +460,16 @@ if (typeof HTMLElement !== "undefined") {
2825
460
  newEl.setAttribute(attr.name, attr.value);
2826
461
  }
2827
462
  }
2828
- this.root?.appendChild(newEl);
463
+ _optionalChain([this, 'access', _39 => _39.root, 'optionalAccess', _40 => _40.appendChild, 'call', _41 => _41(newEl)]);
2829
464
  }
2830
465
  });
2831
466
  }
2832
467
  for (const el of removable) {
2833
- el.parentElement?.removeChild(el);
468
+ _optionalChain([el, 'access', _42 => _42.parentElement, 'optionalAccess', _43 => _43.removeChild, 'call', _44 => _44(el)]);
2834
469
  }
2835
- this.fallbackSlot?.remove();
470
+ _optionalChain([this, 'access', _45 => _45.fallbackSlot, 'optionalAccess', _46 => _46.remove, 'call', _47 => _47()]);
2836
471
  const applyReset = () => {
2837
- if (this.reset && !this.root?.querySelector("link[data-remote-components-reset]")) {
472
+ if (this.reset && !_optionalChain([this, 'access', _48 => _48.root, 'optionalAccess', _49 => _49.querySelector, 'call', _50 => _50("link[data-remote-components-reset]")])) {
2838
473
  const allInitial = document.createElement("link");
2839
474
  allInitial.setAttribute("data-remote-components-reset", "");
2840
475
  const css = `:host { all: initial; }`;
@@ -2851,9 +486,9 @@ if (typeof HTMLElement !== "undefined") {
2851
486
  URL.revokeObjectURL(allInitialHref);
2852
487
  allInitial.removeAttribute("onload");
2853
488
  };
2854
- this.root?.prepend(allInitial);
2855
- } else if (!this.reset && this.root?.querySelector("link[data-remote-components-reset]")) {
2856
- this.root.querySelector("link[data-remote-components-reset]")?.remove();
489
+ _optionalChain([this, 'access', _51 => _51.root, 'optionalAccess', _52 => _52.prepend, 'call', _53 => _53(allInitial)]);
490
+ } else if (!this.reset && _optionalChain([this, 'access', _54 => _54.root, 'optionalAccess', _55 => _55.querySelector, 'call', _56 => _56("link[data-remote-components-reset]")])) {
491
+ _optionalChain([this, 'access', _57 => _57.root, 'access', _58 => _58.querySelector, 'call', _59 => _59("link[data-remote-components-reset]"), 'optionalAccess', _60 => _60.remove, 'call', _61 => _61()]);
2857
492
  }
2858
493
  };
2859
494
  if (!this.reactRoot) {
@@ -2862,18 +497,18 @@ if (typeof HTMLElement !== "undefined") {
2862
497
  const {
2863
498
  self,
2864
499
  createFromReadableStream,
2865
- nextClientPagesLoader: nextClientPagesLoader2,
500
+ nextClientPagesLoader,
2866
501
  preloadScripts
2867
502
  } = await getRuntime(
2868
503
  metadataObj.runtime,
2869
504
  effectiveUrl,
2870
505
  this.bundle,
2871
506
  {
2872
- react: async () => (await import("react")).default,
2873
- "react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
2874
- "react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
2875
- "react-dom": async () => (await import("react-dom")).default,
2876
- "react-dom/client": async () => (await import("react-dom/client")).default
507
+ react: async () => (await Promise.resolve().then(() => _interopRequireWildcard(require("react")))).default,
508
+ "react/jsx-dev-runtime": async () => (await Promise.resolve().then(() => _interopRequireWildcard(require("react/jsx-dev-runtime")))).default,
509
+ "react/jsx-runtime": async () => (await Promise.resolve().then(() => _interopRequireWildcard(require("react/jsx-runtime")))).default,
510
+ "react-dom": async () => (await Promise.resolve().then(() => _interopRequireWildcard(require("react-dom")))).default,
511
+ "react-dom/client": async () => (await Promise.resolve().then(() => _interopRequireWildcard(require("react-dom/client")))).default
2877
512
  },
2878
513
  remoteShared,
2879
514
  resolveClientUrl
@@ -2886,7 +521,7 @@ if (typeof HTMLElement !== "undefined") {
2886
521
  );
2887
522
  if (!url) {
2888
523
  url = new URL(
2889
- component.getAttribute("data-route") ?? "/",
524
+ _nullishCoalesce(component.getAttribute("data-route"), () => ( "/")),
2890
525
  window.location.href
2891
526
  );
2892
527
  }
@@ -2916,30 +551,30 @@ if (typeof HTMLElement !== "undefined") {
2916
551
  }
2917
552
  };
2918
553
  if (rsc) {
2919
- rsc.parentElement?.removeChild(rsc);
2920
- const rscName = `__remote_component_rsc_${escapeString(
554
+ _optionalChain([rsc, 'access', _62 => _62.parentElement, 'optionalAccess', _63 => _63.removeChild, 'call', _64 => _64(rsc)]);
555
+ const rscName = `__remote_component_rsc_${_chunkX6W464D6cjs.escapeString.call(void 0,
2921
556
  url.href
2922
- )}_${escapeString(this.name)}`;
557
+ )}_${_chunkX6W464D6cjs.escapeString.call(void 0, this.name)}`;
2923
558
  const rscClone = document.createElement("script");
2924
559
  rscClone.id = `${rscName}_rsc`;
2925
- rscClone.textContent = rsc.textContent?.replace(
560
+ rscClone.textContent = _nullishCoalesce(_optionalChain([rsc, 'access', _65 => _65.textContent, 'optionalAccess', _66 => _66.replace, 'call', _67 => _67(
2926
561
  new RegExp(`self\\["${this.name}"\\]`, "g"),
2927
562
  `self["${rscName}"]`
2928
- ) ?? "";
563
+ )]), () => ( ""));
2929
564
  document.body.appendChild(rscClone);
2930
565
  let cache;
2931
566
  const RemoteComponentFromReadableStream = ({
2932
567
  name,
2933
568
  initial
2934
569
  }) => {
2935
- const stream = createRSCStream(
570
+ const stream = _chunkI47KE3ECcjs.createRSCStream.call(void 0,
2936
571
  rscName,
2937
- self[rscName] ?? [`0:[null]
2938
- `]
572
+ _nullishCoalesce(self[rscName], () => ( [`0:[null]
573
+ `]))
2939
574
  );
2940
- const Component = cache ?? // cache the component to avoid reloading the RSC flight data
2941
- (cache = createFromReadableStream(stream));
2942
- (0, import_react.useLayoutEffect)(() => {
575
+ const Component = _nullishCoalesce(cache, () => ( // cache the component to avoid reloading the RSC flight data
576
+ (cache = createFromReadableStream(stream))));
577
+ _react.useLayoutEffect.call(void 0, () => {
2943
578
  if (self[name]) {
2944
579
  delete self[name];
2945
580
  }
@@ -2951,21 +586,21 @@ if (typeof HTMLElement !== "undefined") {
2951
586
  applyReset();
2952
587
  if (!initial) {
2953
588
  doAttachStyles().catch((e) => {
2954
- logError("HtmlHost", "Error attaching styles.", e);
589
+ _chunkRUWR74XQcjs.logError.call(void 0, "HtmlHost", "Error attaching styles.", e);
2955
590
  });
2956
591
  }
2957
592
  if (isCurrentLoad()) {
2958
593
  this.hostState.stage = "loaded";
2959
594
  }
2960
- this.emitter.load(this.src ?? "");
595
+ this.emitter.load(_nullishCoalesce(this.src, () => ( "")));
2961
596
  }, [initial, name]);
2962
597
  return Component;
2963
598
  };
2964
599
  if (this.reactRoot) {
2965
600
  const root = this.reactRoot;
2966
- (0, import_react.startTransition)(() => {
601
+ _react.startTransition.call(void 0, () => {
2967
602
  root.render(
2968
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
603
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
2969
604
  RemoteComponentFromReadableStream,
2970
605
  {
2971
606
  initial: false,
@@ -2976,39 +611,39 @@ if (typeof HTMLElement !== "undefined") {
2976
611
  });
2977
612
  return;
2978
613
  }
2979
- this.reactRoot = (0, import_client.hydrateRoot)(
614
+ this.reactRoot = _client.hydrateRoot.call(void 0,
2980
615
  // hydrateRoot expects a document or element, but it works for the shadow DOM too
2981
616
  // @ts-expect-error support for shadow DOM
2982
617
  this.root,
2983
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RemoteComponentFromReadableStream, { initial: true, name: this.name })
618
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, RemoteComponentFromReadableStream, { initial: true, name: this.name })
2984
619
  );
2985
620
  } else if (nextData) {
2986
- const { Component, App } = nextClientPagesLoader2(
621
+ const { Component, App } = nextClientPagesLoader(
2987
622
  this.bundle,
2988
- nextData.page ?? "/",
623
+ _nullishCoalesce(nextData.page, () => ( "/")),
2989
624
  this.root
2990
625
  );
2991
626
  if (Component) {
2992
627
  const RemoteComponentFromNext = ((NextApp, NextComponent, remoteComponent = this) => function RemoteComponentNext({ initial }) {
2993
- (0, import_react.useLayoutEffect)(() => {
628
+ _react.useLayoutEffect.call(void 0, () => {
2994
629
  doCleanup();
2995
630
  if (!initial) {
2996
631
  applyReset();
2997
632
  doAttachStyles().catch((e) => {
2998
- logError("HtmlHost", "Error attaching styles.", e);
633
+ _chunkRUWR74XQcjs.logError.call(void 0, "HtmlHost", "Error attaching styles.", e);
2999
634
  });
3000
635
  }
3001
636
  if (isCurrentLoad()) {
3002
637
  remoteComponent.hostState.stage = "loaded";
3003
638
  }
3004
- remoteComponent.emitter.load(remoteComponent.src ?? "");
639
+ remoteComponent.emitter.load(_nullishCoalesce(remoteComponent.src, () => ( "")));
3005
640
  }, [initial, remoteComponent]);
3006
- return NextApp ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NextApp, { Component: NextComponent, ...nextData.props }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NextComponent, { ...nextData.props });
641
+ return NextApp ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, NextApp, { Component: NextComponent, ...nextData.props }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, NextComponent, { ...nextData.props });
3007
642
  })(App, Component, this);
3008
643
  if (this.reactRoot) {
3009
644
  const root = this.reactRoot;
3010
- (0, import_react.startTransition)(() => {
3011
- root.render(/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RemoteComponentFromNext, { initial: false }));
645
+ _react.startTransition.call(void 0, () => {
646
+ root.render(/* @__PURE__ */ _jsxruntime.jsx.call(void 0, RemoteComponentFromNext, { initial: false }));
3012
647
  doCleanup();
3013
648
  if (isCurrentLoad()) {
3014
649
  this.hostState.stage = "loaded";
@@ -3016,24 +651,24 @@ if (typeof HTMLElement !== "undefined") {
3016
651
  });
3017
652
  return;
3018
653
  }
3019
- this.reactRoot = (0, import_client.hydrateRoot)(
654
+ this.reactRoot = _client.hydrateRoot.call(void 0,
3020
655
  // hydrateRoot expects a document or element, but it works for the shadow DOM too
3021
656
  // @ts-expect-error support for shadow DOM
3022
657
  this.root,
3023
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RemoteComponentFromNext, { initial: true })
658
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, RemoteComponentFromNext, { initial: true })
3024
659
  );
3025
660
  }
3026
661
  if (this.fouc) {
3027
662
  this.root.removeChild(this.fouc);
3028
663
  }
3029
- } else if (getNamespace().mountFns[url.href]) {
664
+ } else if (_chunkZ2SLBFQLcjs.getNamespace.call(void 0, ).mountFns[url.href]) {
3030
665
  await Promise.all(
3031
- Array.from(getNamespace().mountFns[url.href] ?? []).map(
666
+ Array.from(_nullishCoalesce(_chunkZ2SLBFQLcjs.getNamespace.call(void 0, ).mountFns[url.href], () => ( []))).map(
3032
667
  async (mount) => {
3033
668
  try {
3034
669
  await mount(this.root);
3035
670
  } catch (e) {
3036
- logError(
671
+ _chunkRUWR74XQcjs.logError.call(void 0,
3037
672
  "HtmlHost",
3038
673
  `Error while calling mount() for Remote Component from ${url.href}.`,
3039
674
  e
@@ -3042,9 +677,9 @@ if (typeof HTMLElement !== "undefined") {
3042
677
  }
3043
678
  )
3044
679
  );
3045
- this.emitter.load(this.src ?? "");
680
+ this.emitter.load(_nullishCoalesce(this.src, () => ( "")));
3046
681
  } else {
3047
- this.emitter.load(this.src ?? "");
682
+ this.emitter.load(_nullishCoalesce(this.src, () => ( "")));
3048
683
  }
3049
684
  if (isCurrentLoad()) {
3050
685
  this.hostState.stage = "loaded";
@@ -3054,13 +689,12 @@ if (typeof HTMLElement !== "undefined") {
3054
689
  customElements.define("remote-component", RemoteComponent);
3055
690
  }
3056
691
  function registerSharedModules(modules = {}) {
3057
- const ns = getNamespace();
692
+ const ns = _chunkZ2SLBFQLcjs.getNamespace.call(void 0, );
3058
693
  Object.entries(modules).forEach(([key, value]) => {
3059
694
  ns.hostSharedModules[key] = value;
3060
695
  });
3061
696
  }
3062
- // Annotate the CommonJS export names for ESM import in node:
3063
- 0 && (module.exports = {
3064
- registerSharedModules
3065
- });
697
+
698
+
699
+ exports.registerSharedModules = registerSharedModules;
3066
700
  //# sourceMappingURL=html.cjs.map