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.
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/html/host.cjs +758 -0
- package/dist/html/host.cjs.map +1 -0
- package/dist/html/host.d.ts +2 -0
- package/dist/html/host.js +737 -0
- package/dist/html/host.js.map +1 -0
- package/dist/next/config.cjs +347 -0
- package/dist/next/config.cjs.map +1 -0
- package/dist/next/config.d.ts +8 -0
- package/dist/next/config.js +325 -0
- package/dist/next/config.js.map +1 -0
- package/dist/next/host/app-client.cjs +124 -0
- package/dist/next/host/app-client.cjs.map +1 -0
- package/dist/next/host/app-client.d.ts +33 -0
- package/dist/next/host/app-client.js +104 -0
- package/dist/next/host/app-client.js.map +1 -0
- package/dist/next/host/app-server.cjs +61 -0
- package/dist/next/host/app-server.cjs.map +1 -0
- package/dist/next/host/app-server.d.ts +7 -0
- package/dist/next/host/app-server.js +37 -0
- package/dist/next/host/app-server.js.map +1 -0
- package/dist/next/host/pages-client.cjs +52 -0
- package/dist/next/host/pages-client.cjs.map +1 -0
- package/dist/next/host/pages-client.d.ts +17 -0
- package/dist/next/host/pages-client.js +18 -0
- package/dist/next/host/pages-client.js.map +1 -0
- package/dist/next/host/pages-server.cjs +134 -0
- package/dist/next/host/pages-server.cjs.map +1 -0
- package/dist/next/host/pages-server.d.ts +25 -0
- package/dist/next/host/pages-server.js +99 -0
- package/dist/next/host/pages-server.js.map +1 -0
- package/dist/next/remote/pages.cjs +37 -0
- package/dist/next/remote/pages.cjs.map +1 -0
- package/dist/next/remote/pages.d.ts +9 -0
- package/dist/next/remote/pages.js +13 -0
- package/dist/next/remote/pages.js.map +1 -0
- package/dist/next/remote/render-client-turbopack.cjs +51 -0
- package/dist/next/remote/render-client-turbopack.cjs.map +1 -0
- package/dist/next/remote/render-client-turbopack.d.ts +11 -0
- package/dist/next/remote/render-client-turbopack.js +27 -0
- package/dist/next/remote/render-client-turbopack.js.map +1 -0
- package/dist/next/remote/render-client-webpack.cjs +51 -0
- package/dist/next/remote/render-client-webpack.cjs.map +1 -0
- package/dist/next/remote/render-client-webpack.d.ts +11 -0
- package/dist/next/remote/render-client-webpack.js +27 -0
- package/dist/next/remote/render-client-webpack.js.map +1 -0
- package/dist/next/remote/render-client.cjs +106 -0
- package/dist/next/remote/render-client.cjs.map +1 -0
- package/dist/next/remote/render-client.d.ts +15 -0
- package/dist/next/remote/render-client.js +82 -0
- package/dist/next/remote/render-client.js.map +1 -0
- package/dist/next/remote/render-server.cjs +133 -0
- package/dist/next/remote/render-server.cjs.map +1 -0
- package/dist/next/remote/render-server.d.ts +9 -0
- package/dist/next/remote/render-server.js +99 -0
- package/dist/next/remote/render-server.js.map +1 -0
- package/dist/next/remote/server.cjs +29 -0
- package/dist/next/remote/server.cjs.map +1 -0
- package/dist/next/remote/server.d.ts +3 -0
- package/dist/next/remote/server.js +5 -0
- package/dist/next/remote/server.js.map +1 -0
- package/dist/shared/client/remote-component.cjs +558 -0
- package/dist/shared/client/remote-component.cjs.map +1 -0
- package/dist/shared/client/remote-component.d.ts +93 -0
- package/dist/shared/client/remote-component.js +511 -0
- package/dist/shared/client/remote-component.js.map +1 -0
- package/dist/shared/ssr/dom-flight.cjs +185 -0
- package/dist/shared/ssr/dom-flight.cjs.map +1 -0
- package/dist/shared/ssr/dom-flight.d.ts +30 -0
- package/dist/shared/ssr/dom-flight.js +151 -0
- package/dist/shared/ssr/dom-flight.js.map +1 -0
- package/dist/shared/ssr/fetch-remote-component.cjs +162 -0
- package/dist/shared/ssr/fetch-remote-component.cjs.map +1 -0
- package/dist/shared/ssr/fetch-remote-component.d.ts +31 -0
- package/dist/shared/ssr/fetch-remote-component.js +137 -0
- package/dist/shared/ssr/fetch-remote-component.js.map +1 -0
- package/dist/shared/webpack/next-client-pages-loader.cjs +107 -0
- package/dist/shared/webpack/next-client-pages-loader.cjs.map +1 -0
- package/dist/shared/webpack/next-client-pages-loader.d.ts +10 -0
- package/dist/shared/webpack/next-client-pages-loader.js +83 -0
- package/dist/shared/webpack/next-client-pages-loader.js.map +1 -0
- package/dist/shared/webpack/shared-modules.cjs +50 -0
- package/dist/shared/webpack/shared-modules.cjs.map +1 -0
- package/dist/shared/webpack/shared-modules.d.ts +3 -0
- package/dist/shared/webpack/shared-modules.js +26 -0
- package/dist/shared/webpack/shared-modules.js.map +1 -0
- package/dist/types-280a3640.d.ts +8 -0
- package/dist/types-a1bd5b56.d.ts +6 -0
- package/package.json +151 -0
|
@@ -0,0 +1,185 @@
|
|
|
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 dom_flight_exports = {};
|
|
30
|
+
__export(dom_flight_exports, {
|
|
31
|
+
visit: () => visit
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(dom_flight_exports);
|
|
34
|
+
var import_react_property = require("react-property");
|
|
35
|
+
var import_style_to_js = __toESM(require("style-to-js"), 1);
|
|
36
|
+
var import_parse5 = require("parse5");
|
|
37
|
+
import_react_property.possibleStandardNames.fetchpriority = "fetchPriority";
|
|
38
|
+
import_react_property.possibleStandardNames["data-precedence"] = "precedence";
|
|
39
|
+
function visit(node, context = {
|
|
40
|
+
active: false
|
|
41
|
+
}) {
|
|
42
|
+
if (node.nodeName === "script" || node.nodeName === "link") {
|
|
43
|
+
if (node.attrs.find(
|
|
44
|
+
(attr) => attr.name === "id" && attr.value.endsWith("_shared")
|
|
45
|
+
)) {
|
|
46
|
+
context.onShared?.(
|
|
47
|
+
JSON.parse(node.childNodes[0].value)
|
|
48
|
+
);
|
|
49
|
+
return null;
|
|
50
|
+
} else if (node.attrs.find(
|
|
51
|
+
(attr) => attr.name === "id" && attr.value.endsWith("_rsc")
|
|
52
|
+
) && "childNodes" in node) {
|
|
53
|
+
context.onRSC?.(node.childNodes[0].value);
|
|
54
|
+
} else if (node.attrs.find(
|
|
55
|
+
(attr) => attr.name === "id" && attr.value === "__NEXT_DATA__"
|
|
56
|
+
) && "childNodes" in node) {
|
|
57
|
+
context.onHTML?.(
|
|
58
|
+
`<script id="__REMOTE_NEXT_DATA__" type="application/json">${node.childNodes[0].value}</script>`
|
|
59
|
+
);
|
|
60
|
+
context.onNextData?.(
|
|
61
|
+
JSON.parse(node.childNodes[0].value)
|
|
62
|
+
);
|
|
63
|
+
} else if (node.childNodes.length === 0) {
|
|
64
|
+
if (node.nodeName === "script" && !node.attrs.find((attr) => attr.name === "src")) {
|
|
65
|
+
return [
|
|
66
|
+
"$",
|
|
67
|
+
node.nodeName,
|
|
68
|
+
null,
|
|
69
|
+
node.attrs.reduce((props, attr) => {
|
|
70
|
+
props[import_react_property.possibleStandardNames[attr.name] ?? attr.name] = attr.value;
|
|
71
|
+
return props;
|
|
72
|
+
}, {}),
|
|
73
|
+
null,
|
|
74
|
+
null,
|
|
75
|
+
1
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
if (node.nodeName === "script") {
|
|
79
|
+
context.onScript?.(
|
|
80
|
+
node.attrs.reduce((props, attr) => {
|
|
81
|
+
props[attr.name] = attr.value || true;
|
|
82
|
+
return props;
|
|
83
|
+
}, {})
|
|
84
|
+
);
|
|
85
|
+
const src = node.attrs.find((attr) => attr.name === "src")?.value;
|
|
86
|
+
if (src) {
|
|
87
|
+
node.attrs = node.attrs.filter((attr) => attr.name !== "src");
|
|
88
|
+
node.attrs.push({
|
|
89
|
+
name: "data-src",
|
|
90
|
+
value: src
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
context.onHTML?.((0, import_parse5.serializeOuter)(node));
|
|
94
|
+
} else {
|
|
95
|
+
context.onLink?.(
|
|
96
|
+
node.attrs.reduce((props, attr) => {
|
|
97
|
+
props[import_react_property.possibleStandardNames[attr.name] ?? attr.name] = attr.value || true;
|
|
98
|
+
return props;
|
|
99
|
+
}, {})
|
|
100
|
+
);
|
|
101
|
+
context.onHTML?.((0, import_parse5.serializeOuter)(node));
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (!context.active) {
|
|
107
|
+
if ("childNodes" in node) {
|
|
108
|
+
node.childNodes.forEach((childNode) => {
|
|
109
|
+
visit(childNode, context);
|
|
110
|
+
});
|
|
111
|
+
} else
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
switch (node.nodeName) {
|
|
115
|
+
case "#document-fragment":
|
|
116
|
+
return node.childNodes.map((childNode) => visit(childNode, context)).filter((it) => it !== null);
|
|
117
|
+
case "#text":
|
|
118
|
+
return node.value;
|
|
119
|
+
case "#comment":
|
|
120
|
+
case "head":
|
|
121
|
+
case "meta":
|
|
122
|
+
case "title":
|
|
123
|
+
case "noscript":
|
|
124
|
+
return null;
|
|
125
|
+
default: {
|
|
126
|
+
if (node.nodeName === "div" && (node.attrs.find((it) => it.name === "id" && it.value === "__next") || (context.name ? node.attrs.find(
|
|
127
|
+
(it) => it.name === "id" && it.value.startsWith(
|
|
128
|
+
context.name ?? "__vercel_remote_component"
|
|
129
|
+
)
|
|
130
|
+
) : node.attrs.find((it) => it.name === "data-bundle" && it.value)) && node.attrs.find((it) => it.name === "data-route") && node.attrs.find(
|
|
131
|
+
(it) => it.name === "id" && it.value.endsWith("_ssr")
|
|
132
|
+
))) {
|
|
133
|
+
context.onMetadata?.({
|
|
134
|
+
bundle: node.attrs.find((it) => it.name === "data-bundle" && it.value)?.value ?? "",
|
|
135
|
+
route: node.attrs.find((it) => it.name === "data-route")?.value ?? "/",
|
|
136
|
+
runtime: node.attrs.find((it) => it.name === "data-runtime")?.value ?? "webpack",
|
|
137
|
+
id: node.attrs.find(
|
|
138
|
+
(it) => it.name === "id" && it.value.endsWith("_ssr")
|
|
139
|
+
)?.value ?? "__vercel_remote_component"
|
|
140
|
+
});
|
|
141
|
+
context.onHTML?.((0, import_parse5.serializeOuter)(node));
|
|
142
|
+
return node.childNodes.map((childNode) => visit(childNode, { ...context, active: true })).filter((it) => it !== null);
|
|
143
|
+
}
|
|
144
|
+
const childNodes = node.childNodes.map((childNode) => visit(childNode, context)).filter((childNode) => childNode !== null);
|
|
145
|
+
const children = childNodes.length > 1 ? childNodes : childNodes[0];
|
|
146
|
+
const nodeProps = node.attrs.reduce((props, attr) => {
|
|
147
|
+
if (attr.name === "style") {
|
|
148
|
+
props.style = (0, import_style_to_js.default)(attr.value, {
|
|
149
|
+
reactCompat: true
|
|
150
|
+
});
|
|
151
|
+
return props;
|
|
152
|
+
}
|
|
153
|
+
if (node.nodeName === "input" && attr.name === "value") {
|
|
154
|
+
props.defaultValue = attr.value;
|
|
155
|
+
return props;
|
|
156
|
+
}
|
|
157
|
+
if ((0, import_react_property.isCustomAttribute)(attr.name)) {
|
|
158
|
+
props[attr.name] = attr.value;
|
|
159
|
+
return props;
|
|
160
|
+
}
|
|
161
|
+
props[import_react_property.possibleStandardNames[attr.name] ?? attr.name] = attr.value;
|
|
162
|
+
return props;
|
|
163
|
+
}, {});
|
|
164
|
+
if (typeof children !== "undefined") {
|
|
165
|
+
if (node.nodeName === "script" && typeof children === "string" && children.startsWith("$")) {
|
|
166
|
+
nodeProps.children = `$${children}`;
|
|
167
|
+
} else {
|
|
168
|
+
nodeProps.children = children;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (!context.active) {
|
|
172
|
+
if (childNodes.length > 0) {
|
|
173
|
+
return childNodes;
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
return ["$", node.nodeName, null, nodeProps, null, null, 1];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
182
|
+
0 && (module.exports = {
|
|
183
|
+
visit
|
|
184
|
+
});
|
|
185
|
+
//# sourceMappingURL=dom-flight.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/shared/ssr/dom-flight.ts"],"sourcesContent":["import { isCustomAttribute, possibleStandardNames } from 'react-property';\nimport styleToJs from 'style-to-js';\nimport type {\n ChildNode,\n Element,\n Node,\n TextNode,\n} from 'parse5/dist/tree-adapters/default';\nimport { serializeOuter } from 'parse5';\nimport type { RemoteComponentMetadata } from './types';\n\n// add fetch-priority to the possible standard names\npossibleStandardNames.fetchpriority = 'fetchPriority';\npossibleStandardNames['data-precedence'] = 'precedence';\n\nexport interface Context {\n name?: string;\n url?: URL;\n origin?: string;\n defer?: boolean;\n active?: boolean;\n onMetadata?: (metadata: RemoteComponentMetadata) => void;\n onScript?: (attrs: Record<string, string | boolean>) => void;\n onLink?: (attrs: Record<string, string | boolean>) => void;\n onRSC?: (rsc: string) => void;\n onNextData?: (data: {\n props: {\n pageProps: Record<string, unknown>;\n __REMOTE_COMPONENT__?: {\n bundle: string;\n runtime: string;\n };\n };\n page?: string;\n }) => void;\n onHTML?: (html: string) => void;\n onShared?: (shared: Record<string, string>) => void;\n}\n\ntype RSC =\n | ['$', string, null, Record<string, unknown>, null, null, number]\n | (\n | ['$', string, null, Record<string, unknown>, null, null, number]\n | string\n | null\n )[]\n | string\n | null;\n\nexport function visit(\n node: Node | ChildNode,\n context: Context = {\n active: false,\n },\n): RSC | RSC[] | string | null {\n if (node.nodeName === 'script' || node.nodeName === 'link') {\n if (\n node.attrs.find(\n (attr) => attr.name === 'id' && attr.value.endsWith('_shared'),\n )\n ) {\n context.onShared?.(\n JSON.parse((node.childNodes[0] as TextNode).value) as Record<\n string,\n string\n >,\n );\n return null;\n } else if (\n node.attrs.find(\n (attr) => attr.name === 'id' && attr.value.endsWith('_rsc'),\n ) &&\n 'childNodes' in node\n ) {\n context.onRSC?.((node.childNodes[0] as TextNode).value);\n } else if (\n node.attrs.find(\n (attr) => attr.name === 'id' && attr.value === '__NEXT_DATA__',\n ) &&\n 'childNodes' in node\n ) {\n context.onHTML?.(\n `<script id=\"__REMOTE_NEXT_DATA__\" type=\"application/json\">${(node.childNodes[0] as TextNode).value}</script>`,\n );\n context.onNextData?.(\n JSON.parse((node.childNodes[0] as TextNode).value) as {\n props: { pageProps: Record<string, unknown> };\n },\n );\n } else if (node.childNodes.length === 0) {\n if (\n node.nodeName === 'script' &&\n !node.attrs.find((attr) => attr.name === 'src')\n ) {\n return [\n '$',\n node.nodeName,\n null,\n node.attrs.reduce<Record<string, string>>((props, attr) => {\n props[possibleStandardNames[attr.name] ?? attr.name] = attr.value;\n return props;\n }, {}),\n null,\n null,\n 1,\n ] as RSC;\n }\n if (node.nodeName === 'script') {\n context.onScript?.(\n node.attrs.reduce<Record<string, string | boolean>>((props, attr) => {\n props[attr.name] = attr.value || true;\n return props;\n }, {}),\n );\n const src = node.attrs.find((attr) => attr.name === 'src')?.value;\n if (src) {\n node.attrs = node.attrs.filter((attr) => attr.name !== 'src');\n node.attrs.push({\n name: 'data-src',\n value: src,\n });\n }\n context.onHTML?.(serializeOuter(node));\n } else {\n context.onLink?.(\n node.attrs.reduce<Record<string, string | boolean>>((props, attr) => {\n props[possibleStandardNames[attr.name] ?? attr.name] =\n attr.value || true;\n return props;\n }, {}),\n );\n context.onHTML?.(serializeOuter(node));\n }\n return null;\n }\n }\n\n if (!context.active) {\n if ('childNodes' in node) {\n (node as Element).childNodes.forEach((childNode) => {\n visit(childNode, context);\n });\n } else return null;\n }\n\n switch (node.nodeName) {\n case '#document-fragment':\n return node.childNodes\n .map((childNode) => visit(childNode, context))\n .filter((it) => it !== null) as unknown as RSC;\n case '#text':\n return (node as TextNode).value;\n case '#comment':\n case 'head':\n case 'meta':\n case 'title':\n case 'noscript':\n return null;\n default: {\n if (\n node.nodeName === 'div' &&\n (node.attrs.find((it) => it.name === 'id' && it.value === '__next') ||\n ((context.name\n ? node.attrs.find(\n (it) =>\n it.name === 'id' &&\n it.value.startsWith(\n context.name ?? '__vercel_remote_component',\n ),\n )\n : node.attrs.find((it) => it.name === 'data-bundle' && it.value)) &&\n node.attrs.find((it) => it.name === 'data-route') &&\n node.attrs.find(\n (it) => it.name === 'id' && it.value.endsWith('_ssr'),\n )))\n ) {\n context.onMetadata?.({\n bundle:\n node.attrs.find((it) => it.name === 'data-bundle' && it.value)\n ?.value ?? '',\n route:\n node.attrs.find((it) => it.name === 'data-route')?.value ?? '/',\n runtime: (node.attrs.find((it) => it.name === 'data-runtime')\n ?.value ?? 'webpack') as RemoteComponentMetadata['runtime'],\n id:\n node.attrs.find(\n (it) => it.name === 'id' && it.value.endsWith('_ssr'),\n )?.value ?? '__vercel_remote_component',\n });\n context.onHTML?.(serializeOuter(node));\n return node.childNodes\n .map((childNode) => visit(childNode, { ...context, active: true }))\n .filter((it) => it !== null) as unknown as RSC;\n }\n const childNodes = (node as Element).childNodes\n .map((childNode) => visit(childNode, context))\n .filter((childNode) => childNode !== null);\n const children = childNodes.length > 1 ? childNodes : childNodes[0];\n const nodeProps = (node as Element).attrs.reduce<\n Record<string, string | ReturnType<typeof styleToJs>> & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n children?: any;\n }\n >((props, attr) => {\n if (attr.name === 'style') {\n props.style = styleToJs(attr.value, {\n reactCompat: true,\n });\n return props;\n }\n if (node.nodeName === 'input' && attr.name === 'value') {\n props.defaultValue = attr.value;\n return props;\n }\n if (isCustomAttribute(attr.name)) {\n props[attr.name] = attr.value;\n return props;\n }\n props[possibleStandardNames[attr.name] ?? attr.name] = attr.value;\n return props;\n }, {});\n if (typeof children !== 'undefined') {\n if (\n node.nodeName === 'script' &&\n typeof children === 'string' &&\n children.startsWith('$')\n ) {\n nodeProps.children = `$${children}`;\n } else {\n nodeProps.children = children;\n }\n }\n if (!context.active) {\n if (childNodes.length > 0) {\n return childNodes as RSC;\n }\n return null;\n }\n return ['$', node.nodeName, null, nodeProps, null, null, 1] as RSC;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAyD;AACzD,yBAAsB;AAOtB,oBAA+B;AAI/B,4CAAsB,gBAAgB;AACtC,4CAAsB,iBAAiB,IAAI;AAoCpC,SAAS,MACd,MACA,UAAmB;AAAA,EACjB,QAAQ;AACV,GAC6B;AAC7B,MAAI,KAAK,aAAa,YAAY,KAAK,aAAa,QAAQ;AAC1D,QACE,KAAK,MAAM;AAAA,MACT,CAAC,SAAS,KAAK,SAAS,QAAQ,KAAK,MAAM,SAAS,SAAS;AAAA,IAC/D,GACA;AACA,cAAQ;AAAA,QACN,KAAK,MAAO,KAAK,W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;AACA,cAAM,4CAAsB,KAAK,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK;AAC5D,eAAO;AAAA,MACT,GAAG,CAAC,CAAC;AACL,UAAI,OAAO,aAAa,aAAa;AACnC,YACE,KAAK,aAAa,YAClB,OAAO,aAAa,YACpB,SAAS,WAAW,GAAG,GACvB;AACA,oBAAU,WAAW,IAAI;AAAA,QAC3B,OAAO;AACL,oBAAU,WAAW;AAAA,QACvB;AAAA,MACF;AACA,UAAI,CAAC,QAAQ,QAAQ;AACnB,YAAI,WAAW,SAAS,GAAG;AACzB,iBAAO;AAAA,QACT;AACA,eAAO;AAAA,MACT;AACA,aAAO,CAAC,KAAK,KAAK,UAAU,MAAM,WAAW,MAAM,MAAM,CAAC;AAAA,IAC5D;AAAA,EACF;AACF;","names":["styleToJs"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Node, ChildNode } from 'parse5/dist/tree-adapters/default';
|
|
2
|
+
import { R as RemoteComponentMetadata } from '../../types-280a3640.js';
|
|
3
|
+
|
|
4
|
+
interface Context {
|
|
5
|
+
name?: string;
|
|
6
|
+
url?: URL;
|
|
7
|
+
origin?: string;
|
|
8
|
+
defer?: boolean;
|
|
9
|
+
active?: boolean;
|
|
10
|
+
onMetadata?: (metadata: RemoteComponentMetadata) => void;
|
|
11
|
+
onScript?: (attrs: Record<string, string | boolean>) => void;
|
|
12
|
+
onLink?: (attrs: Record<string, string | boolean>) => void;
|
|
13
|
+
onRSC?: (rsc: string) => void;
|
|
14
|
+
onNextData?: (data: {
|
|
15
|
+
props: {
|
|
16
|
+
pageProps: Record<string, unknown>;
|
|
17
|
+
__REMOTE_COMPONENT__?: {
|
|
18
|
+
bundle: string;
|
|
19
|
+
runtime: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
page?: string;
|
|
23
|
+
}) => void;
|
|
24
|
+
onHTML?: (html: string) => void;
|
|
25
|
+
onShared?: (shared: Record<string, string>) => void;
|
|
26
|
+
}
|
|
27
|
+
type RSC = ['$', string, null, Record<string, unknown>, null, null, number] | (['$', string, null, Record<string, unknown>, null, null, number] | string | null)[] | string | null;
|
|
28
|
+
declare function visit(node: Node | ChildNode, context?: Context): RSC | RSC[] | string | null;
|
|
29
|
+
|
|
30
|
+
export { Context, visit };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { isCustomAttribute, possibleStandardNames } from "react-property";
|
|
2
|
+
import styleToJs from "style-to-js";
|
|
3
|
+
import { serializeOuter } from "parse5";
|
|
4
|
+
possibleStandardNames.fetchpriority = "fetchPriority";
|
|
5
|
+
possibleStandardNames["data-precedence"] = "precedence";
|
|
6
|
+
function visit(node, context = {
|
|
7
|
+
active: false
|
|
8
|
+
}) {
|
|
9
|
+
if (node.nodeName === "script" || node.nodeName === "link") {
|
|
10
|
+
if (node.attrs.find(
|
|
11
|
+
(attr) => attr.name === "id" && attr.value.endsWith("_shared")
|
|
12
|
+
)) {
|
|
13
|
+
context.onShared?.(
|
|
14
|
+
JSON.parse(node.childNodes[0].value)
|
|
15
|
+
);
|
|
16
|
+
return null;
|
|
17
|
+
} else if (node.attrs.find(
|
|
18
|
+
(attr) => attr.name === "id" && attr.value.endsWith("_rsc")
|
|
19
|
+
) && "childNodes" in node) {
|
|
20
|
+
context.onRSC?.(node.childNodes[0].value);
|
|
21
|
+
} else if (node.attrs.find(
|
|
22
|
+
(attr) => attr.name === "id" && attr.value === "__NEXT_DATA__"
|
|
23
|
+
) && "childNodes" in node) {
|
|
24
|
+
context.onHTML?.(
|
|
25
|
+
`<script id="__REMOTE_NEXT_DATA__" type="application/json">${node.childNodes[0].value}</script>`
|
|
26
|
+
);
|
|
27
|
+
context.onNextData?.(
|
|
28
|
+
JSON.parse(node.childNodes[0].value)
|
|
29
|
+
);
|
|
30
|
+
} else if (node.childNodes.length === 0) {
|
|
31
|
+
if (node.nodeName === "script" && !node.attrs.find((attr) => attr.name === "src")) {
|
|
32
|
+
return [
|
|
33
|
+
"$",
|
|
34
|
+
node.nodeName,
|
|
35
|
+
null,
|
|
36
|
+
node.attrs.reduce((props, attr) => {
|
|
37
|
+
props[possibleStandardNames[attr.name] ?? attr.name] = attr.value;
|
|
38
|
+
return props;
|
|
39
|
+
}, {}),
|
|
40
|
+
null,
|
|
41
|
+
null,
|
|
42
|
+
1
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
if (node.nodeName === "script") {
|
|
46
|
+
context.onScript?.(
|
|
47
|
+
node.attrs.reduce((props, attr) => {
|
|
48
|
+
props[attr.name] = attr.value || true;
|
|
49
|
+
return props;
|
|
50
|
+
}, {})
|
|
51
|
+
);
|
|
52
|
+
const src = node.attrs.find((attr) => attr.name === "src")?.value;
|
|
53
|
+
if (src) {
|
|
54
|
+
node.attrs = node.attrs.filter((attr) => attr.name !== "src");
|
|
55
|
+
node.attrs.push({
|
|
56
|
+
name: "data-src",
|
|
57
|
+
value: src
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
context.onHTML?.(serializeOuter(node));
|
|
61
|
+
} else {
|
|
62
|
+
context.onLink?.(
|
|
63
|
+
node.attrs.reduce((props, attr) => {
|
|
64
|
+
props[possibleStandardNames[attr.name] ?? attr.name] = attr.value || true;
|
|
65
|
+
return props;
|
|
66
|
+
}, {})
|
|
67
|
+
);
|
|
68
|
+
context.onHTML?.(serializeOuter(node));
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!context.active) {
|
|
74
|
+
if ("childNodes" in node) {
|
|
75
|
+
node.childNodes.forEach((childNode) => {
|
|
76
|
+
visit(childNode, context);
|
|
77
|
+
});
|
|
78
|
+
} else
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
switch (node.nodeName) {
|
|
82
|
+
case "#document-fragment":
|
|
83
|
+
return node.childNodes.map((childNode) => visit(childNode, context)).filter((it) => it !== null);
|
|
84
|
+
case "#text":
|
|
85
|
+
return node.value;
|
|
86
|
+
case "#comment":
|
|
87
|
+
case "head":
|
|
88
|
+
case "meta":
|
|
89
|
+
case "title":
|
|
90
|
+
case "noscript":
|
|
91
|
+
return null;
|
|
92
|
+
default: {
|
|
93
|
+
if (node.nodeName === "div" && (node.attrs.find((it) => it.name === "id" && it.value === "__next") || (context.name ? node.attrs.find(
|
|
94
|
+
(it) => it.name === "id" && it.value.startsWith(
|
|
95
|
+
context.name ?? "__vercel_remote_component"
|
|
96
|
+
)
|
|
97
|
+
) : node.attrs.find((it) => it.name === "data-bundle" && it.value)) && node.attrs.find((it) => it.name === "data-route") && node.attrs.find(
|
|
98
|
+
(it) => it.name === "id" && it.value.endsWith("_ssr")
|
|
99
|
+
))) {
|
|
100
|
+
context.onMetadata?.({
|
|
101
|
+
bundle: node.attrs.find((it) => it.name === "data-bundle" && it.value)?.value ?? "",
|
|
102
|
+
route: node.attrs.find((it) => it.name === "data-route")?.value ?? "/",
|
|
103
|
+
runtime: node.attrs.find((it) => it.name === "data-runtime")?.value ?? "webpack",
|
|
104
|
+
id: node.attrs.find(
|
|
105
|
+
(it) => it.name === "id" && it.value.endsWith("_ssr")
|
|
106
|
+
)?.value ?? "__vercel_remote_component"
|
|
107
|
+
});
|
|
108
|
+
context.onHTML?.(serializeOuter(node));
|
|
109
|
+
return node.childNodes.map((childNode) => visit(childNode, { ...context, active: true })).filter((it) => it !== null);
|
|
110
|
+
}
|
|
111
|
+
const childNodes = node.childNodes.map((childNode) => visit(childNode, context)).filter((childNode) => childNode !== null);
|
|
112
|
+
const children = childNodes.length > 1 ? childNodes : childNodes[0];
|
|
113
|
+
const nodeProps = node.attrs.reduce((props, attr) => {
|
|
114
|
+
if (attr.name === "style") {
|
|
115
|
+
props.style = styleToJs(attr.value, {
|
|
116
|
+
reactCompat: true
|
|
117
|
+
});
|
|
118
|
+
return props;
|
|
119
|
+
}
|
|
120
|
+
if (node.nodeName === "input" && attr.name === "value") {
|
|
121
|
+
props.defaultValue = attr.value;
|
|
122
|
+
return props;
|
|
123
|
+
}
|
|
124
|
+
if (isCustomAttribute(attr.name)) {
|
|
125
|
+
props[attr.name] = attr.value;
|
|
126
|
+
return props;
|
|
127
|
+
}
|
|
128
|
+
props[possibleStandardNames[attr.name] ?? attr.name] = attr.value;
|
|
129
|
+
return props;
|
|
130
|
+
}, {});
|
|
131
|
+
if (typeof children !== "undefined") {
|
|
132
|
+
if (node.nodeName === "script" && typeof children === "string" && children.startsWith("$")) {
|
|
133
|
+
nodeProps.children = `$${children}`;
|
|
134
|
+
} else {
|
|
135
|
+
nodeProps.children = children;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (!context.active) {
|
|
139
|
+
if (childNodes.length > 0) {
|
|
140
|
+
return childNodes;
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
return ["$", node.nodeName, null, nodeProps, null, null, 1];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export {
|
|
149
|
+
visit
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=dom-flight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/shared/ssr/dom-flight.ts"],"sourcesContent":["import { isCustomAttribute, possibleStandardNames } from 'react-property';\nimport styleToJs from 'style-to-js';\nimport type {\n ChildNode,\n Element,\n Node,\n TextNode,\n} from 'parse5/dist/tree-adapters/default';\nimport { serializeOuter } from 'parse5';\nimport type { RemoteComponentMetadata } from './types';\n\n// add fetch-priority to the possible standard names\npossibleStandardNames.fetchpriority = 'fetchPriority';\npossibleStandardNames['data-precedence'] = 'precedence';\n\nexport interface Context {\n name?: string;\n url?: URL;\n origin?: string;\n defer?: boolean;\n active?: boolean;\n onMetadata?: (metadata: RemoteComponentMetadata) => void;\n onScript?: (attrs: Record<string, string | boolean>) => void;\n onLink?: (attrs: Record<string, string | boolean>) => void;\n onRSC?: (rsc: string) => void;\n onNextData?: (data: {\n props: {\n pageProps: Record<string, unknown>;\n __REMOTE_COMPONENT__?: {\n bundle: string;\n runtime: string;\n };\n };\n page?: string;\n }) => void;\n onHTML?: (html: string) => void;\n onShared?: (shared: Record<string, string>) => void;\n}\n\ntype RSC =\n | ['$', string, null, Record<string, unknown>, null, null, number]\n | (\n | ['$', string, null, Record<string, unknown>, null, null, number]\n | string\n | null\n )[]\n | string\n | null;\n\nexport function visit(\n node: Node | ChildNode,\n context: Context = {\n active: false,\n },\n): RSC | RSC[] | string | null {\n if (node.nodeName === 'script' || node.nodeName === 'link') {\n if (\n node.attrs.find(\n (attr) => attr.name === 'id' && attr.value.endsWith('_shared'),\n )\n ) {\n context.onShared?.(\n JSON.parse((node.childNodes[0] as TextNode).value) as Record<\n string,\n string\n >,\n );\n return null;\n } else if (\n node.attrs.find(\n (attr) => attr.name === 'id' && attr.value.endsWith('_rsc'),\n ) &&\n 'childNodes' in node\n ) {\n context.onRSC?.((node.childNodes[0] as TextNode).value);\n } else if (\n node.attrs.find(\n (attr) => attr.name === 'id' && attr.value === '__NEXT_DATA__',\n ) &&\n 'childNodes' in node\n ) {\n context.onHTML?.(\n `<script id=\"__REMOTE_NEXT_DATA__\" type=\"application/json\">${(node.childNodes[0] as TextNode).value}</script>`,\n );\n context.onNextData?.(\n JSON.parse((node.childNodes[0] as TextNode).value) as {\n props: { pageProps: Record<string, unknown> };\n },\n );\n } else if (node.childNodes.length === 0) {\n if (\n node.nodeName === 'script' &&\n !node.attrs.find((attr) => attr.name === 'src')\n ) {\n return [\n '$',\n node.nodeName,\n null,\n node.attrs.reduce<Record<string, string>>((props, attr) => {\n props[possibleStandardNames[attr.name] ?? attr.name] = attr.value;\n return props;\n }, {}),\n null,\n null,\n 1,\n ] as RSC;\n }\n if (node.nodeName === 'script') {\n context.onScript?.(\n node.attrs.reduce<Record<string, string | boolean>>((props, attr) => {\n props[attr.name] = attr.value || true;\n return props;\n }, {}),\n );\n const src = node.attrs.find((attr) => attr.name === 'src')?.value;\n if (src) {\n node.attrs = node.attrs.filter((attr) => attr.name !== 'src');\n node.attrs.push({\n name: 'data-src',\n value: src,\n });\n }\n context.onHTML?.(serializeOuter(node));\n } else {\n context.onLink?.(\n node.attrs.reduce<Record<string, string | boolean>>((props, attr) => {\n props[possibleStandardNames[attr.name] ?? attr.name] =\n attr.value || true;\n return props;\n }, {}),\n );\n context.onHTML?.(serializeOuter(node));\n }\n return null;\n }\n }\n\n if (!context.active) {\n if ('childNodes' in node) {\n (node as Element).childNodes.forEach((childNode) => {\n visit(childNode, context);\n });\n } else return null;\n }\n\n switch (node.nodeName) {\n case '#document-fragment':\n return node.childNodes\n .map((childNode) => visit(childNode, context))\n .filter((it) => it !== null) as unknown as RSC;\n case '#text':\n return (node as TextNode).value;\n case '#comment':\n case 'head':\n case 'meta':\n case 'title':\n case 'noscript':\n return null;\n default: {\n if (\n node.nodeName === 'div' &&\n (node.attrs.find((it) => it.name === 'id' && it.value === '__next') ||\n ((context.name\n ? node.attrs.find(\n (it) =>\n it.name === 'id' &&\n it.value.startsWith(\n context.name ?? '__vercel_remote_component',\n ),\n )\n : node.attrs.find((it) => it.name === 'data-bundle' && it.value)) &&\n node.attrs.find((it) => it.name === 'data-route') &&\n node.attrs.find(\n (it) => it.name === 'id' && it.value.endsWith('_ssr'),\n )))\n ) {\n context.onMetadata?.({\n bundle:\n node.attrs.find((it) => it.name === 'data-bundle' && it.value)\n ?.value ?? '',\n route:\n node.attrs.find((it) => it.name === 'data-route')?.value ?? '/',\n runtime: (node.attrs.find((it) => it.name === 'data-runtime')\n ?.value ?? 'webpack') as RemoteComponentMetadata['runtime'],\n id:\n node.attrs.find(\n (it) => it.name === 'id' && it.value.endsWith('_ssr'),\n )?.value ?? '__vercel_remote_component',\n });\n context.onHTML?.(serializeOuter(node));\n return node.childNodes\n .map((childNode) => visit(childNode, { ...context, active: true }))\n .filter((it) => it !== null) as unknown as RSC;\n }\n const childNodes = (node as Element).childNodes\n .map((childNode) => visit(childNode, context))\n .filter((childNode) => childNode !== null);\n const children = childNodes.length > 1 ? childNodes : childNodes[0];\n const nodeProps = (node as Element).attrs.reduce<\n Record<string, string | ReturnType<typeof styleToJs>> & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n children?: any;\n }\n >((props, attr) => {\n if (attr.name === 'style') {\n props.style = styleToJs(attr.value, {\n reactCompat: true,\n });\n return props;\n }\n if (node.nodeName === 'input' && attr.name === 'value') {\n props.defaultValue = attr.value;\n return props;\n }\n if (isCustomAttribute(attr.name)) {\n props[attr.name] = attr.value;\n return props;\n }\n props[possibleStandardNames[attr.name] ?? attr.name] = attr.value;\n return props;\n }, {});\n if (typeof children !== 'undefined') {\n if (\n node.nodeName === 'script' &&\n typeof children === 'string' &&\n children.startsWith('$')\n ) {\n nodeProps.children = `$${children}`;\n } else {\n nodeProps.children = children;\n }\n }\n if (!context.active) {\n if (childNodes.length > 0) {\n return childNodes as RSC;\n }\n return null;\n }\n return ['$', node.nodeName, null, nodeProps, null, null, 1] as RSC;\n }\n }\n}\n"],"mappings":"AAAA,SAAS,mBAAmB,6BAA6B;AACzD,OAAO,eAAe;AAOtB,SAAS,sBAAsB;AAI/B,sBAAsB,gBAAgB;AACtC,sBAAsB,iBAAiB,IAAI;AAoCpC,SAAS,MACd,MACA,UAAmB;AAAA,EACjB,QAAQ;AACV,GAC6B;AAC7B,MAAI,KAAK,aAAa,YAAY,KAAK,aAAa,QAAQ;AAC1D,QACE,KAAK,MAAM;AAAA,MACT,CAAC,SAAS,KAAK,SAAS,QAAQ,KAAK,MAAM,SAAS,SAAS;AAAA,IAC/D,GACA;AACA,cAAQ;AAAA,QACN,KAAK,MAAO,KAAK,WAAW,CAAC,EAAe,KAAK;AAAA,MAInD;AACA,aAAO;AAAA,IACT,WACE,KAAK,MAAM;AAAA,MACT,CAAC,SAAS,KAAK,SAAS,QAAQ,KAAK,MAAM,SAAS,MAAM;AAAA,IAC5D,KACA,gBAAgB,MAChB;AACA,cAAQ,QAAS,KAAK,WAAW,CAAC,EAAe,KAAK;AAAA,IACxD,WACE,KAAK,MAA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WAAW;AAAA,QACvB;AAAA,MACF;AACA,UAAI,CAAC,QAAQ,QAAQ;AACnB,YAAI,WAAW,SAAS,GAAG;AACzB,iBAAO;AAAA,QACT;AACA,eAAO;AAAA,MACT;AACA,aAAO,CAAC,KAAK,KAAK,UAAU,MAAM,WAAW,MAAM,MAAM,CAAC;AAAA,IAC5D;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var fetch_remote_component_exports = {};
|
|
20
|
+
__export(fetch_remote_component_exports, {
|
|
21
|
+
fetchRemoteComponent: () => fetchRemoteComponent,
|
|
22
|
+
getBaseUrl: () => getBaseUrl
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(fetch_remote_component_exports);
|
|
25
|
+
var import_client = require("next/dist/compiled/react-server-dom-webpack/client.edge");
|
|
26
|
+
var import_parse5 = require("parse5");
|
|
27
|
+
var import_dom_flight = require("./dom-flight");
|
|
28
|
+
const CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;
|
|
29
|
+
function getBaseUrl(reqHeaders) {
|
|
30
|
+
const host = reqHeaders.get("host");
|
|
31
|
+
if (host) {
|
|
32
|
+
return host.startsWith("localhost") ? `http://${host}` : `https://${host}`;
|
|
33
|
+
}
|
|
34
|
+
const forwardedHost = reqHeaders.get("x-forwarded-host");
|
|
35
|
+
if (forwardedHost) {
|
|
36
|
+
return `https://${forwardedHost}`;
|
|
37
|
+
}
|
|
38
|
+
if (process.env.VERCEL_PROJECT_PRODUCTION_URL) {
|
|
39
|
+
return `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`;
|
|
40
|
+
}
|
|
41
|
+
return `http://localhost:${process.env.MFE_LOCAL_PROXY_PORT || 3024}`;
|
|
42
|
+
}
|
|
43
|
+
async function fetchRemoteComponent(src, headers, createComponent = false) {
|
|
44
|
+
const url = new URL(src, getBaseUrl(headers));
|
|
45
|
+
const fetchInit = {
|
|
46
|
+
method: "GET",
|
|
47
|
+
headers: {
|
|
48
|
+
// pass all headers to the remote component
|
|
49
|
+
...Object.fromEntries(headers.entries()),
|
|
50
|
+
Accept: "text/html",
|
|
51
|
+
// pass the public address of the remote component to the server used for module map mutation
|
|
52
|
+
"Vercel-Remote-Component-Url": url.href
|
|
53
|
+
},
|
|
54
|
+
credentials: "include"
|
|
55
|
+
};
|
|
56
|
+
const res = await fetch(url, fetchInit);
|
|
57
|
+
if (!res.ok) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Failed to fetch remote component "${url.href}": ${res.status}`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const parser = import_parse5.Parser.getFragmentParser();
|
|
63
|
+
if (!res.body) {
|
|
64
|
+
throw new Error(`No response body for remote component "${url.href}"`);
|
|
65
|
+
}
|
|
66
|
+
const decoder = new TextDecoder();
|
|
67
|
+
for await (const chunk of res.body) {
|
|
68
|
+
parser.tokenizer.write(decoder.decode(chunk), false);
|
|
69
|
+
}
|
|
70
|
+
const fragment = parser.getFragment();
|
|
71
|
+
let metadata = {
|
|
72
|
+
bundle: CURRENT_ZONE ?? "__vercel_remote_component",
|
|
73
|
+
route: "/",
|
|
74
|
+
runtime: "webpack",
|
|
75
|
+
id: "__vercel_remote_component"
|
|
76
|
+
};
|
|
77
|
+
let remoteShared = {};
|
|
78
|
+
const scripts = [];
|
|
79
|
+
const links = [];
|
|
80
|
+
const hydrationData = [];
|
|
81
|
+
let nextData;
|
|
82
|
+
let html = "";
|
|
83
|
+
const rsc = (0, import_dom_flight.visit)(fragment, {
|
|
84
|
+
url,
|
|
85
|
+
onMetadata(_metadata) {
|
|
86
|
+
metadata = _metadata;
|
|
87
|
+
},
|
|
88
|
+
onScript(attrs) {
|
|
89
|
+
if (!scripts.find((it) => it.src === attrs.src)) {
|
|
90
|
+
scripts.push({ src: attrs.src });
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
onLink(attrs) {
|
|
94
|
+
if (!links.find((it) => it.href === attrs.href && it.rel === attrs.rel)) {
|
|
95
|
+
links.push(attrs);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
onRSC(chunk) {
|
|
99
|
+
hydrationData.push(chunk);
|
|
100
|
+
},
|
|
101
|
+
onNextData(data) {
|
|
102
|
+
nextData = data;
|
|
103
|
+
if (data.props.__REMOTE_COMPONENT__) {
|
|
104
|
+
Object.assign(metadata, data.props.__REMOTE_COMPONENT__);
|
|
105
|
+
metadata.id = "__next";
|
|
106
|
+
metadata.route = data.page ?? "/";
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
onHTML(_html) {
|
|
110
|
+
if (!html.includes(_html)) {
|
|
111
|
+
html += _html;
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
onShared(_shared) {
|
|
115
|
+
remoteShared = _shared;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
let component;
|
|
119
|
+
if (createComponent) {
|
|
120
|
+
const componentRSC = `0:${JSON.stringify(rsc)}
|
|
121
|
+
`;
|
|
122
|
+
component = await (0, import_client.createFromReadableStream)(
|
|
123
|
+
new ReadableStream({
|
|
124
|
+
type: "bytes",
|
|
125
|
+
start(controller) {
|
|
126
|
+
const encoder = new TextEncoder();
|
|
127
|
+
controller.enqueue(encoder.encode(componentRSC));
|
|
128
|
+
controller.close();
|
|
129
|
+
}
|
|
130
|
+
}),
|
|
131
|
+
{
|
|
132
|
+
serverConsumerManifest: {
|
|
133
|
+
moduleLoading: {
|
|
134
|
+
prefix: url.origin,
|
|
135
|
+
crossOrigin: true
|
|
136
|
+
},
|
|
137
|
+
moduleMap: {}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
const name = metadata.id.replace(/_ssr$/, "");
|
|
143
|
+
return {
|
|
144
|
+
name,
|
|
145
|
+
url,
|
|
146
|
+
metadata,
|
|
147
|
+
rsc,
|
|
148
|
+
scripts,
|
|
149
|
+
links,
|
|
150
|
+
hydrationData,
|
|
151
|
+
nextData,
|
|
152
|
+
component,
|
|
153
|
+
html,
|
|
154
|
+
remoteShared
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
158
|
+
0 && (module.exports = {
|
|
159
|
+
fetchRemoteComponent,
|
|
160
|
+
getBaseUrl
|
|
161
|
+
});
|
|
162
|
+
//# sourceMappingURL=fetch-remote-component.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/shared/ssr/fetch-remote-component.ts"],"sourcesContent":["import { createFromReadableStream } from 'next/dist/compiled/react-server-dom-webpack/client.edge';\nimport { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport type { RemoteComponentMetadata } from './types';\nimport { visit } from './dom-flight';\n\nconst CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;\n\n/**\n * Resolves the base URL that should be used to fetch the remote component.\n * This function must support local development, Vercel environments, and SSG\n * and dynamic rendering.\n */\nexport function getBaseUrl(reqHeaders: Headers): string {\n const host = reqHeaders.get('host');\n if (host) {\n return host.startsWith('localhost') ? `http://${host}` : `https://${host}`;\n }\n const forwardedHost = reqHeaders.get('x-forwarded-host');\n if (forwardedHost) {\n return `https://${forwardedHost}`;\n }\n if (process.env.VERCEL_PROJECT_PRODUCTION_URL) {\n return `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`;\n }\n // TODO: Resolve the correct URL in local development when the proxy is not running.\n return `http://localhost:${process.env.MFE_LOCAL_PROXY_PORT || 3024}`;\n}\n\nexport async function fetchRemoteComponent(\n src: string | URL,\n headers: Headers,\n createComponent = false,\n) {\n const url = new URL(src, getBaseUrl(headers));\n\n const fetchInit = {\n method: 'GET',\n headers: {\n // pass all headers to the remote component\n ...Object.fromEntries(headers.entries()),\n Accept: 'text/html',\n // pass the public address of the remote component to the server used for module map mutation\n 'Vercel-Remote-Component-Url': url.href,\n },\n credentials: 'include',\n } as RequestInit;\n\n const res = await fetch(url, fetchInit);\n\n if (!res.ok) {\n throw new Error(\n `Failed to fetch remote component \"${url.href}\": ${res.status}`,\n );\n }\n\n // create a parser for the HTML response\n const parser = Parser.getFragmentParser<DefaultTreeAdapterMap>();\n\n if (!res.body) {\n throw new Error(`No response body for remote component \"${url.href}\"`);\n }\n\n const decoder = new TextDecoder();\n // read the response body as a stream and parse it using the parse5 fragment parser\n for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {\n parser.tokenizer.write(decoder.decode(chunk), false);\n }\n const fragment = parser.getFragment();\n\n let metadata: RemoteComponentMetadata = {\n bundle: CURRENT_ZONE ?? '__vercel_remote_component',\n route: '/',\n runtime: 'webpack',\n id: '__vercel_remote_component',\n };\n let remoteShared: Record<string, string> = {};\n const scripts: { src: string }[] = [];\n const links: Record<string, string | boolean>[] = [];\n const hydrationData: string[] = [];\n let nextData:\n | {\n props: { pageProps: Record<string, unknown> };\n buildId?: string;\n }\n | undefined;\n let html = '';\n // convert the parsed HTML fragment into an RSC flight data\n // and extract the metadata, scripts, links and remote component RSC flight data\n const rsc = visit(fragment, {\n url,\n onMetadata(_metadata) {\n metadata = _metadata;\n },\n onScript(attrs) {\n if (!scripts.find((it) => it.src === attrs.src)) {\n scripts.push({ src: attrs.src as string });\n }\n },\n onLink(attrs) {\n if (!links.find((it) => it.href === attrs.href && it.rel === attrs.rel)) {\n links.push(attrs);\n }\n },\n onRSC(chunk) {\n hydrationData.push(chunk);\n },\n onNextData(data) {\n nextData = data;\n\n // use the Next.js Pages Router props data to extract remote component metadata\n if (data.props.__REMOTE_COMPONENT__) {\n Object.assign(metadata, data.props.__REMOTE_COMPONENT__);\n // only a singleton remote component is supported per page when using the Next.js Pages Router\n metadata.id = '__next';\n metadata.route = data.page ?? '/';\n }\n },\n onHTML(_html) {\n if (!html.includes(_html)) {\n html += _html;\n }\n },\n onShared(_shared) {\n remoteShared = _shared;\n },\n });\n\n let component: React.ReactNode | undefined;\n\n // only create a React component if requested\n if (createComponent) {\n // RSC flight data for the static HTML in a single RSC line\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n\n // create a React tree from the RSC flight data\n component = await createFromReadableStream(\n new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n controller.enqueue(encoder.encode(componentRSC));\n controller.close();\n },\n }),\n {\n serverConsumerManifest: {\n moduleLoading: {\n prefix: url.origin,\n crossOrigin: true,\n },\n moduleMap: {},\n },\n },\n );\n }\n\n const name = metadata.id.replace(/_ssr$/, '');\n return {\n name,\n url,\n metadata,\n rsc,\n scripts,\n links,\n hydrationData,\n nextData,\n component,\n html,\n remoteShared,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyC;AACzC,oBAAmD;AAEnD,wBAAsB;AAEtB,MAAM,eAAe,QAAQ,IAAI;AAO1B,SAAS,WAAW,YAA6B;AACtD,QAAM,OAAO,WAAW,IAAI,MAAM;AA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YACb,QAAQ,IAAI;AAAA,YACZ,aAAa;AAAA,UACf;AAAA,UACA,WAAW,CAAC;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,OAAO,SAAS,GAAG,QAAQ,SAAS,EAAE;AAC5C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { R as RemoteComponentMetadata } from '../../types-280a3640.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the base URL that should be used to fetch the remote component.
|
|
6
|
+
* This function must support local development, Vercel environments, and SSG
|
|
7
|
+
* and dynamic rendering.
|
|
8
|
+
*/
|
|
9
|
+
declare function getBaseUrl(reqHeaders: Headers): string;
|
|
10
|
+
declare function fetchRemoteComponent(src: string | URL, headers: Headers, createComponent?: boolean): Promise<{
|
|
11
|
+
name: string;
|
|
12
|
+
url: URL;
|
|
13
|
+
metadata: RemoteComponentMetadata;
|
|
14
|
+
rsc: (string | ["$", string, null, Record<string, unknown>, null, null, number] | (string | ["$", string, null, Record<string, unknown>, null, null, number] | null)[] | null) | (string | ["$", string, null, Record<string, unknown>, null, null, number] | (string | ["$", string, null, Record<string, unknown>, null, null, number] | null)[] | null)[];
|
|
15
|
+
scripts: {
|
|
16
|
+
src: string;
|
|
17
|
+
}[];
|
|
18
|
+
links: Record<string, string | boolean>[];
|
|
19
|
+
hydrationData: string[];
|
|
20
|
+
nextData: {
|
|
21
|
+
props: {
|
|
22
|
+
pageProps: Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
buildId?: string;
|
|
25
|
+
} | undefined;
|
|
26
|
+
component: react.ReactNode;
|
|
27
|
+
html: string;
|
|
28
|
+
remoteShared: Record<string, string>;
|
|
29
|
+
}>;
|
|
30
|
+
|
|
31
|
+
export { fetchRemoteComponent, getBaseUrl };
|