remote-components 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/dist/html/host.cjs +758 -0
  4. package/dist/html/host.cjs.map +1 -0
  5. package/dist/html/host.d.ts +2 -0
  6. package/dist/html/host.js +737 -0
  7. package/dist/html/host.js.map +1 -0
  8. package/dist/next/config.cjs +347 -0
  9. package/dist/next/config.cjs.map +1 -0
  10. package/dist/next/config.d.ts +8 -0
  11. package/dist/next/config.js +325 -0
  12. package/dist/next/config.js.map +1 -0
  13. package/dist/next/host/app-client.cjs +124 -0
  14. package/dist/next/host/app-client.cjs.map +1 -0
  15. package/dist/next/host/app-client.d.ts +33 -0
  16. package/dist/next/host/app-client.js +104 -0
  17. package/dist/next/host/app-client.js.map +1 -0
  18. package/dist/next/host/app-server.cjs +61 -0
  19. package/dist/next/host/app-server.cjs.map +1 -0
  20. package/dist/next/host/app-server.d.ts +7 -0
  21. package/dist/next/host/app-server.js +37 -0
  22. package/dist/next/host/app-server.js.map +1 -0
  23. package/dist/next/host/pages-client.cjs +52 -0
  24. package/dist/next/host/pages-client.cjs.map +1 -0
  25. package/dist/next/host/pages-client.d.ts +17 -0
  26. package/dist/next/host/pages-client.js +18 -0
  27. package/dist/next/host/pages-client.js.map +1 -0
  28. package/dist/next/host/pages-server.cjs +134 -0
  29. package/dist/next/host/pages-server.cjs.map +1 -0
  30. package/dist/next/host/pages-server.d.ts +25 -0
  31. package/dist/next/host/pages-server.js +99 -0
  32. package/dist/next/host/pages-server.js.map +1 -0
  33. package/dist/next/remote/pages.cjs +37 -0
  34. package/dist/next/remote/pages.cjs.map +1 -0
  35. package/dist/next/remote/pages.d.ts +9 -0
  36. package/dist/next/remote/pages.js +13 -0
  37. package/dist/next/remote/pages.js.map +1 -0
  38. package/dist/next/remote/render-client-turbopack.cjs +51 -0
  39. package/dist/next/remote/render-client-turbopack.cjs.map +1 -0
  40. package/dist/next/remote/render-client-turbopack.d.ts +11 -0
  41. package/dist/next/remote/render-client-turbopack.js +27 -0
  42. package/dist/next/remote/render-client-turbopack.js.map +1 -0
  43. package/dist/next/remote/render-client-webpack.cjs +51 -0
  44. package/dist/next/remote/render-client-webpack.cjs.map +1 -0
  45. package/dist/next/remote/render-client-webpack.d.ts +11 -0
  46. package/dist/next/remote/render-client-webpack.js +27 -0
  47. package/dist/next/remote/render-client-webpack.js.map +1 -0
  48. package/dist/next/remote/render-client.cjs +106 -0
  49. package/dist/next/remote/render-client.cjs.map +1 -0
  50. package/dist/next/remote/render-client.d.ts +15 -0
  51. package/dist/next/remote/render-client.js +82 -0
  52. package/dist/next/remote/render-client.js.map +1 -0
  53. package/dist/next/remote/render-server.cjs +133 -0
  54. package/dist/next/remote/render-server.cjs.map +1 -0
  55. package/dist/next/remote/render-server.d.ts +9 -0
  56. package/dist/next/remote/render-server.js +99 -0
  57. package/dist/next/remote/render-server.js.map +1 -0
  58. package/dist/next/remote/server.cjs +29 -0
  59. package/dist/next/remote/server.cjs.map +1 -0
  60. package/dist/next/remote/server.d.ts +3 -0
  61. package/dist/next/remote/server.js +5 -0
  62. package/dist/next/remote/server.js.map +1 -0
  63. package/dist/shared/client/remote-component.cjs +558 -0
  64. package/dist/shared/client/remote-component.cjs.map +1 -0
  65. package/dist/shared/client/remote-component.d.ts +93 -0
  66. package/dist/shared/client/remote-component.js +511 -0
  67. package/dist/shared/client/remote-component.js.map +1 -0
  68. package/dist/shared/ssr/dom-flight.cjs +185 -0
  69. package/dist/shared/ssr/dom-flight.cjs.map +1 -0
  70. package/dist/shared/ssr/dom-flight.d.ts +30 -0
  71. package/dist/shared/ssr/dom-flight.js +151 -0
  72. package/dist/shared/ssr/dom-flight.js.map +1 -0
  73. package/dist/shared/ssr/fetch-remote-component.cjs +162 -0
  74. package/dist/shared/ssr/fetch-remote-component.cjs.map +1 -0
  75. package/dist/shared/ssr/fetch-remote-component.d.ts +31 -0
  76. package/dist/shared/ssr/fetch-remote-component.js +137 -0
  77. package/dist/shared/ssr/fetch-remote-component.js.map +1 -0
  78. package/dist/shared/webpack/next-client-pages-loader.cjs +107 -0
  79. package/dist/shared/webpack/next-client-pages-loader.cjs.map +1 -0
  80. package/dist/shared/webpack/next-client-pages-loader.d.ts +10 -0
  81. package/dist/shared/webpack/next-client-pages-loader.js +83 -0
  82. package/dist/shared/webpack/next-client-pages-loader.js.map +1 -0
  83. package/dist/shared/webpack/shared-modules.cjs +50 -0
  84. package/dist/shared/webpack/shared-modules.cjs.map +1 -0
  85. package/dist/shared/webpack/shared-modules.d.ts +3 -0
  86. package/dist/shared/webpack/shared-modules.js +26 -0
  87. package/dist/shared/webpack/shared-modules.js.map +1 -0
  88. package/dist/types-280a3640.d.ts +8 -0
  89. package/dist/types-a1bd5b56.d.ts +6 -0
  90. package/package.json +151 -0
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { createFromReadableStream as ssrCreateFromReadableStream } from "react-server-dom-turbopack/client.edge";
4
+ import { createFromReadableStream } from "react-server-dom-turbopack/client.browser";
5
+ import { RemoteComponentSSR as GenericRemoteComponentSSR } from "./render-client";
6
+ function RemoteComponentSSR({
7
+ name,
8
+ data,
9
+ moduleLoading,
10
+ moduleMap
11
+ }) {
12
+ return /* @__PURE__ */ jsx(
13
+ GenericRemoteComponentSSR,
14
+ {
15
+ createFromReadableStream,
16
+ data,
17
+ moduleLoading,
18
+ moduleMap,
19
+ name,
20
+ ssrCreateFromReadableStream
21
+ }
22
+ );
23
+ }
24
+ export {
25
+ RemoteComponentSSR
26
+ };
27
+ //# sourceMappingURL=render-client-turbopack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/next/remote/render-client-turbopack.tsx"],"sourcesContent":["'use client';\n\n// these components are in a client component file to use these in the SSR and client layers\n\nimport { createFromReadableStream as ssrCreateFromReadableStream } from 'react-server-dom-turbopack/client.edge';\nimport { createFromReadableStream } from 'react-server-dom-turbopack/client.browser';\nimport { RemoteComponentSSR as GenericRemoteComponentSSR } from './render-client';\nimport type { ModuleLoading } from './types';\n\n// server-side component to render the remote component into HTML (SSR layer)\nexport function RemoteComponentSSR({\n name,\n data,\n moduleLoading,\n moduleMap,\n}: {\n name: string;\n data: string[];\n moduleLoading: ModuleLoading;\n moduleMap: Record<string, unknown>;\n}) {\n // use the client-side component to load the RSC payload into a React component in the browser\n // <RemoteComponentClient> will only have a reference to the component as children on the server-side\n return (\n <GenericRemoteComponentSSR\n createFromReadableStream={createFromReadableStream}\n data={data}\n moduleLoading={moduleLoading}\n moduleMap={moduleMap}\n name={name}\n ssrCreateFromReadableStream={ssrCreateFromReadableStream}\n />\n );\n}\n"],"mappings":";AAwBI;AApBJ,SAAS,4BAA4B,mCAAmC;AACxE,SAAS,gCAAgC;AACzC,SAAS,sBAAsB,iCAAiC;AAIzD,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKG;AAGD,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACF;AAEJ;","names":[]}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var render_client_webpack_exports = {};
21
+ __export(render_client_webpack_exports, {
22
+ RemoteComponentSSR: () => RemoteComponentSSR
23
+ });
24
+ module.exports = __toCommonJS(render_client_webpack_exports);
25
+ var import_jsx_runtime = require("react/jsx-runtime");
26
+ var import_client = require("react-server-dom-webpack/client.edge");
27
+ var import_client2 = require("react-server-dom-webpack/client.browser");
28
+ var import_render_client = require("./render-client");
29
+ function RemoteComponentSSR({
30
+ name,
31
+ data,
32
+ moduleLoading,
33
+ moduleMap
34
+ }) {
35
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
36
+ import_render_client.RemoteComponentSSR,
37
+ {
38
+ createFromReadableStream: import_client2.createFromReadableStream,
39
+ data,
40
+ moduleLoading,
41
+ moduleMap,
42
+ name,
43
+ ssrCreateFromReadableStream: import_client.createFromReadableStream
44
+ }
45
+ );
46
+ }
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ RemoteComponentSSR
50
+ });
51
+ //# sourceMappingURL=render-client-webpack.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/next/remote/render-client-webpack.tsx"],"sourcesContent":["'use client';\n\n// these components are in a client component file to use these in the SSR and client layers\n\nimport { createFromReadableStream as ssrCreateFromReadableStream } from 'react-server-dom-webpack/client.edge';\nimport { createFromReadableStream } from 'react-server-dom-webpack/client.browser';\nimport { RemoteComponentSSR as GenericRemoteComponentSSR } from './render-client';\nimport type { ModuleLoading } from './types';\n\n// server-side component to render the remote component into HTML (SSR layer)\nexport function RemoteComponentSSR({\n name,\n data,\n moduleLoading,\n moduleMap,\n}: {\n name: string;\n data: string[];\n moduleLoading: ModuleLoading;\n moduleMap: Record<string, unknown>;\n}) {\n // use the client-side component to load the RSC payload into a React component in the browser\n // <RemoteComponentClient> will only have a reference to the component as children on the server-side\n return (\n <GenericRemoteComponentSSR\n createFromReadableStream={createFromReadableStream}\n data={data}\n moduleLoading={moduleLoading}\n moduleMap={moduleMap}\n name={name}\n ssrCreateFromReadableStream={ssrCreateFromReadableStream}\n />\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBI;AApBJ,oBAAwE;AACxE,IAAAA,iBAAyC;AACzC,2BAAgE;AAIzD,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKG;AAGD,SACE;AAAA,IAAC,qBAAAC;AAAA,IAAA;AAAA,MACC,0BAA0B;AAAA,MAC1B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,6BAA6B,cAAAC;AAAA;AAAA,EAC/B;AAEJ;","names":["import_client","GenericRemoteComponentSSR","ssrCreateFromReadableStream"]}
@@ -0,0 +1,11 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { M as ModuleLoading } from '../../types-a1bd5b56.js';
3
+
4
+ declare function RemoteComponentSSR({ name, data, moduleLoading, moduleMap, }: {
5
+ name: string;
6
+ data: string[];
7
+ moduleLoading: ModuleLoading;
8
+ moduleMap: Record<string, unknown>;
9
+ }): react_jsx_runtime.JSX.Element;
10
+
11
+ export { RemoteComponentSSR };
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { createFromReadableStream as ssrCreateFromReadableStream } from "react-server-dom-webpack/client.edge";
4
+ import { createFromReadableStream } from "react-server-dom-webpack/client.browser";
5
+ import { RemoteComponentSSR as GenericRemoteComponentSSR } from "./render-client";
6
+ function RemoteComponentSSR({
7
+ name,
8
+ data,
9
+ moduleLoading,
10
+ moduleMap
11
+ }) {
12
+ return /* @__PURE__ */ jsx(
13
+ GenericRemoteComponentSSR,
14
+ {
15
+ createFromReadableStream,
16
+ data,
17
+ moduleLoading,
18
+ moduleMap,
19
+ name,
20
+ ssrCreateFromReadableStream
21
+ }
22
+ );
23
+ }
24
+ export {
25
+ RemoteComponentSSR
26
+ };
27
+ //# sourceMappingURL=render-client-webpack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/next/remote/render-client-webpack.tsx"],"sourcesContent":["'use client';\n\n// these components are in a client component file to use these in the SSR and client layers\n\nimport { createFromReadableStream as ssrCreateFromReadableStream } from 'react-server-dom-webpack/client.edge';\nimport { createFromReadableStream } from 'react-server-dom-webpack/client.browser';\nimport { RemoteComponentSSR as GenericRemoteComponentSSR } from './render-client';\nimport type { ModuleLoading } from './types';\n\n// server-side component to render the remote component into HTML (SSR layer)\nexport function RemoteComponentSSR({\n name,\n data,\n moduleLoading,\n moduleMap,\n}: {\n name: string;\n data: string[];\n moduleLoading: ModuleLoading;\n moduleMap: Record<string, unknown>;\n}) {\n // use the client-side component to load the RSC payload into a React component in the browser\n // <RemoteComponentClient> will only have a reference to the component as children on the server-side\n return (\n <GenericRemoteComponentSSR\n createFromReadableStream={createFromReadableStream}\n data={data}\n moduleLoading={moduleLoading}\n moduleMap={moduleMap}\n name={name}\n ssrCreateFromReadableStream={ssrCreateFromReadableStream}\n />\n );\n}\n"],"mappings":";AAwBI;AApBJ,SAAS,4BAA4B,mCAAmC;AACxE,SAAS,gCAAgC;AACzC,SAAS,sBAAsB,iCAAiC;AAIzD,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKG;AAGD,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACF;AAEJ;","names":[]}
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var render_client_exports = {};
21
+ __export(render_client_exports, {
22
+ RemoteComponentSSR: () => RemoteComponentSSR
23
+ });
24
+ module.exports = __toCommonJS(render_client_exports);
25
+ var import_jsx_runtime = require("react/jsx-runtime");
26
+ var import_remote = require("@remote-component/shared/remote");
27
+ var import_react = require("react");
28
+ function RemoteComponentClient({
29
+ name,
30
+ children,
31
+ createFromReadableStream
32
+ }) {
33
+ const [component, setComponent] = (0, import_react.useState)(null);
34
+ (0, import_react.useEffect)(() => {
35
+ if (!component) {
36
+ setComponent(
37
+ createFromReadableStream(
38
+ // create a new ReadableStream to load the RSC payload
39
+ new ReadableStream({
40
+ // createFromReadableStream works with a byte stream
41
+ type: "bytes",
42
+ start(controller) {
43
+ const encoder = new TextEncoder();
44
+ (self[name] ?? [`0:[null]
45
+ `]).forEach((chunk) => {
46
+ controller.enqueue(encoder.encode(chunk));
47
+ });
48
+ controller.close();
49
+ }
50
+ })
51
+ )
52
+ );
53
+ }
54
+ }, [component, name, createFromReadableStream]);
55
+ return component ?? children;
56
+ }
57
+ function RemoteComponentSSR({
58
+ name,
59
+ data,
60
+ moduleLoading,
61
+ moduleMap,
62
+ createFromReadableStream,
63
+ ssrCreateFromReadableStream
64
+ }) {
65
+ const [component] = (0, import_react.useState)(
66
+ // only initialize the component when this runs on the server-side in the SSR layer
67
+ // this converts the RSC flight data into a React component to get server-side rendering into HTML
68
+ data.length > 0 && typeof document === "undefined" ? ssrCreateFromReadableStream(
69
+ // convert the RSC payload to a ReadableStream
70
+ new ReadableStream({
71
+ // createFromReadableStream works with a byte stream
72
+ type: "bytes",
73
+ start(controller) {
74
+ const encoder = new TextEncoder();
75
+ data.forEach((chunk) => {
76
+ controller.enqueue(encoder.encode(chunk));
77
+ });
78
+ controller.close();
79
+ }
80
+ }),
81
+ // pass module metadata to be able to use client components
82
+ {
83
+ serverConsumerManifest: {
84
+ moduleLoading,
85
+ moduleMap
86
+ }
87
+ }
88
+ ) : null
89
+ );
90
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
91
+ RemoteComponentClient,
92
+ {
93
+ createFromReadableStream,
94
+ name,
95
+ children: [
96
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", { id: `${name}_shared`, type: "application/json", children: JSON.stringify(import_remote.shared) }),
97
+ component
98
+ ]
99
+ }
100
+ );
101
+ }
102
+ // Annotate the CommonJS export names for ESM import in node:
103
+ 0 && (module.exports = {
104
+ RemoteComponentSSR
105
+ });
106
+ //# sourceMappingURL=render-client.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/next/remote/render-client.tsx"],"sourcesContent":["'use client';\n\n// these components are in a client component file to use these in the SSR and client layers\nimport type { createFromReadableStream as typeofSsrCreateFromReadableStream } from 'react-server-dom-webpack/client.edge';\nimport type { createFromReadableStream as typeofCreateFromReadableStream } from 'react-server-dom-webpack/client.browser';\nimport { shared } from '@remote-component/shared/remote';\nimport { useEffect, useState } from 'react';\nimport type { ModuleLoading } from './types';\n\n// client-side component to load the RSC payload into a React component (client layer)\nfunction RemoteComponentClient({\n name,\n children,\n createFromReadableStream,\n}: {\n name: string;\n children: React.ReactNode;\n createFromReadableStream: typeof typeofCreateFromReadableStream;\n}) {\n // component is initialized to null to use the original RSC children\n const [component, setComponent] = useState<React.ReactNode>(null);\n\n // useEffect will only run on the client-side\n // this initial run deserializes the RSC payload into a React component\n useEffect(() => {\n // when the component is not yet created, create it using React createFromReadableStream API\n if (!component) {\n setComponent(\n createFromReadableStream(\n // create a new ReadableStream to load the RSC payload\n new ReadableStream({\n // createFromReadableStream works with a byte stream\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n // try to load the RSC payload using the remote component name\n // <RemoteComponentData> inserts the required RSC flight data using <script> elements\n // if the RSC data is not found, fallback to an empty RSC payload\n (\n (self as Window & typeof globalThis & Record<string, string[]>)[\n name\n ] ?? [`0:[null]\\n`]\n )\n // RSC flight data is stored in an array\n .forEach((chunk) => {\n // encode the chunk to a byte buffer\n controller.enqueue(encoder.encode(chunk));\n });\n // close the stream when all chunks are enqueued\n controller.close();\n },\n }),\n ),\n );\n }\n }, [component, name, createFromReadableStream]);\n\n return component ?? children;\n}\n\n// server-side component to render the remote component into HTML (SSR layer)\nexport function RemoteComponentSSR({\n name,\n data,\n moduleLoading,\n moduleMap,\n createFromReadableStream,\n ssrCreateFromReadableStream,\n}: {\n name: string;\n data: string[];\n moduleLoading: ModuleLoading;\n moduleMap: Record<string, unknown>;\n createFromReadableStream: typeof typeofCreateFromReadableStream;\n ssrCreateFromReadableStream: typeof typeofSsrCreateFromReadableStream;\n}) {\n // a useState hook is used to initialize the component only once and to pass the component reference to the client-side as children\n // eslint-disable-next-line react/hook-use-state\n const [component] = useState(\n // only initialize the component when this runs on the server-side in the SSR layer\n // this converts the RSC flight data into a React component to get server-side rendering into HTML\n data.length > 0 && typeof document === 'undefined'\n ? ssrCreateFromReadableStream(\n // convert the RSC payload to a ReadableStream\n new ReadableStream({\n // createFromReadableStream works with a byte stream\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n // RSC flight data is stored in an array\n data.forEach((chunk) => {\n // encode the chunk to a byte buffer\n controller.enqueue(encoder.encode(chunk));\n });\n // close the stream when all chunks are enqueued\n controller.close();\n },\n }),\n // pass module metadata to be able to use client components\n {\n serverConsumerManifest: {\n moduleLoading,\n moduleMap,\n },\n },\n )\n : null,\n );\n\n // use the client-side component to load the RSC payload into a React component in the browser\n // <RemoteComponentClient> will only have a reference to the component as children on the server-side\n return (\n <RemoteComponentClient\n createFromReadableStream={createFromReadableStream}\n name={name}\n >\n <script id={`${name}_shared`} type=\"application/json\">\n {JSON.stringify(shared)}\n </script>\n {component}\n </RemoteComponentClient>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgHI;AA3GJ,oBAAuB;AACvB,mBAAoC;AAIpC,SAAS,sBAAsB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AACF,GAIG;AAED,QAAM,CAAC,WAAW,YAAY,QAAI,uBAA0B,IAAI;AAIhE,8BAAU,MAAM;AAEd,QAAI,CAAC,WAAW;AACd;AAAA,QACE;AAAA;AAAA,UAEE,IAAI,eAAe;AAAA;AAAA,YAEjB,MAAM;AAAA,YACN,MAAM,YAAY;AAChB,oBAAM,UAAU,IAAI,YAAY;AAIhC,eACG,KACC,IACF,KAAK,CAAC;AAAA,CAAY,GAGjB,QAAQ,CAAC,UAAU;AAElB,2BAAW,QAAQ,QAAQ,OAAO,KAAK,CAAC;AAAA,cAC1C,CAAC;AAEH,yBAAW,MAAM;AAAA,YACnB;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,WAAW,MAAM,wBAAwB,CAAC;AAE9C,SAAO,aAAa;AACtB;AAGO,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAOG;AAGD,QAAM,CAAC,SAAS,QAAI;AAAA;AAAA;AAAA,IAGlB,KAAK,SAAS,KAAK,OAAO,aAAa,cACnC;AAAA;AAAA,MAEE,IAAI,eAAe;AAAA;AAAA,QAEjB,MAAM;AAAA,QACN,MAAM,YAAY;AAChB,gBAAM,UAAU,IAAI,YAAY;AAEhC,eAAK,QAAQ,CAAC,UAAU;AAEtB,uBAAW,QAAQ,QAAQ,OAAO,KAAK,CAAC;AAAA,UAC1C,CAAC;AAED,qBAAW,MAAM;AAAA,QACnB;AAAA,MACF,CAAC;AAAA;AAAA,MAED;AAAA,QACE,wBAAwB;AAAA,UACtB;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF,IACA;AAAA,EACN;AAIA,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MAEA;AAAA,oDAAC,YAAO,IAAI,GAAG,eAAe,MAAK,oBAChC,eAAK,UAAU,oBAAM,GACxB;AAAA,QACC;AAAA;AAAA;AAAA,EACH;AAEJ;","names":[]}
@@ -0,0 +1,15 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { createFromReadableStream as createFromReadableStream$1 } from 'react-server-dom-webpack/client.edge';
3
+ import { createFromReadableStream } from 'react-server-dom-webpack/client.browser';
4
+ import { M as ModuleLoading } from '../../types-a1bd5b56.js';
5
+
6
+ declare function RemoteComponentSSR({ name, data, moduleLoading, moduleMap, createFromReadableStream, ssrCreateFromReadableStream, }: {
7
+ name: string;
8
+ data: string[];
9
+ moduleLoading: ModuleLoading;
10
+ moduleMap: Record<string, unknown>;
11
+ createFromReadableStream: typeof createFromReadableStream;
12
+ ssrCreateFromReadableStream: typeof createFromReadableStream$1;
13
+ }): react_jsx_runtime.JSX.Element;
14
+
15
+ export { RemoteComponentSSR };
@@ -0,0 +1,82 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { shared } from "@remote-component/shared/remote";
4
+ import { useEffect, useState } from "react";
5
+ function RemoteComponentClient({
6
+ name,
7
+ children,
8
+ createFromReadableStream
9
+ }) {
10
+ const [component, setComponent] = useState(null);
11
+ useEffect(() => {
12
+ if (!component) {
13
+ setComponent(
14
+ createFromReadableStream(
15
+ // create a new ReadableStream to load the RSC payload
16
+ new ReadableStream({
17
+ // createFromReadableStream works with a byte stream
18
+ type: "bytes",
19
+ start(controller) {
20
+ const encoder = new TextEncoder();
21
+ (self[name] ?? [`0:[null]
22
+ `]).forEach((chunk) => {
23
+ controller.enqueue(encoder.encode(chunk));
24
+ });
25
+ controller.close();
26
+ }
27
+ })
28
+ )
29
+ );
30
+ }
31
+ }, [component, name, createFromReadableStream]);
32
+ return component ?? children;
33
+ }
34
+ function RemoteComponentSSR({
35
+ name,
36
+ data,
37
+ moduleLoading,
38
+ moduleMap,
39
+ createFromReadableStream,
40
+ ssrCreateFromReadableStream
41
+ }) {
42
+ const [component] = useState(
43
+ // only initialize the component when this runs on the server-side in the SSR layer
44
+ // this converts the RSC flight data into a React component to get server-side rendering into HTML
45
+ data.length > 0 && typeof document === "undefined" ? ssrCreateFromReadableStream(
46
+ // convert the RSC payload to a ReadableStream
47
+ new ReadableStream({
48
+ // createFromReadableStream works with a byte stream
49
+ type: "bytes",
50
+ start(controller) {
51
+ const encoder = new TextEncoder();
52
+ data.forEach((chunk) => {
53
+ controller.enqueue(encoder.encode(chunk));
54
+ });
55
+ controller.close();
56
+ }
57
+ }),
58
+ // pass module metadata to be able to use client components
59
+ {
60
+ serverConsumerManifest: {
61
+ moduleLoading,
62
+ moduleMap
63
+ }
64
+ }
65
+ ) : null
66
+ );
67
+ return /* @__PURE__ */ jsxs(
68
+ RemoteComponentClient,
69
+ {
70
+ createFromReadableStream,
71
+ name,
72
+ children: [
73
+ /* @__PURE__ */ jsx("script", { id: `${name}_shared`, type: "application/json", children: JSON.stringify(shared) }),
74
+ component
75
+ ]
76
+ }
77
+ );
78
+ }
79
+ export {
80
+ RemoteComponentSSR
81
+ };
82
+ //# sourceMappingURL=render-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/next/remote/render-client.tsx"],"sourcesContent":["'use client';\n\n// these components are in a client component file to use these in the SSR and client layers\nimport type { createFromReadableStream as typeofSsrCreateFromReadableStream } from 'react-server-dom-webpack/client.edge';\nimport type { createFromReadableStream as typeofCreateFromReadableStream } from 'react-server-dom-webpack/client.browser';\nimport { shared } from '@remote-component/shared/remote';\nimport { useEffect, useState } from 'react';\nimport type { ModuleLoading } from './types';\n\n// client-side component to load the RSC payload into a React component (client layer)\nfunction RemoteComponentClient({\n name,\n children,\n createFromReadableStream,\n}: {\n name: string;\n children: React.ReactNode;\n createFromReadableStream: typeof typeofCreateFromReadableStream;\n}) {\n // component is initialized to null to use the original RSC children\n const [component, setComponent] = useState<React.ReactNode>(null);\n\n // useEffect will only run on the client-side\n // this initial run deserializes the RSC payload into a React component\n useEffect(() => {\n // when the component is not yet created, create it using React createFromReadableStream API\n if (!component) {\n setComponent(\n createFromReadableStream(\n // create a new ReadableStream to load the RSC payload\n new ReadableStream({\n // createFromReadableStream works with a byte stream\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n // try to load the RSC payload using the remote component name\n // <RemoteComponentData> inserts the required RSC flight data using <script> elements\n // if the RSC data is not found, fallback to an empty RSC payload\n (\n (self as Window & typeof globalThis & Record<string, string[]>)[\n name\n ] ?? [`0:[null]\\n`]\n )\n // RSC flight data is stored in an array\n .forEach((chunk) => {\n // encode the chunk to a byte buffer\n controller.enqueue(encoder.encode(chunk));\n });\n // close the stream when all chunks are enqueued\n controller.close();\n },\n }),\n ),\n );\n }\n }, [component, name, createFromReadableStream]);\n\n return component ?? children;\n}\n\n// server-side component to render the remote component into HTML (SSR layer)\nexport function RemoteComponentSSR({\n name,\n data,\n moduleLoading,\n moduleMap,\n createFromReadableStream,\n ssrCreateFromReadableStream,\n}: {\n name: string;\n data: string[];\n moduleLoading: ModuleLoading;\n moduleMap: Record<string, unknown>;\n createFromReadableStream: typeof typeofCreateFromReadableStream;\n ssrCreateFromReadableStream: typeof typeofSsrCreateFromReadableStream;\n}) {\n // a useState hook is used to initialize the component only once and to pass the component reference to the client-side as children\n // eslint-disable-next-line react/hook-use-state\n const [component] = useState(\n // only initialize the component when this runs on the server-side in the SSR layer\n // this converts the RSC flight data into a React component to get server-side rendering into HTML\n data.length > 0 && typeof document === 'undefined'\n ? ssrCreateFromReadableStream(\n // convert the RSC payload to a ReadableStream\n new ReadableStream({\n // createFromReadableStream works with a byte stream\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n // RSC flight data is stored in an array\n data.forEach((chunk) => {\n // encode the chunk to a byte buffer\n controller.enqueue(encoder.encode(chunk));\n });\n // close the stream when all chunks are enqueued\n controller.close();\n },\n }),\n // pass module metadata to be able to use client components\n {\n serverConsumerManifest: {\n moduleLoading,\n moduleMap,\n },\n },\n )\n : null,\n );\n\n // use the client-side component to load the RSC payload into a React component in the browser\n // <RemoteComponentClient> will only have a reference to the component as children on the server-side\n return (\n <RemoteComponentClient\n createFromReadableStream={createFromReadableStream}\n name={name}\n >\n <script id={`${name}_shared`} type=\"application/json\">\n {JSON.stringify(shared)}\n </script>\n {component}\n </RemoteComponentClient>\n );\n}\n"],"mappings":";AAgHI,SAIE,KAJF;AA3GJ,SAAS,cAAc;AACvB,SAAS,WAAW,gBAAgB;AAIpC,SAAS,sBAAsB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AACF,GAIG;AAED,QAAM,CAAC,WAAW,YAAY,IAAI,SAA0B,IAAI;AAIhE,YAAU,MAAM;AAEd,QAAI,CAAC,WAAW;AACd;AAAA,QACE;AAAA;AAAA,UAEE,IAAI,eAAe;AAAA;AAAA,YAEjB,MAAM;AAAA,YACN,MAAM,YAAY;AAChB,oBAAM,UAAU,IAAI,YAAY;AAIhC,eACG,KACC,IACF,KAAK,CAAC;AAAA,CAAY,GAGjB,QAAQ,CAAC,UAAU;AAElB,2BAAW,QAAQ,QAAQ,OAAO,KAAK,CAAC;AAAA,cAC1C,CAAC;AAEH,yBAAW,MAAM;AAAA,YACnB;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,WAAW,MAAM,wBAAwB,CAAC;AAE9C,SAAO,aAAa;AACtB;AAGO,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAOG;AAGD,QAAM,CAAC,SAAS,IAAI;AAAA;AAAA;AAAA,IAGlB,KAAK,SAAS,KAAK,OAAO,aAAa,cACnC;AAAA;AAAA,MAEE,IAAI,eAAe;AAAA;AAAA,QAEjB,MAAM;AAAA,QACN,MAAM,YAAY;AAChB,gBAAM,UAAU,IAAI,YAAY;AAEhC,eAAK,QAAQ,CAAC,UAAU;AAEtB,uBAAW,QAAQ,QAAQ,OAAO,KAAK,CAAC;AAAA,UAC1C,CAAC;AAED,qBAAW,MAAM;AAAA,QACnB;AAAA,MACF,CAAC;AAAA;AAAA,MAED;AAAA,QACE,wBAAwB;AAAA,UACtB;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF,IACA;AAAA,EACN;AAIA,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MAEA;AAAA,4BAAC,YAAO,IAAI,GAAG,eAAe,MAAK,oBAChC,eAAK,UAAU,MAAM,GACxB;AAAA,QACC;AAAA;AAAA;AAAA,EACH;AAEJ;","names":[]}
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var render_server_exports = {};
30
+ __export(render_server_exports, {
31
+ RemoteComponent: () => RemoteComponent
32
+ });
33
+ module.exports = __toCommonJS(render_server_exports);
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var import_headers = require("next/headers");
36
+ var import_work_async_storage = require("next/dist/server/app-render/work-async-storage.external");
37
+ const SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(
38
+ "next.server.action-manifests"
39
+ );
40
+ const CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;
41
+ function RemoteComponentData({ name, data }) {
42
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", { id: `${name}_rsc`, children: data.map(
43
+ (chunk, i) => (
44
+ // make the data handling somewhat safe
45
+ `${i === 0 ? `self["${name}"]=self["${name}"]||[];` : ""}self["${name}"].push(${JSON.stringify(
46
+ chunk
47
+ )});`
48
+ )
49
+ ).join("\n") });
50
+ }
51
+ async function RemoteComponent({
52
+ name = "__vercel_remote_component",
53
+ children
54
+ }) {
55
+ const headersList = await (0, import_headers.headers)();
56
+ const url = headersList.get("Vercel-Remote-Component-Url");
57
+ const isRemote = url !== null;
58
+ if (!isRemote) {
59
+ return children;
60
+ }
61
+ const { pathname } = new URL(url);
62
+ const { page, route } = import_work_async_storage.workAsyncStorage.getStore() ?? { page: pathname };
63
+ const manifests = globalThis[SERVER_ACTION_MANIFESTS_SINGLETON];
64
+ const manifest = manifests.clientReferenceManifestsPerPage?.[route ?? page];
65
+ const self = globalThis;
66
+ self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};
67
+ self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;
68
+ let clientModules = manifest?.clientModules ?? {};
69
+ const ssrModuleMapping = { ...manifest?.ssrModuleMapping };
70
+ clientModules = Object.fromEntries(
71
+ Object.entries(clientModules).map(([key, value]) => {
72
+ const remoteId = `[${CURRENT_ZONE}] ${value.id}`;
73
+ ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];
74
+ return [
75
+ key,
76
+ {
77
+ ...value,
78
+ id: remoteId,
79
+ // prepend the current zone to the chunks to handle remote component chunk loading in Webpack
80
+ // this is required to avoid loading the wrong chunk in the host application
81
+ chunks: value.chunks.map((chunk) => `[${CURRENT_ZONE}] ${chunk}`)
82
+ // async: true,
83
+ }
84
+ ];
85
+ })
86
+ );
87
+ const [{ renderToReadableStream }, { RemoteComponentSSR }] = await Promise.all(
88
+ process.env.TURBOPACK ? [
89
+ import("react-server-dom-turbopack/server.edge"),
90
+ import("./render-client-turbopack")
91
+ ] : [
92
+ import("react-server-dom-webpack/server.edge"),
93
+ import("./render-client-webpack")
94
+ ]
95
+ );
96
+ const stream = renderToReadableStream(children, clientModules);
97
+ const data = [];
98
+ const decoder = new TextDecoder();
99
+ for await (const chunk of stream) {
100
+ data.push(decoder.decode(chunk));
101
+ }
102
+ const runtime = process.env.TURBOPACK ? "turbopack" : "webpack";
103
+ const remoteComponentName = `${name}_${route?.replace(/\//g, "_")}`;
104
+ return (
105
+ // wrap the remote component content into a div to know which part of the HTML belongs to the remote component
106
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
107
+ "div",
108
+ {
109
+ "data-bundle": CURRENT_ZONE,
110
+ "data-route": route,
111
+ "data-runtime": runtime,
112
+ id: `${remoteComponentName}_ssr`,
113
+ children: [
114
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
115
+ RemoteComponentSSR,
116
+ {
117
+ data,
118
+ moduleLoading: manifest?.moduleLoading ?? {},
119
+ moduleMap: ssrModuleMapping,
120
+ name: remoteComponentName
121
+ }
122
+ ),
123
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RemoteComponentData, { data, name: remoteComponentName })
124
+ ]
125
+ }
126
+ )
127
+ );
128
+ }
129
+ // Annotate the CommonJS export names for ESM import in node:
130
+ 0 && (module.exports = {
131
+ RemoteComponent
132
+ });
133
+ //# sourceMappingURL=render-server.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/next/remote/render-server.tsx"],"sourcesContent":["import { headers } from 'next/headers';\nimport { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport type { Manifest } from './types';\n\n// internal Next.js symbol to access the manifest which is stored in the global scope\nconst SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\n\nconst CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;\n\n// inject the RSC flight data into the HTML response using <script>\n// the RSC flight data is used to hydrate the remote component on the host\n// this approach is similar to an island architecture on the host\n// the remote component is static HTML until it is hydrated using this RSC flight data\nfunction RemoteComponentData({ name, data }: { name: string; data: string[] }) {\n return (\n <script id={`${name}_rsc`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''}self[\"${name}\"].push(${JSON.stringify(\n chunk,\n )});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\n// a React Server Component to start rendering of the remote component\n// this is a temporary solution until the Next.js team provides a better way to handle remote components\nexport async function RemoteComponent({\n name = '__vercel_remote_component',\n children,\n}: {\n name?: string;\n children: React.ReactNode;\n}) {\n const headersList = await headers();\n const url = headersList.get('Vercel-Remote-Component-Url');\n const isRemote = url !== null;\n\n if (!isRemote) {\n return children;\n }\n\n // this URL passed by the remote component consumer is only used to know the public address of the remote component\n // it is only used to determine if we need to mutate the client module map for now\n\n const { pathname } = new URL(url);\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? { page: pathname };\n\n // get reference to the manifests from the global scope\n const manifests = (\n globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n }\n )[SERVER_ACTION_MANIFESTS_SINGLETON];\n const manifest = manifests.clientReferenceManifestsPerPage?.[route ?? page];\n\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n };\n\n // manually handle the internal Next.js manifest\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\n let clientModules = manifest?.clientModules ?? {};\n const ssrModuleMapping = { ...manifest?.ssrModuleMapping };\n\n // if the remote component is used in a hosting application, we need to mutate the module map to include the zone\n clientModules = Object.fromEntries(\n Object.entries(clientModules).map(([key, value]) => {\n // append a prefix to each entry in the module map to include the zone of the remote component\n const remoteId = `[${CURRENT_ZONE}] ${value.id}`;\n ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];\n // override the original id with the new remote id\n return [\n key,\n {\n ...value,\n id: remoteId,\n // prepend the current zone to the chunks to handle remote component chunk loading in Webpack\n // this is required to avoid loading the wrong chunk in the host application\n chunks: value.chunks.map((chunk) => `[${CURRENT_ZONE}] ${chunk}`),\n // async: true,\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [{ renderToReadableStream }, { RemoteComponentSSR }] =\n await Promise.all(\n process.env.TURBOPACK\n ? [\n import('react-server-dom-turbopack/server.edge'),\n import('./render-client-turbopack'),\n ]\n : [\n import('react-server-dom-webpack/server.edge'),\n import('./render-client-webpack'),\n ],\n );\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules);\n\n const data = [];\n const decoder = new TextDecoder();\n\n // convert the stream to an array for safe passing to the client\n for await (const chunk of stream as unknown as AsyncIterable<Uint8Array>) {\n data.push(decoder.decode(chunk));\n }\n\n const runtime = process.env.TURBOPACK ? 'turbopack' : 'webpack';\n const remoteComponentName = `${name}_${route?.replace(/\\//g, '_')}`;\n\n return (\n // wrap the remote component content into a div to know which part of the HTML belongs to the remote component\n <div\n data-bundle={CURRENT_ZONE}\n data-route={route}\n data-runtime={runtime}\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSSR\n data={data}\n moduleLoading={manifest?.moduleLoading ?? {}}\n moduleMap={ssrModuleMapping}\n name={remoteComponentName}\n />\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBI;AAjBJ,qBAAwB;AACxB,gCAAiC;AAIjC,MAAM,oCAAoC,OAAO;AAAA,EAC/C;AACF;AAEA,MAAM,eAAe,QAAQ,IAAI;AAMjC,SAAS,oBAAoB,EAAE,MAAM,KAAK,GAAqC;AAC7E,SACE,4CAAC,YAAO,IAAI,GAAG,YACZ,eACE;AAAA,IACC,CAAC,OAAO;AAAA;AAAA,MAEN,GAAG,MAAM,IAAI,SAAS,gBAAgB,gBAAgB,WAAW,eAAe,KAAK;AAAA,QACnF;AAAA,MACF;AAAA;AAAA,EACJ,EACC,KAAK,IAAI,GACd;AAEJ;AAIA,eAAsB,gBAAgB;AAAA,EACpC,OAAO;AAAA,EACP;AACF,GAGG;AACD,QAAM,cAAc,UAAM,wBAAQ;AAClC,QAAM,MAAM,YAAY,IAAI,6BAA6B;AACzD,QAAM,WAAW,QAAQ;AAEzB,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAKA,QAAM,EAAE,SAAS,IAAI,IAAI,IAAI,GAAG;AAEhC,QAAM,EAAE,MAAM,MAAM,IAAI,2CAAiB,SAAS,KAAK,EAAE,MAAM,SAAS;AAGxE,QAAM,YACJ,WAKA,iCAAiC;AACnC,QAAM,WAAW,UAAU,kCAAkC,SAAS,IAAI;AAE1E,QAAM,OAAO;AAQb,OAAK,iBAAiB,KAAK,kBAAkB,CAAC;AAC9C,OAAK,eAAe,IAAI,IAAI,KAAK,eAAe,IAAI,KAAK;AAGzD,MAAI,gBAAgB,UAAU,iBAAiB,CAAC;AAChD,QAAM,mBAAmB,EAAE,GAAG,UAAU,iBAAiB;AAGzD,kBAAgB,OAAO;AAAA,IACrB,OAAO,QAAQ,aAAa,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAElD,YAAM,WAAW,IAAI,iBAAiB,MAAM;AAC5C,uBAAiB,QAAQ,IAAI,iBAAiB,MAAM,EAAE;AAEtD,aAAO;AAAA,QACL;AAAA,QACA;AAAA,UACE,GAAG;AAAA,UACH,IAAI;AAAA;AAAA;AAAA,UAGJ,QAAQ,MAAM,OAAO,IAAI,CAAC,UAAU,IAAI,iBAAiB,OAAO;AAAA;AAAA,QAElE;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAGA,QAAM,CAAC,EAAE,uBAAuB,GAAG,EAAE,mBAAmB,CAAC,IACvD,MAAM,QAAQ;AAAA,IACZ,QAAQ,IAAI,YACR;AAAA,MACE,OAAO,wCAAwC;AAAA,MAC/C,OAAO,2BAA2B;AAAA,IACpC,IACA;AAAA,MACE,OAAO,sCAAsC;AAAA,MAC7C,OAAO,yBAAyB;AAAA,IAClC;AAAA,EACN;AAEF,QAAM,SAAS,uBAAuB,UAAU,aAAa;AAE7D,QAAM,OAAO,CAAC;AACd,QAAM,UAAU,IAAI,YAAY;AAGhC,mBAAiB,SAAS,QAAgD;AACxE,SAAK,KAAK,QAAQ,OAAO,KAAK,CAAC;AAAA,EACjC;AAEA,QAAM,UAAU,QAAQ,IAAI,YAAY,cAAc;AACtD,QAAM,sBAAsB,GAAG,QAAQ,OAAO,QAAQ,OAAO,GAAG;AAEhE;AAAA;AAAA,IAEE;AAAA,MAAC;AAAA;AAAA,QACC,eAAa;AAAA,QACb,cAAY;AAAA,QACZ,gBAAc;AAAA,QACd,IAAI,GAAG;AAAA,QAEP;AAAA;AAAA,YAAC;AAAA;AAAA,cACC;AAAA,cACA,eAAe,UAAU,iBAAiB,CAAC;AAAA,cAC3C,WAAW;AAAA,cACX,MAAM;AAAA;AAAA,UACR;AAAA,UAEA,4CAAC,uBAAoB,MAAY,MAAM,qBAAqB;AAAA;AAAA;AAAA,IAC9D;AAAA;AAEJ;","names":[]}
@@ -0,0 +1,9 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+
4
+ declare function RemoteComponent({ name, children, }: {
5
+ name?: string;
6
+ children: React.ReactNode;
7
+ }): Promise<string | number | bigint | boolean | Iterable<react.ReactNode> | react_jsx_runtime.JSX.Element | null | undefined>;
8
+
9
+ export { RemoteComponent };
@@ -0,0 +1,99 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { headers } from "next/headers";
3
+ import { workAsyncStorage } from "next/dist/server/app-render/work-async-storage.external";
4
+ const SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(
5
+ "next.server.action-manifests"
6
+ );
7
+ const CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;
8
+ function RemoteComponentData({ name, data }) {
9
+ return /* @__PURE__ */ jsx("script", { id: `${name}_rsc`, children: data.map(
10
+ (chunk, i) => (
11
+ // make the data handling somewhat safe
12
+ `${i === 0 ? `self["${name}"]=self["${name}"]||[];` : ""}self["${name}"].push(${JSON.stringify(
13
+ chunk
14
+ )});`
15
+ )
16
+ ).join("\n") });
17
+ }
18
+ async function RemoteComponent({
19
+ name = "__vercel_remote_component",
20
+ children
21
+ }) {
22
+ const headersList = await headers();
23
+ const url = headersList.get("Vercel-Remote-Component-Url");
24
+ const isRemote = url !== null;
25
+ if (!isRemote) {
26
+ return children;
27
+ }
28
+ const { pathname } = new URL(url);
29
+ const { page, route } = workAsyncStorage.getStore() ?? { page: pathname };
30
+ const manifests = globalThis[SERVER_ACTION_MANIFESTS_SINGLETON];
31
+ const manifest = manifests.clientReferenceManifestsPerPage?.[route ?? page];
32
+ const self = globalThis;
33
+ self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};
34
+ self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;
35
+ let clientModules = manifest?.clientModules ?? {};
36
+ const ssrModuleMapping = { ...manifest?.ssrModuleMapping };
37
+ clientModules = Object.fromEntries(
38
+ Object.entries(clientModules).map(([key, value]) => {
39
+ const remoteId = `[${CURRENT_ZONE}] ${value.id}`;
40
+ ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];
41
+ return [
42
+ key,
43
+ {
44
+ ...value,
45
+ id: remoteId,
46
+ // prepend the current zone to the chunks to handle remote component chunk loading in Webpack
47
+ // this is required to avoid loading the wrong chunk in the host application
48
+ chunks: value.chunks.map((chunk) => `[${CURRENT_ZONE}] ${chunk}`)
49
+ // async: true,
50
+ }
51
+ ];
52
+ })
53
+ );
54
+ const [{ renderToReadableStream }, { RemoteComponentSSR }] = await Promise.all(
55
+ process.env.TURBOPACK ? [
56
+ import("react-server-dom-turbopack/server.edge"),
57
+ import("./render-client-turbopack")
58
+ ] : [
59
+ import("react-server-dom-webpack/server.edge"),
60
+ import("./render-client-webpack")
61
+ ]
62
+ );
63
+ const stream = renderToReadableStream(children, clientModules);
64
+ const data = [];
65
+ const decoder = new TextDecoder();
66
+ for await (const chunk of stream) {
67
+ data.push(decoder.decode(chunk));
68
+ }
69
+ const runtime = process.env.TURBOPACK ? "turbopack" : "webpack";
70
+ const remoteComponentName = `${name}_${route?.replace(/\//g, "_")}`;
71
+ return (
72
+ // wrap the remote component content into a div to know which part of the HTML belongs to the remote component
73
+ /* @__PURE__ */ jsxs(
74
+ "div",
75
+ {
76
+ "data-bundle": CURRENT_ZONE,
77
+ "data-route": route,
78
+ "data-runtime": runtime,
79
+ id: `${remoteComponentName}_ssr`,
80
+ children: [
81
+ /* @__PURE__ */ jsx(
82
+ RemoteComponentSSR,
83
+ {
84
+ data,
85
+ moduleLoading: manifest?.moduleLoading ?? {},
86
+ moduleMap: ssrModuleMapping,
87
+ name: remoteComponentName
88
+ }
89
+ ),
90
+ /* @__PURE__ */ jsx(RemoteComponentData, { data, name: remoteComponentName })
91
+ ]
92
+ }
93
+ )
94
+ );
95
+ }
96
+ export {
97
+ RemoteComponent
98
+ };
99
+ //# sourceMappingURL=render-server.js.map