remote-components 0.0.23 → 0.0.24
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/dist/html/host.cjs +297 -82
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +300 -82
- package/dist/html/host.js.map +1 -1
- package/dist/internal/next/host/app-router-client.cjs +176 -70
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.js +184 -71
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/next/host/app-router-compat.cjs +114 -0
- package/dist/internal/next/host/app-router-compat.cjs.map +1 -0
- package/dist/internal/next/host/app-router-compat.d.ts +31 -0
- package/dist/internal/next/host/app-router-compat.js +79 -0
- package/dist/internal/next/host/app-router-compat.js.map +1 -0
- package/dist/internal/next/remote/render-client.cjs +10 -2
- package/dist/internal/next/remote/render-client.cjs.map +1 -1
- package/dist/internal/next/remote/render-client.js +10 -2
- package/dist/internal/next/remote/render-client.js.map +1 -1
- package/dist/internal/shared/client/apply-origin.cjs +61 -0
- package/dist/internal/shared/client/apply-origin.cjs.map +1 -0
- package/dist/internal/shared/client/apply-origin.d.ts +3 -0
- package/dist/internal/shared/client/apply-origin.js +37 -0
- package/dist/internal/shared/client/apply-origin.js.map +1 -0
- package/dist/internal/shared/client/polyfill.cjs +149 -0
- package/dist/internal/shared/client/polyfill.cjs.map +1 -0
- package/dist/internal/shared/client/polyfill.d.ts +6 -0
- package/dist/internal/shared/client/polyfill.js +124 -0
- package/dist/internal/shared/client/polyfill.js.map +1 -0
- package/dist/internal/shared/client/remote-component.cjs +3 -3
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +1 -1
- package/dist/internal/shared/client/remote-component.js +3 -3
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.cjs +40 -0
- package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.js +40 -0
- package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.cjs +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.d.ts +6 -0
- package/dist/internal/shared/ssr/fetch-remote-component.js +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
- package/dist/next/config.cjs +50 -28
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +50 -28
- package/dist/next/config.js.map +1 -1
- package/dist/next/host/client/index.cjs +16 -1
- package/dist/next/host/client/index.cjs.map +1 -1
- package/dist/next/host/client/index.js +16 -1
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs +27 -13
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.js +27 -13
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/next/middleware.cjs +5 -2
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +1 -0
- package/dist/next/middleware.js +5 -2
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/remote/pages-router.cjs +3 -1
- package/dist/next/remote/pages-router.cjs.map +1 -1
- package/dist/next/remote/pages-router.d.ts +1 -0
- package/dist/next/remote/pages-router.js +3 -1
- package/dist/next/remote/pages-router.js.map +1 -1
- package/dist/react/index.cjs +203 -159
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +192 -148
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -36,10 +36,50 @@ var import_style_to_js = __toESM(require("style-to-js"), 1);
|
|
|
36
36
|
var import_parse5 = require("parse5");
|
|
37
37
|
import_react_property.possibleStandardNames.fetchpriority = "fetchPriority";
|
|
38
38
|
import_react_property.possibleStandardNames["data-precedence"] = "precedence";
|
|
39
|
+
const applyOriginToNodes = [
|
|
40
|
+
"img",
|
|
41
|
+
"source",
|
|
42
|
+
"video",
|
|
43
|
+
"audio",
|
|
44
|
+
"track",
|
|
45
|
+
"iframe",
|
|
46
|
+
"embed",
|
|
47
|
+
"script",
|
|
48
|
+
"link"
|
|
49
|
+
];
|
|
39
50
|
function visit(node, context = {
|
|
40
51
|
url: new URL("http://localhost"),
|
|
41
52
|
active: false
|
|
42
53
|
}) {
|
|
54
|
+
if (applyOriginToNodes.includes(node.nodeName.toLowerCase()) && "attrs" in node) {
|
|
55
|
+
const origin = context.origin ?? context.url.origin;
|
|
56
|
+
const src = node.attrs.find((attr) => attr.name === "src")?.value;
|
|
57
|
+
if (src) {
|
|
58
|
+
const url = new URL(src, origin);
|
|
59
|
+
node.attrs = node.attrs.map((attr) => {
|
|
60
|
+
if (attr.name === "src") {
|
|
61
|
+
attr.value = url.href;
|
|
62
|
+
}
|
|
63
|
+
return attr;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const srcSet = node.attrs.find((attr) => attr.name === "srcset")?.value;
|
|
67
|
+
if (srcSet) {
|
|
68
|
+
const srcSetValue = srcSet.split(",").map((entry) => {
|
|
69
|
+
const [url, descriptor] = entry.trim().split(/\s+/);
|
|
70
|
+
if (!url)
|
|
71
|
+
return entry;
|
|
72
|
+
const absoluteUrl = new URL(url, origin).href;
|
|
73
|
+
return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
|
|
74
|
+
}).join(", ");
|
|
75
|
+
node.attrs = node.attrs.map((attr) => {
|
|
76
|
+
if (attr.name === "srcset") {
|
|
77
|
+
attr.value = srcSetValue;
|
|
78
|
+
}
|
|
79
|
+
return attr;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
43
83
|
if (node.nodeName === "script" || node.nodeName === "link") {
|
|
44
84
|
const nodeId = node.attrs.find((attr) => attr.name === "id")?.value;
|
|
45
85
|
if (nodeId?.endsWith("_shared")) {
|
|
@@ -1 +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 visitedRSCNodes?: Set<Node>;\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 url: new URL('http://localhost'),\n active: false,\n },\n): RSC | RSC[] | string | null {\n if (node.nodeName === 'script' || node.nodeName === 'link') {\n const nodeId = node.attrs.find((attr) => attr.name === 'id')?.value;\n if (nodeId?.endsWith('_shared')) {\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 (nodeId?.endsWith('_rsc') && 'childNodes' in node) {\n if (!context.visitedRSCNodes) {\n context.visitedRSCNodes = new Set();\n }\n if (\n !context.visitedRSCNodes.has(node) &&\n (context.name ? nodeId.startsWith(context.name) : true)\n ) {\n context.visitedRSCNodes.add(node);\n context.onRSC?.((node.childNodes[0] as TextNode).value);\n }\n } else if (nodeId === '__NEXT_DATA__' && 'childNodes' in node) {\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 if (attr.name === 'href') {\n attr.value = new URL(attr.value, context.url.origin).href;\n }\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 const nodeId = Array.isArray((node as Element).attrs)\n ? (node as Element).attrs.find((attr) => attr.name === 'id')?.value\n : undefined;\n\n if (\n node.nodeName === 'div' &&\n (nodeId === '__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 nodeId?.endsWith('_ssr')))\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: nodeId?.endsWith('_ssr') ? nodeId : '__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, nodePro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S,QAAQ,KAAK,CAAC,CAAC,EACjE,OAAO,CAAC,OAAO,OAAO,IAAI;AAAA,MAC/B;AACA,YAAM,aAAc,KAAiB,WAClC,IAAI,CAAC,cAAc,MAAM,WAAW,OAAO,CAAC,EAC5C,OAAO,CAAC,cAAc,cAAc,IAAI;AAC3C,YAAM,WAAW,WAAW,SAAS,IAAI,aAAa,WAAW,CAAC;AAClE,YAAM,YAAa,KAAiB,MAAM,OAKxC,CAAC,OAAO,SAAS;AACjB,YAAI,KAAK,SAAS,SAAS;AACzB,gBAAM,YAAQ,mBAAAA,SAAU,KAAK,OAAO;AAAA,YAClC,aAAa;AAAA,UACf,CAAC;AACD,iBAAO;AAAA,QACT;AACA,YAAI,KAAK,aAAa,WAAW,KAAK,SAAS,SAAS;AACtD,gBAAM,eAAe,KAAK;AAC1B,iBAAO;AAAA,QACT;AACA,gBAAI,yCAAkB,KAAK,IAAI,GAAG;AAChC,gBAAM,KAAK,IAAI,IAAI,KAAK;AACxB,iBAAO;AAAA,QACT;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"]}
|
|
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 visitedRSCNodes?: Set<Node>;\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\nconst applyOriginToNodes = [\n 'img',\n 'source',\n 'video',\n 'audio',\n 'track',\n 'iframe',\n 'embed',\n 'script',\n 'link',\n];\n\nexport function visit(\n node: Node | ChildNode,\n context: Context = {\n url: new URL('http://localhost'),\n active: false,\n },\n): RSC | RSC[] | string | null {\n // apply origin to src and srcset attributes\n if (\n applyOriginToNodes.includes(node.nodeName.toLowerCase()) &&\n 'attrs' in node\n ) {\n const origin = context.origin ?? context.url.origin;\n const src = node.attrs.find((attr) => attr.name === 'src')?.value;\n if (src) {\n const url = new URL(src, origin);\n node.attrs = node.attrs.map((attr) => {\n if (attr.name === 'src') {\n attr.value = url.href;\n }\n return attr;\n });\n }\n\n const srcSet = node.attrs.find((attr) => attr.name === 'srcset')?.value;\n if (srcSet) {\n const srcSetValue = srcSet\n .split(',')\n .map((entry) => {\n const [url, descriptor] = entry.trim().split(/\\s+/);\n if (!url) return entry;\n\n const absoluteUrl = new URL(url, origin).href;\n return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;\n })\n .join(', ');\n node.attrs = node.attrs.map((attr) => {\n if (attr.name === 'srcset') {\n attr.value = srcSetValue;\n }\n return attr;\n });\n }\n }\n\n if (node.nodeName === 'script' || node.nodeName === 'link') {\n const nodeId = node.attrs.find((attr) => attr.name === 'id')?.value;\n if (nodeId?.endsWith('_shared')) {\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 (nodeId?.endsWith('_rsc') && 'childNodes' in node) {\n if (!context.visitedRSCNodes) {\n context.visitedRSCNodes = new Set();\n }\n if (\n !context.visitedRSCNodes.has(node) &&\n (context.name ? nodeId.startsWith(context.name) : true)\n ) {\n context.visitedRSCNodes.add(node);\n context.onRSC?.((node.childNodes[0] as TextNode).value);\n }\n } else if (nodeId === '__NEXT_DATA__' && 'childNodes' in node) {\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 if (attr.name === 'href') {\n attr.value = new URL(attr.value, context.url.origin).href;\n }\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 const nodeId = Array.isArray((node as Element).attrs)\n ? (node as Element).attrs.find((attr) => attr.name === 'id')?.value\n : undefined;\n\n if (\n node.nodeName === 'div' &&\n (nodeId === '__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 nodeId?.endsWith('_ssr')))\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: nodeId?.endsWith('_ssr') ? nodeId : '__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;AAqC3C,MAAM,qBAAqB;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,MACd,MACA,UAAmB;AAAA,EACjB,KAAK,IAAI,IAAI,kBAAkB;AAAA,EAC/B,QAAQ;AACV,GAC6B;AAE7B,MACE,mBAAmB,SAAS,KAAK,SAAS,YAAY,CAAC,KACvD,WAAW,MACX;AACA,UAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI;AAC7C,UAAM,MAAM,KAAK,MAAM,KAAK,CAAC,SAAS,KAAK,SAAS,KAAK,GAAG;AAC5D,QAAI,KAAK;AACP,YAAM,MAAM,IAAI,IAAI,KAAK,M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AAW,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"]}
|
|
@@ -3,10 +3,50 @@ import styleToJs from "style-to-js";
|
|
|
3
3
|
import { serializeOuter } from "parse5";
|
|
4
4
|
possibleStandardNames.fetchpriority = "fetchPriority";
|
|
5
5
|
possibleStandardNames["data-precedence"] = "precedence";
|
|
6
|
+
const applyOriginToNodes = [
|
|
7
|
+
"img",
|
|
8
|
+
"source",
|
|
9
|
+
"video",
|
|
10
|
+
"audio",
|
|
11
|
+
"track",
|
|
12
|
+
"iframe",
|
|
13
|
+
"embed",
|
|
14
|
+
"script",
|
|
15
|
+
"link"
|
|
16
|
+
];
|
|
6
17
|
function visit(node, context = {
|
|
7
18
|
url: new URL("http://localhost"),
|
|
8
19
|
active: false
|
|
9
20
|
}) {
|
|
21
|
+
if (applyOriginToNodes.includes(node.nodeName.toLowerCase()) && "attrs" in node) {
|
|
22
|
+
const origin = context.origin ?? context.url.origin;
|
|
23
|
+
const src = node.attrs.find((attr) => attr.name === "src")?.value;
|
|
24
|
+
if (src) {
|
|
25
|
+
const url = new URL(src, origin);
|
|
26
|
+
node.attrs = node.attrs.map((attr) => {
|
|
27
|
+
if (attr.name === "src") {
|
|
28
|
+
attr.value = url.href;
|
|
29
|
+
}
|
|
30
|
+
return attr;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const srcSet = node.attrs.find((attr) => attr.name === "srcset")?.value;
|
|
34
|
+
if (srcSet) {
|
|
35
|
+
const srcSetValue = srcSet.split(",").map((entry) => {
|
|
36
|
+
const [url, descriptor] = entry.trim().split(/\s+/);
|
|
37
|
+
if (!url)
|
|
38
|
+
return entry;
|
|
39
|
+
const absoluteUrl = new URL(url, origin).href;
|
|
40
|
+
return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
|
|
41
|
+
}).join(", ");
|
|
42
|
+
node.attrs = node.attrs.map((attr) => {
|
|
43
|
+
if (attr.name === "srcset") {
|
|
44
|
+
attr.value = srcSetValue;
|
|
45
|
+
}
|
|
46
|
+
return attr;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
10
50
|
if (node.nodeName === "script" || node.nodeName === "link") {
|
|
11
51
|
const nodeId = node.attrs.find((attr) => attr.name === "id")?.value;
|
|
12
52
|
if (nodeId?.endsWith("_shared")) {
|
|
@@ -1 +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 visitedRSCNodes?: Set<Node>;\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 url: new URL('http://localhost'),\n active: false,\n },\n): RSC | RSC[] | string | null {\n if (node.nodeName === 'script' || node.nodeName === 'link') {\n const nodeId = node.attrs.find((attr) => attr.name === 'id')?.value;\n if (nodeId?.endsWith('_shared')) {\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 (nodeId?.endsWith('_rsc') && 'childNodes' in node) {\n if (!context.visitedRSCNodes) {\n context.visitedRSCNodes = new Set();\n }\n if (\n !context.visitedRSCNodes.has(node) &&\n (context.name ? nodeId.startsWith(context.name) : true)\n ) {\n context.visitedRSCNodes.add(node);\n context.onRSC?.((node.childNodes[0] as TextNode).value);\n }\n } else if (nodeId === '__NEXT_DATA__' && 'childNodes' in node) {\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 if (attr.name === 'href') {\n attr.value = new URL(attr.value, context.url.origin).href;\n }\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 const nodeId = Array.isArray((node as Element).attrs)\n ? (node as Element).attrs.find((attr) => attr.name === 'id')?.value\n : undefined;\n\n if (\n node.nodeName === 'div' &&\n (nodeId === '__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 nodeId?.endsWith('_ssr')))\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: nodeId?.endsWith('_ssr') ? nodeId : '__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;AAqCpC,SAAS,MACd,MACA,UAAmB;AAAA,EACjB,KAAK,IAAI,IAAI,kBAAkB;AAAA,EAC/B,QAAQ;AACV,GAC6B;AAC7B,MAAI,KAAK,aAAa,YAAY,KAAK,aAAa,QAAQ;AAC1D,UAAM,SAAS,KAAK,MAAM,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,GAAG;AAC9D,QAAI,QAAQ,SAAS,SAAS,GAAG;AAC/B,cAAQ;AAAA,QACN,KAAK,MAAO,KAAK,WAAW,CAAC,EAAe,KAAK;AAAA,MAInD;AACA,aAAO;AAAA,IACT,WAAW,QAAQ,SAAS,MAAM,KAAK,gBAAgB,MAAM;AAC3D,UAAI,CAAC,QAAQ,iBAAiB;AAC5B,gBAAQ,kBAAkB,oBAAI,IAAI;AAAA,MACpC;AACA,UACE,CAAC,QAAQ,gBAAgB,IAAI,IAAI,MAChC,QAAQ,OAAO,OAAO,WAAW,QAAQ,IAAI,IAAI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a,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":[]}
|
|
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 visitedRSCNodes?: Set<Node>;\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\nconst applyOriginToNodes = [\n 'img',\n 'source',\n 'video',\n 'audio',\n 'track',\n 'iframe',\n 'embed',\n 'script',\n 'link',\n];\n\nexport function visit(\n node: Node | ChildNode,\n context: Context = {\n url: new URL('http://localhost'),\n active: false,\n },\n): RSC | RSC[] | string | null {\n // apply origin to src and srcset attributes\n if (\n applyOriginToNodes.includes(node.nodeName.toLowerCase()) &&\n 'attrs' in node\n ) {\n const origin = context.origin ?? context.url.origin;\n const src = node.attrs.find((attr) => attr.name === 'src')?.value;\n if (src) {\n const url = new URL(src, origin);\n node.attrs = node.attrs.map((attr) => {\n if (attr.name === 'src') {\n attr.value = url.href;\n }\n return attr;\n });\n }\n\n const srcSet = node.attrs.find((attr) => attr.name === 'srcset')?.value;\n if (srcSet) {\n const srcSetValue = srcSet\n .split(',')\n .map((entry) => {\n const [url, descriptor] = entry.trim().split(/\\s+/);\n if (!url) return entry;\n\n const absoluteUrl = new URL(url, origin).href;\n return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;\n })\n .join(', ');\n node.attrs = node.attrs.map((attr) => {\n if (attr.name === 'srcset') {\n attr.value = srcSetValue;\n }\n return attr;\n });\n }\n }\n\n if (node.nodeName === 'script' || node.nodeName === 'link') {\n const nodeId = node.attrs.find((attr) => attr.name === 'id')?.value;\n if (nodeId?.endsWith('_shared')) {\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 (nodeId?.endsWith('_rsc') && 'childNodes' in node) {\n if (!context.visitedRSCNodes) {\n context.visitedRSCNodes = new Set();\n }\n if (\n !context.visitedRSCNodes.has(node) &&\n (context.name ? nodeId.startsWith(context.name) : true)\n ) {\n context.visitedRSCNodes.add(node);\n context.onRSC?.((node.childNodes[0] as TextNode).value);\n }\n } else if (nodeId === '__NEXT_DATA__' && 'childNodes' in node) {\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 if (attr.name === 'href') {\n attr.value = new URL(attr.value, context.url.origin).href;\n }\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 const nodeId = Array.isArray((node as Element).attrs)\n ? (node as Element).attrs.find((attr) => attr.name === 'id')?.value\n : undefined;\n\n if (\n node.nodeName === 'div' &&\n (nodeId === '__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 nodeId?.endsWith('_ssr')))\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: nodeId?.endsWith('_ssr') ? nodeId : '__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;AAqC3C,MAAM,qBAAqB;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AA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SAAS;AACtD,gBAAM,eAAe,KAAK;AAC1B,iBAAO;AAAA,QACT;AACA,YAAI,kBAAkB,KAAK,IAAI,GAAG;AAChC,gBAAM,KAAK,IAAI,IAAI,KAAK;AACxB,iBAAO;AAAA,QACT;AACA,cAAM,sBAAsB,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":[]}
|
|
@@ -171,7 +171,7 @@ async function fetchRemoteComponent(src, headers = new Headers(), options = {
|
|
|
171
171
|
nextData,
|
|
172
172
|
component,
|
|
173
173
|
html,
|
|
174
|
-
remoteShared
|
|
174
|
+
remoteShared: nextData?.props.__REMOTE_COMPONENT__?.shared ?? remoteShared
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
177
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/shared/ssr/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { visit } from '#internal/shared/ssr/dom-flight';\nimport type { RemoteComponentMetadata } from './types';\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 = new Headers(),\n options: {\n name?: string;\n rsc?: boolean;\n } = {\n rsc: false,\n },\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 },\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: {
|
|
1
|
+
{"version":3,"sources":["../../../../src/shared/ssr/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { visit } from '#internal/shared/ssr/dom-flight';\nimport type { RemoteComponentMetadata } from './types';\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 = new Headers(),\n options: {\n name?: string;\n rsc?: boolean;\n } = {\n rsc: false,\n },\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 },\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: {\n pageProps: Record<string, unknown>;\n __REMOTE_COMPONENT__?: {\n bundle: string;\n runtime: string;\n shared?: Record<string, string>;\n };\n };\n page?: string;\n buildId?: string;\n }\n | undefined;\n let html = '';\n\n const remoteName =\n options.name || url.hash ? url.hash.substring(1) : undefined;\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 name: remoteName,\n onMetadata(_metadata) {\n metadata = _metadata;\n },\n onScript(attrs) {\n if (!scripts.find((it) => it.src === attrs.src)) {\n scripts.push({\n src: new URL(attrs.src as string, new URL(url).origin).href,\n });\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: new URL(attrs.href as string, new URL(url).origin).href,\n };\n if (\n !links.find(\n (it) => it.href === relativeAttrs.href && it.rel === attrs.rel,\n )\n ) {\n links.push(relativeAttrs);\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 (options.rsc) {\n // RSC flight data for the static HTML in a single RSC line\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n\n const { createFromReadableStream } = await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\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: nextData?.props.__REMOTE_COMPONENT__?.shared ?? remoteShared,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmD;AACnD,wBAAsB;AAGtB,MAAM,eAAe,QAAQ,IAAI;AAO1B,SAAS,WAAW,YAA6B;AACtD,QAAM,OAAO,WAAW,IAAI,MAAM;AAClC,MAAI,MAAM;AACR,WAAO,KAAK,WAAW,WAAW,IAAI,UAAU,SAAS,WAAW;AAAA,EACtE;AACA,QAAM,gBAAgB,WAAW,IAAI,kBAAkB;AACvD,MAAI,eAAe;AACjB,WAAO,WAAW;AAAA,EACpB;AACA,MAAI,QAAQ,IAAI,+BAA+B;AAC7C,WAAO,WAAW,QAAQ,IAAI;AAAA,EAChC;AAEA,SAAO,oBAAoB,QAAQ,IAAI,wBAAwB;AACjE;AAEA,eAAsB,qBACpB,KACA,UAAmB,IAAI,QAAQ,GAC/B,UAGI;AAAA,EACF,KAAK;AACP,GACA;AACA,QAAM,MAAM,IAAI,IAAI,KAAK,WAAW,OAAO,CAAC;AAE5C,QAAM,YAAY;AAAA,IAChB,QAAQ;AAAA,IACR,SAAS;AAAA;AAAA,MAEP,GAAG,OAAO,YAAY,QAAQ,QAAQ,CAAC;AAAA,MACvC,QAAQ;AAAA,IACV;AAAA,IACA,aAAa;AAAA,EACf;AAEA,QAAM,MAAM,MAAM,MAAM,KAAK,SAAS;AAEtC,MAAI,CAAC,IAAI,IAAI;AACX,UAAM,IAAI;AAAA,MACR,qC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]}
|
|
@@ -23,7 +23,13 @@ declare function fetchRemoteComponent(src: string | URL, headers?: Headers, opti
|
|
|
23
23
|
nextData: {
|
|
24
24
|
props: {
|
|
25
25
|
pageProps: Record<string, unknown>;
|
|
26
|
+
__REMOTE_COMPONENT__?: {
|
|
27
|
+
bundle: string;
|
|
28
|
+
runtime: string;
|
|
29
|
+
shared?: Record<string, string>;
|
|
30
|
+
};
|
|
26
31
|
};
|
|
32
|
+
page?: string;
|
|
27
33
|
buildId?: string;
|
|
28
34
|
} | undefined;
|
|
29
35
|
component: react.ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/shared/ssr/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { visit } from '#internal/shared/ssr/dom-flight';\nimport type { RemoteComponentMetadata } from './types';\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 = new Headers(),\n options: {\n name?: string;\n rsc?: boolean;\n } = {\n rsc: false,\n },\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 },\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: {
|
|
1
|
+
{"version":3,"sources":["../../../../src/shared/ssr/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { visit } from '#internal/shared/ssr/dom-flight';\nimport type { RemoteComponentMetadata } from './types';\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 = new Headers(),\n options: {\n name?: string;\n rsc?: boolean;\n } = {\n rsc: false,\n },\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 },\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: {\n pageProps: Record<string, unknown>;\n __REMOTE_COMPONENT__?: {\n bundle: string;\n runtime: string;\n shared?: Record<string, string>;\n };\n };\n page?: string;\n buildId?: string;\n }\n | undefined;\n let html = '';\n\n const remoteName =\n options.name || url.hash ? url.hash.substring(1) : undefined;\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 name: remoteName,\n onMetadata(_metadata) {\n metadata = _metadata;\n },\n onScript(attrs) {\n if (!scripts.find((it) => it.src === attrs.src)) {\n scripts.push({\n src: new URL(attrs.src as string, new URL(url).origin).href,\n });\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: new URL(attrs.href as string, new URL(url).origin).href,\n };\n if (\n !links.find(\n (it) => it.href === relativeAttrs.href && it.rel === attrs.rel,\n )\n ) {\n links.push(relativeAttrs);\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 (options.rsc) {\n // RSC flight data for the static HTML in a single RSC line\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n\n const { createFromReadableStream } = await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\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: nextData?.props.__REMOTE_COMPONENT__?.shared ?? remoteShared,\n };\n}\n"],"mappings":"AAAA,SAAqC,cAAc;AACnD,SAAS,aAAa;AAGtB,MAAM,eAAe,QAAQ,IAAI;AAO1B,SAAS,WAAW,YAA6B;AACtD,QAAM,OAAO,WAAW,IAAI,MAAM;AAClC,MAAI,MAAM;AACR,WAAO,KAAK,WAAW,WAAW,IAAI,UAAU,SAAS,WAAW;AAAA,EACtE;AACA,QA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;AAGA,gBAAY,MAAM;AAAA,MAChB,IAAI,eAAe;AAAA,QACjB,MAAM;AAAA,QACN,MAAM,YAAY;AAChB,gBAAM,UAAU,IAAI,YAAY;AAChC,qBAAW,QAAQ,QAAQ,OAAO,YAAY,CAAC;AAC/C,qBAAW,MAAM;AAAA,QACnB;AAAA,MACF,CAAC;AAAA,MACD;AAAA,QACE,wBAAwB;AAAA,UACtB,eAAe;AAAA,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,cAAc,UAAU,MAAM,sBAAsB,UAAU;AAAA,EAChE;AACF;","names":[]}
|
package/dist/next/config.cjs
CHANGED
|
@@ -188,6 +188,9 @@ var ConditionalExecPlugin = class {
|
|
|
188
188
|
|
|
189
189
|
// src/next/config/webpack/plugins/patch-require.ts
|
|
190
190
|
var PatchRequirePlugin = class {
|
|
191
|
+
constructor(appName) {
|
|
192
|
+
this.appName = appName;
|
|
193
|
+
}
|
|
191
194
|
apply(compiler) {
|
|
192
195
|
const { sources } = compiler.webpack;
|
|
193
196
|
compiler.hooks.thisCompilation.tap("PatchRequirePlugin", (compilation) => {
|
|
@@ -217,7 +220,7 @@ __webpack_require__.l = function __remote_webpack_require_l__(url, done, key, ch
|
|
|
217
220
|
const bundle = match?.groups?.bundle;
|
|
218
221
|
const id = match?.groups?.id;
|
|
219
222
|
if (!(id && bundle)) {
|
|
220
|
-
return __webpack_require_l__(url, done, key, chunkId);
|
|
223
|
+
return __webpack_require_l__(new URL(url, globalThis.__remote_bundle_url__?.["${this.appName}"] ?? location.origin).href, done, key, chunkId);
|
|
221
224
|
}
|
|
222
225
|
return done();
|
|
223
226
|
};
|
|
@@ -262,7 +265,7 @@ function transform(nextConfig, {
|
|
|
262
265
|
new RemoteWebpackRequirePlugin(app.name),
|
|
263
266
|
new ModuleIdEmbedPlugin(app.name),
|
|
264
267
|
new ConditionalExecPlugin(app.name),
|
|
265
|
-
new PatchRequirePlugin()
|
|
268
|
+
new PatchRequirePlugin(app.name)
|
|
266
269
|
);
|
|
267
270
|
if (!webpackContext.isServer) {
|
|
268
271
|
config.output.chunkLoadingGlobal = `__remote_chunk_loading_global_${app.name}__`;
|
|
@@ -287,10 +290,15 @@ function transform(nextConfig, {
|
|
|
287
290
|
|
|
288
291
|
// src/next/config/index.ts
|
|
289
292
|
function withRemoteComponents(nextConfig, options) {
|
|
290
|
-
const
|
|
293
|
+
const virtualRemoteComponentAppSharedRemote = (0, import_node_path3.join)(
|
|
294
|
+
process.cwd(),
|
|
295
|
+
nextConfig.distDir ?? ".next",
|
|
296
|
+
"remote-components/shared/app-remote.tsx"
|
|
297
|
+
);
|
|
298
|
+
const virtualRemoteComponentPagesSharedRemote = (0, import_node_path3.join)(
|
|
291
299
|
process.cwd(),
|
|
292
300
|
nextConfig.distDir ?? ".next",
|
|
293
|
-
"remote-components/shared/remote.tsx"
|
|
301
|
+
"remote-components/shared/pages-remote.tsx"
|
|
294
302
|
);
|
|
295
303
|
const virtualRemoteComponentAppSharedHost = (0, import_node_path3.join)(
|
|
296
304
|
process.cwd(),
|
|
@@ -329,7 +337,12 @@ function withRemoteComponents(nextConfig, options) {
|
|
|
329
337
|
"react/jsx-dev-runtime",
|
|
330
338
|
"react/jsx-runtime",
|
|
331
339
|
"react-dom",
|
|
332
|
-
"react-dom/client"
|
|
340
|
+
"react-dom/client",
|
|
341
|
+
"next/router",
|
|
342
|
+
"next/link",
|
|
343
|
+
"next/image",
|
|
344
|
+
"next/script",
|
|
345
|
+
"next/form"
|
|
333
346
|
],
|
|
334
347
|
...options?.shared ?? []
|
|
335
348
|
]);
|
|
@@ -350,10 +363,8 @@ function withRemoteComponents(nextConfig, options) {
|
|
|
350
363
|
]
|
|
351
364
|
} : {}
|
|
352
365
|
});
|
|
353
|
-
const
|
|
354
|
-
module.exports = { shared: { ${Array.from(
|
|
355
|
-
appShared
|
|
356
|
-
).reduce((acc, curr) => {
|
|
366
|
+
const generateSharedRemote = (sharedRemote) => `'use client';
|
|
367
|
+
module.exports = { shared: { ${Array.from(sharedRemote).reduce((acc, curr) => {
|
|
357
368
|
let path;
|
|
358
369
|
try {
|
|
359
370
|
path = resolve(process.cwd(), curr);
|
|
@@ -368,31 +379,36 @@ module.exports = { shared: { ${Array.from(
|
|
|
368
379
|
acc.push(
|
|
369
380
|
`[${vendorShared[curr] ?? (path ? `'${path}'` : `require.resolve('${curr}')`)}]: '${curr}',`
|
|
370
381
|
);
|
|
371
|
-
acc.push(
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
`;
|
|
375
|
-
const appSharedHost = `'use client';
|
|
376
|
-
module.exports = { shared: { ${Array.from(
|
|
377
|
-
appShared
|
|
378
|
-
).reduce((acc, curr) => {
|
|
379
|
-
acc.push(`['${curr}']: () => import('${curr}'),`);
|
|
382
|
+
acc.push(
|
|
383
|
+
`['__remote_shared_module_${curr}']: () => import('${curr}'),`
|
|
384
|
+
);
|
|
380
385
|
return acc;
|
|
381
386
|
}, []).join("\n")} } };
|
|
382
387
|
`;
|
|
383
|
-
const
|
|
384
|
-
module.exports = { shared: { ${Array.from(
|
|
385
|
-
pagesShared
|
|
386
|
-
).reduce((acc, curr) => {
|
|
388
|
+
const generateSharedHost = (sharedHost) => `'use client';
|
|
389
|
+
module.exports = { shared: { ${Array.from(sharedHost).reduce((acc, curr) => {
|
|
387
390
|
acc.push(`['${curr}']: () => import('${curr}'),`);
|
|
388
391
|
return acc;
|
|
389
392
|
}, []).join("\n")} } };
|
|
390
393
|
`;
|
|
394
|
+
const appSharedRemote = generateSharedRemote(appShared);
|
|
395
|
+
const pagesSharedRemote = generateSharedRemote(pagesShared);
|
|
396
|
+
const appSharedHost = generateSharedHost(appShared);
|
|
397
|
+
const pagesSharedHost = generateSharedHost(pagesShared);
|
|
391
398
|
const emitSharedFiles = () => {
|
|
392
|
-
(0, import_node_fs.mkdirSync)((0, import_node_path3.dirname)(
|
|
399
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path3.dirname)(virtualRemoteComponentAppSharedRemote), {
|
|
393
400
|
recursive: true
|
|
394
401
|
});
|
|
395
|
-
(0, import_node_fs.writeFileSync)(
|
|
402
|
+
(0, import_node_fs.writeFileSync)(
|
|
403
|
+
virtualRemoteComponentAppSharedRemote,
|
|
404
|
+
appSharedRemote,
|
|
405
|
+
"utf-8"
|
|
406
|
+
);
|
|
407
|
+
(0, import_node_fs.writeFileSync)(
|
|
408
|
+
virtualRemoteComponentPagesSharedRemote,
|
|
409
|
+
pagesSharedRemote,
|
|
410
|
+
"utf-8"
|
|
411
|
+
);
|
|
396
412
|
(0, import_node_fs.writeFileSync)(virtualRemoteComponentAppSharedHost, appSharedHost, "utf-8");
|
|
397
413
|
(0, import_node_fs.writeFileSync)(
|
|
398
414
|
virtualRemoteComponentPagesSharedHost,
|
|
@@ -407,13 +423,19 @@ module.exports = { shared: { ${Array.from(
|
|
|
407
423
|
"remote-components/next/host",
|
|
408
424
|
"remote-components/next/host/pages-router",
|
|
409
425
|
"remote-components/next/host/client",
|
|
410
|
-
"@remote-components/shared/remote",
|
|
411
|
-
"@remote-components/shared/
|
|
426
|
+
"@remote-components/shared/remote/app",
|
|
427
|
+
"@remote-components/shared/remote/pages",
|
|
428
|
+
"@remote-components/shared/host/app",
|
|
429
|
+
"@remote-components/shared/host/pages"
|
|
412
430
|
];
|
|
413
431
|
const alias = {
|
|
414
|
-
"@remote-components/shared/remote": `./${(0, import_node_path3.relative)(
|
|
432
|
+
"@remote-components/shared/remote/app": `./${(0, import_node_path3.relative)(
|
|
433
|
+
process.cwd(),
|
|
434
|
+
virtualRemoteComponentAppSharedRemote
|
|
435
|
+
)}`,
|
|
436
|
+
"@remote-components/shared/remote/pages": `./${(0, import_node_path3.relative)(
|
|
415
437
|
process.cwd(),
|
|
416
|
-
|
|
438
|
+
virtualRemoteComponentPagesSharedRemote
|
|
417
439
|
)}`,
|
|
418
440
|
"@remote-components/shared/host/app": `./${(0, import_node_path3.relative)(
|
|
419
441
|
process.cwd(),
|