remote-components 0.0.1

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 (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/dist/html/host.cjs +758 -0
  4. package/dist/html/host.cjs.map +1 -0
  5. package/dist/html/host.d.ts +2 -0
  6. package/dist/html/host.js +737 -0
  7. package/dist/html/host.js.map +1 -0
  8. package/dist/next/config.cjs +347 -0
  9. package/dist/next/config.cjs.map +1 -0
  10. package/dist/next/config.d.ts +8 -0
  11. package/dist/next/config.js +325 -0
  12. package/dist/next/config.js.map +1 -0
  13. package/dist/next/host/app-client.cjs +124 -0
  14. package/dist/next/host/app-client.cjs.map +1 -0
  15. package/dist/next/host/app-client.d.ts +33 -0
  16. package/dist/next/host/app-client.js +104 -0
  17. package/dist/next/host/app-client.js.map +1 -0
  18. package/dist/next/host/app-server.cjs +61 -0
  19. package/dist/next/host/app-server.cjs.map +1 -0
  20. package/dist/next/host/app-server.d.ts +7 -0
  21. package/dist/next/host/app-server.js +37 -0
  22. package/dist/next/host/app-server.js.map +1 -0
  23. package/dist/next/host/pages-client.cjs +52 -0
  24. package/dist/next/host/pages-client.cjs.map +1 -0
  25. package/dist/next/host/pages-client.d.ts +17 -0
  26. package/dist/next/host/pages-client.js +18 -0
  27. package/dist/next/host/pages-client.js.map +1 -0
  28. package/dist/next/host/pages-server.cjs +134 -0
  29. package/dist/next/host/pages-server.cjs.map +1 -0
  30. package/dist/next/host/pages-server.d.ts +25 -0
  31. package/dist/next/host/pages-server.js +99 -0
  32. package/dist/next/host/pages-server.js.map +1 -0
  33. package/dist/next/remote/pages.cjs +37 -0
  34. package/dist/next/remote/pages.cjs.map +1 -0
  35. package/dist/next/remote/pages.d.ts +9 -0
  36. package/dist/next/remote/pages.js +13 -0
  37. package/dist/next/remote/pages.js.map +1 -0
  38. package/dist/next/remote/render-client-turbopack.cjs +51 -0
  39. package/dist/next/remote/render-client-turbopack.cjs.map +1 -0
  40. package/dist/next/remote/render-client-turbopack.d.ts +11 -0
  41. package/dist/next/remote/render-client-turbopack.js +27 -0
  42. package/dist/next/remote/render-client-turbopack.js.map +1 -0
  43. package/dist/next/remote/render-client-webpack.cjs +51 -0
  44. package/dist/next/remote/render-client-webpack.cjs.map +1 -0
  45. package/dist/next/remote/render-client-webpack.d.ts +11 -0
  46. package/dist/next/remote/render-client-webpack.js +27 -0
  47. package/dist/next/remote/render-client-webpack.js.map +1 -0
  48. package/dist/next/remote/render-client.cjs +106 -0
  49. package/dist/next/remote/render-client.cjs.map +1 -0
  50. package/dist/next/remote/render-client.d.ts +15 -0
  51. package/dist/next/remote/render-client.js +82 -0
  52. package/dist/next/remote/render-client.js.map +1 -0
  53. package/dist/next/remote/render-server.cjs +133 -0
  54. package/dist/next/remote/render-server.cjs.map +1 -0
  55. package/dist/next/remote/render-server.d.ts +9 -0
  56. package/dist/next/remote/render-server.js +99 -0
  57. package/dist/next/remote/render-server.js.map +1 -0
  58. package/dist/next/remote/server.cjs +29 -0
  59. package/dist/next/remote/server.cjs.map +1 -0
  60. package/dist/next/remote/server.d.ts +3 -0
  61. package/dist/next/remote/server.js +5 -0
  62. package/dist/next/remote/server.js.map +1 -0
  63. package/dist/shared/client/remote-component.cjs +558 -0
  64. package/dist/shared/client/remote-component.cjs.map +1 -0
  65. package/dist/shared/client/remote-component.d.ts +93 -0
  66. package/dist/shared/client/remote-component.js +511 -0
  67. package/dist/shared/client/remote-component.js.map +1 -0
  68. package/dist/shared/ssr/dom-flight.cjs +185 -0
  69. package/dist/shared/ssr/dom-flight.cjs.map +1 -0
  70. package/dist/shared/ssr/dom-flight.d.ts +30 -0
  71. package/dist/shared/ssr/dom-flight.js +151 -0
  72. package/dist/shared/ssr/dom-flight.js.map +1 -0
  73. package/dist/shared/ssr/fetch-remote-component.cjs +162 -0
  74. package/dist/shared/ssr/fetch-remote-component.cjs.map +1 -0
  75. package/dist/shared/ssr/fetch-remote-component.d.ts +31 -0
  76. package/dist/shared/ssr/fetch-remote-component.js +137 -0
  77. package/dist/shared/ssr/fetch-remote-component.js.map +1 -0
  78. package/dist/shared/webpack/next-client-pages-loader.cjs +107 -0
  79. package/dist/shared/webpack/next-client-pages-loader.cjs.map +1 -0
  80. package/dist/shared/webpack/next-client-pages-loader.d.ts +10 -0
  81. package/dist/shared/webpack/next-client-pages-loader.js +83 -0
  82. package/dist/shared/webpack/next-client-pages-loader.js.map +1 -0
  83. package/dist/shared/webpack/shared-modules.cjs +50 -0
  84. package/dist/shared/webpack/shared-modules.cjs.map +1 -0
  85. package/dist/shared/webpack/shared-modules.d.ts +3 -0
  86. package/dist/shared/webpack/shared-modules.js +26 -0
  87. package/dist/shared/webpack/shared-modules.js.map +1 -0
  88. package/dist/types-280a3640.d.ts +8 -0
  89. package/dist/types-a1bd5b56.d.ts +6 -0
  90. package/package.json +151 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/next/remote/render-server.tsx"],"sourcesContent":["import { headers } from 'next/headers';\nimport { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport type { Manifest } from './types';\n\n// internal Next.js symbol to access the manifest which is stored in the global scope\nconst SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\n\nconst CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;\n\n// inject the RSC flight data into the HTML response using <script>\n// the RSC flight data is used to hydrate the remote component on the host\n// this approach is similar to an island architecture on the host\n// the remote component is static HTML until it is hydrated using this RSC flight data\nfunction RemoteComponentData({ name, data }: { name: string; data: string[] }) {\n return (\n <script id={`${name}_rsc`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''}self[\"${name}\"].push(${JSON.stringify(\n chunk,\n )});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\n// a React Server Component to start rendering of the remote component\n// this is a temporary solution until the Next.js team provides a better way to handle remote components\nexport async function RemoteComponent({\n name = '__vercel_remote_component',\n children,\n}: {\n name?: string;\n children: React.ReactNode;\n}) {\n const headersList = await headers();\n const url = headersList.get('Vercel-Remote-Component-Url');\n const isRemote = url !== null;\n\n if (!isRemote) {\n return children;\n }\n\n // this URL passed by the remote component consumer is only used to know the public address of the remote component\n // it is only used to determine if we need to mutate the client module map for now\n\n const { pathname } = new URL(url);\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? { page: pathname };\n\n // get reference to the manifests from the global scope\n const manifests = (\n globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n }\n )[SERVER_ACTION_MANIFESTS_SINGLETON];\n const manifest = manifests.clientReferenceManifestsPerPage?.[route ?? page];\n\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n };\n\n // manually handle the internal Next.js manifest\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\n let clientModules = manifest?.clientModules ?? {};\n const ssrModuleMapping = { ...manifest?.ssrModuleMapping };\n\n // if the remote component is used in a hosting application, we need to mutate the module map to include the zone\n clientModules = Object.fromEntries(\n Object.entries(clientModules).map(([key, value]) => {\n // append a prefix to each entry in the module map to include the zone of the remote component\n const remoteId = `[${CURRENT_ZONE}] ${value.id}`;\n ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];\n // override the original id with the new remote id\n return [\n key,\n {\n ...value,\n id: remoteId,\n // prepend the current zone to the chunks to handle remote component chunk loading in Webpack\n // this is required to avoid loading the wrong chunk in the host application\n chunks: value.chunks.map((chunk) => `[${CURRENT_ZONE}] ${chunk}`),\n // async: true,\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [{ renderToReadableStream }, { RemoteComponentSSR }] =\n await Promise.all(\n process.env.TURBOPACK\n ? [\n import('react-server-dom-turbopack/server.edge'),\n import('./render-client-turbopack'),\n ]\n : [\n import('react-server-dom-webpack/server.edge'),\n import('./render-client-webpack'),\n ],\n );\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules);\n\n const data = [];\n const decoder = new TextDecoder();\n\n // convert the stream to an array for safe passing to the client\n for await (const chunk of stream as unknown as AsyncIterable<Uint8Array>) {\n data.push(decoder.decode(chunk));\n }\n\n const runtime = process.env.TURBOPACK ? 'turbopack' : 'webpack';\n const remoteComponentName = `${name}_${route?.replace(/\\//g, '_')}`;\n\n return (\n // wrap the remote component content into a div to know which part of the HTML belongs to the remote component\n <div\n data-bundle={CURRENT_ZONE}\n data-route={route}\n data-runtime={runtime}\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSSR\n data={data}\n moduleLoading={manifest?.moduleLoading ?? {}}\n moduleMap={ssrModuleMapping}\n name={remoteComponentName}\n />\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":"AAiBI,cAiHA,YAjHA;AAjBJ,SAAS,eAAe;AACxB,SAAS,wBAAwB;AAIjC,MAAM,oCAAoC,OAAO;AAAA,EAC/C;AACF;AAEA,MAAM,eAAe,QAAQ,IAAI;AAMjC,SAAS,oBAAoB,EAAE,MAAM,KAAK,GAAqC;AAC7E,SACE,oBAAC,YAAO,IAAI,GAAG,YACZ,eACE;AAAA,IACC,CAAC,OAAO;AAAA;AAAA,MAEN,GAAG,MAAM,IAAI,SAAS,gBAAgB,gBAAgB,WAAW,eAAe,KAAK;AAAA,QACnF;AAAA,MACF;AAAA;AAAA,EACJ,EACC,KAAK,IAAI,GACd;AAEJ;AAIA,eAAsB,gBAAgB;AAAA,EACpC,OAAO;AAAA,EACP;AACF,GAGG;AACD,QAAM,cAAc,MAAM,QAAQ;AAClC,QAAM,MAAM,YAAY,IAAI,6BAA6B;AACzD,QAAM,WAAW,QAAQ;AAEzB,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAKA,QAAM,EAAE,SAAS,IAAI,IAAI,IAAI,GAAG;AAEhC,QAAM,EAAE,MAAM,MAAM,IAAI,iBAAiB,SAAS,KAAK,EAAE,MAAM,SAAS;AAGxE,QAAM,YACJ,WAKA,iCAAiC;AACnC,QAAM,WAAW,UAAU,kCAAkC,SAAS,IAAI;AAE1E,QAAM,OAAO;AAQb,OAAK,iBAAiB,KAAK,kBAAkB,CAAC;AAC9C,OAAK,eAAe,IAAI,IAAI,KAAK,eAAe,IAAI,KAAK;AAGzD,MAAI,gBAAgB,UAAU,iBAAiB,CAAC;AAChD,QAAM,mBAAmB,EAAE,GAAG,UAAU,iBAAiB;AAGzD,kBAAgB,OAAO;AAAA,IACrB,OAAO,QAAQ,aAAa,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAElD,YAAM,WAAW,IAAI,iBAAiB,MAAM;AAC5C,uBAAiB,QAAQ,IAAI,iBAAiB,MAAM,EAAE;AAEtD,aAAO;AAAA,QACL;AAAA,QACA;AAAA,UACE,GAAG;AAAA,UACH,IAAI;AAAA;AAAA;AAAA,UAGJ,QAAQ,MAAM,OAAO,IAAI,CAAC,UAAU,IAAI,iBAAiB,OAAO;AAAA;AAAA,QAElE;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAGA,QAAM,CAAC,EAAE,uBAAuB,GAAG,EAAE,mBAAmB,CAAC,IACvD,MAAM,QAAQ;AAAA,IACZ,QAAQ,IAAI,YACR;AAAA,MACE,OAAO,wCAAwC;AAAA,MAC/C,OAAO,2BAA2B;AAAA,IACpC,IACA;AAAA,MACE,OAAO,sCAAsC;AAAA,MAC7C,OAAO,yBAAyB;AAAA,IAClC;AAAA,EACN;AAEF,QAAM,SAAS,uBAAuB,UAAU,aAAa;AAE7D,QAAM,OAAO,CAAC;AACd,QAAM,UAAU,IAAI,YAAY;AAGhC,mBAAiB,SAAS,QAAgD;AACxE,SAAK,KAAK,QAAQ,OAAO,KAAK,CAAC;AAAA,EACjC;AAEA,QAAM,UAAU,QAAQ,IAAI,YAAY,cAAc;AACtD,QAAM,sBAAsB,GAAG,QAAQ,OAAO,QAAQ,OAAO,GAAG;AAEhE;AAAA;AAAA,IAEE;AAAA,MAAC;AAAA;AAAA,QACC,eAAa;AAAA,QACb,cAAY;AAAA,QACZ,gBAAc;AAAA,QACd,IAAI,GAAG;AAAA,QAEP;AAAA;AAAA,YAAC;AAAA;AAAA,cACC;AAAA,cACA,eAAe,UAAU,iBAAiB,CAAC;AAAA,cAC3C,WAAW;AAAA,cACX,MAAM;AAAA;AAAA,UACR;AAAA,UAEA,oBAAC,uBAAoB,MAAY,MAAM,qBAAqB;AAAA;AAAA;AAAA,IAC9D;AAAA;AAEJ;","names":[]}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var server_exports = {};
20
+ __export(server_exports, {
21
+ RemoteComponent: () => import_render_server.RemoteComponent
22
+ });
23
+ module.exports = __toCommonJS(server_exports);
24
+ var import_render_server = require("./render-server");
25
+ // Annotate the CommonJS export names for ESM import in node:
26
+ 0 && (module.exports = {
27
+ RemoteComponent
28
+ });
29
+ //# sourceMappingURL=server.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/next/remote/server.ts"],"sourcesContent":["export { RemoteComponent } from './render-server';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAgC;","names":[]}
@@ -0,0 +1,3 @@
1
+ export { RemoteComponent } from './render-server.js';
2
+ import 'react/jsx-runtime';
3
+ import 'react';
@@ -0,0 +1,5 @@
1
+ import { RemoteComponent } from "./render-server";
2
+ export {
3
+ RemoteComponent
4
+ };
5
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/next/remote/server.ts"],"sourcesContent":["export { RemoteComponent } from './render-server';\n"],"mappings":"AAAA,SAAS,uBAAuB;","names":[]}
@@ -0,0 +1,558 @@
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 __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/shared/client/remote-component.ts
31
+ var remote_component_exports = {};
32
+ __export(remote_component_exports, {
33
+ DEFAULT_ROUTE: () => DEFAULT_ROUTE,
34
+ REMOTE_COMPONENT_PREFIX: () => REMOTE_COMPONENT_PREFIX,
35
+ REMOTE_COMPONENT_REGEX: () => REMOTE_COMPONENT_REGEX,
36
+ RUNTIME_TURBOPACK: () => RUNTIME_TURBOPACK,
37
+ RUNTIME_WEBPACK: () => RUNTIME_WEBPACK,
38
+ createRSCStream: () => createRSCStream,
39
+ fixPayload: () => fixPayload,
40
+ getBundleKey: () => getBundleKey,
41
+ loadRemoteComponent: () => loadRemoteComponent,
42
+ loadScripts: () => loadScripts,
43
+ setupWebpackRuntime: () => setupWebpackRuntime
44
+ });
45
+ module.exports = __toCommonJS(remote_component_exports);
46
+
47
+ // src/shared/client/component-loader.ts
48
+ var React = __toESM(require("react"), 1);
49
+ var ReactDOM = __toESM(require("react-dom"), 1);
50
+ var JSXDevRuntime = __toESM(require("react/jsx-dev-runtime"), 1);
51
+ var JSXRuntime = __toESM(require("react/jsx-runtime"), 1);
52
+
53
+ // src/shared/webpack/shared-modules.ts
54
+ function applySharedModules(bundle, resolve) {
55
+ const self = globalThis;
56
+ if (self.__remote_webpack_require__?.[bundle]) {
57
+ const modulePaths = Object.keys(
58
+ self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
59
+ );
60
+ for (const [key, value] of Object.entries(resolve)) {
61
+ const ids = modulePaths.filter((p) => p.includes(key));
62
+ for (let id of ids) {
63
+ const webpackBundle = self.__remote_webpack_require__[bundle];
64
+ if (webpackBundle.m) {
65
+ if (self.__remote_webpack_module_map__?.[bundle]?.[id]) {
66
+ id = `${self.__remote_webpack_module_map__[bundle][id]}`;
67
+ }
68
+ webpackBundle.m[id] = (module2) => {
69
+ module2.exports = value;
70
+ };
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+ // src/shared/webpack/next-client-pages-loader.ts
78
+ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
79
+ const self = globalThis;
80
+ const nextCssOriginal = document.getElementById("__next_css__DO_NOT_USE__");
81
+ if (nextCssOriginal) {
82
+ nextCssOriginal.parentNode?.removeChild(nextCssOriginal);
83
+ }
84
+ const nextCss = document.createElement("noscript");
85
+ nextCss.id = "__next_css__DO_NOT_USE__";
86
+ const lastNode = document.head.childNodes[document.head.childNodes.length - 1];
87
+ document.head.appendChild(nextCss);
88
+ const componentLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
89
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}`)
90
+ ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
91
+ (key) => key.includes("/next/dist/client/page-loader.js")
92
+ ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
93
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}`)
94
+ ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
95
+ (key) => key.includes("/next/dist/client/page-loader.js")
96
+ ) ?? ""] ?? -1;
97
+ const appLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
98
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
99
+ ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
100
+ (key) => key.includes("/next/dist/client/page-loader.js")
101
+ ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
102
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
103
+ ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
104
+ (key) => key.includes("/next/dist/client/page-loader.js")
105
+ ) ?? ""] ?? -1;
106
+ if (!(componentLoaderChunk && appLoaderChunk)) {
107
+ throw new Error(
108
+ `Next.js client pages loader not found in bundle "${bundle}"`
109
+ );
110
+ }
111
+ const __NEXT_P_ORIGINAL = self.__NEXT_P;
112
+ const selfOriginal = self;
113
+ delete selfOriginal.__NEXT_P;
114
+ self.__remote_webpack_require__?.[bundle]?.(componentLoaderChunk);
115
+ if (typeof appLoaderChunk === "string" || typeof appLoaderChunk === "number" && appLoaderChunk !== -1) {
116
+ self.__remote_webpack_require__?.[bundle]?.(appLoaderChunk);
117
+ }
118
+ if (self.__NEXT_P) {
119
+ const [, componentLoader] = self.__NEXT_P[0] ?? [
120
+ void 0,
121
+ () => ({ default: null })
122
+ ];
123
+ const [, appLoader] = self.__NEXT_P[2] ?? [
124
+ void 0,
125
+ () => ({
126
+ default: null
127
+ })
128
+ ];
129
+ const { default: Component } = componentLoader();
130
+ const { default: App } = appLoader();
131
+ const cssRE = /\.s?css$/;
132
+ Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).filter((id) => cssRE.test(id)).forEach((id) => {
133
+ self.__remote_webpack_require__?.[bundle]?.(id);
134
+ });
135
+ Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {}).filter((path) => cssRE.test(path)).forEach((path) => {
136
+ const id = self.__remote_webpack_module_map__?.[bundle]?.[path];
137
+ if (id) {
138
+ self.__remote_webpack_require__?.[bundle]?.(id);
139
+ }
140
+ });
141
+ if (styleContainer) {
142
+ let node = nextCss.previousSibling;
143
+ while (node && node !== lastNode) {
144
+ styleContainer.appendChild(node);
145
+ node = nextCss.previousSibling;
146
+ }
147
+ }
148
+ delete self.__NEXT_P;
149
+ self.__NEXT_P = __NEXT_P_ORIGINAL;
150
+ if (nextCssOriginal) {
151
+ nextCssOriginal.parentNode?.appendChild(nextCssOriginal);
152
+ }
153
+ return { Component, App };
154
+ }
155
+ return { Component: null, App: null };
156
+ }
157
+
158
+ // src/shared/client/script-loader.ts
159
+ async function loadScripts(scripts) {
160
+ await Promise.all(
161
+ scripts.map((script) => {
162
+ return new Promise((resolve, reject) => {
163
+ const newSrc = new URL(
164
+ // remove the remote component bundle name identifier from the script src
165
+ script.src.replace(/\/_next\/\[.+\] /, "/_next/"),
166
+ location.origin
167
+ ).href;
168
+ const newScript = document.createElement("script");
169
+ newScript.onload = () => {
170
+ resolve();
171
+ };
172
+ newScript.onerror = () => {
173
+ reject(
174
+ new Error(
175
+ `Failed to load script ${script.src} for remote component`
176
+ )
177
+ );
178
+ };
179
+ newScript.src = newSrc;
180
+ newScript.async = true;
181
+ document.head.appendChild(newScript);
182
+ });
183
+ })
184
+ );
185
+ }
186
+ function loadCSS(url) {
187
+ const link = document.createElement("link");
188
+ link.rel = "stylesheet";
189
+ link.href = url;
190
+ document.head.appendChild(link);
191
+ }
192
+
193
+ // src/shared/client/const.ts
194
+ var DEFAULT_ROUTE = "/";
195
+ var RUNTIME_WEBPACK = "webpack";
196
+ var RUNTIME_TURBOPACK = "turbopack";
197
+ var REMOTE_COMPONENT_PREFIX = "[remote-component-";
198
+ var REMOTE_COMPONENT_REGEX = /(?<prefix>.*)?\[(?<bundle>remote-component-(?:[^\]]+))\](?:%20| )(?<id>.+)/;
199
+ function getBundleKey(bundle) {
200
+ return bundle.replace(/-/g, "_");
201
+ }
202
+
203
+ // src/shared/client/webpack-adapter.ts
204
+ async function setupWebpackRuntime(runtime, scripts = [], bundle, shared = {}, remoteShared = {}) {
205
+ const self = globalThis;
206
+ self.__DISABLE_WEBPACK_EXEC__ = true;
207
+ await initializeSharedModules(bundle ?? "default", shared, remoteShared);
208
+ if (typeof self.__webpack_require__ !== "function" || self.__webpack_require_type__ !== "turbopack") {
209
+ if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
210
+ self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
211
+ self.__original_webpack_require__ = self.__webpack_require__;
212
+ }
213
+ self.__webpack_chunk_load__ = createChunkLoader(runtime);
214
+ self.__webpack_require__ = createModuleRequire(runtime);
215
+ self.__webpack_require_type__ = runtime;
216
+ if (self.__remote_webpack_require__) {
217
+ const remoteBundle = bundle ?? "default";
218
+ self.__remote_webpack_require__[remoteBundle] = self.__webpack_require__;
219
+ self.__remote_webpack_require__[remoteBundle].type = "turbopack";
220
+ }
221
+ }
222
+ await Promise.all(
223
+ scripts.map((script) => {
224
+ if (script.src) {
225
+ return self.__webpack_chunk_load__?.(script.src, bundle);
226
+ }
227
+ return Promise.resolve(void 0);
228
+ })
229
+ );
230
+ }
231
+ function createChunkLoader(runtime) {
232
+ return function __turbopack_chunk_load__(chunkId, scriptBundle) {
233
+ if (runtime === RUNTIME_WEBPACK) {
234
+ return Promise.resolve(void 0);
235
+ }
236
+ const {
237
+ bundle,
238
+ id: path,
239
+ prefix
240
+ } = REMOTE_COMPONENT_REGEX.exec(chunkId)?.groups ?? {
241
+ bundle: scriptBundle ?? "",
242
+ id: chunkId
243
+ };
244
+ const url = new URL(
245
+ path ? `${prefix ?? ""}${path}`.replace(
246
+ /(?<char>[^:])(?<double>\/\/)/g,
247
+ "$1/"
248
+ ) : "/",
249
+ location.origin
250
+ ).href;
251
+ if (url.endsWith(".css")) {
252
+ loadCSS(url);
253
+ return;
254
+ }
255
+ return new Promise((resolve, reject) => {
256
+ fetch(url).then((res) => res.text()).then((code) => {
257
+ if (code.includes("globalThis.TURBOPACK")) {
258
+ return handleTurbopackChunk(code, bundle ?? "", url);
259
+ }
260
+ }).then(resolve).catch(reject);
261
+ });
262
+ };
263
+ }
264
+ async function handleTurbopackChunk(code, bundle, url) {
265
+ if (code.includes("/next/dist/client/app-next-turbopack.js") && code.includes("importScripts(...self.TURBOPACK_NEXT_CHUNK_URLS")) {
266
+ const preloadLinks = document.querySelectorAll(
267
+ `link[rel="preload"][href="${new URL(url).pathname}"]`
268
+ );
269
+ preloadLinks.forEach((preloadLink) => preloadLink.remove());
270
+ return;
271
+ }
272
+ const self = globalThis;
273
+ const bundleKey = getBundleKey(bundle);
274
+ const transformedCode = code.replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(
275
+ /TURBOPACK_WORKER_LOCATION/g,
276
+ `TURBOPACK_WORKER_LOCATION_${bundleKey}`
277
+ ).replace(
278
+ /TURBOPACK_NEXT_CHUNK_URLS/g,
279
+ `TURBOPACK_NEXT_CHUNK_URLS_${bundleKey}`
280
+ ).replace(
281
+ /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,
282
+ `TURBOPACK_CHUNK_UPDATE_LISTENERS_${bundleKey}`
283
+ ).replace(/__next_require__/g, `__${bundleKey}_next_require__`).replace(
284
+ /\/\/# sourceMappingURL=(?<name>.+)\._\.js\.map/g,
285
+ `//# sourceMappingURL=${new URL(".", new URL(url)).pathname}$1._.js.map`
286
+ );
287
+ await new Promise((scriptResolve, scriptReject) => {
288
+ const blob = new Blob([transformedCode], {
289
+ type: "application/javascript"
290
+ });
291
+ const scriptUrl = URL.createObjectURL(blob);
292
+ const script = document.createElement("script");
293
+ script.src = scriptUrl;
294
+ script.async = true;
295
+ script.onload = () => {
296
+ URL.revokeObjectURL(scriptUrl);
297
+ scriptResolve(void 0);
298
+ };
299
+ script.onerror = (error) => {
300
+ URL.revokeObjectURL(scriptUrl);
301
+ scriptReject(
302
+ new Error(
303
+ `Failed to load script: ${error instanceof Error ? error.message : String(error)}`
304
+ )
305
+ );
306
+ };
307
+ document.head.appendChild(script);
308
+ });
309
+ const chunkLists = self[`TURBOPACK_${bundleKey}_CHUNK_LISTS`];
310
+ const loadChunkLists = [];
311
+ while (chunkLists?.length) {
312
+ const { chunks } = chunkLists.shift() ?? { chunks: [] };
313
+ if (chunks.length > 0) {
314
+ chunks.forEach((id) => {
315
+ const chunkLoadResult = self.__webpack_chunk_load__?.(
316
+ `[${bundle}] ${url.slice(0, url.indexOf("/_next"))}/_next/${id}`
317
+ );
318
+ if (chunkLoadResult) {
319
+ loadChunkLists.push(chunkLoadResult);
320
+ }
321
+ });
322
+ }
323
+ }
324
+ if (loadChunkLists.length > 0) {
325
+ await Promise.all(loadChunkLists);
326
+ }
327
+ }
328
+ function createModuleRequire(runtime) {
329
+ return (id) => {
330
+ const self = globalThis;
331
+ try {
332
+ const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? { bundle: "", id };
333
+ if (runtime === RUNTIME_WEBPACK && bundle && moduleId) {
334
+ return self.__remote_webpack_require__?.[bundle]?.(moduleId);
335
+ }
336
+ const sharedModule = getSharedModule(bundle ?? "default", moduleId ?? id);
337
+ if (sharedModule) {
338
+ return sharedModule;
339
+ }
340
+ if (bundle && moduleId) {
341
+ return handleTurbopackModule(bundle, moduleId, id);
342
+ }
343
+ throw new Error(`Module ${id} not found`);
344
+ } catch {
345
+ return self.__original_webpack_require__?.(id);
346
+ }
347
+ };
348
+ }
349
+ function initializeSharedModules(bundle, shared = {}, remoteShared = {}) {
350
+ const self = globalThis;
351
+ self.__remote_shared_modules__ = self.__remote_shared_modules__ ?? {};
352
+ if (!self.__remote_shared_modules__[bundle]) {
353
+ self.__remote_shared_modules__[bundle] = {};
354
+ }
355
+ return Promise.all(
356
+ Object.entries(remoteShared).map(async ([id, module2]) => {
357
+ if (self.__remote_shared_modules__?.[bundle]) {
358
+ self.__remote_shared_modules__[bundle][id.replace("[app-ssr]", "[app-client]")] = await (shared[module2] ?? (() => {
359
+ console.warn(
360
+ `Shared dependency not found for "${bundle}": ${module2}`
361
+ );
362
+ return Promise.resolve({});
363
+ }))();
364
+ }
365
+ })
366
+ );
367
+ }
368
+ function getSharedModule(bundle, id) {
369
+ const self = globalThis;
370
+ for (const [key, value] of Object.entries(
371
+ self.__remote_shared_modules__?.[bundle] ?? {}
372
+ )) {
373
+ if (id.includes(key)) {
374
+ return value;
375
+ }
376
+ }
377
+ return null;
378
+ }
379
+ function handleTurbopackModule(bundle, moduleId, id) {
380
+ const self = globalThis;
381
+ const bundleKey = getBundleKey(bundle);
382
+ const modules = self[`TURBOPACK_${bundleKey}`]?.find((mod) => moduleId in mod[1])?.[1];
383
+ const moduleInit = modules?.[moduleId];
384
+ if (typeof moduleInit !== "function") {
385
+ throw new Error(
386
+ `Module ${id} not found in bundle ${bundle} with id ${moduleId}`
387
+ );
388
+ }
389
+ const exports = {};
390
+ moduleInit({
391
+ // HMR not implemented for Remote Components
392
+ k: {
393
+ register() {
394
+ },
395
+ registerExports() {
396
+ },
397
+ signature() {
398
+ return () => {
399
+ };
400
+ }
401
+ },
402
+ s(m) {
403
+ for (const [key, value] of Object.entries(m)) {
404
+ exports[key] = value;
405
+ }
406
+ },
407
+ i(iid) {
408
+ return self.__webpack_require__?.(`[${bundle}] ${iid}`);
409
+ },
410
+ r(rid) {
411
+ return self.__webpack_require__?.(`[${bundle}] ${rid}`);
412
+ },
413
+ m: {
414
+ exports
415
+ }
416
+ });
417
+ for (const [key, value] of Object.entries(exports)) {
418
+ if (typeof value === "function") {
419
+ exports[key] = value();
420
+ }
421
+ }
422
+ return exports;
423
+ }
424
+
425
+ // src/shared/client/rsc.ts
426
+ function fixPayload(payload) {
427
+ if (Array.isArray(payload)) {
428
+ if (payload[0] === "$") {
429
+ fixPayload(payload[3]);
430
+ if (payload.length === 4) {
431
+ payload.push(null, null, 1);
432
+ }
433
+ } else {
434
+ for (const item of payload) {
435
+ fixPayload(item);
436
+ }
437
+ }
438
+ } else if (typeof payload === "object" && payload !== null) {
439
+ for (const key in payload) {
440
+ fixPayload(payload[key]);
441
+ }
442
+ }
443
+ }
444
+ function createRSCStream(name, data) {
445
+ return new ReadableStream({
446
+ type: "bytes",
447
+ start(controller) {
448
+ const encoder = new TextEncoder();
449
+ const self = globalThis;
450
+ if (!self[name] && data.length > 0) {
451
+ data.forEach((chunk) => {
452
+ const lines = chunk.split("\n");
453
+ for (const line of lines) {
454
+ const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
455
+ if (match?.groups?.rsc) {
456
+ self[name] = self[name] ?? [];
457
+ self[name].push(JSON.parse(`"${match.groups.rsc}"`));
458
+ }
459
+ }
460
+ });
461
+ }
462
+ const allChunks = (self[name] ?? [`0:[null]
463
+ `]).join("");
464
+ allChunks.split("\n").forEach((chunk) => {
465
+ if (chunk.length > 0) {
466
+ const { id, prefix, payload } = /(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
467
+ chunk
468
+ )?.groups ?? {};
469
+ if (payload) {
470
+ const jsonPayload = JSON.parse(payload);
471
+ fixPayload(jsonPayload);
472
+ const reconstruct = `${id}:${prefix ?? ""}${JSON.stringify(jsonPayload)}`;
473
+ controller.enqueue(encoder.encode(`${reconstruct}
474
+ `));
475
+ } else {
476
+ controller.enqueue(encoder.encode(`${chunk}
477
+ `));
478
+ }
479
+ } else {
480
+ controller.enqueue(encoder.encode(`${chunk}
481
+ `));
482
+ }
483
+ });
484
+ controller.close();
485
+ }
486
+ });
487
+ }
488
+
489
+ // src/shared/client/component-loader.ts
490
+ async function loadRemoteComponent({
491
+ name,
492
+ bundle,
493
+ route = "/",
494
+ runtime = "webpack",
495
+ data,
496
+ nextData,
497
+ scripts = [],
498
+ shared = {},
499
+ remoteShared = {}
500
+ }) {
501
+ try {
502
+ if (runtime === "webpack") {
503
+ await loadScripts(scripts);
504
+ }
505
+ await setupWebpackRuntime(runtime, scripts, bundle, shared, remoteShared);
506
+ if (bundle) {
507
+ const resolve = {
508
+ "/react/index.js": React,
509
+ "/react/jsx-dev-runtime.js": JSXDevRuntime,
510
+ "/react/jsx-runtime.js": JSXRuntime,
511
+ "/react-dom/index.js": ReactDOM
512
+ };
513
+ applySharedModules(bundle, resolve);
514
+ }
515
+ if (data.length > 0) {
516
+ return await loadRSCComponent(name, data);
517
+ } else if (nextData) {
518
+ return loadNextPagesComponent(bundle, route, nextData, name);
519
+ }
520
+ throw new Error(`No valid data provided for remote component ${name}`);
521
+ } catch (error) {
522
+ return {
523
+ component: null,
524
+ error: error instanceof Error ? error : new Error(String(error))
525
+ };
526
+ }
527
+ }
528
+ async function loadRSCComponent(name, data) {
529
+ const { createFromReadableStream } = await import("next/dist/compiled/react-server-dom-webpack/client.browser");
530
+ const stream = createRSCStream(name, data);
531
+ const component = createFromReadableStream(stream);
532
+ return { component };
533
+ }
534
+ function loadNextPagesComponent(bundle, route, nextData, name) {
535
+ const { Component, App } = nextClientPagesLoader(bundle, route);
536
+ if (!Component) {
537
+ throw new Error(
538
+ `Remote component ${name} is trying to load the component for route ${route} but it is not available.`
539
+ );
540
+ }
541
+ const component = App ? React.createElement(App, { Component, ...nextData.props }) : React.createElement(Component, nextData.props);
542
+ return { component };
543
+ }
544
+ // Annotate the CommonJS export names for ESM import in node:
545
+ 0 && (module.exports = {
546
+ DEFAULT_ROUTE,
547
+ REMOTE_COMPONENT_PREFIX,
548
+ REMOTE_COMPONENT_REGEX,
549
+ RUNTIME_TURBOPACK,
550
+ RUNTIME_WEBPACK,
551
+ createRSCStream,
552
+ fixPayload,
553
+ getBundleKey,
554
+ loadRemoteComponent,
555
+ loadScripts,
556
+ setupWebpackRuntime
557
+ });
558
+ //# sourceMappingURL=remote-component.cjs.map