remote-components 0.3.2 → 0.3.4

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 (213) hide show
  1. package/dist/config/nextjs.cjs +122 -62
  2. package/dist/config/nextjs.cjs.map +1 -1
  3. package/dist/config/nextjs.js +116 -56
  4. package/dist/config/nextjs.js.map +1 -1
  5. package/dist/config/webpack.cjs +5 -1
  6. package/dist/config/webpack.cjs.map +1 -1
  7. package/dist/config/webpack.js +5 -1
  8. package/dist/config/webpack.js.map +1 -1
  9. package/dist/host/defaults/app.cjs +2 -5
  10. package/dist/host/defaults/app.cjs.map +1 -1
  11. package/dist/host/defaults/app.d.ts +1 -3
  12. package/dist/host/defaults/app.js +1 -4
  13. package/dist/host/defaults/app.js.map +1 -1
  14. package/dist/host/defaults/pages.cjs +2 -5
  15. package/dist/host/defaults/pages.cjs.map +1 -1
  16. package/dist/host/defaults/pages.d.ts +1 -3
  17. package/dist/host/defaults/pages.js +1 -4
  18. package/dist/host/defaults/pages.js.map +1 -1
  19. package/dist/host/defaults/shared.cjs +32 -0
  20. package/dist/host/defaults/shared.cjs.map +1 -0
  21. package/dist/host/defaults/shared.d.ts +3 -0
  22. package/dist/host/defaults/shared.js +8 -0
  23. package/dist/host/defaults/shared.js.map +1 -0
  24. package/dist/host/html.cjs +533 -351
  25. package/dist/host/html.cjs.map +1 -1
  26. package/dist/host/html.js +533 -351
  27. package/dist/host/html.js.map +1 -1
  28. package/dist/host/nextjs/app/client-only.cjs +494 -285
  29. package/dist/host/nextjs/app/client-only.cjs.map +1 -1
  30. package/dist/host/nextjs/app/client-only.js +468 -259
  31. package/dist/host/nextjs/app/client-only.js.map +1 -1
  32. package/dist/host/react.cjs +412 -241
  33. package/dist/host/react.cjs.map +1 -1
  34. package/dist/host/react.js +412 -241
  35. package/dist/host/react.js.map +1 -1
  36. package/dist/internal/config/webpack/apply-shared-modules.cjs +6 -4
  37. package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -1
  38. package/dist/internal/config/webpack/apply-shared-modules.js +6 -4
  39. package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -1
  40. package/dist/internal/config/webpack/next-client-pages-loader.cjs +6 -7
  41. package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
  42. package/dist/internal/config/webpack/next-client-pages-loader.js +6 -7
  43. package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
  44. package/dist/internal/host/nextjs/app-client.cjs +6 -22
  45. package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
  46. package/dist/internal/host/nextjs/app-client.js +5 -11
  47. package/dist/internal/host/nextjs/app-client.js.map +1 -1
  48. package/dist/internal/host/nextjs/dom-flight.cjs +19 -39
  49. package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
  50. package/dist/internal/host/nextjs/dom-flight.js +31 -39
  51. package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
  52. package/dist/internal/host/nextjs/image-shared.cjs +39 -3
  53. package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
  54. package/dist/internal/host/nextjs/image-shared.d.ts +5 -10
  55. package/dist/internal/host/nextjs/image-shared.js +29 -3
  56. package/dist/internal/host/nextjs/image-shared.js.map +1 -1
  57. package/dist/internal/host/nextjs/shared-import.cjs +46 -0
  58. package/dist/internal/host/nextjs/shared-import.cjs.map +1 -0
  59. package/dist/internal/host/nextjs/shared-import.d.ts +3 -0
  60. package/dist/internal/host/nextjs/shared-import.js +12 -0
  61. package/dist/internal/host/nextjs/shared-import.js.map +1 -0
  62. package/dist/internal/host/server/fetch-remote-component.cjs +2 -1
  63. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
  64. package/dist/internal/host/server/fetch-remote-component.js +2 -1
  65. package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
  66. package/dist/internal/host/shared/polyfill.cjs +8 -7
  67. package/dist/internal/host/shared/polyfill.cjs.map +1 -1
  68. package/dist/internal/host/shared/polyfill.js +8 -7
  69. package/dist/internal/host/shared/polyfill.js.map +1 -1
  70. package/dist/internal/host/shared/shared-module-resolver.cjs +117 -0
  71. package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -0
  72. package/dist/internal/host/shared/shared-module-resolver.d.ts +64 -0
  73. package/dist/internal/host/shared/shared-module-resolver.js +78 -0
  74. package/dist/internal/host/shared/shared-module-resolver.js.map +1 -0
  75. package/dist/internal/remote/nextjs/next-internals.cjs +53 -0
  76. package/dist/internal/remote/nextjs/next-internals.cjs.map +1 -0
  77. package/dist/internal/remote/nextjs/next-internals.d.ts +42 -0
  78. package/dist/internal/remote/nextjs/next-internals.js +26 -0
  79. package/dist/internal/remote/nextjs/next-internals.js.map +1 -0
  80. package/dist/internal/runtime/html/apply-origin.cjs +11 -32
  81. package/dist/internal/runtime/html/apply-origin.cjs.map +1 -1
  82. package/dist/internal/runtime/html/apply-origin.js +11 -32
  83. package/dist/internal/runtime/html/apply-origin.js.map +1 -1
  84. package/dist/internal/runtime/html/html-spec.cjs +78 -0
  85. package/dist/internal/runtime/html/html-spec.cjs.map +1 -0
  86. package/dist/internal/runtime/html/html-spec.d.ts +23 -0
  87. package/dist/internal/runtime/html/html-spec.js +41 -0
  88. package/dist/internal/runtime/html/html-spec.js.map +1 -0
  89. package/dist/internal/runtime/html/parse-remote-html.cjs +15 -12
  90. package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
  91. package/dist/internal/runtime/html/parse-remote-html.js +29 -12
  92. package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
  93. package/dist/internal/runtime/html/rewrite-srcset.cjs +38 -0
  94. package/dist/internal/runtime/html/rewrite-srcset.cjs.map +1 -0
  95. package/dist/internal/runtime/html/rewrite-srcset.d.ts +12 -0
  96. package/dist/internal/runtime/html/rewrite-srcset.js +14 -0
  97. package/dist/internal/runtime/html/rewrite-srcset.js.map +1 -0
  98. package/dist/internal/runtime/loaders/component-loader.cjs +25 -44
  99. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
  100. package/dist/internal/runtime/loaders/component-loader.d.ts +3 -1
  101. package/dist/internal/runtime/loaders/component-loader.js +28 -44
  102. package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
  103. package/dist/internal/runtime/loaders/script-loader.cjs +7 -0
  104. package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -1
  105. package/dist/internal/runtime/loaders/script-loader.js +7 -0
  106. package/dist/internal/runtime/loaders/script-loader.js.map +1 -1
  107. package/dist/internal/runtime/loaders/static-loader.cjs +15 -21
  108. package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -1
  109. package/dist/internal/runtime/loaders/static-loader.d.ts +3 -1
  110. package/dist/internal/runtime/loaders/static-loader.js +15 -21
  111. package/dist/internal/runtime/loaders/static-loader.js.map +1 -1
  112. package/dist/internal/runtime/namespace.cjs +82 -0
  113. package/dist/internal/runtime/namespace.cjs.map +1 -0
  114. package/dist/internal/runtime/namespace.d.ts +5 -0
  115. package/dist/internal/runtime/namespace.js +58 -0
  116. package/dist/internal/runtime/namespace.js.map +1 -0
  117. package/dist/internal/runtime/rsc-imports.cjs +86 -0
  118. package/dist/internal/runtime/rsc-imports.cjs.map +1 -0
  119. package/dist/internal/runtime/rsc-imports.d.ts +39 -0
  120. package/dist/internal/runtime/rsc-imports.js +50 -0
  121. package/dist/internal/runtime/rsc-imports.js.map +1 -0
  122. package/dist/internal/{host/shared/resolved-data.cjs → runtime/rsc-runtime.cjs} +3 -3
  123. package/dist/internal/runtime/rsc-runtime.cjs.map +1 -0
  124. package/dist/internal/runtime/rsc-runtime.d.ts +37 -0
  125. package/dist/internal/runtime/rsc-runtime.js +1 -0
  126. package/dist/internal/runtime/rsc.cjs +23 -12
  127. package/dist/internal/runtime/rsc.cjs.map +1 -1
  128. package/dist/internal/runtime/rsc.d.ts +19 -2
  129. package/dist/internal/runtime/rsc.js +20 -11
  130. package/dist/internal/runtime/rsc.js.map +1 -1
  131. package/dist/internal/runtime/turbopack/chunk-loader.cjs +53 -35
  132. package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
  133. package/dist/internal/runtime/turbopack/chunk-loader.d.ts +1 -1
  134. package/dist/internal/runtime/turbopack/chunk-loader.js +53 -35
  135. package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
  136. package/dist/internal/runtime/turbopack/module.cjs +19 -17
  137. package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
  138. package/dist/internal/runtime/turbopack/module.d.ts +23 -1
  139. package/dist/internal/runtime/turbopack/module.js +19 -18
  140. package/dist/internal/runtime/turbopack/module.js.map +1 -1
  141. package/dist/internal/runtime/turbopack/patterns.cjs +26 -10
  142. package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -1
  143. package/dist/internal/runtime/turbopack/patterns.d.ts +44 -49
  144. package/dist/internal/runtime/turbopack/patterns.js +23 -7
  145. package/dist/internal/runtime/turbopack/patterns.js.map +1 -1
  146. package/dist/internal/runtime/turbopack/{webpack-runtime.cjs → remote-scope-setup.cjs} +35 -32
  147. package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -0
  148. package/dist/internal/runtime/turbopack/remote-scope-setup.d.ts +25 -0
  149. package/dist/internal/runtime/turbopack/{webpack-runtime.js → remote-scope-setup.js} +36 -19
  150. package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -0
  151. package/dist/internal/runtime/turbopack/remote-scope.cjs +4 -6
  152. package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
  153. package/dist/internal/runtime/turbopack/remote-scope.d.ts +20 -1
  154. package/dist/internal/runtime/turbopack/remote-scope.js +4 -6
  155. package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
  156. package/dist/internal/runtime/turbopack/shared-modules.cjs +23 -15
  157. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
  158. package/dist/internal/runtime/turbopack/shared-modules.d.ts +13 -1
  159. package/dist/internal/runtime/turbopack/shared-modules.js +25 -18
  160. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
  161. package/dist/internal/runtime/types.cjs.map +1 -1
  162. package/dist/internal/runtime/types.d.ts +5 -41
  163. package/dist/internal/utils/logger.cjs +1 -1
  164. package/dist/internal/utils/logger.cjs.map +1 -1
  165. package/dist/internal/utils/logger.d.ts +2 -2
  166. package/dist/internal/utils/logger.js +1 -1
  167. package/dist/internal/utils/logger.js.map +1 -1
  168. package/dist/internal/utils/project-id-env.cjs +31 -0
  169. package/dist/internal/utils/project-id-env.cjs.map +1 -0
  170. package/dist/internal/utils/project-id-env.d.ts +7 -0
  171. package/dist/internal/utils/project-id-env.js +7 -0
  172. package/dist/internal/utils/project-id-env.js.map +1 -0
  173. package/dist/internal/utils/project-id.cjs +46 -0
  174. package/dist/internal/utils/project-id.cjs.map +1 -0
  175. package/dist/internal/utils/project-id.d.ts +8 -0
  176. package/dist/internal/utils/project-id.js +22 -0
  177. package/dist/internal/utils/project-id.js.map +1 -0
  178. package/dist/remote/defaults/app.cjs +2 -5
  179. package/dist/remote/defaults/app.cjs.map +1 -1
  180. package/dist/remote/defaults/app.d.ts +1 -3
  181. package/dist/remote/defaults/app.js +1 -4
  182. package/dist/remote/defaults/app.js.map +1 -1
  183. package/dist/remote/defaults/pages.cjs +2 -5
  184. package/dist/remote/defaults/pages.cjs.map +1 -1
  185. package/dist/remote/defaults/pages.d.ts +1 -3
  186. package/dist/remote/defaults/pages.js +1 -4
  187. package/dist/remote/defaults/pages.js.map +1 -1
  188. package/dist/remote/defaults/shared.cjs +32 -0
  189. package/dist/remote/defaults/shared.cjs.map +1 -0
  190. package/dist/remote/defaults/shared.d.ts +3 -0
  191. package/dist/remote/defaults/shared.js +8 -0
  192. package/dist/remote/defaults/shared.js.map +1 -0
  193. package/dist/remote/html.cjs +78 -22
  194. package/dist/remote/html.cjs.map +1 -1
  195. package/dist/remote/html.js +78 -22
  196. package/dist/remote/html.js.map +1 -1
  197. package/dist/remote/nextjs/app.cjs +16 -56
  198. package/dist/remote/nextjs/app.cjs.map +1 -1
  199. package/dist/remote/nextjs/app.js +26 -46
  200. package/dist/remote/nextjs/app.js.map +1 -1
  201. package/dist/remote/nextjs/pages.cjs +2 -1
  202. package/dist/remote/nextjs/pages.cjs.map +1 -1
  203. package/dist/remote/nextjs/pages.js +2 -1
  204. package/dist/remote/nextjs/pages.js.map +1 -1
  205. package/dist/types-59251814.d.ts +94 -0
  206. package/package.json +1 -1
  207. package/dist/internal/host/shared/resolved-data.cjs.map +0 -1
  208. package/dist/internal/host/shared/resolved-data.d.ts +0 -48
  209. package/dist/internal/host/shared/resolved-data.js +0 -1
  210. package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +0 -1
  211. package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +0 -23
  212. package/dist/internal/runtime/turbopack/webpack-runtime.js.map +0 -1
  213. /package/dist/internal/{host/shared/resolved-data.js.map → runtime/rsc-runtime.js.map} +0 -0
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
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
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var app_exports = {};
30
20
  __export(app_exports, {
@@ -33,25 +23,17 @@ __export(app_exports, {
33
23
  module.exports = __toCommonJS(app_exports);
34
24
  var import_jsx_runtime = require("react/jsx-runtime");
35
25
  var import_wrapper = require("remote-components/remote/defaults/wrapper");
36
- var import_work_async_storage = require("next/dist/server/app-render/work-async-storage.external");
37
26
  var import_react = require("react");
38
27
  var import_app_client = require("#internal/remote/nextjs/app-client");
28
+ var import_next_internals = require("#internal/remote/nextjs/next-internals");
39
29
  var import_constants = require("#internal/runtime/constants");
30
+ var import_html_spec = require("#internal/runtime/html/html-spec");
31
+ var import_rsc_imports = require("#internal/runtime/rsc-imports");
40
32
  var import_error = require("#internal/utils/error");
41
- const SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(
42
- "next.server.action-manifests"
43
- );
44
- const MANIFESTS_SINGLETON = Symbol.for("next.server.manifests");
45
- const PROJECT_ID = process.env.REMOTE_COMPONENTS_PROJECT_ID || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || process.env.VERCEL_PROJECT_ID;
46
- async function tryImport(importer) {
47
- try {
48
- return await importer();
49
- } catch {
50
- return {};
51
- }
52
- }
33
+ var import_project_id_env = require("#internal/utils/project-id-env");
34
+ const PROJECT_ID = (0, import_project_id_env.resolveProjectIdFromEnv)();
53
35
  function RemoteComponentData({ name, data }) {
54
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", { id: `${name}_rsc`, children: data.map(
36
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", { id: `${name}${import_html_spec.ID_SUFFIX_RSC}`, children: data.map(
55
37
  (chunk, i) => (
56
38
  // make the data handling somewhat safe
57
39
  `${i === 0 ? `self["${name}"]=self["${name}"]||[];` : ""}self["${name}"].push(${JSON.stringify(chunk)});`
@@ -62,13 +44,9 @@ async function ExposeRemoteComponent({
62
44
  name = import_constants.DEFAULT_COMPONENT_NAME,
63
45
  children
64
46
  }) {
65
- const { page, route } = import_work_async_storage.workAsyncStorage.getStore() ?? {
66
- page: "/",
67
- route: "/"
68
- };
47
+ const { page, route } = (0, import_next_internals.getWorkStore)();
48
+ const manifest = (0, import_next_internals.resolveManifest)(route);
69
49
  const self = globalThis;
70
- const manifests = self[MANIFESTS_SINGLETON] ?? self[SERVER_ACTION_MANIFESTS_SINGLETON] ?? {};
71
- const manifest = "clientReferenceManifestsPerRoute" in manifests ? manifests.clientReferenceManifestsPerRoute?.get?.(route) : "clientReferenceManifestsPerPage" in manifests ? manifests.clientReferenceManifestsPerPage?.[route] : void 0;
72
50
  self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};
73
51
  self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;
74
52
  self.__RSC_SERVER_MANIFEST = self.__RSC_SERVER_MANIFEST || {};
@@ -90,27 +68,7 @@ async function ExposeRemoteComponent({
90
68
  ];
91
69
  })
92
70
  );
93
- const [
94
- { renderToReadableStream: nextRenderToReadableStream },
95
- { renderToReadableStream: legacyRenderToReadableStream }
96
- ] = await Promise.all(
97
- process.env.TURBOPACK ? [
98
- tryImport(
99
- () => import("react-server-dom-turbopack/server")
100
- ),
101
- tryImport(
102
- () => import("react-server-dom-turbopack/server.edge")
103
- )
104
- ] : [
105
- tryImport(
106
- () => import("react-server-dom-webpack/server")
107
- ),
108
- tryImport(
109
- () => import("react-server-dom-webpack/server.edge")
110
- )
111
- ]
112
- );
113
- const renderToReadableStream = nextRenderToReadableStream ?? legacyRenderToReadableStream;
71
+ const { renderToReadableStream } = await (0, import_rsc_imports.importRSCServer)();
114
72
  if (typeof renderToReadableStream !== "function") {
115
73
  throw new import_error.RemoteComponentsError(
116
74
  "No valid `renderToReadableStream()` function found. Do you have Next.js installed?"
@@ -134,11 +92,13 @@ async function ExposeRemoteComponent({
134
92
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
135
93
  "div",
136
94
  {
137
- "data-bundle": PROJECT_ID,
138
- "data-route": route,
139
- "data-runtime": runtime,
140
- "data-type": "nextjs",
141
- id: `${remoteComponentName}_ssr`,
95
+ ...{
96
+ [import_html_spec.DATA_BUNDLE]: PROJECT_ID,
97
+ [import_html_spec.DATA_ROUTE]: route,
98
+ [import_html_spec.DATA_RUNTIME]: runtime,
99
+ [import_html_spec.DATA_TYPE]: "nextjs"
100
+ },
101
+ id: `${remoteComponentName}${import_html_spec.ID_SUFFIX_SSR}`,
142
102
  children: [
143
103
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_app_client.RemoteComponentSharedRemote, { name: remoteComponentName }),
144
104
  typeof error !== "undefined" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/remote/nextjs/app.tsx"],"sourcesContent":["import 'remote-components/remote/defaults/wrapper';\nimport { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport { Suspense } from 'react';\nimport type { ConsumeLifecycleCallbacks } from '#internal/host/shared/config';\nimport { RemoteComponentSharedRemote } from '#internal/remote/nextjs/app-client';\nimport { DEFAULT_COMPONENT_NAME } from '#internal/runtime/constants';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\ninterface Manifest {\n clientModules?: Record<\n string,\n { id: string; name: string; chunks: string[]; async: boolean }\n >;\n moduleLoading: { prefix?: string; crossOrigin?: boolean | null };\n ssrModuleMapping?: Record<string, unknown>;\n}\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);\nconst MANIFESTS_SINGLETON = Symbol.for('next.server.manifests');\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nasync function tryImport<T>(importer: () => Promise<T>) {\n try {\n return (await importer()) as T;\n } catch {\n return {} as T;\n }\n}\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 `${\n i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''\n }self[\"${name}\"].push(${JSON.stringify(chunk)});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\n/**\n * Props for exposing a Next.js component as a remote component.\n *\n * Extends {@link ConsumeLifecycleCallbacks} so the consuming host can wire up lifecycle\n * events. The `children` prop is the component content to expose (required,\n * unlike host props where children are an optional loading fallback).\n */\nexport interface ExposeRemoteComponentProps extends ConsumeLifecycleCallbacks {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * ExposeRemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<ExposeRemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { ExposeRemoteComponent } from 'remote-components/remote/nextjs/app';\n *\n * export default function MyPage() {\n * return (\n * <ExposeRemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </ExposeRemoteComponent>\n * );\n * }\n * ```\n */\nexport async function ExposeRemoteComponent({\n name = DEFAULT_COMPONENT_NAME,\n children,\n}: ExposeRemoteComponentProps): Promise<React.ReactElement> {\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? {\n page: '/',\n route: '/',\n };\n\n // get reference to the manifests from the global scope\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n [MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerRoute?: Map<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n __RSC_SERVER_MANIFEST?: Record<string, unknown>;\n };\n const manifests =\n self[MANIFESTS_SINGLETON] ?? self[SERVER_ACTION_MANIFESTS_SINGLETON] ?? {};\n const manifest =\n 'clientReferenceManifestsPerRoute' in manifests\n ? manifests.clientReferenceManifestsPerRoute?.get?.(route)\n : 'clientReferenceManifestsPerPage' in manifests\n ? manifests.clientReferenceManifestsPerPage?.[route]\n : undefined;\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 self.__RSC_SERVER_MANIFEST = self.__RSC_SERVER_MANIFEST || {};\n self.__RSC_SERVER_MANIFEST[page] =\n self.__RSC_SERVER_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\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 const clientModules = Object.fromEntries(\n Object.entries(manifest?.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 = `[${PROJECT_ID}] ${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) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [\n { renderToReadableStream: nextRenderToReadableStream },\n { renderToReadableStream: legacyRenderToReadableStream },\n ] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n const renderToReadableStream =\n nextRenderToReadableStream ?? legacyRenderToReadableStream;\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\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={PROJECT_ID}\n data-route={route}\n data-runtime={runtime}\n data-type=\"nextjs\"\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0CI;AA1CJ,qBAAO;AACP,gCAAiC;AACjC,mBAAyB;AAEzB,wBAA4C;AAC5C,uBAAuC;AACvC,mBAAsC;AAYtC,MAAM,oCAAoC,OAA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gBAAc;AAAA,QACd,aAAU;AAAA,QACV,IAAI,GAAG;AAAA,QAEP;AAAA,sDAAC,iDAA4B,MAAM,qBAAqB;AAAA,UACvD,OAAO,UAAU,cAChB,4EACE;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,2BACE,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,gBAEvD,yBACE,iBAAiB,QAAS,MAAM,SAAS,KAAM;AAAA;AAAA,YAEnD;AAAA,YACA,4CAAC,yBAAS,UAAU,MAAO,UAAS;AAAA,aACtC,IAEA;AAAA,UAGF,4CAAC,uBAAoB,MAAY,MAAM,qBAAqB;AAAA;AAAA;AAAA,IAC9D;AAAA;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/remote/nextjs/app.tsx"],"sourcesContent":["import 'remote-components/remote/defaults/wrapper';\nimport { Suspense } from 'react';\nimport type { ConsumeLifecycleCallbacks } from '#internal/host/shared/config';\nimport { RemoteComponentSharedRemote } from '#internal/remote/nextjs/app-client';\nimport {\n getWorkStore,\n resolveManifest,\n} from '#internal/remote/nextjs/next-internals';\nimport { DEFAULT_COMPONENT_NAME } from '#internal/runtime/constants';\nimport {\n DATA_BUNDLE,\n DATA_ROUTE,\n DATA_RUNTIME,\n DATA_TYPE,\n ID_SUFFIX_RSC,\n ID_SUFFIX_SSR,\n} from '#internal/runtime/html/html-spec';\nimport { importRSCServer } from '#internal/runtime/rsc-imports';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { resolveProjectIdFromEnv } from '#internal/utils/project-id-env';\n\nconst PROJECT_ID = resolveProjectIdFromEnv();\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}${ID_SUFFIX_RSC}`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${\n i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''\n }self[\"${name}\"].push(${JSON.stringify(chunk)});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\n/**\n * Props for exposing a Next.js component as a remote component.\n *\n * Extends {@link ConsumeLifecycleCallbacks} so the consuming host can wire up lifecycle\n * events. The `children` prop is the component content to expose (required,\n * unlike host props where children are an optional loading fallback).\n */\nexport interface ExposeRemoteComponentProps extends ConsumeLifecycleCallbacks {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * ExposeRemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<ExposeRemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { ExposeRemoteComponent } from 'remote-components/remote/nextjs/app';\n *\n * export default function MyPage() {\n * return (\n * <ExposeRemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </ExposeRemoteComponent>\n * );\n * }\n * ```\n */\nexport async function ExposeRemoteComponent({\n name = DEFAULT_COMPONENT_NAME,\n children,\n}: ExposeRemoteComponentProps): Promise<React.ReactElement> {\n const { page, route } = getWorkStore();\n\n const manifest = resolveManifest(route);\n\n // Populate the global RSC manifest cache that Next.js reads during rendering\n const self = globalThis as typeof globalThis & {\n __RSC_MANIFEST?: Record<string, unknown>;\n __RSC_SERVER_MANIFEST?: Record<string, unknown>;\n };\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n self.__RSC_SERVER_MANIFEST = self.__RSC_SERVER_MANIFEST || {};\n self.__RSC_SERVER_MANIFEST[page] =\n self.__RSC_SERVER_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\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 const clientModules = Object.fromEntries(\n Object.entries(manifest?.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 = `[${PROJECT_ID}] ${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) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n const { renderToReadableStream } = await importRSCServer();\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\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 {...{\n [DATA_BUNDLE]: PROJECT_ID,\n [DATA_ROUTE]: route,\n [DATA_RUNTIME]: runtime,\n [DATA_TYPE]: 'nextjs',\n }}\n id={`${remoteComponentName}${ID_SUFFIX_SSR}`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA6BI;AA7BJ,qBAAO;AACP,mBAAyB;AAEzB,wBAA4C;AAC5C,4BAGO;AACP,uBAAuC;AACvC,uBAOO;AACP,yBAAgC;AAChC,mBAAsC;AACtC,4BAAwC;AAExC,MAAM,iBAAa,+CAAwB;AAM3C,SAAS,oBAAoB,EAAE,MAAM,KAAK,GAAqC;AAC7E,SACE,4CAAC,YAAO,IAAI,GAAG,OAAO,kCACnB,eACE;AAAA,IACC,CAAC,OAAO;AAAA;AAAA,MAEN,GACE,MAAM,IAAI,SAAS,gBAAgB,gBAAgB,WAC5C,eAAe,KAAK,UAAU,KAAK;AAAA;AAAA,EAChD,EACC,KAAK,IAAI,GACd;AAEJ;AAyCA,eAAsB,sBAAsB;AAAA,EAC1C,OAAO;AAAA,EACP;AACF,GAA4D;AAC1D,QAAM,EAAE,MAAM,MAAM,QAAI,oCAAa;AAErC,QAAM,eAAW,uCAAgB,KAAK;AAGtC,QAAM,OAAO;AAIb,OAAK,iBAAiB,KAAK,kBAAkB,CAAC;AAC9C,OAAK,eAAe,IAAI,IAAI,KAAK,eAAe,IAAI,KAAK;AACzD,OAAK,wBAAwB,KAAK,yBAAyB,CAAC;AAC5D,OAAK,sBAAsB,IAAI,IAC7B,KAAK,sBAAsB,IAAI,KAAK;AAGtC,QAAM,mBAAmB,EAAE,GAAG,UAAU,iBAAiB;AAGzD,QAAM,gBAAgB,OAAO;AAAA,IAC3B,OAAO,QAAQ,UAAU,iBAAiB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAElE,YAAM,WAAW,IAAI,eAAe,MAAM;AAC1C,uBAAiB,QAAQ,IAAI,iBAAiB,M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F,4CAAC,uBAAoB,MAAY,MAAM,qBAAqB;AAAA;AAAA;AAAA,IAC9D;AAAA;AAEJ;","names":[]}
@@ -1,24 +1,26 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import "remote-components/remote/defaults/wrapper";
3
- import { workAsyncStorage } from "next/dist/server/app-render/work-async-storage.external";
4
3
  import { Suspense } from "react";
5
4
  import { RemoteComponentSharedRemote } from "#internal/remote/nextjs/app-client";
5
+ import {
6
+ getWorkStore,
7
+ resolveManifest
8
+ } from "#internal/remote/nextjs/next-internals";
6
9
  import { DEFAULT_COMPONENT_NAME } from "#internal/runtime/constants";
10
+ import {
11
+ DATA_BUNDLE,
12
+ DATA_ROUTE,
13
+ DATA_RUNTIME,
14
+ DATA_TYPE,
15
+ ID_SUFFIX_RSC,
16
+ ID_SUFFIX_SSR
17
+ } from "#internal/runtime/html/html-spec";
18
+ import { importRSCServer } from "#internal/runtime/rsc-imports";
7
19
  import { RemoteComponentsError } from "#internal/utils/error";
8
- const SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(
9
- "next.server.action-manifests"
10
- );
11
- const MANIFESTS_SINGLETON = Symbol.for("next.server.manifests");
12
- const PROJECT_ID = process.env.REMOTE_COMPONENTS_PROJECT_ID || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || process.env.VERCEL_PROJECT_ID;
13
- async function tryImport(importer) {
14
- try {
15
- return await importer();
16
- } catch {
17
- return {};
18
- }
19
- }
20
+ import { resolveProjectIdFromEnv } from "#internal/utils/project-id-env";
21
+ const PROJECT_ID = resolveProjectIdFromEnv();
20
22
  function RemoteComponentData({ name, data }) {
21
- return /* @__PURE__ */ jsx("script", { id: `${name}_rsc`, children: data.map(
23
+ return /* @__PURE__ */ jsx("script", { id: `${name}${ID_SUFFIX_RSC}`, children: data.map(
22
24
  (chunk, i) => (
23
25
  // make the data handling somewhat safe
24
26
  `${i === 0 ? `self["${name}"]=self["${name}"]||[];` : ""}self["${name}"].push(${JSON.stringify(chunk)});`
@@ -29,13 +31,9 @@ async function ExposeRemoteComponent({
29
31
  name = DEFAULT_COMPONENT_NAME,
30
32
  children
31
33
  }) {
32
- const { page, route } = workAsyncStorage.getStore() ?? {
33
- page: "/",
34
- route: "/"
35
- };
34
+ const { page, route } = getWorkStore();
35
+ const manifest = resolveManifest(route);
36
36
  const self = globalThis;
37
- const manifests = self[MANIFESTS_SINGLETON] ?? self[SERVER_ACTION_MANIFESTS_SINGLETON] ?? {};
38
- const manifest = "clientReferenceManifestsPerRoute" in manifests ? manifests.clientReferenceManifestsPerRoute?.get?.(route) : "clientReferenceManifestsPerPage" in manifests ? manifests.clientReferenceManifestsPerPage?.[route] : void 0;
39
37
  self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};
40
38
  self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;
41
39
  self.__RSC_SERVER_MANIFEST = self.__RSC_SERVER_MANIFEST || {};
@@ -57,27 +55,7 @@ async function ExposeRemoteComponent({
57
55
  ];
58
56
  })
59
57
  );
60
- const [
61
- { renderToReadableStream: nextRenderToReadableStream },
62
- { renderToReadableStream: legacyRenderToReadableStream }
63
- ] = await Promise.all(
64
- process.env.TURBOPACK ? [
65
- tryImport(
66
- () => import("react-server-dom-turbopack/server")
67
- ),
68
- tryImport(
69
- () => import("react-server-dom-turbopack/server.edge")
70
- )
71
- ] : [
72
- tryImport(
73
- () => import("react-server-dom-webpack/server")
74
- ),
75
- tryImport(
76
- () => import("react-server-dom-webpack/server.edge")
77
- )
78
- ]
79
- );
80
- const renderToReadableStream = nextRenderToReadableStream ?? legacyRenderToReadableStream;
58
+ const { renderToReadableStream } = await importRSCServer();
81
59
  if (typeof renderToReadableStream !== "function") {
82
60
  throw new RemoteComponentsError(
83
61
  "No valid `renderToReadableStream()` function found. Do you have Next.js installed?"
@@ -101,11 +79,13 @@ async function ExposeRemoteComponent({
101
79
  /* @__PURE__ */ jsxs(
102
80
  "div",
103
81
  {
104
- "data-bundle": PROJECT_ID,
105
- "data-route": route,
106
- "data-runtime": runtime,
107
- "data-type": "nextjs",
108
- id: `${remoteComponentName}_ssr`,
82
+ ...{
83
+ [DATA_BUNDLE]: PROJECT_ID,
84
+ [DATA_ROUTE]: route,
85
+ [DATA_RUNTIME]: runtime,
86
+ [DATA_TYPE]: "nextjs"
87
+ },
88
+ id: `${remoteComponentName}${ID_SUFFIX_SSR}`,
109
89
  children: [
110
90
  /* @__PURE__ */ jsx(RemoteComponentSharedRemote, { name: remoteComponentName }),
111
91
  typeof error !== "undefined" ? /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/remote/nextjs/app.tsx"],"sourcesContent":["import 'remote-components/remote/defaults/wrapper';\nimport { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport { Suspense } from 'react';\nimport type { ConsumeLifecycleCallbacks } from '#internal/host/shared/config';\nimport { RemoteComponentSharedRemote } from '#internal/remote/nextjs/app-client';\nimport { DEFAULT_COMPONENT_NAME } from '#internal/runtime/constants';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\ninterface Manifest {\n clientModules?: Record<\n string,\n { id: string; name: string; chunks: string[]; async: boolean }\n >;\n moduleLoading: { prefix?: string; crossOrigin?: boolean | null };\n ssrModuleMapping?: Record<string, unknown>;\n}\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);\nconst MANIFESTS_SINGLETON = Symbol.for('next.server.manifests');\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nasync function tryImport<T>(importer: () => Promise<T>) {\n try {\n return (await importer()) as T;\n } catch {\n return {} as T;\n }\n}\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 `${\n i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''\n }self[\"${name}\"].push(${JSON.stringify(chunk)});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\n/**\n * Props for exposing a Next.js component as a remote component.\n *\n * Extends {@link ConsumeLifecycleCallbacks} so the consuming host can wire up lifecycle\n * events. The `children` prop is the component content to expose (required,\n * unlike host props where children are an optional loading fallback).\n */\nexport interface ExposeRemoteComponentProps extends ConsumeLifecycleCallbacks {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * ExposeRemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<ExposeRemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { ExposeRemoteComponent } from 'remote-components/remote/nextjs/app';\n *\n * export default function MyPage() {\n * return (\n * <ExposeRemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </ExposeRemoteComponent>\n * );\n * }\n * ```\n */\nexport async function ExposeRemoteComponent({\n name = DEFAULT_COMPONENT_NAME,\n children,\n}: ExposeRemoteComponentProps): Promise<React.ReactElement> {\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? {\n page: '/',\n route: '/',\n };\n\n // get reference to the manifests from the global scope\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n [MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerRoute?: Map<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n __RSC_SERVER_MANIFEST?: Record<string, unknown>;\n };\n const manifests =\n self[MANIFESTS_SINGLETON] ?? self[SERVER_ACTION_MANIFESTS_SINGLETON] ?? {};\n const manifest =\n 'clientReferenceManifestsPerRoute' in manifests\n ? manifests.clientReferenceManifestsPerRoute?.get?.(route)\n : 'clientReferenceManifestsPerPage' in manifests\n ? manifests.clientReferenceManifestsPerPage?.[route]\n : undefined;\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 self.__RSC_SERVER_MANIFEST = self.__RSC_SERVER_MANIFEST || {};\n self.__RSC_SERVER_MANIFEST[page] =\n self.__RSC_SERVER_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\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 const clientModules = Object.fromEntries(\n Object.entries(manifest?.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 = `[${PROJECT_ID}] ${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) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [\n { renderToReadableStream: nextRenderToReadableStream },\n { renderToReadableStream: legacyRenderToReadableStream },\n ] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n const renderToReadableStream =\n nextRenderToReadableStream ?? legacyRenderToReadableStream;\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\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={PROJECT_ID}\n data-route={route}\n data-runtime={runtime}\n data-type=\"nextjs\"\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":"AA0CI,SA+KI,UA/KJ,KA+KI,YA/KJ;AA1CJ,OAAO;AACP,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;AAEzB,SAAS,mCAAmC;AAC5C,SAAS,8BAA8B;AACvC,SAAS,6BAA6B;AAYtC,MAAM,oCAAoC,OAAO;AAAA,EAC/C;AACF;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AU;AAAA,QACV,IAAI,GAAG;AAAA,QAEP;AAAA,8BAAC,+BAA4B,MAAM,qBAAqB;AAAA,UACvD,OAAO,UAAU,cAChB,iCACE;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,2BACE,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,gBAEvD,yBACE,iBAAiB,QAAS,MAAM,SAAS,KAAM;AAAA;AAAA,YAEnD;AAAA,YACA,oBAAC,YAAS,UAAU,MAAO,UAAS;AAAA,aACtC,IAEA;AAAA,UAGF,oBAAC,uBAAoB,MAAY,MAAM,qBAAqB;AAAA;AAAA;AAAA,IAC9D;AAAA;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/remote/nextjs/app.tsx"],"sourcesContent":["import 'remote-components/remote/defaults/wrapper';\nimport { Suspense } from 'react';\nimport type { ConsumeLifecycleCallbacks } from '#internal/host/shared/config';\nimport { RemoteComponentSharedRemote } from '#internal/remote/nextjs/app-client';\nimport {\n getWorkStore,\n resolveManifest,\n} from '#internal/remote/nextjs/next-internals';\nimport { DEFAULT_COMPONENT_NAME } from '#internal/runtime/constants';\nimport {\n DATA_BUNDLE,\n DATA_ROUTE,\n DATA_RUNTIME,\n DATA_TYPE,\n ID_SUFFIX_RSC,\n ID_SUFFIX_SSR,\n} from '#internal/runtime/html/html-spec';\nimport { importRSCServer } from '#internal/runtime/rsc-imports';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { resolveProjectIdFromEnv } from '#internal/utils/project-id-env';\n\nconst PROJECT_ID = resolveProjectIdFromEnv();\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}${ID_SUFFIX_RSC}`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${\n i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''\n }self[\"${name}\"].push(${JSON.stringify(chunk)});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\n/**\n * Props for exposing a Next.js component as a remote component.\n *\n * Extends {@link ConsumeLifecycleCallbacks} so the consuming host can wire up lifecycle\n * events. The `children` prop is the component content to expose (required,\n * unlike host props where children are an optional loading fallback).\n */\nexport interface ExposeRemoteComponentProps extends ConsumeLifecycleCallbacks {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * ExposeRemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<ExposeRemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { ExposeRemoteComponent } from 'remote-components/remote/nextjs/app';\n *\n * export default function MyPage() {\n * return (\n * <ExposeRemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </ExposeRemoteComponent>\n * );\n * }\n * ```\n */\nexport async function ExposeRemoteComponent({\n name = DEFAULT_COMPONENT_NAME,\n children,\n}: ExposeRemoteComponentProps): Promise<React.ReactElement> {\n const { page, route } = getWorkStore();\n\n const manifest = resolveManifest(route);\n\n // Populate the global RSC manifest cache that Next.js reads during rendering\n const self = globalThis as typeof globalThis & {\n __RSC_MANIFEST?: Record<string, unknown>;\n __RSC_SERVER_MANIFEST?: Record<string, unknown>;\n };\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n self.__RSC_SERVER_MANIFEST = self.__RSC_SERVER_MANIFEST || {};\n self.__RSC_SERVER_MANIFEST[page] =\n self.__RSC_SERVER_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\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 const clientModules = Object.fromEntries(\n Object.entries(manifest?.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 = `[${PROJECT_ID}] ${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) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n const { renderToReadableStream } = await importRSCServer();\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\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 {...{\n [DATA_BUNDLE]: PROJECT_ID,\n [DATA_ROUTE]: route,\n [DATA_RUNTIME]: runtime,\n [DATA_TYPE]: 'nextjs',\n }}\n id={`${remoteComponentName}${ID_SUFFIX_SSR}`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":"AA6BI,SAuII,UAvIJ,KAuII,YAvIJ;AA7BJ,OAAO;AACP,SAAS,gBAAgB;AAEzB,SAAS,mCAAmC;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;AACvC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AAExC,MAAM,aAAa,wBAAwB;AAM3C,SAAS,oBAAoB,EAAE,MAAM,KAAK,GAAqC;AAC7E,SACE,oBAAC,YAAO,IAAI,GAAG,OAAO,iBACnB,eACE;AAAA,IACC,CAAC,OAAO;AAAA;AAAA,MAEN,GACE,MAAM,IAAI,SAAS,gBAAgB,gBAAgB,WAC5C,eAAe,KAAK,UAAU,KAAK;AAAA;AAAA,EAChD,EACC,KAAK,IAAI,GACd;AAEJ;AAyCA,eAAsB,sBAAsB;AAAA,EAC1C,OAAO;AAAA,EACP;AACF,GAA4D;AAC1D,QAAM,EAAE,MAAM,MAAM,IAAI,aAAa;AAErC,QAAM,WAAW,gBAAgB,KAAK;AAGtC,QAAM,OAAO;AAIb,OAAK,iBAAiB,KAAK,kBAAkB,CAAC;AAC9C,OAAK,eAAe,IAAI,IAAI,KAAK,eAAe,IAAI,KAAK;AACzD,OAAK,wBAAwB,KAAK,yBAAyB,CAAC;AAC5D,OAAK,sBAAsB,IAAI,IAC7B,KAAK,sBAAsB,IAAI,KAAK;AAGtC,QAAM,mBAAmB,EAAE,GAAG,UAAU,iBAAiB;AAGzD,QAAM,gBAAgB,OAAO;AAAA,IAC3B,OAAO,QAAQ,UAAU,iBAAiB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,KAAK,KAA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YAEnD;AAAA,YACA,oBAAC,YAAS,UAAU,MAAO,UAAS;AAAA,aACtC,IAEA;AAAA,UAGF,oBAAC,uBAAoB,MAAY,MAAM,qBAAqB;AAAA;AAAA;AAAA,IAC9D;AAAA;AAEJ;","names":[]}
@@ -21,8 +21,9 @@ __export(pages_exports, {
21
21
  getExposeRemoteComponentProps: () => getExposeRemoteComponentProps
22
22
  });
23
23
  module.exports = __toCommonJS(pages_exports);
24
+ var import_project_id_env = require("#internal/utils/project-id-env");
24
25
  var import_pages = require("#remote-components/remote/defaults/pages");
25
- const PROJECT_ID = process.env.REMOTE_COMPONENTS_PROJECT_ID || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || process.env.VERCEL_PROJECT_ID;
26
+ const PROJECT_ID = (0, import_project_id_env.resolveProjectIdFromEnv)();
26
27
  function getExposeRemoteComponentProps() {
27
28
  return {
28
29
  __REMOTE_COMPONENT__: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/remote/nextjs/pages.ts"],"sourcesContent":["import { shared } from '#remote-components/remote/defaults/pages';\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nexport interface ExposeRemoteComponentProps {\n __REMOTE_COMPONENT__: {\n bundle: string | undefined;\n runtime: 'turbopack' | 'webpack';\n shared?: Record<string, string>;\n };\n}\n\n/**\n * Returns the metadata for the remote component.\n * This metadata is used to identify the remote component and its bundle.\n *\n * Extend your Next.js Pages Router page props with this metadata to ensure proper remote component loading.\n *\n * @returns The metadata for the remote component.\n *\n * @example\n *\n * Create a custom App component in your Next.js application to include the remote component metadata:\n *\n * ```\n * import {\n * getExposeRemoteComponentProps,\n * type ExposeRemoteComponentProps,\n * } from 'remote-components/remote/nextjs/pages';\n * import App from 'next/app';\n * import type { AppContext, AppInitialProps, AppProps } from 'next/app';\n *\n * export default function MyApp({ Component, pageProps }: AppProps) {\n * return <Component {...pageProps} />;\n * }\n *\n * MyApp.getInitialProps = async (\n * context: AppContext,\n * ): Promise<ExposeRemoteComponentProps & AppInitialProps> => {\n * const ctx = await App.getInitialProps(context);\n * return { ...ctx, ...getExposeRemoteComponentProps() };\n * };\n * ```\n */\nexport function getExposeRemoteComponentProps(): ExposeRemoteComponentProps {\n return {\n __REMOTE_COMPONENT__: {\n bundle: PROJECT_ID,\n runtime: process.env.TURBOPACK ? 'turbopack' : 'webpack',\n shared,\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAuB;AAEvB,MAAM,aACJ,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI;AA0CP,SAAS,gCAA4D;AAC1E,SAAO;AAAA,IACL,sBAAsB;AAAA,MACpB,QAAQ;AAAA,MACR,SAAS,QAAQ,IAAI,YAAY,cAAc;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/remote/nextjs/pages.ts"],"sourcesContent":["import { resolveProjectIdFromEnv } from '#internal/utils/project-id-env';\nimport { shared } from '#remote-components/remote/defaults/pages';\n\nconst PROJECT_ID = resolveProjectIdFromEnv();\n\nexport interface ExposeRemoteComponentProps {\n __REMOTE_COMPONENT__: {\n bundle: string | undefined;\n runtime: 'turbopack' | 'webpack';\n shared?: Record<string, string>;\n };\n}\n\n/**\n * Returns the metadata for the remote component.\n * This metadata is used to identify the remote component and its bundle.\n *\n * Extend your Next.js Pages Router page props with this metadata to ensure proper remote component loading.\n *\n * @returns The metadata for the remote component.\n *\n * @example\n *\n * Create a custom App component in your Next.js application to include the remote component metadata:\n *\n * ```\n * import {\n * getExposeRemoteComponentProps,\n * type ExposeRemoteComponentProps,\n * } from 'remote-components/remote/nextjs/pages';\n * import App from 'next/app';\n * import type { AppContext, AppInitialProps, AppProps } from 'next/app';\n *\n * export default function MyApp({ Component, pageProps }: AppProps) {\n * return <Component {...pageProps} />;\n * }\n *\n * MyApp.getInitialProps = async (\n * context: AppContext,\n * ): Promise<ExposeRemoteComponentProps & AppInitialProps> => {\n * const ctx = await App.getInitialProps(context);\n * return { ...ctx, ...getExposeRemoteComponentProps() };\n * };\n * ```\n */\nexport function getExposeRemoteComponentProps(): ExposeRemoteComponentProps {\n return {\n __REMOTE_COMPONENT__: {\n bundle: PROJECT_ID,\n runtime: process.env.TURBOPACK ? 'turbopack' : 'webpack',\n shared,\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAwC;AACxC,mBAAuB;AAEvB,MAAM,iBAAa,+CAAwB;AA0CpC,SAAS,gCAA4D;AAC1E,SAAO;AAAA,IACL,sBAAsB;AAAA,MACpB,QAAQ;AAAA,MACR,SAAS,QAAQ,IAAI,YAAY,cAAc;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1,5 +1,6 @@
1
+ import { resolveProjectIdFromEnv } from "#internal/utils/project-id-env";
1
2
  import { shared } from "#remote-components/remote/defaults/pages";
2
- const PROJECT_ID = process.env.REMOTE_COMPONENTS_PROJECT_ID || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || process.env.VERCEL_PROJECT_ID;
3
+ const PROJECT_ID = resolveProjectIdFromEnv();
3
4
  function getExposeRemoteComponentProps() {
4
5
  return {
5
6
  __REMOTE_COMPONENT__: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/remote/nextjs/pages.ts"],"sourcesContent":["import { shared } from '#remote-components/remote/defaults/pages';\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nexport interface ExposeRemoteComponentProps {\n __REMOTE_COMPONENT__: {\n bundle: string | undefined;\n runtime: 'turbopack' | 'webpack';\n shared?: Record<string, string>;\n };\n}\n\n/**\n * Returns the metadata for the remote component.\n * This metadata is used to identify the remote component and its bundle.\n *\n * Extend your Next.js Pages Router page props with this metadata to ensure proper remote component loading.\n *\n * @returns The metadata for the remote component.\n *\n * @example\n *\n * Create a custom App component in your Next.js application to include the remote component metadata:\n *\n * ```\n * import {\n * getExposeRemoteComponentProps,\n * type ExposeRemoteComponentProps,\n * } from 'remote-components/remote/nextjs/pages';\n * import App from 'next/app';\n * import type { AppContext, AppInitialProps, AppProps } from 'next/app';\n *\n * export default function MyApp({ Component, pageProps }: AppProps) {\n * return <Component {...pageProps} />;\n * }\n *\n * MyApp.getInitialProps = async (\n * context: AppContext,\n * ): Promise<ExposeRemoteComponentProps & AppInitialProps> => {\n * const ctx = await App.getInitialProps(context);\n * return { ...ctx, ...getExposeRemoteComponentProps() };\n * };\n * ```\n */\nexport function getExposeRemoteComponentProps(): ExposeRemoteComponentProps {\n return {\n __REMOTE_COMPONENT__: {\n bundle: PROJECT_ID,\n runtime: process.env.TURBOPACK ? 'turbopack' : 'webpack',\n shared,\n },\n };\n}\n"],"mappings":"AAAA,SAAS,cAAc;AAEvB,MAAM,aACJ,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI;AA0CP,SAAS,gCAA4D;AAC1E,SAAO;AAAA,IACL,sBAAsB;AAAA,MACpB,QAAQ;AAAA,MACR,SAAS,QAAQ,IAAI,YAAY,cAAc;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/remote/nextjs/pages.ts"],"sourcesContent":["import { resolveProjectIdFromEnv } from '#internal/utils/project-id-env';\nimport { shared } from '#remote-components/remote/defaults/pages';\n\nconst PROJECT_ID = resolveProjectIdFromEnv();\n\nexport interface ExposeRemoteComponentProps {\n __REMOTE_COMPONENT__: {\n bundle: string | undefined;\n runtime: 'turbopack' | 'webpack';\n shared?: Record<string, string>;\n };\n}\n\n/**\n * Returns the metadata for the remote component.\n * This metadata is used to identify the remote component and its bundle.\n *\n * Extend your Next.js Pages Router page props with this metadata to ensure proper remote component loading.\n *\n * @returns The metadata for the remote component.\n *\n * @example\n *\n * Create a custom App component in your Next.js application to include the remote component metadata:\n *\n * ```\n * import {\n * getExposeRemoteComponentProps,\n * type ExposeRemoteComponentProps,\n * } from 'remote-components/remote/nextjs/pages';\n * import App from 'next/app';\n * import type { AppContext, AppInitialProps, AppProps } from 'next/app';\n *\n * export default function MyApp({ Component, pageProps }: AppProps) {\n * return <Component {...pageProps} />;\n * }\n *\n * MyApp.getInitialProps = async (\n * context: AppContext,\n * ): Promise<ExposeRemoteComponentProps & AppInitialProps> => {\n * const ctx = await App.getInitialProps(context);\n * return { ...ctx, ...getExposeRemoteComponentProps() };\n * };\n * ```\n */\nexport function getExposeRemoteComponentProps(): ExposeRemoteComponentProps {\n return {\n __REMOTE_COMPONENT__: {\n bundle: PROJECT_ID,\n runtime: process.env.TURBOPACK ? 'turbopack' : 'webpack',\n shared,\n },\n };\n}\n"],"mappings":"AAAA,SAAS,+BAA+B;AACxC,SAAS,cAAc;AAEvB,MAAM,aAAa,wBAAwB;AA0CpC,SAAS,gCAA4D;AAC1E,SAAO;AAAA,IACL,sBAAsB;AAAA,MACpB,QAAQ;AAAA,MACR,SAAS,QAAQ,IAAI,YAAY,cAAc;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,94 @@
1
+ import { RemoteComponentMetadata } from './internal/runtime/metadata.js';
2
+ import { RemoteScope } from './internal/runtime/turbopack/remote-scope.js';
3
+
4
+ /**
5
+ * Typed namespace for all remote-components runtime state.
6
+ *
7
+ * Consolidates scattered `globalThis` globals into a single object at
8
+ * `globalThis.__remote_components__`. Each property corresponds to a
9
+ * previously independent global — see inline `@see` tags for the original
10
+ * global name. Code that previously read from those globals still works
11
+ * because each migration writes through to both the namespace and the
12
+ * legacy global (pointing at the same underlying object).
13
+ */
14
+ interface RemoteComponentsNamespace {
15
+ /** @see `__remote_component_scopes__` */
16
+ scopes: Map<string, RemoteScope>;
17
+ /** @see `__remote_components_turbopack_chunk_loader_promise__` */
18
+ chunkCache: Record<string, Promise<unknown>>;
19
+ /** @see `__remote_script_entrypoint_mount__` */
20
+ mountFns: Record<string, Set<MountOrUnmountFunction>>;
21
+ /** @see `__remote_script_entrypoint_unmount__` */
22
+ unmountFns: Record<string, Set<MountOrUnmountFunction>>;
23
+ /** @see `__remote_bundle_url__` */
24
+ bundleUrls: Record<string, string | URL>;
25
+ /** @see `__rc_module_registry__` */
26
+ moduleRegistry: Record<string, unknown>;
27
+ /** @see `__webpack_require_type__` */
28
+ dispatcherRuntime: string | undefined;
29
+ /** @see `__remote_component_host_shared_modules__` */
30
+ hostSharedModules: Record<string, () => Promise<unknown>>;
31
+ /** @see `__remote_next_css__` */
32
+ cssCache: Record<string, ChildNode[]>;
33
+ /** @see `__remote_components_shadowroot_*` */
34
+ shadowRoots: Record<string, ShadowRoot | null>;
35
+ }
36
+ /**
37
+ * Returns the single shared `RemoteComponentsNamespace` instance, creating
38
+ * it on first access. The namespace lives at `globalThis.__remote_components__`
39
+ * so every module in the page shares the same state regardless of how many
40
+ * copies of the library are loaded.
41
+ *
42
+ * On first initialization this function also handles backward compatibility
43
+ * with legacy globals:
44
+ * 1. **Adopt**: if a legacy global already exists (written by older code before
45
+ * the namespace was created), its value becomes the initial namespace value.
46
+ * 2. **Alias**: legacy globals are assigned to point at the namespace's objects,
47
+ * so older code that reads the legacy global sees the same reference.
48
+ */
49
+ declare function getNamespace(): RemoteComponentsNamespace;
50
+
51
+ interface GlobalScope {
52
+ /** Consolidated namespace — prefer `getNamespace()` over individual globals. */
53
+ __remote_components__?: RemoteComponentsNamespace;
54
+ __DISABLE_WEBPACK_EXEC__?: Record<string, boolean>;
55
+ __webpack_chunk_load__?: (chunkId: string, scriptBundle?: string) => Promise<unknown> | undefined;
56
+ __original_webpack_chunk_load__?: (chunkId: string, scriptBundle?: string) => Promise<unknown> | undefined;
57
+ __webpack_require__?: (id: string) => unknown;
58
+ __webpack_get_script_filename__?: (id: string) => string | null | undefined;
59
+ __original_webpack_require__?: (id: string) => unknown;
60
+ __remote_webpack_require__?: Record<string, ((remoteId: string | number) => unknown) & {
61
+ c?: Record<string | number, {
62
+ id: string;
63
+ parents: string[];
64
+ children: string[];
65
+ }>;
66
+ m?: Record<string | number, (module: {
67
+ exports: unknown;
68
+ }) => void>;
69
+ type?: 'turbopack' | 'webpack' | 'script';
70
+ }>;
71
+ /** @deprecated since 0.3.4 — use `getNamespace().dispatcherRuntime` instead. */
72
+ __webpack_require_type__?: RemoteComponentMetadata['runtime'];
73
+ /** @deprecated since 0.3.4 — use `getNamespace().bundleUrls` instead. */
74
+ __remote_bundle_url__?: Record<string, string | URL>;
75
+ /** @deprecated since 0.3.4 — use `getNamespace().chunkCache` instead. */
76
+ __remote_components_turbopack_chunk_loader_promise__?: Record<string, Promise<unknown>>;
77
+ /** @deprecated since 0.3.4 — use `getNamespace().scopes` instead. */
78
+ __remote_component_scopes__?: Map<string, unknown>;
79
+ [key: string]: unknown;
80
+ }
81
+ interface LoaderResult {
82
+ component: React.ReactNode;
83
+ error?: Error;
84
+ }
85
+ type RSCKey = `__remote_component_rsc_${string}__`;
86
+ type MountOrUnmountFunction = (el?: ShadowRoot | DocumentFragment | HTMLElement | HTMLCollection | null) => Promise<void> | void;
87
+ interface MountUnmountFunctions {
88
+ /** @deprecated since 0.3.4 — use `getNamespace().mountFns` instead. */
89
+ __remote_script_entrypoint_mount__?: Record<string, Set<MountOrUnmountFunction>>;
90
+ /** @deprecated since 0.3.4 — use `getNamespace().unmountFns` instead. */
91
+ __remote_script_entrypoint_unmount__?: Record<string, Set<MountOrUnmountFunction>>;
92
+ }
93
+
94
+ export { GlobalScope as G, LoaderResult as L, MountOrUnmountFunction as M, RemoteComponentsNamespace as R, RSCKey as a, MountUnmountFunctions as b, getNamespace as g };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remote-components",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "private": false,
5
5
  "description": "Compose remote components at runtime between microfrontends applications.",
6
6
  "keywords": [
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/host/shared/resolved-data.ts"],"sourcesContent":["import type * as React from 'react';\nimport type {\n LinkDescriptor,\n ScriptDescriptor,\n} from '#internal/host/shared/asset-descriptors';\nimport type { ShadowDomConfig } from '#internal/host/shared/config';\nimport type { RemoteComponentMetadata } from '#internal/runtime/metadata';\n\n/**\n * The subset of the remote component fetch response that the client-side\n * loader needs to hydrate or mount a remote component.\n *\n * Both {@link ConsumeRemoteComponentServerData} and {@link LoadRemoteComponentProps}\n * compose this interface — it is the shared base for the RSC→client handoff\n * and the loader function arguments.\n */\nexport interface RemoteComponentLoaderPayload {\n name: string;\n bundle: string;\n route?: string;\n runtime?: RemoteComponentMetadata['runtime'];\n data: string[];\n nextData?: {\n props: { pageProps: Record<string, unknown> };\n buildId?: string;\n } | null;\n scripts?: ScriptDescriptor[];\n remoteShared?: Record<string, string>;\n}\n\n/**\n * Internal RSC→client handoff type for embedding a remote component.\n *\n * Combines the loader payload with Shadow DOM config and fields that are\n * only needed by the renderer (links, type) and host (src, serverUrl, children).\n * Produced by the server component, consumed by the client renderer.\n */\nexport interface ConsumeRemoteComponentServerData\n extends RemoteComponentLoaderPayload,\n ShadowDomConfig {\n /** The src provided to the `<ConsumeRemoteComponent>` component, resolved to a string. */\n src: string;\n /** The src converted to a URL string. For relative URLs, the VERCEL_URL is used as the origin. */\n serverUrl: string;\n links?: LinkDescriptor[];\n type?: RemoteComponentMetadata['type'];\n children: React.ReactNode;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,48 +0,0 @@
1
- import * as react from 'react';
2
- import { ScriptDescriptor, LinkDescriptor } from './asset-descriptors.js';
3
- import { ShadowDomConfig } from './config.js';
4
- import { RemoteComponentMetadata } from '../../runtime/metadata.js';
5
- import '../../runtime/url/resolve-client-url.js';
6
- import './fetch-interceptors.js';
7
-
8
- /**
9
- * The subset of the remote component fetch response that the client-side
10
- * loader needs to hydrate or mount a remote component.
11
- *
12
- * Both {@link ConsumeRemoteComponentServerData} and {@link LoadRemoteComponentProps}
13
- * compose this interface — it is the shared base for the RSC→client handoff
14
- * and the loader function arguments.
15
- */
16
- interface RemoteComponentLoaderPayload {
17
- name: string;
18
- bundle: string;
19
- route?: string;
20
- runtime?: RemoteComponentMetadata['runtime'];
21
- data: string[];
22
- nextData?: {
23
- props: {
24
- pageProps: Record<string, unknown>;
25
- };
26
- buildId?: string;
27
- } | null;
28
- scripts?: ScriptDescriptor[];
29
- remoteShared?: Record<string, string>;
30
- }
31
- /**
32
- * Internal RSC→client handoff type for embedding a remote component.
33
- *
34
- * Combines the loader payload with Shadow DOM config and fields that are
35
- * only needed by the renderer (links, type) and host (src, serverUrl, children).
36
- * Produced by the server component, consumed by the client renderer.
37
- */
38
- interface ConsumeRemoteComponentServerData extends RemoteComponentLoaderPayload, ShadowDomConfig {
39
- /** The src provided to the `<ConsumeRemoteComponent>` component, resolved to a string. */
40
- src: string;
41
- /** The src converted to a URL string. For relative URLs, the VERCEL_URL is used as the origin. */
42
- serverUrl: string;
43
- links?: LinkDescriptor[];
44
- type?: RemoteComponentMetadata['type'];
45
- children: react.ReactNode;
46
- }
47
-
48
- export { ConsumeRemoteComponentServerData, RemoteComponentLoaderPayload };
@@ -1 +0,0 @@
1
- //# sourceMappingURL=resolved-data.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/runtime/turbopack/webpack-runtime.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n RUNTIME_TURBOPACK,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { createChunkDispatcher, loadChunkWithScope } from './chunk-loader';\nimport { requireModule } from './module';\nimport { createScope, getScope, registerScope } from './remote-scope';\nimport { initializeSharedModules } from './shared-modules';\n\n/**\n * Sets up webpack runtime environment for remote components.\n *\n * Creates a RemoteScope that encapsulates all per-remote state (base URL,\n * proxy callback, module cache, shared modules) and registers it in the\n * global scope registry. Global dispatchers (__webpack_require__,\n * __webpack_chunk_load__) are set once and route to the correct scope.\n *\n * @param runtime - The bundler runtime type ('webpack' or 'turbopack')\n * @param scripts - Initial script chunks to load for Turbopack runtime\n * @param url - Base URL for the remote component bundle\n * @param bundle - Bundle identifier (defaults to 'default')\n * @param shared - Host-provided shared modules (e.g., React)\n * @param remoteShared - Mapping of remote module IDs to shared module names\n */\nexport async function setupWebpackRuntime(\n runtime: Runtime,\n scripts: { src: string | null }[] = [],\n url: URL = new URL(location.href),\n bundle?: string,\n shared: Record<string, () => Promise<unknown>> = {},\n remoteShared: Record<string, string> = {},\n resolveClientUrl?: InternalResolveClientUrl,\n): Promise<void> {\n const self = globalThis as GlobalScope;\n const bundleName = bundle ?? 'default';\n\n // Create and register a scope for this remote\n const scope = createScope(bundleName, url, runtime, resolveClientUrl);\n registerScope(scope);\n\n // Still needed by patch-require.ts (webpack plugin that generates runtime\n // code as a string template — can't call getScope at build time) and the\n // HTML host (html/index.tsx writes this before setupWebpackRuntime runs).\n if (!self.__remote_bundle_url__) {\n self.__remote_bundle_url__ = {};\n }\n self.__remote_bundle_url__[bundleName] = url;\n // Also register under scopedName so webpack hosts (patch-require.ts) can\n // resolve cross-origin remotes whose bundle identifiers were rewritten.\n if (scope.scopedName !== bundleName) {\n self.__remote_bundle_url__[scope.scopedName] = url;\n }\n self.__webpack_get_script_filename__ = () => null;\n\n const willCreateDispatchers =\n typeof self.__webpack_require__ !== 'function' ||\n self.__webpack_require_type__ !== 'turbopack';\n\n if (willCreateDispatchers) {\n // preserve original webpack functions for fallback\n if (\n !self.__original_webpack_require__ &&\n !self.__original_webpack_chunk_load__\n ) {\n self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;\n self.__original_webpack_require__ = self.__webpack_require__;\n }\n\n self.__webpack_chunk_load__ = createChunkDispatcher();\n self.__webpack_require__ = createModuleDispatcher(runtime);\n self.__webpack_require_type__ = runtime;\n\n if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {\n self.__remote_webpack_require__[bundleName] =\n self.__webpack_require__ as (remoteId: string | number) => unknown;\n self.__remote_webpack_require__[bundleName].type = 'turbopack';\n }\n }\n\n // Alias __remote_webpack_require__ under the scoped name so the module\n // dispatcher can find it when RSC data uses the rewritten bundle identifier.\n // For turbopack remotes the entry was just created above; for webpack remotes\n // it was populated by the remote's own scripts under the plain name.\n if (\n self.__remote_webpack_require__?.[bundleName] &&\n scope.scopedName !== bundleName\n ) {\n self.__remote_webpack_require__[scope.scopedName] =\n self.__remote_webpack_require__[bundleName];\n }\n\n // load all initial chunks directly via scope — no global dispatch needed\n if (runtime === RUNTIME_TURBOPACK) {\n const results = await Promise.allSettled(\n scripts.map((script) => {\n if (script.src) {\n return loadChunkWithScope(scope, script.src);\n }\n return Promise.resolve(undefined);\n }),\n );\n\n for (const result of results) {\n if (result.status === 'rejected') {\n logWarn(\n 'WebpackRuntime',\n `Initial chunk load failed: ${String(result.reason)}`,\n );\n }\n }\n }\n\n // initialize shared modules with core React dependencies\n const coreShared = {\n react: async () => (await import('react')).default,\n 'react-dom': async () => (await import('react-dom')).default,\n 'react/jsx-dev-runtime': async () =>\n (await import('react/jsx-dev-runtime')).default,\n 'react/jsx-runtime': async () =>\n (await import('react/jsx-runtime')).default,\n 'react-dom/client': async () => (await import('react-dom/client')).default,\n ...shared,\n };\n await initializeSharedModules(scope, coreShared, remoteShared);\n}\n\n/**\n * Creates the global module dispatcher for __webpack_require__.\n * Called by external code (React's RSC runtime) that doesn't have access to\n * a scope. Parses the module ID to find the correct scope and delegates\n * to scope-local module resolution.\n */\nfunction createModuleDispatcher(runtime: Runtime): (id: string) => unknown {\n return (id: string) => {\n const self = globalThis as GlobalScope;\n const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)\n ?.groups ?? {\n bundle: 'default',\n id,\n };\n const bundleName = bundle ?? 'default';\n const remoteRuntime = self.__remote_webpack_require__?.[bundleName]\n ? self.__remote_webpack_require__[bundleName]?.type || 'webpack'\n : runtime;\n\n logDebug(\n 'ModuleDispatcher',\n `Resolving \"${id}\" (bundle: \"${bundleName}\", runtime: \"${remoteRuntime}\")`,\n );\n\n try {\n // for webpack remotes, use the pre-loaded require function\n if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {\n return self.__remote_webpack_require__?.[bundle]?.(moduleId);\n }\n\n // Look up scope by parsed bundle name. Works with both the scoped\n // name (Next.js hosts with server-side rewriting) and the plain\n // bundle name (static/HTML hosts with unrewritten chunks).\n const scope = getScope(bundleName);\n if (scope) {\n return requireModule(scope, moduleId ?? id, id);\n }\n\n throw new Error(\n `Module \"${id}\" not found — no scope for bundle \"${bundleName}\".`,\n );\n } catch (requireError) {\n logWarn(\n 'ModuleDispatcher',\n `Module require failed: ${String(requireError)}`,\n );\n if (typeof self.__original_webpack_require__ !== 'function') {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n {\n cause: requireError instanceof Error ? requireError : undefined,\n },\n );\n }\n try {\n logDebug(\n 'ModuleDispatcher',\n 'Falling back to original webpack require',\n );\n return self.__original_webpack_require__(id);\n } catch (originalError) {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n { cause: originalError instanceof Error ? originalError : undefined },\n );\n }\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAIO;AACP,sBAAuC;AAEvC,mBAAsC;AACtC,oBAAkC;AAClC,0BAA0D;AAC1D,oBAA8B;AAC9B,0BAAqD;AACrD,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,MAC/C;AACA,UAAI,OAAO,KAAK,iCAAiC,YAAY;AAC3D,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD;AAAA,YACE,OAAO,wBAAwB,QAAQ,eAAe;AAAA,UACxD;AAAA,QACF;AAAA,MACF;AACA,UAAI;AACF;AAAA,UACE;AAAA,UACA;AAAA,QACF;AACA,eAAO,KAAK,6BAA6B,EAAE;AAAA,MAC7C,SAAS,eAAP;AACA,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD,EAAE,OAAO,yBAAyB,QAAQ,gBAAgB,OAAU;AAAA,QACtE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1,23 +0,0 @@
1
- import { InternalResolveClientUrl } from '../url/resolve-client-url.js';
2
- import { Runtime } from '../constants.js';
3
-
4
- /**
5
- * Sets up webpack runtime environment for remote components.
6
- *
7
- * Creates a RemoteScope that encapsulates all per-remote state (base URL,
8
- * proxy callback, module cache, shared modules) and registers it in the
9
- * global scope registry. Global dispatchers (__webpack_require__,
10
- * __webpack_chunk_load__) are set once and route to the correct scope.
11
- *
12
- * @param runtime - The bundler runtime type ('webpack' or 'turbopack')
13
- * @param scripts - Initial script chunks to load for Turbopack runtime
14
- * @param url - Base URL for the remote component bundle
15
- * @param bundle - Bundle identifier (defaults to 'default')
16
- * @param shared - Host-provided shared modules (e.g., React)
17
- * @param remoteShared - Mapping of remote module IDs to shared module names
18
- */
19
- declare function setupWebpackRuntime(runtime: Runtime, scripts?: {
20
- src: string | null;
21
- }[], url?: URL, bundle?: string, shared?: Record<string, () => Promise<unknown>>, remoteShared?: Record<string, string>, resolveClientUrl?: InternalResolveClientUrl): Promise<void>;
22
-
23
- export { setupWebpackRuntime };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/runtime/turbopack/webpack-runtime.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n RUNTIME_TURBOPACK,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { createChunkDispatcher, loadChunkWithScope } from './chunk-loader';\nimport { requireModule } from './module';\nimport { createScope, getScope, registerScope } from './remote-scope';\nimport { initializeSharedModules } from './shared-modules';\n\n/**\n * Sets up webpack runtime environment for remote components.\n *\n * Creates a RemoteScope that encapsulates all per-remote state (base URL,\n * proxy callback, module cache, shared modules) and registers it in the\n * global scope registry. Global dispatchers (__webpack_require__,\n * __webpack_chunk_load__) are set once and route to the correct scope.\n *\n * @param runtime - The bundler runtime type ('webpack' or 'turbopack')\n * @param scripts - Initial script chunks to load for Turbopack runtime\n * @param url - Base URL for the remote component bundle\n * @param bundle - Bundle identifier (defaults to 'default')\n * @param shared - Host-provided shared modules (e.g., React)\n * @param remoteShared - Mapping of remote module IDs to shared module names\n */\nexport async function setupWebpackRuntime(\n runtime: Runtime,\n scripts: { src: string | null }[] = [],\n url: URL = new URL(location.href),\n bundle?: string,\n shared: Record<string, () => Promise<unknown>> = {},\n remoteShared: Record<string, string> = {},\n resolveClientUrl?: InternalResolveClientUrl,\n): Promise<void> {\n const self = globalThis as GlobalScope;\n const bundleName = bundle ?? 'default';\n\n // Create and register a scope for this remote\n const scope = createScope(bundleName, url, runtime, resolveClientUrl);\n registerScope(scope);\n\n // Still needed by patch-require.ts (webpack plugin that generates runtime\n // code as a string template — can't call getScope at build time) and the\n // HTML host (html/index.tsx writes this before setupWebpackRuntime runs).\n if (!self.__remote_bundle_url__) {\n self.__remote_bundle_url__ = {};\n }\n self.__remote_bundle_url__[bundleName] = url;\n // Also register under scopedName so webpack hosts (patch-require.ts) can\n // resolve cross-origin remotes whose bundle identifiers were rewritten.\n if (scope.scopedName !== bundleName) {\n self.__remote_bundle_url__[scope.scopedName] = url;\n }\n self.__webpack_get_script_filename__ = () => null;\n\n const willCreateDispatchers =\n typeof self.__webpack_require__ !== 'function' ||\n self.__webpack_require_type__ !== 'turbopack';\n\n if (willCreateDispatchers) {\n // preserve original webpack functions for fallback\n if (\n !self.__original_webpack_require__ &&\n !self.__original_webpack_chunk_load__\n ) {\n self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;\n self.__original_webpack_require__ = self.__webpack_require__;\n }\n\n self.__webpack_chunk_load__ = createChunkDispatcher();\n self.__webpack_require__ = createModuleDispatcher(runtime);\n self.__webpack_require_type__ = runtime;\n\n if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {\n self.__remote_webpack_require__[bundleName] =\n self.__webpack_require__ as (remoteId: string | number) => unknown;\n self.__remote_webpack_require__[bundleName].type = 'turbopack';\n }\n }\n\n // Alias __remote_webpack_require__ under the scoped name so the module\n // dispatcher can find it when RSC data uses the rewritten bundle identifier.\n // For turbopack remotes the entry was just created above; for webpack remotes\n // it was populated by the remote's own scripts under the plain name.\n if (\n self.__remote_webpack_require__?.[bundleName] &&\n scope.scopedName !== bundleName\n ) {\n self.__remote_webpack_require__[scope.scopedName] =\n self.__remote_webpack_require__[bundleName];\n }\n\n // load all initial chunks directly via scope — no global dispatch needed\n if (runtime === RUNTIME_TURBOPACK) {\n const results = await Promise.allSettled(\n scripts.map((script) => {\n if (script.src) {\n return loadChunkWithScope(scope, script.src);\n }\n return Promise.resolve(undefined);\n }),\n );\n\n for (const result of results) {\n if (result.status === 'rejected') {\n logWarn(\n 'WebpackRuntime',\n `Initial chunk load failed: ${String(result.reason)}`,\n );\n }\n }\n }\n\n // initialize shared modules with core React dependencies\n const coreShared = {\n react: async () => (await import('react')).default,\n 'react-dom': async () => (await import('react-dom')).default,\n 'react/jsx-dev-runtime': async () =>\n (await import('react/jsx-dev-runtime')).default,\n 'react/jsx-runtime': async () =>\n (await import('react/jsx-runtime')).default,\n 'react-dom/client': async () => (await import('react-dom/client')).default,\n ...shared,\n };\n await initializeSharedModules(scope, coreShared, remoteShared);\n}\n\n/**\n * Creates the global module dispatcher for __webpack_require__.\n * Called by external code (React's RSC runtime) that doesn't have access to\n * a scope. Parses the module ID to find the correct scope and delegates\n * to scope-local module resolution.\n */\nfunction createModuleDispatcher(runtime: Runtime): (id: string) => unknown {\n return (id: string) => {\n const self = globalThis as GlobalScope;\n const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)\n ?.groups ?? {\n bundle: 'default',\n id,\n };\n const bundleName = bundle ?? 'default';\n const remoteRuntime = self.__remote_webpack_require__?.[bundleName]\n ? self.__remote_webpack_require__[bundleName]?.type || 'webpack'\n : runtime;\n\n logDebug(\n 'ModuleDispatcher',\n `Resolving \"${id}\" (bundle: \"${bundleName}\", runtime: \"${remoteRuntime}\")`,\n );\n\n try {\n // for webpack remotes, use the pre-loaded require function\n if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {\n return self.__remote_webpack_require__?.[bundle]?.(moduleId);\n }\n\n // Look up scope by parsed bundle name. Works with both the scoped\n // name (Next.js hosts with server-side rewriting) and the plain\n // bundle name (static/HTML hosts with unrewritten chunks).\n const scope = getScope(bundleName);\n if (scope) {\n return requireModule(scope, moduleId ?? id, id);\n }\n\n throw new Error(\n `Module \"${id}\" not found — no scope for bundle \"${bundleName}\".`,\n );\n } catch (requireError) {\n logWarn(\n 'ModuleDispatcher',\n `Module require failed: ${String(requireError)}`,\n );\n if (typeof self.__original_webpack_require__ !== 'function') {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n {\n cause: requireError instanceof Error ? requireError : undefined,\n },\n );\n }\n try {\n logDebug(\n 'ModuleDispatcher',\n 'Falling back to original webpack require',\n );\n return self.__original_webpack_require__(id);\n } catch (originalError) {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n { cause: originalError instanceof Error ? originalError : undefined },\n );\n }\n }\n };\n}\n"],"mappings":"AACA;AAAA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