remote-components 0.3.5 → 0.3.6

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 (124) 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-2VQGCACH.js +190 -0
  6. package/dist/chunk-2VQGCACH.js.map +1 -0
  7. package/dist/chunk-42N2ZLE2.js +703 -0
  8. package/dist/chunk-42N2ZLE2.js.map +1 -0
  9. package/dist/chunk-6IUP26UK.cjs +57 -0
  10. package/dist/chunk-6IUP26UK.cjs.map +1 -0
  11. package/dist/chunk-7MVFHOIP.cjs +60 -0
  12. package/dist/chunk-7MVFHOIP.cjs.map +1 -0
  13. package/dist/chunk-CREXMFMF.cjs +155 -0
  14. package/dist/chunk-CREXMFMF.cjs.map +1 -0
  15. package/dist/chunk-CTUJSWCM.js +215 -0
  16. package/dist/chunk-CTUJSWCM.js.map +1 -0
  17. package/dist/chunk-ENYGL5CO.js +11 -0
  18. package/dist/chunk-ENYGL5CO.js.map +1 -0
  19. package/dist/chunk-ER73O65F.cjs +703 -0
  20. package/dist/chunk-ER73O65F.cjs.map +1 -0
  21. package/dist/chunk-F44NODUS.cjs +709 -0
  22. package/dist/chunk-F44NODUS.cjs.map +1 -0
  23. package/dist/chunk-GAXJTFBV.js +20 -0
  24. package/dist/chunk-GAXJTFBV.js.map +1 -0
  25. package/dist/chunk-HNZVEIKN.js +358 -0
  26. package/dist/chunk-HNZVEIKN.js.map +1 -0
  27. package/dist/chunk-KE7QPAQ4.cjs +21 -0
  28. package/dist/chunk-KE7QPAQ4.cjs.map +1 -0
  29. package/dist/chunk-KEPHL25S.js +60 -0
  30. package/dist/chunk-KEPHL25S.js.map +1 -0
  31. package/dist/chunk-KKBEMQU7.cjs +670 -0
  32. package/dist/chunk-KKBEMQU7.cjs.map +1 -0
  33. package/dist/chunk-KYJWRZ2B.js +709 -0
  34. package/dist/chunk-KYJWRZ2B.js.map +1 -0
  35. package/dist/chunk-N5VQR2PW.cjs +215 -0
  36. package/dist/chunk-N5VQR2PW.cjs.map +1 -0
  37. package/dist/chunk-OO4AMJWO.js +155 -0
  38. package/dist/chunk-OO4AMJWO.js.map +1 -0
  39. package/dist/chunk-R4QFK5TN.cjs +358 -0
  40. package/dist/chunk-R4QFK5TN.cjs.map +1 -0
  41. package/dist/chunk-RUWR74XQ.cjs +152 -0
  42. package/dist/chunk-RUWR74XQ.cjs.map +1 -0
  43. package/dist/chunk-S2A4TFLS.js +152 -0
  44. package/dist/chunk-S2A4TFLS.js.map +1 -0
  45. package/dist/chunk-SHFJ5OQA.cjs +11 -0
  46. package/dist/chunk-SHFJ5OQA.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-W5ESPGHH.js +670 -0
  50. package/dist/chunk-W5ESPGHH.js.map +1 -0
  51. package/dist/chunk-X6YKUJKH.js +21 -0
  52. package/dist/chunk-X6YKUJKH.js.map +1 -0
  53. package/dist/chunk-XCFYWSLD.cjs +190 -0
  54. package/dist/chunk-XCFYWSLD.cjs.map +1 -0
  55. package/dist/chunk-ZPMTZ3KJ.js +57 -0
  56. package/dist/chunk-ZPMTZ3KJ.js.map +1 -0
  57. package/dist/config/nextjs.cjs +76 -351
  58. package/dist/config/nextjs.cjs.map +1 -1
  59. package/dist/config/nextjs.js +26 -266
  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/host/server/fetch-remote-component.cjs +1 -18
  86. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
  87. package/dist/internal/host/server/fetch-remote-component.js +1 -18
  88. package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
  89. package/dist/internal/runtime/loaders/component-loader.cjs +5 -2
  90. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
  91. package/dist/internal/runtime/loaders/component-loader.js +5 -2
  92. package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
  93. package/dist/internal/runtime/turbopack/remote-scope.cjs +1 -5
  94. package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
  95. package/dist/internal/runtime/turbopack/remote-scope.js +1 -5
  96. package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
  97. package/dist/internal/utils.cjs +1 -1
  98. package/dist/internal/utils.cjs.map +1 -1
  99. package/dist/internal/utils.d.ts +5 -5
  100. package/dist/internal/utils.js +1 -1
  101. package/dist/internal/utils.js.map +1 -1
  102. package/dist/remote/html.cjs +15 -314
  103. package/dist/remote/html.cjs.map +1 -1
  104. package/dist/remote/html.js +7 -305
  105. package/dist/remote/html.js.map +1 -1
  106. package/dist/remote/middleware.cjs +16 -41
  107. package/dist/remote/middleware.cjs.map +1 -1
  108. package/dist/script-6W5JRBZK.cjs +26 -0
  109. package/dist/script-6W5JRBZK.cjs.map +1 -0
  110. package/dist/script-IFEBOLIA.js +26 -0
  111. package/dist/script-IFEBOLIA.js.map +1 -0
  112. package/dist/static-loader-X4TSF5KW.js +11 -0
  113. package/dist/static-loader-X4TSF5KW.js.map +1 -0
  114. package/dist/static-loader-ZYD5BO4D.cjs +11 -0
  115. package/dist/static-loader-ZYD5BO4D.cjs.map +1 -0
  116. package/dist/turbopack-NPGO3MWS.js +55 -0
  117. package/dist/turbopack-NPGO3MWS.js.map +1 -0
  118. package/dist/turbopack-WRMKPNN4.cjs +55 -0
  119. package/dist/turbopack-WRMKPNN4.cjs.map +1 -0
  120. package/dist/webpack-DUBHPYD6.js +92 -0
  121. package/dist/webpack-DUBHPYD6.js.map +1 -0
  122. package/dist/webpack-KSCMCL7M.cjs +92 -0
  123. package/dist/webpack-KSCMCL7M.cjs.map +1 -0
  124. package/package.json +9 -2
@@ -0,0 +1,709 @@
1
+ import {
2
+ REMOTE_COMPONENT_REGEX,
3
+ RUNTIME_TURBOPACK,
4
+ RUNTIME_WEBPACK,
5
+ collapseDoubleSlashes,
6
+ createScope,
7
+ formatRemoteId,
8
+ getScope,
9
+ parseRemoteId,
10
+ registerScope
11
+ } from "./chunk-HNZVEIKN.js";
12
+ import {
13
+ getNamespace
14
+ } from "./chunk-KEPHL25S.js";
15
+ import {
16
+ RemoteComponentsError,
17
+ failedProxiedAssetError,
18
+ logDebug,
19
+ logError,
20
+ logWarn,
21
+ warnCrossOriginFetchError
22
+ } from "./chunk-S2A4TFLS.js";
23
+ import {
24
+ isProxiedUrl
25
+ } from "./chunk-X6YKUJKH.js";
26
+
27
+ // src/runtime/turbopack/patterns.ts
28
+ var MODULE_ID_PATTERN = '"[^"]+"|[0-9]+';
29
+ function stripQuotes(value) {
30
+ if (value.startsWith('"') && value.endsWith('"')) {
31
+ return value.slice(1, -1);
32
+ }
33
+ return value;
34
+ }
35
+ function extractGroup(re, input, group) {
36
+ const raw = re.exec(input)?.groups?.[group];
37
+ return raw ? stripQuotes(raw) : void 0;
38
+ }
39
+ var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
40
+ var REMOTE_SHARED_ASSIGNMENT_RE = new RegExp(
41
+ `\\.TURBOPACK_REMOTE_SHARED\\s*=\\s*await (?:__turbopack_context__|[a-z])\\.A\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\)`
42
+ );
43
+ var ASYNC_MODULE_LOADER_RE = new RegExp(
44
+ `(?:__turbopack_context__|[a-z])\\.A\\((?<asyncSharedModuleId>${MODULE_ID_PATTERN})\\)`
45
+ );
46
+ var ASYNC_MODULE_CALLBACK_RE = new RegExp(
47
+ `(?:parentImport|[a-z])\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\)`
48
+ );
49
+ var TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
50
+
51
+ // src/runtime/turbopack/chunk-loader.ts
52
+ function loadChunkWithScope(scope, chunkId) {
53
+ logDebug(
54
+ "ChunkLoader",
55
+ `loadChunkWithScope: "${chunkId}" (scope: "${scope.scopedName}")`
56
+ );
57
+ const self = globalThis;
58
+ const ns = getNamespace();
59
+ const { bundle, path, prefix } = parseRemoteId(chunkId);
60
+ const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : scope.runtime;
61
+ if (remoteRuntime === RUNTIME_WEBPACK) {
62
+ return Promise.resolve(void 0);
63
+ }
64
+ const rawPath = path ? collapseDoubleSlashes(`${prefix}${path}`) : "/";
65
+ const url = new URL(rawPath, scope.url).href;
66
+ if (url.endsWith(".css")) {
67
+ return;
68
+ }
69
+ if (ns.chunkCache[url]) {
70
+ logDebug("ChunkLoader", `Cache hit for "${chunkId}" (url="${url}")`);
71
+ return ns.chunkCache[url];
72
+ }
73
+ const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;
74
+ if (resolvedUrl !== url) {
75
+ logDebug("ChunkLoader", `Proxied chunk URL: "${url}" \u2192 "${resolvedUrl}"`);
76
+ }
77
+ ns.chunkCache[url] = new Promise((resolve, reject) => {
78
+ fetch(resolvedUrl).then((res) => res.text()).then((code) => {
79
+ const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);
80
+ if (hasTurbopack) {
81
+ return handleTurbopackChunk(code, scope, url);
82
+ }
83
+ }).then(resolve).catch((error) => {
84
+ const isProxied = isProxiedUrl(resolvedUrl);
85
+ if (isProxied) {
86
+ reject(failedProxiedAssetError("chunk", url, resolvedUrl));
87
+ } else {
88
+ warnCrossOriginFetchError("ChunkLoader", url);
89
+ reject(error);
90
+ }
91
+ });
92
+ });
93
+ return ns.chunkCache[url];
94
+ }
95
+ function createChunkDispatcher() {
96
+ return function __chunk_dispatcher__(chunkId, scriptBundle) {
97
+ logDebug("ChunkDispatcher", `Dispatching chunk: "${chunkId}"`);
98
+ const { bundle } = parseRemoteId(chunkId);
99
+ const bundleName = bundle || scriptBundle || "default";
100
+ const scope = getScope(bundleName);
101
+ logDebug(
102
+ "ChunkDispatcher",
103
+ `Scope resolution: bundle="${bundleName}", scope=${scope?.scopedName ?? "null"}`
104
+ );
105
+ if (!scope) {
106
+ logWarn("ChunkDispatcher", `No scope found for bundle "${bundleName}"`);
107
+ return Promise.resolve(void 0);
108
+ }
109
+ return loadChunkWithScope(scope, chunkId);
110
+ };
111
+ }
112
+ async function handleTurbopackChunk(code, scope, url) {
113
+ if (/importScripts\(\.\.\.self.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {
114
+ const preloadLinks = document.querySelectorAll(
115
+ `link[rel="preload"][href="${new URL(url).pathname}"]`
116
+ );
117
+ preloadLinks.forEach((preloadLink) => preloadLink.remove());
118
+ return;
119
+ }
120
+ const self = globalThis;
121
+ const { globalKey } = scope;
122
+ const transformedCode = code.replace(
123
+ /globalThis\[\s*["']TURBOPACK["']\s*\]/g,
124
+ `globalThis["TURBOPACK_${globalKey}"]`
125
+ ).replace(
126
+ /self\[\s*["']TURBOPACK["']\s*\]/g,
127
+ `self["TURBOPACK_${globalKey}"]`
128
+ ).replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${globalKey}`).replace(/self\.TURBOPACK(?!_)/g, `self.TURBOPACK_${globalKey}`).replace(
129
+ /TURBOPACK_WORKER_LOCATION/g,
130
+ `TURBOPACK_WORKER_LOCATION_${globalKey}`
131
+ ).replace(
132
+ /TURBOPACK_NEXT_CHUNK_URLS/g,
133
+ `TURBOPACK_NEXT_CHUNK_URLS_${globalKey}`
134
+ ).replace(
135
+ /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,
136
+ `TURBOPACK_CHUNK_UPDATE_LISTENERS_${globalKey}`
137
+ ).replace(/__next_require__/g, `__${globalKey}_next_require__`).replace(
138
+ /\/\/# sourceMappingURL=(?<name>.+)(?<optional>\._)?\.js\.map/g,
139
+ `//# sourceMappingURL=${new URL(".", new URL(url, scope.url)).href}$1$2.js.map`
140
+ );
141
+ if (!self[`TURBOPACK_${globalKey}`]) {
142
+ const wrapPush = (target) => {
143
+ const originalPush = target.push;
144
+ if (typeof originalPush !== "function")
145
+ return target;
146
+ target.push = (...items) => {
147
+ for (const item of items) {
148
+ if (Array.isArray(item)) {
149
+ for (const entry of item) {
150
+ scope.turbopackModules.push(entry);
151
+ }
152
+ } else {
153
+ scope.turbopackModules.push(item);
154
+ }
155
+ }
156
+ return originalPush.apply(target, items);
157
+ };
158
+ return target;
159
+ };
160
+ const globalProp = `TURBOPACK_${globalKey}`;
161
+ let currentValue = wrapPush([]);
162
+ Object.defineProperty(self, globalProp, {
163
+ get() {
164
+ return currentValue;
165
+ },
166
+ set(newValue) {
167
+ if (newValue && typeof newValue === "object") {
168
+ wrapPush(newValue);
169
+ }
170
+ currentValue = newValue;
171
+ },
172
+ configurable: true,
173
+ enumerable: true
174
+ });
175
+ }
176
+ await new Promise((scriptResolve, scriptReject) => {
177
+ const blob = new Blob([transformedCode], {
178
+ type: "application/javascript; charset=UTF-8"
179
+ });
180
+ const scriptUrl = URL.createObjectURL(blob);
181
+ const script = document.createElement("script");
182
+ script.setAttribute("data-turbopack-src", url);
183
+ script.src = scriptUrl;
184
+ script.async = true;
185
+ script.onload = () => {
186
+ URL.revokeObjectURL(scriptUrl);
187
+ scriptResolve(void 0);
188
+ script.remove();
189
+ };
190
+ script.onerror = () => {
191
+ URL.revokeObjectURL(scriptUrl);
192
+ scriptReject(
193
+ new RemoteComponentsError(
194
+ `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
195
+ )
196
+ );
197
+ script.remove();
198
+ };
199
+ document.head.appendChild(script);
200
+ });
201
+ const chunkLists = self[`TURBOPACK_${globalKey}_CHUNK_LISTS`];
202
+ const loadChunkPromises = [];
203
+ while (chunkLists?.length) {
204
+ const { chunks } = chunkLists.shift() ?? { chunks: [] };
205
+ if (chunks.length > 0) {
206
+ for (const id of chunks) {
207
+ const baseUrl = url.slice(0, url.indexOf("/_next"));
208
+ const chunkLoadResult = loadChunkWithScope(
209
+ scope,
210
+ formatRemoteId(scope, `${baseUrl}/_next/${id}`)
211
+ );
212
+ if (chunkLoadResult) {
213
+ loadChunkPromises.push(chunkLoadResult);
214
+ }
215
+ }
216
+ }
217
+ }
218
+ if (loadChunkPromises.length > 0) {
219
+ await Promise.all(loadChunkPromises);
220
+ }
221
+ }
222
+
223
+ // src/runtime/turbopack/module.ts
224
+ function requireModule(scope, moduleId, fullId) {
225
+ const idStr = String(moduleId);
226
+ if (scope.moduleCache[idStr])
227
+ return scope.moduleCache[idStr];
228
+ const sharedModule = getSharedModule(scope, moduleId);
229
+ if (sharedModule)
230
+ return sharedModule;
231
+ return handleTurbopackModule(
232
+ scope,
233
+ idStr,
234
+ fullId ?? formatRemoteId(scope, idStr)
235
+ );
236
+ }
237
+ function handleTurbopackModule(scope, moduleId, id) {
238
+ if (scope.moduleCache[moduleId]) {
239
+ return scope.moduleCache[moduleId];
240
+ }
241
+ const modules = getTurbopackModules(scope);
242
+ if (!modules) {
243
+ logError(
244
+ "TurbopackModule",
245
+ `TURBOPACK_${scope.globalKey} is undefined (scope: "${scope.scopedName}")`
246
+ );
247
+ }
248
+ const moduleInit = findModuleInit(modules, moduleId);
249
+ const exports = {};
250
+ const moduleExports = { exports };
251
+ if (typeof moduleInit !== "function") {
252
+ throw new Error(
253
+ `Module ${id} not found in bundle ${scope.name} with id ${moduleId}`
254
+ );
255
+ }
256
+ scope.moduleCache[moduleId] = moduleExports.exports;
257
+ moduleInit(
258
+ createTurbopackContext(
259
+ scope,
260
+ exports,
261
+ moduleExports,
262
+ modules,
263
+ moduleInit,
264
+ id
265
+ ),
266
+ moduleExports,
267
+ exports
268
+ );
269
+ if (scope.moduleCache[moduleId] !== moduleExports.exports) {
270
+ scope.moduleCache[moduleId] = moduleExports.exports;
271
+ }
272
+ return moduleExports.exports;
273
+ }
274
+ function findModuleInit(modules, moduleId) {
275
+ if (!modules || typeof modules !== "object")
276
+ return;
277
+ if (!Array.isArray(modules)) {
278
+ const key = moduleId in modules ? moduleId : Object.keys(modules).find((k) => k.startsWith(moduleId));
279
+ return key !== void 0 ? modules[key] : void 0;
280
+ }
281
+ const flat = modules.flat();
282
+ let idx = flat.findIndex((e) => String(e) === String(moduleId));
283
+ if (idx < 0) {
284
+ idx = flat.findIndex(
285
+ (e) => typeof e === "string" && e.startsWith(moduleId)
286
+ );
287
+ }
288
+ if (idx >= 0) {
289
+ return flat.slice(idx + 1).find((e) => typeof e === "function");
290
+ }
291
+ for (const entry of flat) {
292
+ if (!entry || typeof entry !== "object")
293
+ continue;
294
+ const obj = entry;
295
+ if (moduleId in obj)
296
+ return obj[moduleId];
297
+ const prefixKey = Object.keys(obj).find((k) => k.startsWith(moduleId));
298
+ if (prefixKey)
299
+ return obj[prefixKey];
300
+ }
301
+ return void 0;
302
+ }
303
+ function createTurbopackContext(scope, exports, moduleExports, modules, moduleInit, id) {
304
+ const scopedRequire = (moduleId) => requireModule(scope, moduleId, formatRemoteId(scope, String(moduleId)));
305
+ return {
306
+ // HMR not implemented for Remote Components
307
+ k: {
308
+ register() {
309
+ },
310
+ registerExports() {
311
+ },
312
+ signature() {
313
+ return (fn) => fn;
314
+ }
315
+ },
316
+ // ESM exports setup
317
+ s(bindings, esmId) {
318
+ let mod = exports;
319
+ if (typeof esmId === "string" || typeof esmId === "number") {
320
+ if (!scope.moduleCache[esmId]) {
321
+ scope.moduleCache[esmId] = {};
322
+ }
323
+ mod = scope.moduleCache[esmId];
324
+ }
325
+ Object.defineProperty(mod, "__esModule", { value: true });
326
+ if (Array.isArray(bindings)) {
327
+ let i = 0;
328
+ while (i < bindings.length) {
329
+ const propName = bindings[i++];
330
+ const tagOrFunc = bindings[i++];
331
+ if (typeof tagOrFunc === "number") {
332
+ Object.defineProperty(mod, propName, {
333
+ value: bindings[i++],
334
+ enumerable: true,
335
+ writable: false
336
+ });
337
+ } else {
338
+ const getterFn = tagOrFunc;
339
+ if (typeof bindings[i] === "function") {
340
+ const setterFn = bindings[i++];
341
+ Object.defineProperty(mod, propName, {
342
+ get: getterFn,
343
+ set: setterFn,
344
+ enumerable: true
345
+ });
346
+ } else {
347
+ Object.defineProperty(mod, propName, {
348
+ get: getterFn,
349
+ enumerable: true
350
+ });
351
+ }
352
+ }
353
+ }
354
+ }
355
+ },
356
+ // import — resolves directly via scope, no global dispatch
357
+ i(importId) {
358
+ let mod;
359
+ if (typeof importId === "string") {
360
+ const { exportSource, exportName } = /\s+<export (?<exportSource>.*?) as (?<exportName>.*?)>$/.exec(
361
+ importId
362
+ )?.groups ?? {};
363
+ const normalizedId = importId.replace(
364
+ /\s+<export(?<specifier>.*)>$/,
365
+ ""
366
+ );
367
+ mod = scopedRequire(normalizedId);
368
+ if (mod && exportSource && exportName && (exportSource === "*" || typeof mod[exportSource] !== "undefined") && typeof mod[exportName] === "undefined") {
369
+ if (exportSource === "*") {
370
+ mod[exportName] = mod;
371
+ } else {
372
+ mod[exportName] = mod[exportSource];
373
+ }
374
+ }
375
+ } else {
376
+ mod = scopedRequire(importId);
377
+ }
378
+ if (typeof mod !== "object" || mod === null) {
379
+ mod = { default: mod };
380
+ } else if (!("default" in mod) && // ES module namespace objects have a null prototype, so calling
381
+ // mod.toString() directly throws. Use Object.prototype.toString
382
+ // to safely detect them.
383
+ Object.prototype.toString.call(mod) !== "[object Module]") {
384
+ try {
385
+ mod.default = mod;
386
+ } catch {
387
+ }
388
+ }
389
+ return mod;
390
+ },
391
+ // require — resolves directly via scope
392
+ r(requireId) {
393
+ return scopedRequire(requireId);
394
+ },
395
+ // value exports
396
+ v(value) {
397
+ if (typeof value === "function") {
398
+ exports.default = value((vid) => scopedRequire(vid));
399
+ } else {
400
+ moduleExports.exports = value;
401
+ }
402
+ },
403
+ // async module initializer
404
+ async a(mod) {
405
+ let result;
406
+ await mod(
407
+ () => {
408
+ },
409
+ (value) => result = value
410
+ );
411
+ exports.default = result;
412
+ },
413
+ // async module loader — resolves directly via scope
414
+ async A(Aid) {
415
+ const mod = scopedRequire(Aid);
416
+ return mod.default((parentId) => scopedRequire(parentId));
417
+ },
418
+ // dynamic import tracking — no-op for remote components
419
+ j() {
420
+ },
421
+ // chunk loader — loads directly via scope, no global dispatch
422
+ l(url) {
423
+ const flatModules = Array.isArray(modules) ? modules : [];
424
+ const moduleInitIndex = flatModules.indexOf(moduleInit);
425
+ if (moduleInitIndex !== -1) {
426
+ const scriptIndex = flatModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
427
+ if (scriptIndex !== -1) {
428
+ const script = flatModules[scriptIndex];
429
+ const scriptSrc = script.getAttribute("data-turbopack-src") || "";
430
+ const nextIndex = scriptSrc.indexOf("/_next");
431
+ const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
432
+ const chunkUrl = `${baseUrl}/_next/${url}`;
433
+ return loadChunkWithScope(scope, formatRemoteId(scope, chunkUrl));
434
+ }
435
+ }
436
+ throw new Error(
437
+ `Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
438
+ );
439
+ },
440
+ // globalThis substitute shared across all modules in this scope
441
+ g: scope.moduleGlobal,
442
+ m: moduleExports,
443
+ e: exports
444
+ };
445
+ }
446
+
447
+ // src/runtime/turbopack/shared-modules.ts
448
+ var DEDUPLICATION_WARNING = "This module will not be deduplicated \u2014 the remote may load its own copy, which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).";
449
+ function getTurbopackModules(scope) {
450
+ if (scope.turbopackModules.length > 0) {
451
+ return scope.turbopackModules;
452
+ }
453
+ const self = globalThis;
454
+ const raw = self[`TURBOPACK_${scope.globalKey}`];
455
+ if (!raw)
456
+ return void 0;
457
+ if (Array.isArray(raw)) {
458
+ return raw.flat();
459
+ }
460
+ return Object.entries(raw).flat();
461
+ }
462
+ async function initializeSharedModules(scope, hostShared = {}, remoteShared = {}) {
463
+ const allModules = getTurbopackModules(scope);
464
+ logDebug(
465
+ "SharedModules",
466
+ `initializeSharedModules: scope="${scope.scopedName}", allModules=${allModules ? allModules.length : "null"}, hostShared=[${Object.keys(hostShared).join(", ")}], remoteShared=${JSON.stringify(remoteShared)}`
467
+ );
468
+ let sharedModuleInitializer = null;
469
+ if (allModules) {
470
+ const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {
471
+ if (typeof idOrFunc !== "function") {
472
+ return false;
473
+ }
474
+ const funcCode = idOrFunc.toString();
475
+ return REMOTE_SHARED_MARKER_RE.test(funcCode);
476
+ });
477
+ if (sharedModuleInitializerIndex > 0) {
478
+ const sharedModuleInitializerCode = allModules[sharedModuleInitializerIndex].toString();
479
+ const sharedModuleInitializerId = allModules[sharedModuleInitializerIndex - 1];
480
+ const sharedModuleId = extractGroup(
481
+ REMOTE_SHARED_ASSIGNMENT_RE,
482
+ sharedModuleInitializerCode,
483
+ "sharedModuleId"
484
+ );
485
+ if (sharedModuleId) {
486
+ const { default: sharedModuleInitializerInstance } = handleTurbopackModule(
487
+ scope,
488
+ sharedModuleId,
489
+ formatRemoteId(scope, String(sharedModuleInitializerId))
490
+ );
491
+ sharedModuleInitializer = sharedModuleInitializerInstance;
492
+ }
493
+ }
494
+ if (sharedModuleInitializer) {
495
+ const { shared } = await sharedModuleInitializer;
496
+ const sharedModuleIds = extractSharedModuleIds(shared, scope);
497
+ logDebug(
498
+ "SharedModules",
499
+ `Resolved shared modules for scope="${scope.scopedName}": ${JSON.stringify(sharedModuleIds)}`
500
+ );
501
+ return Promise.all(
502
+ Object.entries(sharedModuleIds).map(async ([id, module]) => {
503
+ if (hostShared[module]) {
504
+ scope.sharedModules[id] = await hostShared[module](scope.name);
505
+ } else {
506
+ logError(
507
+ "SharedModules",
508
+ `Host shared module "${module}" not found for ID ${id}. ${DEDUPLICATION_WARNING}`
509
+ );
510
+ }
511
+ })
512
+ );
513
+ }
514
+ logWarn(
515
+ "SharedModules",
516
+ `No shared module initializer found in bundle for scope="${scope.scopedName}" \u2014 falling back to remoteShared mapping`
517
+ );
518
+ } else {
519
+ logWarn(
520
+ "SharedModules",
521
+ `No TURBOPACK modules found for scope="${scope.scopedName}" (TURBOPACK_${scope.globalKey} is empty)`
522
+ );
523
+ }
524
+ return Promise.all(
525
+ Object.entries(remoteShared).map(async ([id, module]) => {
526
+ if (hostShared[module]) {
527
+ const normalizedId = id.replace("[app-ssr]", "[app-client]");
528
+ scope.sharedModules[normalizedId] = await hostShared[module](
529
+ scope.name
530
+ );
531
+ } else {
532
+ logError(
533
+ "SharedModules",
534
+ `Shared module "${module}" not found for "${scope.name}". ${DEDUPLICATION_WARNING}`
535
+ );
536
+ }
537
+ })
538
+ );
539
+ }
540
+ function extractSharedModuleIds(shared, scope) {
541
+ return Object.entries(shared).filter(([, value]) => typeof value === "function").reduce((acc, [key, value]) => {
542
+ const asyncSharedModuleId = extractGroup(
543
+ ASYNC_MODULE_LOADER_RE,
544
+ value.toString(),
545
+ "asyncSharedModuleId"
546
+ );
547
+ if (asyncSharedModuleId) {
548
+ const asyncSharedModule = findModuleInit(
549
+ getTurbopackModules(scope),
550
+ asyncSharedModuleId
551
+ );
552
+ if (asyncSharedModule) {
553
+ const sharedModuleId = extractGroup(
554
+ ASYNC_MODULE_CALLBACK_RE,
555
+ asyncSharedModule.toString(),
556
+ "sharedModuleId"
557
+ );
558
+ acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(
559
+ "__remote_shared_module_",
560
+ ""
561
+ );
562
+ }
563
+ }
564
+ return acc;
565
+ }, {});
566
+ }
567
+ function getSharedModule(scope, id) {
568
+ const idStr = String(id);
569
+ if (scope.sharedModules[idStr] !== void 0) {
570
+ return scope.sharedModules[idStr];
571
+ }
572
+ for (const [key, value] of Object.entries(scope.sharedModules)) {
573
+ if (typeof value !== "undefined" && idStr !== key && idStr.endsWith(key)) {
574
+ return value;
575
+ }
576
+ }
577
+ return null;
578
+ }
579
+
580
+ // src/runtime/turbopack/remote-scope-setup.ts
581
+ async function setupRemoteScope(runtime, scripts = [], url = new URL(location.href), bundle, resolveClientUrl) {
582
+ const self = globalThis;
583
+ const ns = getNamespace();
584
+ const bundleName = bundle ?? "default";
585
+ const existingScope = getScope(bundleName);
586
+ if (existingScope && existingScope.url.origin === url.origin) {
587
+ logDebug(
588
+ "WebpackRuntime",
589
+ `Reusing scope "${existingScope.scopedName}" (turbopackModules=${existingScope.turbopackModules.length})`
590
+ );
591
+ existingScope.resolveClientUrl = resolveClientUrl;
592
+ if (runtime === RUNTIME_TURBOPACK) {
593
+ await Promise.allSettled(
594
+ scripts.map(
595
+ (script) => script.src ? loadChunkWithScope(existingScope, script.src) : Promise.resolve(void 0)
596
+ )
597
+ );
598
+ }
599
+ return existingScope;
600
+ }
601
+ const scope = createScope(bundleName, url, runtime, resolveClientUrl);
602
+ registerScope(scope);
603
+ if (runtime === RUNTIME_WEBPACK && self.__remote_webpack_require__?.[bundleName]) {
604
+ scope.webpackRequire = self.__remote_webpack_require__[bundleName];
605
+ }
606
+ ns.bundleUrls[bundleName] = url;
607
+ if (scope.scopedName !== bundleName) {
608
+ ns.bundleUrls[scope.scopedName] = url;
609
+ }
610
+ self.__webpack_get_script_filename__ = () => null;
611
+ const willCreateDispatchers = typeof self.__webpack_require__ !== "function" || ns.dispatcherRuntime !== "turbopack";
612
+ if (willCreateDispatchers) {
613
+ if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
614
+ self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
615
+ self.__original_webpack_require__ = self.__webpack_require__;
616
+ }
617
+ self.__webpack_chunk_load__ = createChunkDispatcher();
618
+ self.__webpack_require__ = createModuleDispatcher(runtime);
619
+ ns.dispatcherRuntime = runtime;
620
+ self.__webpack_require_type__ = runtime;
621
+ if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
622
+ self.__remote_webpack_require__[bundleName] = self.__webpack_require__;
623
+ self.__remote_webpack_require__[bundleName].type = "turbopack";
624
+ }
625
+ }
626
+ if (self.__remote_webpack_require__?.[bundleName] && scope.scopedName !== bundleName) {
627
+ self.__remote_webpack_require__[scope.scopedName] = self.__remote_webpack_require__[bundleName];
628
+ }
629
+ if (runtime === RUNTIME_TURBOPACK) {
630
+ const results = await Promise.allSettled(
631
+ scripts.map((script) => {
632
+ if (script.src) {
633
+ return loadChunkWithScope(scope, script.src);
634
+ }
635
+ return Promise.resolve(void 0);
636
+ })
637
+ );
638
+ for (const result of results) {
639
+ if (result.status === "rejected") {
640
+ logWarn(
641
+ "WebpackRuntime",
642
+ `Initial chunk load failed: ${String(result.reason)}`
643
+ );
644
+ }
645
+ }
646
+ }
647
+ return scope;
648
+ }
649
+ function createModuleDispatcher(runtime) {
650
+ return (id) => {
651
+ const self = globalThis;
652
+ const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? {
653
+ bundle: "default",
654
+ id
655
+ };
656
+ const bundleName = bundle ?? "default";
657
+ const remoteRuntime = self.__remote_webpack_require__?.[bundleName] ? self.__remote_webpack_require__[bundleName]?.type || "webpack" : runtime;
658
+ logDebug(
659
+ "ModuleDispatcher",
660
+ `Resolving "${id}" (bundle: "${bundleName}", runtime: "${remoteRuntime}")`
661
+ );
662
+ try {
663
+ if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
664
+ const scope2 = getScope(bundle);
665
+ if (scope2?.webpackRequire)
666
+ return scope2.webpackRequire(moduleId);
667
+ return self.__remote_webpack_require__?.[bundle]?.(moduleId);
668
+ }
669
+ const scope = getScope(bundleName);
670
+ if (scope) {
671
+ return requireModule(scope, moduleId ?? id, id);
672
+ }
673
+ throw new Error(
674
+ `Module "${id}" not found \u2014 no scope for bundle "${bundleName}".`
675
+ );
676
+ } catch (requireError) {
677
+ logWarn(
678
+ "ModuleDispatcher",
679
+ `Module require failed: ${String(requireError)}`
680
+ );
681
+ if (typeof self.__original_webpack_require__ !== "function") {
682
+ throw new RemoteComponentsError(
683
+ `Module "${id}" not found in remote component bundle "${bundleName}".`,
684
+ {
685
+ cause: requireError instanceof Error ? requireError : void 0
686
+ }
687
+ );
688
+ }
689
+ try {
690
+ logDebug(
691
+ "ModuleDispatcher",
692
+ "Falling back to original webpack require"
693
+ );
694
+ return self.__original_webpack_require__(id);
695
+ } catch (originalError) {
696
+ throw new RemoteComponentsError(
697
+ `Module "${id}" not found in remote component bundle "${bundleName}".`,
698
+ { cause: originalError instanceof Error ? originalError : void 0 }
699
+ );
700
+ }
701
+ }
702
+ };
703
+ }
704
+
705
+ export {
706
+ initializeSharedModules,
707
+ setupRemoteScope
708
+ };
709
+ //# sourceMappingURL=chunk-KYJWRZ2B.js.map