remote-components 0.3.0 → 0.3.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/dist/host/html.cjs +88 -53
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +88 -53
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +64 -22
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +64 -22
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/nextjs/app.cjs +5 -6
- package/dist/host/nextjs/app.cjs.map +1 -1
- package/dist/host/nextjs/app.js +5 -6
- package/dist/host/nextjs/app.js.map +1 -1
- package/dist/host/nextjs/pages.cjs +6 -11
- package/dist/host/nextjs/pages.cjs.map +1 -1
- package/dist/host/nextjs/pages.js +9 -11
- package/dist/host/nextjs/pages.js.map +1 -1
- package/dist/host/react.cjs +64 -22
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +64 -22
- package/dist/host/react.js.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.cjs +16 -7
- package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.d.ts +2 -2
- package/dist/internal/host/nextjs/dom-flight.js +16 -7
- package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.cjs +164 -149
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.js +166 -149
- package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
- package/dist/internal/runtime/constants.cjs +6 -6
- package/dist/internal/runtime/constants.cjs.map +1 -1
- package/dist/internal/runtime/constants.d.ts +3 -3
- package/dist/internal/runtime/constants.js +4 -4
- package/dist/internal/runtime/constants.js.map +1 -1
- package/dist/internal/runtime/html/parse-remote-html.cjs +11 -15
- package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
- package/dist/internal/runtime/html/parse-remote-html.d.ts +2 -12
- package/dist/internal/runtime/html/parse-remote-html.js +17 -15
- package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
- package/dist/internal/runtime/loaders/script-loader.cjs +2 -2
- package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/script-loader.js +1 -1
- package/dist/internal/runtime/loaders/script-loader.js.map +1 -1
- package/dist/internal/runtime/metadata.cjs +42 -0
- package/dist/internal/runtime/metadata.cjs.map +1 -1
- package/dist/internal/runtime/metadata.d.ts +21 -1
- package/dist/internal/runtime/metadata.js +38 -0
- package/dist/internal/runtime/metadata.js.map +1 -1
- package/dist/internal/runtime/patterns.cjs +38 -0
- package/dist/internal/runtime/patterns.cjs.map +1 -0
- package/dist/internal/runtime/patterns.d.ts +5 -0
- package/dist/internal/runtime/patterns.js +12 -0
- package/dist/internal/runtime/patterns.js.map +1 -0
- package/dist/internal/runtime/turbopack/chunk-loader.cjs +4 -3
- package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.js +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs +11 -2
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.js +10 -2
- package/dist/internal/runtime/turbopack/webpack-runtime.js.map +1 -1
- package/dist/remote/nextjs/app.cjs +2 -1
- package/dist/remote/nextjs/app.cjs.map +1 -1
- package/dist/remote/nextjs/app.js +2 -1
- package/dist/remote/nextjs/app.js.map +1 -1
- package/package.json +1 -1
|
@@ -18,7 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var parse_remote_html_exports = {};
|
|
20
20
|
__export(parse_remote_html_exports, {
|
|
21
|
-
extractComponentMetadata: () => extractComponentMetadata,
|
|
22
21
|
extractLinks: () => extractLinks,
|
|
23
22
|
extractRemoteShared: () => extractRemoteShared,
|
|
24
23
|
extractScripts: () => extractScripts,
|
|
@@ -31,6 +30,7 @@ __export(parse_remote_html_exports, {
|
|
|
31
30
|
});
|
|
32
31
|
module.exports = __toCommonJS(parse_remote_html_exports);
|
|
33
32
|
var import_constants = require("#internal/runtime/constants");
|
|
33
|
+
var import_metadata = require("#internal/runtime/metadata");
|
|
34
34
|
var import_error = require("#internal/utils/error");
|
|
35
35
|
function validateSingleComponent(doc, name, url) {
|
|
36
36
|
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) || doc.querySelectorAll("remote-component:not([src])").length > 1 && !doc.querySelector(`remote-component[name="${name}"]`)) {
|
|
@@ -50,14 +50,6 @@ function resolveComponentName(component, nextData, fallbackName) {
|
|
|
50
50
|
const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
|
|
51
51
|
return { name, isRemoteComponent };
|
|
52
52
|
}
|
|
53
|
-
function extractComponentMetadata(component, nextData, name, url) {
|
|
54
|
-
return {
|
|
55
|
-
name,
|
|
56
|
-
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
|
|
57
|
-
route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || import_constants.DEFAULT_ROUTE),
|
|
58
|
-
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || import_constants.RUNTIME_SCRIPT)
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
53
|
function extractRemoteShared(doc, name, nextData) {
|
|
62
54
|
const remoteSharedEl = doc.querySelector(
|
|
63
55
|
`#${name}_shared[data-remote-components-shared]`
|
|
@@ -69,7 +61,7 @@ function extractRemoteShared(doc, name, nextData) {
|
|
|
69
61
|
function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
|
|
70
62
|
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
71
63
|
throw new import_error.RemoteComponentsError(
|
|
72
|
-
`Remote Component not found on ${url}.${name !==
|
|
64
|
+
`Remote Component not found on ${url}.${name !== import_constants.DEFAULT_COMPONENT_NAME ? ` The name for the <RemoteComponent> is "${name}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
|
|
73
65
|
);
|
|
74
66
|
}
|
|
75
67
|
}
|
|
@@ -95,10 +87,15 @@ function parseRemoteComponentDocument(doc, name, url) {
|
|
|
95
87
|
name
|
|
96
88
|
);
|
|
97
89
|
const rsc = doc.querySelector(`#${resolvedName}_rsc`);
|
|
98
|
-
const metadata =
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
const metadata = (0, import_metadata.buildMetadata)(
|
|
91
|
+
{
|
|
92
|
+
name: resolvedName,
|
|
93
|
+
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle,
|
|
94
|
+
route: component?.getAttribute("data-route") ?? nextData?.page,
|
|
95
|
+
runtime: component?.getAttribute("data-runtime") ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? import_constants.RUNTIME_SCRIPT,
|
|
96
|
+
id: component?.getAttribute("id"),
|
|
97
|
+
type: component?.getAttribute("data-type")
|
|
98
|
+
},
|
|
102
99
|
url
|
|
103
100
|
);
|
|
104
101
|
const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
|
|
@@ -126,7 +123,6 @@ function parseRemoteComponentDocument(doc, name, url) {
|
|
|
126
123
|
}
|
|
127
124
|
// Annotate the CommonJS export names for ESM import in node:
|
|
128
125
|
0 && (module.exports = {
|
|
129
|
-
extractComponentMetadata,
|
|
130
126
|
extractLinks,
|
|
131
127
|
extractRemoteShared,
|
|
132
128
|
extractScripts,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/html/parse-remote-html.ts"],"sourcesContent":["import type { NextData } from '#internal/host/server/types';\nimport { DEFAULT_ROUTE, RUNTIME_SCRIPT } from '#internal/runtime/constants';\nimport type { RemoteComponentMetadata } from '#internal/runtime/metadata';\nimport {\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\n\nexport interface ParsedRemoteComponent {\n /** The DOM element representing the remote component content. */\n component: Element;\n /** Resolved name of the remote component (with _ssr suffix stripped). */\n name: string;\n /** Whether the component is a <remote-component> custom element. */\n isRemoteComponent: boolean;\n /** Component metadata: bundle, route, runtime. */\n metadata: {\n name: string;\n bundle: string;\n route: string;\n runtime: RemoteComponentMetadata['runtime'];\n };\n /** Parsed __NEXT_DATA__ or __REMOTE_NEXT_DATA__, or null. */\n nextData: NextData | null;\n /** The RSC flight data script element, or null. */\n rsc: Element | null;\n /** Shared module map extracted from the component's shared data script. */\n remoteShared: Record<string, string>;\n /** Link elements extracted from the document (outside the component). */\n links: HTMLLinkElement[];\n /** Script elements extracted from the component or document. */\n scripts: HTMLScriptElement[];\n}\n\n/**\n * Validates that the document does not contain multiple unnamed remote components.\n * When multiple components exist, the consumer must specify a name to select one.\n */\nexport function validateSingleComponent(\n doc: Document,\n name: string,\n url: string,\n): void {\n if (\n (doc.querySelectorAll('div[data-bundle][data-route]').length > 1 &&\n !doc.querySelector(`div[data-bundle][data-route][id^=\"${name}\"]`)) ||\n (doc.querySelectorAll('remote-component:not([src])').length > 1 &&\n !doc.querySelector(`remote-component[name=\"${name}\"]`))\n ) {\n throw multipleRemoteComponentsError(url);\n }\n}\n\n/**\n * Finds the remote component element in the parsed HTML document using the\n * standard querySelector chain. Returns null if no component is found.\n */\nexport function findComponentElement(\n doc: Document,\n name: string,\n): Element | null {\n return (\n doc.querySelector(`div[data-bundle][data-route][id^=\"${name}\"]`) ??\n doc.querySelector('div[data-bundle][data-route]') ??\n doc.querySelector('div#__next') ??\n doc.querySelector(`remote-component[name=\"${name}\"]:not([src])`) ??\n doc.querySelector('remote-component:not([src])')\n );\n}\n\n/**\n * Parses the __NEXT_DATA__ or __REMOTE_NEXT_DATA__ script element from the document.\n */\nexport function parseNextData(doc: Document): NextData | null {\n return JSON.parse(\n (\n doc.querySelector('#__NEXT_DATA__') ??\n doc.querySelector('#__REMOTE_NEXT_DATA__')\n )?.textContent ?? 'null',\n ) as NextData | null;\n}\n\n/**\n * Resolves the component name from the element's id attribute, the name attribute\n * (for <remote-component> elements), nextData, or a fallback value.\n * Strips the _ssr suffix from the id if present.\n */\nexport function resolveComponentName(\n component: Element | null,\n nextData: NextData | null,\n fallbackName: string,\n): { name: string; isRemoteComponent: boolean } {\n const isRemoteComponent =\n component?.tagName.toLowerCase() === 'remote-component';\n\n const name =\n component?.getAttribute('id')?.replace(/_ssr$/, '') ||\n (isRemoteComponent && component?.getAttribute('name')) ||\n (nextData ? '__next' : fallbackName);\n\n return { name, isRemoteComponent };\n}\n\n/**\n * Extracts component metadata (bundle, route, runtime) from the component element\n * and Next.js data.\n */\nexport function extractComponentMetadata(\n component: Element | null,\n nextData: NextData | null,\n name: string,\n url: URL,\n): ParsedRemoteComponent['metadata'] {\n return {\n name,\n bundle:\n component?.getAttribute('data-bundle') ||\n nextData?.props.__REMOTE_COMPONENT__?.bundle ||\n 'default',\n route:\n component?.getAttribute('data-route') ??\n nextData?.page ??\n (url.pathname || DEFAULT_ROUTE),\n runtime: (component?.getAttribute('data-runtime') ??\n (nextData?.props.__REMOTE_COMPONENT__?.runtime ||\n RUNTIME_SCRIPT)) as RemoteComponentMetadata['runtime'],\n };\n}\n\n/**\n * Extracts the shared module map from the document and removes the element.\n * Falls back to nextData's shared modules if available.\n */\nexport function extractRemoteShared(\n doc: Document,\n name: string,\n nextData: NextData | null,\n): Record<string, string> {\n const remoteSharedEl = doc.querySelector(\n `#${name}_shared[data-remote-components-shared]`,\n );\n const remoteShared =\n nextData?.props.__REMOTE_COMPONENT__?.shared ??\n ((JSON.parse(remoteSharedEl?.textContent ?? '{}') ?? {}) as Record<\n string,\n string\n >);\n remoteSharedEl?.remove();\n return remoteShared;\n}\n\n/**\n * Validates that a remote component was found in the document and that it has\n * RSC data, Next.js data, or is a <remote-component> element.\n * Acts as a type assertion - narrows component to non-null on success.\n */\nexport function validateComponentFound(\n component: Element | null,\n rsc: Element | null,\n nextData: NextData | null,\n isRemoteComponent: boolean,\n url: string,\n name: string,\n): asserts component is Element {\n if (!component || !(rsc || nextData || isRemoteComponent)) {\n throw new RemoteComponentsError(\n `Remote Component not found on ${url}.${\n name !== '__vercel_remote_component'\n ? ` The name for the <RemoteComponent> is \"${name}\". Check <RemoteComponent> usage.`\n : ''\n } Did you forget to wrap the content in <RemoteComponent>?`,\n );\n }\n}\n\n/**\n * Extracts link elements from the document that are not inside the component.\n */\nexport function extractLinks(\n doc: Document,\n component: Element,\n): HTMLLinkElement[] {\n return Array.from(doc.querySelectorAll<HTMLLinkElement>('link[href]')).filter(\n (link) => !component.contains(link),\n );\n}\n\n/**\n * Extracts script elements from the component or document, depending on whether\n * the component is a <remote-component> custom element.\n */\nexport function extractScripts(\n doc: Document,\n component: Element,\n isRemoteComponent: boolean,\n): HTMLScriptElement[] {\n return Array.from(\n (isRemoteComponent ? component : doc).querySelectorAll<HTMLScriptElement>(\n 'script[src],script[data-src]',\n ),\n );\n}\n\n/**\n * Parses a remote component HTML document and extracts all data needed for\n * loading and hydrating the component. This is the main orchestrator that\n * calls the individual extraction functions.\n */\nexport function parseRemoteComponentDocument(\n doc: Document,\n name: string,\n url: URL,\n): ParsedRemoteComponent {\n validateSingleComponent(doc, name, url.href);\n\n const component = findComponentElement(doc, name);\n const nextData = parseNextData(doc);\n\n const { name: resolvedName, isRemoteComponent } = resolveComponentName(\n component,\n nextData,\n name,\n );\n\n const rsc = doc.querySelector(`#${resolvedName}_rsc`);\n const metadata = extractComponentMetadata(\n component,\n nextData,\n resolvedName,\n url,\n );\n const remoteShared = extractRemoteShared(doc, resolvedName, nextData);\n\n validateComponentFound(\n component,\n rsc,\n nextData,\n isRemoteComponent,\n url.href,\n resolvedName,\n );\n\n const links = extractLinks(doc, component);\n const scripts = extractScripts(doc, component, isRemoteComponent);\n\n return {\n component,\n name: resolvedName,\n isRemoteComponent,\n metadata,\n nextData,\n rsc,\n remoteShared,\n links,\n scripts,\n };\n}\n"],"mappings":"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","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/html/parse-remote-html.ts"],"sourcesContent":["import type { NextData } from '#internal/host/server/types';\nimport {\n DEFAULT_COMPONENT_NAME,\n RUNTIME_SCRIPT,\n} from '#internal/runtime/constants';\nimport {\n buildMetadata,\n type RemoteComponentMetadata,\n} from '#internal/runtime/metadata';\nimport {\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\n\nexport interface ParsedRemoteComponent {\n /** The DOM element representing the remote component content. */\n component: Element;\n /** Resolved name of the remote component (with _ssr suffix stripped). */\n name: string;\n /** Whether the component is a <remote-component> custom element. */\n isRemoteComponent: boolean;\n /** Component metadata: bundle, route, runtime. */\n metadata: RemoteComponentMetadata;\n /** Parsed __NEXT_DATA__ or __REMOTE_NEXT_DATA__, or null. */\n nextData: NextData | null;\n /** The RSC flight data script element, or null. */\n rsc: Element | null;\n /** Shared module map extracted from the component's shared data script. */\n remoteShared: Record<string, string>;\n /** Link elements extracted from the document (outside the component). */\n links: HTMLLinkElement[];\n /** Script elements extracted from the component or document. */\n scripts: HTMLScriptElement[];\n}\n\n/**\n * Validates that the document does not contain multiple unnamed remote components.\n * When multiple components exist, the consumer must specify a name to select one.\n */\nexport function validateSingleComponent(\n doc: Document,\n name: string,\n url: string,\n): void {\n if (\n (doc.querySelectorAll('div[data-bundle][data-route]').length > 1 &&\n !doc.querySelector(`div[data-bundle][data-route][id^=\"${name}\"]`)) ||\n (doc.querySelectorAll('remote-component:not([src])').length > 1 &&\n !doc.querySelector(`remote-component[name=\"${name}\"]`))\n ) {\n throw multipleRemoteComponentsError(url);\n }\n}\n\n/**\n * Finds the remote component element in the parsed HTML document using the\n * standard querySelector chain. Returns null if no component is found.\n */\nexport function findComponentElement(\n doc: Document,\n name: string,\n): Element | null {\n return (\n doc.querySelector(`div[data-bundle][data-route][id^=\"${name}\"]`) ??\n doc.querySelector('div[data-bundle][data-route]') ??\n doc.querySelector('div#__next') ??\n doc.querySelector(`remote-component[name=\"${name}\"]:not([src])`) ??\n doc.querySelector('remote-component:not([src])')\n );\n}\n\n/**\n * Parses the __NEXT_DATA__ or __REMOTE_NEXT_DATA__ script element from the document.\n */\nexport function parseNextData(doc: Document): NextData | null {\n return JSON.parse(\n (\n doc.querySelector('#__NEXT_DATA__') ??\n doc.querySelector('#__REMOTE_NEXT_DATA__')\n )?.textContent ?? 'null',\n ) as NextData | null;\n}\n\n/**\n * Resolves the component name from the element's id attribute, the name attribute\n * (for <remote-component> elements), nextData, or a fallback value.\n * Strips the _ssr suffix from the id if present.\n */\nexport function resolveComponentName(\n component: Element | null,\n nextData: NextData | null,\n fallbackName: string,\n): { name: string; isRemoteComponent: boolean } {\n const isRemoteComponent =\n component?.tagName.toLowerCase() === 'remote-component';\n\n const name =\n component?.getAttribute('id')?.replace(/_ssr$/, '') ||\n (isRemoteComponent && component?.getAttribute('name')) ||\n (nextData ? '__next' : fallbackName);\n\n return { name, isRemoteComponent };\n}\n\n/**\n * Extracts the shared module map from the document and removes the element.\n * Falls back to nextData's shared modules if available.\n */\nexport function extractRemoteShared(\n doc: Document,\n name: string,\n nextData: NextData | null,\n): Record<string, string> {\n const remoteSharedEl = doc.querySelector(\n `#${name}_shared[data-remote-components-shared]`,\n );\n const remoteShared =\n nextData?.props.__REMOTE_COMPONENT__?.shared ??\n ((JSON.parse(remoteSharedEl?.textContent ?? '{}') ?? {}) as Record<\n string,\n string\n >);\n remoteSharedEl?.remove();\n return remoteShared;\n}\n\n/**\n * Validates that a remote component was found in the document and that it has\n * RSC data, Next.js data, or is a <remote-component> element.\n * Acts as a type assertion - narrows component to non-null on success.\n */\nexport function validateComponentFound(\n component: Element | null,\n rsc: Element | null,\n nextData: NextData | null,\n isRemoteComponent: boolean,\n url: string,\n name: string,\n): asserts component is Element {\n if (!component || !(rsc || nextData || isRemoteComponent)) {\n throw new RemoteComponentsError(\n `Remote Component not found on ${url}.${\n name !== DEFAULT_COMPONENT_NAME\n ? ` The name for the <RemoteComponent> is \"${name}\". Check <RemoteComponent> usage.`\n : ''\n } Did you forget to wrap the content in <RemoteComponent>?`,\n );\n }\n}\n\n/**\n * Extracts link elements from the document that are not inside the component.\n */\nexport function extractLinks(\n doc: Document,\n component: Element,\n): HTMLLinkElement[] {\n return Array.from(doc.querySelectorAll<HTMLLinkElement>('link[href]')).filter(\n (link) => !component.contains(link),\n );\n}\n\n/**\n * Extracts script elements from the component or document, depending on whether\n * the component is a <remote-component> custom element.\n */\nexport function extractScripts(\n doc: Document,\n component: Element,\n isRemoteComponent: boolean,\n): HTMLScriptElement[] {\n return Array.from(\n (isRemoteComponent ? component : doc).querySelectorAll<HTMLScriptElement>(\n 'script[src],script[data-src]',\n ),\n );\n}\n\n/**\n * Parses a remote component HTML document and extracts all data needed for\n * loading and hydrating the component. This is the main orchestrator that\n * calls the individual extraction functions.\n */\nexport function parseRemoteComponentDocument(\n doc: Document,\n name: string,\n url: URL,\n): ParsedRemoteComponent {\n validateSingleComponent(doc, name, url.href);\n\n const component = findComponentElement(doc, name);\n const nextData = parseNextData(doc);\n\n const { name: resolvedName, isRemoteComponent } = resolveComponentName(\n component,\n nextData,\n name,\n );\n\n const rsc = doc.querySelector(`#${resolvedName}_rsc`);\n const metadata = buildMetadata(\n {\n name: resolvedName,\n bundle:\n component?.getAttribute('data-bundle') ||\n nextData?.props.__REMOTE_COMPONENT__?.bundle,\n route: component?.getAttribute('data-route') ?? nextData?.page,\n runtime:\n component?.getAttribute('data-runtime') ??\n nextData?.props.__REMOTE_COMPONENT__?.runtime ??\n RUNTIME_SCRIPT,\n id: component?.getAttribute('id'),\n type: component?.getAttribute('data-type'),\n },\n url,\n );\n const remoteShared = extractRemoteShared(doc, resolvedName, nextData);\n\n validateComponentFound(\n component,\n rsc,\n nextData,\n isRemoteComponent,\n url.href,\n resolvedName,\n );\n\n const links = extractLinks(doc, component);\n const scripts = extractScripts(doc, component, isRemoteComponent);\n\n return {\n component,\n name: resolvedName,\n isRemoteComponent,\n metadata,\n nextData,\n rsc,\n remoteShared,\n links,\n scripts,\n };\n}\n"],"mappings":"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","names":[]}
|
|
@@ -13,12 +13,7 @@ interface ParsedRemoteComponent {
|
|
|
13
13
|
/** Whether the component is a <remote-component> custom element. */
|
|
14
14
|
isRemoteComponent: boolean;
|
|
15
15
|
/** Component metadata: bundle, route, runtime. */
|
|
16
|
-
metadata:
|
|
17
|
-
name: string;
|
|
18
|
-
bundle: string;
|
|
19
|
-
route: string;
|
|
20
|
-
runtime: RemoteComponentMetadata['runtime'];
|
|
21
|
-
};
|
|
16
|
+
metadata: RemoteComponentMetadata;
|
|
22
17
|
/** Parsed __NEXT_DATA__ or __REMOTE_NEXT_DATA__, or null. */
|
|
23
18
|
nextData: NextData | null;
|
|
24
19
|
/** The RSC flight data script element, or null. */
|
|
@@ -53,11 +48,6 @@ declare function resolveComponentName(component: Element | null, nextData: NextD
|
|
|
53
48
|
name: string;
|
|
54
49
|
isRemoteComponent: boolean;
|
|
55
50
|
};
|
|
56
|
-
/**
|
|
57
|
-
* Extracts component metadata (bundle, route, runtime) from the component element
|
|
58
|
-
* and Next.js data.
|
|
59
|
-
*/
|
|
60
|
-
declare function extractComponentMetadata(component: Element | null, nextData: NextData | null, name: string, url: URL): ParsedRemoteComponent['metadata'];
|
|
61
51
|
/**
|
|
62
52
|
* Extracts the shared module map from the document and removes the element.
|
|
63
53
|
* Falls back to nextData's shared modules if available.
|
|
@@ -85,4 +75,4 @@ declare function extractScripts(doc: Document, component: Element, isRemoteCompo
|
|
|
85
75
|
*/
|
|
86
76
|
declare function parseRemoteComponentDocument(doc: Document, name: string, url: URL): ParsedRemoteComponent;
|
|
87
77
|
|
|
88
|
-
export { ParsedRemoteComponent,
|
|
78
|
+
export { ParsedRemoteComponent, extractLinks, extractRemoteShared, extractScripts, findComponentElement, parseNextData, parseRemoteComponentDocument, resolveComponentName, validateComponentFound, validateSingleComponent };
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_COMPONENT_NAME,
|
|
3
|
+
RUNTIME_SCRIPT
|
|
4
|
+
} from "#internal/runtime/constants";
|
|
5
|
+
import {
|
|
6
|
+
buildMetadata
|
|
7
|
+
} from "#internal/runtime/metadata";
|
|
2
8
|
import {
|
|
3
9
|
multipleRemoteComponentsError,
|
|
4
10
|
RemoteComponentsError
|
|
@@ -21,14 +27,6 @@ function resolveComponentName(component, nextData, fallbackName) {
|
|
|
21
27
|
const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
|
|
22
28
|
return { name, isRemoteComponent };
|
|
23
29
|
}
|
|
24
|
-
function extractComponentMetadata(component, nextData, name, url) {
|
|
25
|
-
return {
|
|
26
|
-
name,
|
|
27
|
-
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
|
|
28
|
-
route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
|
|
29
|
-
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
30
|
function extractRemoteShared(doc, name, nextData) {
|
|
33
31
|
const remoteSharedEl = doc.querySelector(
|
|
34
32
|
`#${name}_shared[data-remote-components-shared]`
|
|
@@ -40,7 +38,7 @@ function extractRemoteShared(doc, name, nextData) {
|
|
|
40
38
|
function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
|
|
41
39
|
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
42
40
|
throw new RemoteComponentsError(
|
|
43
|
-
`Remote Component not found on ${url}.${name !==
|
|
41
|
+
`Remote Component not found on ${url}.${name !== DEFAULT_COMPONENT_NAME ? ` The name for the <RemoteComponent> is "${name}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
|
|
44
42
|
);
|
|
45
43
|
}
|
|
46
44
|
}
|
|
@@ -66,10 +64,15 @@ function parseRemoteComponentDocument(doc, name, url) {
|
|
|
66
64
|
name
|
|
67
65
|
);
|
|
68
66
|
const rsc = doc.querySelector(`#${resolvedName}_rsc`);
|
|
69
|
-
const metadata =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
const metadata = buildMetadata(
|
|
68
|
+
{
|
|
69
|
+
name: resolvedName,
|
|
70
|
+
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle,
|
|
71
|
+
route: component?.getAttribute("data-route") ?? nextData?.page,
|
|
72
|
+
runtime: component?.getAttribute("data-runtime") ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? RUNTIME_SCRIPT,
|
|
73
|
+
id: component?.getAttribute("id"),
|
|
74
|
+
type: component?.getAttribute("data-type")
|
|
75
|
+
},
|
|
73
76
|
url
|
|
74
77
|
);
|
|
75
78
|
const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
|
|
@@ -96,7 +99,6 @@ function parseRemoteComponentDocument(doc, name, url) {
|
|
|
96
99
|
};
|
|
97
100
|
}
|
|
98
101
|
export {
|
|
99
|
-
extractComponentMetadata,
|
|
100
102
|
extractLinks,
|
|
101
103
|
extractRemoteShared,
|
|
102
104
|
extractScripts,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/html/parse-remote-html.ts"],"sourcesContent":["import type { NextData } from '#internal/host/server/types';\nimport { DEFAULT_ROUTE, RUNTIME_SCRIPT } from '#internal/runtime/constants';\nimport type { RemoteComponentMetadata } from '#internal/runtime/metadata';\nimport {\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\n\nexport interface ParsedRemoteComponent {\n /** The DOM element representing the remote component content. */\n component: Element;\n /** Resolved name of the remote component (with _ssr suffix stripped). */\n name: string;\n /** Whether the component is a <remote-component> custom element. */\n isRemoteComponent: boolean;\n /** Component metadata: bundle, route, runtime. */\n metadata: {\n name: string;\n bundle: string;\n route: string;\n runtime: RemoteComponentMetadata['runtime'];\n };\n /** Parsed __NEXT_DATA__ or __REMOTE_NEXT_DATA__, or null. */\n nextData: NextData | null;\n /** The RSC flight data script element, or null. */\n rsc: Element | null;\n /** Shared module map extracted from the component's shared data script. */\n remoteShared: Record<string, string>;\n /** Link elements extracted from the document (outside the component). */\n links: HTMLLinkElement[];\n /** Script elements extracted from the component or document. */\n scripts: HTMLScriptElement[];\n}\n\n/**\n * Validates that the document does not contain multiple unnamed remote components.\n * When multiple components exist, the consumer must specify a name to select one.\n */\nexport function validateSingleComponent(\n doc: Document,\n name: string,\n url: string,\n): void {\n if (\n (doc.querySelectorAll('div[data-bundle][data-route]').length > 1 &&\n !doc.querySelector(`div[data-bundle][data-route][id^=\"${name}\"]`)) ||\n (doc.querySelectorAll('remote-component:not([src])').length > 1 &&\n !doc.querySelector(`remote-component[name=\"${name}\"]`))\n ) {\n throw multipleRemoteComponentsError(url);\n }\n}\n\n/**\n * Finds the remote component element in the parsed HTML document using the\n * standard querySelector chain. Returns null if no component is found.\n */\nexport function findComponentElement(\n doc: Document,\n name: string,\n): Element | null {\n return (\n doc.querySelector(`div[data-bundle][data-route][id^=\"${name}\"]`) ??\n doc.querySelector('div[data-bundle][data-route]') ??\n doc.querySelector('div#__next') ??\n doc.querySelector(`remote-component[name=\"${name}\"]:not([src])`) ??\n doc.querySelector('remote-component:not([src])')\n );\n}\n\n/**\n * Parses the __NEXT_DATA__ or __REMOTE_NEXT_DATA__ script element from the document.\n */\nexport function parseNextData(doc: Document): NextData | null {\n return JSON.parse(\n (\n doc.querySelector('#__NEXT_DATA__') ??\n doc.querySelector('#__REMOTE_NEXT_DATA__')\n )?.textContent ?? 'null',\n ) as NextData | null;\n}\n\n/**\n * Resolves the component name from the element's id attribute, the name attribute\n * (for <remote-component> elements), nextData, or a fallback value.\n * Strips the _ssr suffix from the id if present.\n */\nexport function resolveComponentName(\n component: Element | null,\n nextData: NextData | null,\n fallbackName: string,\n): { name: string; isRemoteComponent: boolean } {\n const isRemoteComponent =\n component?.tagName.toLowerCase() === 'remote-component';\n\n const name =\n component?.getAttribute('id')?.replace(/_ssr$/, '') ||\n (isRemoteComponent && component?.getAttribute('name')) ||\n (nextData ? '__next' : fallbackName);\n\n return { name, isRemoteComponent };\n}\n\n/**\n * Extracts component metadata (bundle, route, runtime) from the component element\n * and Next.js data.\n */\nexport function extractComponentMetadata(\n component: Element | null,\n nextData: NextData | null,\n name: string,\n url: URL,\n): ParsedRemoteComponent['metadata'] {\n return {\n name,\n bundle:\n component?.getAttribute('data-bundle') ||\n nextData?.props.__REMOTE_COMPONENT__?.bundle ||\n 'default',\n route:\n component?.getAttribute('data-route') ??\n nextData?.page ??\n (url.pathname || DEFAULT_ROUTE),\n runtime: (component?.getAttribute('data-runtime') ??\n (nextData?.props.__REMOTE_COMPONENT__?.runtime ||\n RUNTIME_SCRIPT)) as RemoteComponentMetadata['runtime'],\n };\n}\n\n/**\n * Extracts the shared module map from the document and removes the element.\n * Falls back to nextData's shared modules if available.\n */\nexport function extractRemoteShared(\n doc: Document,\n name: string,\n nextData: NextData | null,\n): Record<string, string> {\n const remoteSharedEl = doc.querySelector(\n `#${name}_shared[data-remote-components-shared]`,\n );\n const remoteShared =\n nextData?.props.__REMOTE_COMPONENT__?.shared ??\n ((JSON.parse(remoteSharedEl?.textContent ?? '{}') ?? {}) as Record<\n string,\n string\n >);\n remoteSharedEl?.remove();\n return remoteShared;\n}\n\n/**\n * Validates that a remote component was found in the document and that it has\n * RSC data, Next.js data, or is a <remote-component> element.\n * Acts as a type assertion - narrows component to non-null on success.\n */\nexport function validateComponentFound(\n component: Element | null,\n rsc: Element | null,\n nextData: NextData | null,\n isRemoteComponent: boolean,\n url: string,\n name: string,\n): asserts component is Element {\n if (!component || !(rsc || nextData || isRemoteComponent)) {\n throw new RemoteComponentsError(\n `Remote Component not found on ${url}.${\n name !== '__vercel_remote_component'\n ? ` The name for the <RemoteComponent> is \"${name}\". Check <RemoteComponent> usage.`\n : ''\n } Did you forget to wrap the content in <RemoteComponent>?`,\n );\n }\n}\n\n/**\n * Extracts link elements from the document that are not inside the component.\n */\nexport function extractLinks(\n doc: Document,\n component: Element,\n): HTMLLinkElement[] {\n return Array.from(doc.querySelectorAll<HTMLLinkElement>('link[href]')).filter(\n (link) => !component.contains(link),\n );\n}\n\n/**\n * Extracts script elements from the component or document, depending on whether\n * the component is a <remote-component> custom element.\n */\nexport function extractScripts(\n doc: Document,\n component: Element,\n isRemoteComponent: boolean,\n): HTMLScriptElement[] {\n return Array.from(\n (isRemoteComponent ? component : doc).querySelectorAll<HTMLScriptElement>(\n 'script[src],script[data-src]',\n ),\n );\n}\n\n/**\n * Parses a remote component HTML document and extracts all data needed for\n * loading and hydrating the component. This is the main orchestrator that\n * calls the individual extraction functions.\n */\nexport function parseRemoteComponentDocument(\n doc: Document,\n name: string,\n url: URL,\n): ParsedRemoteComponent {\n validateSingleComponent(doc, name, url.href);\n\n const component = findComponentElement(doc, name);\n const nextData = parseNextData(doc);\n\n const { name: resolvedName, isRemoteComponent } = resolveComponentName(\n component,\n nextData,\n name,\n );\n\n const rsc = doc.querySelector(`#${resolvedName}_rsc`);\n const metadata = extractComponentMetadata(\n component,\n nextData,\n resolvedName,\n url,\n );\n const remoteShared = extractRemoteShared(doc, resolvedName, nextData);\n\n validateComponentFound(\n component,\n rsc,\n nextData,\n isRemoteComponent,\n url.href,\n resolvedName,\n );\n\n const links = extractLinks(doc, component);\n const scripts = extractScripts(doc, component, isRemoteComponent);\n\n return {\n component,\n name: resolvedName,\n isRemoteComponent,\n metadata,\n nextData,\n rsc,\n remoteShared,\n links,\n scripts,\n };\n}\n"],"mappings":"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","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/html/parse-remote-html.ts"],"sourcesContent":["import type { NextData } from '#internal/host/server/types';\nimport {\n DEFAULT_COMPONENT_NAME,\n RUNTIME_SCRIPT,\n} from '#internal/runtime/constants';\nimport {\n buildMetadata,\n type RemoteComponentMetadata,\n} from '#internal/runtime/metadata';\nimport {\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\n\nexport interface ParsedRemoteComponent {\n /** The DOM element representing the remote component content. */\n component: Element;\n /** Resolved name of the remote component (with _ssr suffix stripped). */\n name: string;\n /** Whether the component is a <remote-component> custom element. */\n isRemoteComponent: boolean;\n /** Component metadata: bundle, route, runtime. */\n metadata: RemoteComponentMetadata;\n /** Parsed __NEXT_DATA__ or __REMOTE_NEXT_DATA__, or null. */\n nextData: NextData | null;\n /** The RSC flight data script element, or null. */\n rsc: Element | null;\n /** Shared module map extracted from the component's shared data script. */\n remoteShared: Record<string, string>;\n /** Link elements extracted from the document (outside the component). */\n links: HTMLLinkElement[];\n /** Script elements extracted from the component or document. */\n scripts: HTMLScriptElement[];\n}\n\n/**\n * Validates that the document does not contain multiple unnamed remote components.\n * When multiple components exist, the consumer must specify a name to select one.\n */\nexport function validateSingleComponent(\n doc: Document,\n name: string,\n url: string,\n): void {\n if (\n (doc.querySelectorAll('div[data-bundle][data-route]').length > 1 &&\n !doc.querySelector(`div[data-bundle][data-route][id^=\"${name}\"]`)) ||\n (doc.querySelectorAll('remote-component:not([src])').length > 1 &&\n !doc.querySelector(`remote-component[name=\"${name}\"]`))\n ) {\n throw multipleRemoteComponentsError(url);\n }\n}\n\n/**\n * Finds the remote component element in the parsed HTML document using the\n * standard querySelector chain. Returns null if no component is found.\n */\nexport function findComponentElement(\n doc: Document,\n name: string,\n): Element | null {\n return (\n doc.querySelector(`div[data-bundle][data-route][id^=\"${name}\"]`) ??\n doc.querySelector('div[data-bundle][data-route]') ??\n doc.querySelector('div#__next') ??\n doc.querySelector(`remote-component[name=\"${name}\"]:not([src])`) ??\n doc.querySelector('remote-component:not([src])')\n );\n}\n\n/**\n * Parses the __NEXT_DATA__ or __REMOTE_NEXT_DATA__ script element from the document.\n */\nexport function parseNextData(doc: Document): NextData | null {\n return JSON.parse(\n (\n doc.querySelector('#__NEXT_DATA__') ??\n doc.querySelector('#__REMOTE_NEXT_DATA__')\n )?.textContent ?? 'null',\n ) as NextData | null;\n}\n\n/**\n * Resolves the component name from the element's id attribute, the name attribute\n * (for <remote-component> elements), nextData, or a fallback value.\n * Strips the _ssr suffix from the id if present.\n */\nexport function resolveComponentName(\n component: Element | null,\n nextData: NextData | null,\n fallbackName: string,\n): { name: string; isRemoteComponent: boolean } {\n const isRemoteComponent =\n component?.tagName.toLowerCase() === 'remote-component';\n\n const name =\n component?.getAttribute('id')?.replace(/_ssr$/, '') ||\n (isRemoteComponent && component?.getAttribute('name')) ||\n (nextData ? '__next' : fallbackName);\n\n return { name, isRemoteComponent };\n}\n\n/**\n * Extracts the shared module map from the document and removes the element.\n * Falls back to nextData's shared modules if available.\n */\nexport function extractRemoteShared(\n doc: Document,\n name: string,\n nextData: NextData | null,\n): Record<string, string> {\n const remoteSharedEl = doc.querySelector(\n `#${name}_shared[data-remote-components-shared]`,\n );\n const remoteShared =\n nextData?.props.__REMOTE_COMPONENT__?.shared ??\n ((JSON.parse(remoteSharedEl?.textContent ?? '{}') ?? {}) as Record<\n string,\n string\n >);\n remoteSharedEl?.remove();\n return remoteShared;\n}\n\n/**\n * Validates that a remote component was found in the document and that it has\n * RSC data, Next.js data, or is a <remote-component> element.\n * Acts as a type assertion - narrows component to non-null on success.\n */\nexport function validateComponentFound(\n component: Element | null,\n rsc: Element | null,\n nextData: NextData | null,\n isRemoteComponent: boolean,\n url: string,\n name: string,\n): asserts component is Element {\n if (!component || !(rsc || nextData || isRemoteComponent)) {\n throw new RemoteComponentsError(\n `Remote Component not found on ${url}.${\n name !== DEFAULT_COMPONENT_NAME\n ? ` The name for the <RemoteComponent> is \"${name}\". Check <RemoteComponent> usage.`\n : ''\n } Did you forget to wrap the content in <RemoteComponent>?`,\n );\n }\n}\n\n/**\n * Extracts link elements from the document that are not inside the component.\n */\nexport function extractLinks(\n doc: Document,\n component: Element,\n): HTMLLinkElement[] {\n return Array.from(doc.querySelectorAll<HTMLLinkElement>('link[href]')).filter(\n (link) => !component.contains(link),\n );\n}\n\n/**\n * Extracts script elements from the component or document, depending on whether\n * the component is a <remote-component> custom element.\n */\nexport function extractScripts(\n doc: Document,\n component: Element,\n isRemoteComponent: boolean,\n): HTMLScriptElement[] {\n return Array.from(\n (isRemoteComponent ? component : doc).querySelectorAll<HTMLScriptElement>(\n 'script[src],script[data-src]',\n ),\n );\n}\n\n/**\n * Parses a remote component HTML document and extracts all data needed for\n * loading and hydrating the component. This is the main orchestrator that\n * calls the individual extraction functions.\n */\nexport function parseRemoteComponentDocument(\n doc: Document,\n name: string,\n url: URL,\n): ParsedRemoteComponent {\n validateSingleComponent(doc, name, url.href);\n\n const component = findComponentElement(doc, name);\n const nextData = parseNextData(doc);\n\n const { name: resolvedName, isRemoteComponent } = resolveComponentName(\n component,\n nextData,\n name,\n );\n\n const rsc = doc.querySelector(`#${resolvedName}_rsc`);\n const metadata = buildMetadata(\n {\n name: resolvedName,\n bundle:\n component?.getAttribute('data-bundle') ||\n nextData?.props.__REMOTE_COMPONENT__?.bundle,\n route: component?.getAttribute('data-route') ?? nextData?.page,\n runtime:\n component?.getAttribute('data-runtime') ??\n nextData?.props.__REMOTE_COMPONENT__?.runtime ??\n RUNTIME_SCRIPT,\n id: component?.getAttribute('id'),\n type: component?.getAttribute('data-type'),\n },\n url,\n );\n const remoteShared = extractRemoteShared(doc, resolvedName, nextData);\n\n validateComponentFound(\n component,\n rsc,\n nextData,\n isRemoteComponent,\n url.href,\n resolvedName,\n );\n\n const links = extractLinks(doc, component);\n const scripts = extractScripts(doc, component, isRemoteComponent);\n\n return {\n component,\n name: resolvedName,\n isRemoteComponent,\n metadata,\n nextData,\n rsc,\n remoteShared,\n links,\n scripts,\n };\n}\n"],"mappings":"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","names":[]}
|
|
@@ -21,7 +21,7 @@ __export(script_loader_exports, {
|
|
|
21
21
|
loadScripts: () => loadScripts
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(script_loader_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_patterns = require("#internal/runtime/patterns");
|
|
25
25
|
var import_protected_rc_fallback = require("#internal/runtime/url/protected-rc-fallback");
|
|
26
26
|
var import_error = require("#internal/utils/error");
|
|
27
27
|
var import_logger = require("#internal/utils/logger");
|
|
@@ -31,7 +31,7 @@ async function loadScripts(scripts, resolveClientUrl) {
|
|
|
31
31
|
return new Promise((resolve, reject) => {
|
|
32
32
|
const newSrc = new URL(
|
|
33
33
|
// remove the remote component bundle name identifier from the script src
|
|
34
|
-
script.src.replace(
|
|
34
|
+
script.src.replace(import_patterns.NEXT_BUNDLE_PATH_RE, "/_next/"),
|
|
35
35
|
location.origin
|
|
36
36
|
).href;
|
|
37
37
|
const resolvedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/loaders/script-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { NEXT_BUNDLE_PATH_RE } from '#internal/runtime/
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/loaders/script-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { NEXT_BUNDLE_PATH_RE } from '#internal/runtime/patterns';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport { warnCrossOriginFetchError } from '#internal/utils/logger';\n\n/**\n * Loads external scripts for remote components\n */\nexport async function loadScripts(\n scripts: { src: string }[],\n resolveClientUrl?: InternalResolveClientUrl,\n): Promise<void> {\n await Promise.all(\n scripts.map((script) => {\n return new Promise<void>((resolve, reject) => {\n const newSrc = new URL(\n // remove the remote component bundle name identifier from the script src\n script.src.replace(NEXT_BUNDLE_PATH_RE, '/_next/'),\n location.origin,\n ).href;\n\n const resolvedSrc = resolveClientUrl?.(newSrc) ?? newSrc;\n\n const newScript = document.createElement('script');\n newScript.onload = () => resolve();\n newScript.onerror = () => {\n const isProxied = isProxiedUrl(resolvedSrc);\n if (isProxied) {\n reject(failedProxiedAssetError('script', newSrc, resolvedSrc));\n } else {\n warnCrossOriginFetchError('ScriptLoader', newSrc);\n reject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${newSrc}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n }\n };\n newScript.src = resolvedSrc;\n newScript.async = true;\n document.head.appendChild(newScript);\n });\n }),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAoC;AACpC,mCAA6B;AAC7B,mBAGO;AACP,oBAA0C;AAK1C,eAAsB,YACpB,SACA,kBACe;AACf,QAAM,QAAQ;AAAA,IACZ,QAAQ,IAAI,CAAC,WAAW;AACtB,aAAO,IAAI,QAAc,CAAC,SAAS,WAAW;AAC5C,cAAM,SAAS,IAAI;AAAA;AAAA,UAEjB,OAAO,IAAI,QAAQ,qCAAqB,SAAS;AAAA,UACjD,SAAS;AAAA,QACX,EAAE;AAEF,cAAM,cAAc,mBAAmB,MAAM,KAAK;AAElD,cAAM,YAAY,SAAS,cAAc,QAAQ;AACjD,kBAAU,SAAS,MAAM,QAAQ;AACjC,kBAAU,UAAU,MAAM;AACxB,gBAAM,gBAAY,2CAAa,WAAW;AAC1C,cAAI,WAAW;AACb,uBAAO,sCAAwB,UAAU,QAAQ,WAAW,CAAC;AAAA,UAC/D,OAAO;AACL,yDAA0B,gBAAgB,MAAM;AAChD;AAAA,cACE,IAAI;AAAA,gBACF,+BAA+B;AAAA,cACjC;AAAA,YACF;AAAA,UACF;AAAA,QACF;AACA,kBAAU,MAAM;AAChB,kBAAU,QAAQ;AAClB,iBAAS,KAAK,YAAY,SAAS;AAAA,MACrC,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/loaders/script-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { NEXT_BUNDLE_PATH_RE } from '#internal/runtime/
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/loaders/script-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { NEXT_BUNDLE_PATH_RE } from '#internal/runtime/patterns';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport { warnCrossOriginFetchError } from '#internal/utils/logger';\n\n/**\n * Loads external scripts for remote components\n */\nexport async function loadScripts(\n scripts: { src: string }[],\n resolveClientUrl?: InternalResolveClientUrl,\n): Promise<void> {\n await Promise.all(\n scripts.map((script) => {\n return new Promise<void>((resolve, reject) => {\n const newSrc = new URL(\n // remove the remote component bundle name identifier from the script src\n script.src.replace(NEXT_BUNDLE_PATH_RE, '/_next/'),\n location.origin,\n ).href;\n\n const resolvedSrc = resolveClientUrl?.(newSrc) ?? newSrc;\n\n const newScript = document.createElement('script');\n newScript.onload = () => resolve();\n newScript.onerror = () => {\n const isProxied = isProxiedUrl(resolvedSrc);\n if (isProxied) {\n reject(failedProxiedAssetError('script', newSrc, resolvedSrc));\n } else {\n warnCrossOriginFetchError('ScriptLoader', newSrc);\n reject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${newSrc}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n }\n };\n newScript.src = resolvedSrc;\n newScript.async = true;\n document.head.appendChild(newScript);\n });\n }),\n );\n}\n"],"mappings":"AACA,SAAS,2BAA2B;AACpC,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,iCAAiC;AAK1C,eAAsB,YACpB,SACA,kBACe;AACf,QAAM,QAAQ;AAAA,IACZ,QAAQ,IAAI,CAAC,WAAW;AACtB,aAAO,IAAI,QAAc,CAAC,SAAS,WAAW;AAC5C,cAAM,SAAS,IAAI;AAAA;AAAA,UAEjB,OAAO,IAAI,QAAQ,qBAAqB,SAAS;AAAA,UACjD,SAAS;AAAA,QACX,EAAE;AAEF,cAAM,cAAc,mBAAmB,MAAM,KAAK;AAElD,cAAM,YAAY,SAAS,cAAc,QAAQ;AACjD,kBAAU,SAAS,MAAM,QAAQ;AACjC,kBAAU,UAAU,MAAM;AACxB,gBAAM,YAAY,aAAa,WAAW;AAC1C,cAAI,WAAW;AACb,mBAAO,wBAAwB,UAAU,QAAQ,WAAW,CAAC;AAAA,UAC/D,OAAO;AACL,sCAA0B,gBAAgB,MAAM;AAChD;AAAA,cACE,IAAI;AAAA,gBACF,+BAA+B;AAAA,cACjC;AAAA,YACF;AAAA,UACF;AAAA,QACF;AACA,kBAAU,MAAM;AAChB,kBAAU,QAAQ;AAClB,iBAAS,KAAK,YAAY,SAAS;AAAA,MACrC,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
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
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -13,5 +17,43 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
13
17
|
};
|
|
14
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
19
|
var metadata_exports = {};
|
|
20
|
+
__export(metadata_exports, {
|
|
21
|
+
buildMetadata: () => buildMetadata
|
|
22
|
+
});
|
|
16
23
|
module.exports = __toCommonJS(metadata_exports);
|
|
24
|
+
var import_constants = require("#internal/runtime/constants");
|
|
25
|
+
const VALID_RUNTIMES = /* @__PURE__ */ new Set(["webpack", "turbopack", "script"]);
|
|
26
|
+
const VALID_TYPES = /* @__PURE__ */ new Set([
|
|
27
|
+
"nextjs",
|
|
28
|
+
"remote-component",
|
|
29
|
+
"unknown"
|
|
30
|
+
]);
|
|
31
|
+
function isRuntime(value) {
|
|
32
|
+
return VALID_RUNTIMES.has(value);
|
|
33
|
+
}
|
|
34
|
+
function isComponentType(value) {
|
|
35
|
+
return VALID_TYPES.has(value);
|
|
36
|
+
}
|
|
37
|
+
function toRuntime(value) {
|
|
38
|
+
return value && isRuntime(value) ? value : "webpack";
|
|
39
|
+
}
|
|
40
|
+
function toComponentType(value) {
|
|
41
|
+
return value && isComponentType(value) ? value : "unknown";
|
|
42
|
+
}
|
|
43
|
+
function buildMetadata(attrs, url) {
|
|
44
|
+
const id = attrs.id || import_constants.DEFAULT_COMPONENT_NAME;
|
|
45
|
+
const bundle = attrs.bundle || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || import_constants.DEFAULT_BUNDLE_NAME;
|
|
46
|
+
return {
|
|
47
|
+
name: attrs.name || id.replace(/_ssr$/, ""),
|
|
48
|
+
bundle,
|
|
49
|
+
route: attrs.route || url.pathname || import_constants.DEFAULT_ROUTE,
|
|
50
|
+
runtime: toRuntime(attrs.runtime),
|
|
51
|
+
id,
|
|
52
|
+
type: toComponentType(attrs.type)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
buildMetadata
|
|
58
|
+
});
|
|
17
59
|
//# sourceMappingURL=metadata.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/metadata.ts"],"sourcesContent":["/**\n * Metadata embedded in the HTML response by a remote application.\n *\n * Extracted from a `<script type=\"application/json\" data-remote-component>`\n * element during both SSR parsing ({@link fetchRemoteComponent}) and\n * client-side parsing ({@link parseRemoteComponentDocument}).\n */\nexport interface RemoteComponentMetadata {\n bundle: string;\n route: string;\n runtime: 'webpack' | 'turbopack' | 'script';\n id: string;\n type: 'nextjs' | 'remote-component' | 'unknown';\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/metadata.ts"],"sourcesContent":["import {\n DEFAULT_BUNDLE_NAME,\n DEFAULT_COMPONENT_NAME,\n DEFAULT_ROUTE,\n} from '#internal/runtime/constants';\n\n/**\n * Metadata embedded in the HTML response by a remote application.\n *\n * Extracted from a `<script type=\"application/json\" data-remote-component>`\n * element during both SSR parsing ({@link fetchRemoteComponent}) and\n * client-side parsing ({@link parseRemoteComponentDocument}).\n */\nexport interface RemoteComponentMetadata {\n name: string;\n bundle: string;\n route: string;\n runtime: 'webpack' | 'turbopack' | 'script';\n id: string;\n type: 'nextjs' | 'remote-component' | 'unknown';\n}\n\n/**\n * Raw attribute values before defaults are applied. Accepts nullable strings\n * so callers can pass DOM attributes or parsed JSON directly.\n */\nexport interface RawMetadataAttrs {\n name?: string | null;\n bundle?: string | null;\n route?: string | null;\n runtime?: string | null;\n id?: string | null;\n type?: string | null;\n}\n\nconst VALID_RUNTIMES: Set<string> = new Set(['webpack', 'turbopack', 'script']);\nconst VALID_TYPES: Set<string> = new Set([\n 'nextjs',\n 'remote-component',\n 'unknown',\n]);\n\nfunction isRuntime(value: string): value is RemoteComponentMetadata['runtime'] {\n return VALID_RUNTIMES.has(value);\n}\n\nfunction isComponentType(\n value: string,\n): value is RemoteComponentMetadata['type'] {\n return VALID_TYPES.has(value);\n}\n\nfunction toRuntime(\n value: string | null | undefined,\n): RemoteComponentMetadata['runtime'] {\n return value && isRuntime(value) ? value : 'webpack';\n}\n\nfunction toComponentType(\n value: string | null | undefined,\n): RemoteComponentMetadata['type'] {\n return value && isComponentType(value) ? value : 'unknown';\n}\n\n/**\n * Applies default values to raw metadata attributes and returns a fully\n * resolved {@link RemoteComponentMetadata}. When no bundle is provided, falls\n * back to the `NEXT_PUBLIC_MFE_CURRENT_APPLICATION` env var (the host's\n * application name), then `DEFAULT_BUNDLE_NAME`.\n */\nexport function buildMetadata(\n attrs: RawMetadataAttrs,\n url: URL,\n): RemoteComponentMetadata {\n const id = attrs.id || DEFAULT_COMPONENT_NAME;\n const bundle =\n attrs.bundle ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n DEFAULT_BUNDLE_NAME;\n return {\n name: attrs.name || id.replace(/_ssr$/, ''),\n bundle,\n route: attrs.route || url.pathname || DEFAULT_ROUTE,\n runtime: toRuntime(attrs.runtime),\n id,\n type: toComponentType(attrs.type),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAIO;AA+BP,MAAM,iBAA8B,oBAAI,IAAI,CAAC,WAAW,aAAa,QAAQ,CAAC;AAC9E,MAAM,cAA2B,oBAAI,IAAI;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,UAAU,OAA4D;AAC7E,SAAO,eAAe,IAAI,KAAK;AACjC;AAEA,SAAS,gBACP,OAC0C;AAC1C,SAAO,YAAY,IAAI,KAAK;AAC9B;AAEA,SAAS,UACP,OACoC;AACpC,SAAO,SAAS,UAAU,KAAK,IAAI,QAAQ;AAC7C;AAEA,SAAS,gBACP,OACiC;AACjC,SAAO,SAAS,gBAAgB,KAAK,IAAI,QAAQ;AACnD;AAQO,SAAS,cACd,OACA,KACyB;AACzB,QAAM,KAAK,MAAM,MAAM;AACvB,QAAM,SACJ,MAAM,UACN,QAAQ,IAAI,uCACZ;AACF,SAAO;AAAA,IACL,MAAM,MAAM,QAAQ,GAAG,QAAQ,SAAS,EAAE;AAAA,IAC1C;AAAA,IACA,OAAO,MAAM,SAAS,IAAI,YAAY;AAAA,IACtC,SAAS,UAAU,MAAM,OAAO;AAAA,IAChC;AAAA,IACA,MAAM,gBAAgB,MAAM,IAAI;AAAA,EAClC;AACF;","names":[]}
|
|
@@ -6,11 +6,31 @@
|
|
|
6
6
|
* client-side parsing ({@link parseRemoteComponentDocument}).
|
|
7
7
|
*/
|
|
8
8
|
interface RemoteComponentMetadata {
|
|
9
|
+
name: string;
|
|
9
10
|
bundle: string;
|
|
10
11
|
route: string;
|
|
11
12
|
runtime: 'webpack' | 'turbopack' | 'script';
|
|
12
13
|
id: string;
|
|
13
14
|
type: 'nextjs' | 'remote-component' | 'unknown';
|
|
14
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Raw attribute values before defaults are applied. Accepts nullable strings
|
|
18
|
+
* so callers can pass DOM attributes or parsed JSON directly.
|
|
19
|
+
*/
|
|
20
|
+
interface RawMetadataAttrs {
|
|
21
|
+
name?: string | null;
|
|
22
|
+
bundle?: string | null;
|
|
23
|
+
route?: string | null;
|
|
24
|
+
runtime?: string | null;
|
|
25
|
+
id?: string | null;
|
|
26
|
+
type?: string | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Applies default values to raw metadata attributes and returns a fully
|
|
30
|
+
* resolved {@link RemoteComponentMetadata}. When no bundle is provided, falls
|
|
31
|
+
* back to the `NEXT_PUBLIC_MFE_CURRENT_APPLICATION` env var (the host's
|
|
32
|
+
* application name), then `DEFAULT_BUNDLE_NAME`.
|
|
33
|
+
*/
|
|
34
|
+
declare function buildMetadata(attrs: RawMetadataAttrs, url: URL): RemoteComponentMetadata;
|
|
15
35
|
|
|
16
|
-
export { RemoteComponentMetadata };
|
|
36
|
+
export { RawMetadataAttrs, RemoteComponentMetadata, buildMetadata };
|
|
@@ -1 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_BUNDLE_NAME,
|
|
3
|
+
DEFAULT_COMPONENT_NAME,
|
|
4
|
+
DEFAULT_ROUTE
|
|
5
|
+
} from "#internal/runtime/constants";
|
|
6
|
+
const VALID_RUNTIMES = /* @__PURE__ */ new Set(["webpack", "turbopack", "script"]);
|
|
7
|
+
const VALID_TYPES = /* @__PURE__ */ new Set([
|
|
8
|
+
"nextjs",
|
|
9
|
+
"remote-component",
|
|
10
|
+
"unknown"
|
|
11
|
+
]);
|
|
12
|
+
function isRuntime(value) {
|
|
13
|
+
return VALID_RUNTIMES.has(value);
|
|
14
|
+
}
|
|
15
|
+
function isComponentType(value) {
|
|
16
|
+
return VALID_TYPES.has(value);
|
|
17
|
+
}
|
|
18
|
+
function toRuntime(value) {
|
|
19
|
+
return value && isRuntime(value) ? value : "webpack";
|
|
20
|
+
}
|
|
21
|
+
function toComponentType(value) {
|
|
22
|
+
return value && isComponentType(value) ? value : "unknown";
|
|
23
|
+
}
|
|
24
|
+
function buildMetadata(attrs, url) {
|
|
25
|
+
const id = attrs.id || DEFAULT_COMPONENT_NAME;
|
|
26
|
+
const bundle = attrs.bundle || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || DEFAULT_BUNDLE_NAME;
|
|
27
|
+
return {
|
|
28
|
+
name: attrs.name || id.replace(/_ssr$/, ""),
|
|
29
|
+
bundle,
|
|
30
|
+
route: attrs.route || url.pathname || DEFAULT_ROUTE,
|
|
31
|
+
runtime: toRuntime(attrs.runtime),
|
|
32
|
+
id,
|
|
33
|
+
type: toComponentType(attrs.type)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
buildMetadata
|
|
38
|
+
};
|
|
1
39
|
//# sourceMappingURL=metadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/metadata.ts"],"sourcesContent":["import {\n DEFAULT_BUNDLE_NAME,\n DEFAULT_COMPONENT_NAME,\n DEFAULT_ROUTE,\n} from '#internal/runtime/constants';\n\n/**\n * Metadata embedded in the HTML response by a remote application.\n *\n * Extracted from a `<script type=\"application/json\" data-remote-component>`\n * element during both SSR parsing ({@link fetchRemoteComponent}) and\n * client-side parsing ({@link parseRemoteComponentDocument}).\n */\nexport interface RemoteComponentMetadata {\n name: string;\n bundle: string;\n route: string;\n runtime: 'webpack' | 'turbopack' | 'script';\n id: string;\n type: 'nextjs' | 'remote-component' | 'unknown';\n}\n\n/**\n * Raw attribute values before defaults are applied. Accepts nullable strings\n * so callers can pass DOM attributes or parsed JSON directly.\n */\nexport interface RawMetadataAttrs {\n name?: string | null;\n bundle?: string | null;\n route?: string | null;\n runtime?: string | null;\n id?: string | null;\n type?: string | null;\n}\n\nconst VALID_RUNTIMES: Set<string> = new Set(['webpack', 'turbopack', 'script']);\nconst VALID_TYPES: Set<string> = new Set([\n 'nextjs',\n 'remote-component',\n 'unknown',\n]);\n\nfunction isRuntime(value: string): value is RemoteComponentMetadata['runtime'] {\n return VALID_RUNTIMES.has(value);\n}\n\nfunction isComponentType(\n value: string,\n): value is RemoteComponentMetadata['type'] {\n return VALID_TYPES.has(value);\n}\n\nfunction toRuntime(\n value: string | null | undefined,\n): RemoteComponentMetadata['runtime'] {\n return value && isRuntime(value) ? value : 'webpack';\n}\n\nfunction toComponentType(\n value: string | null | undefined,\n): RemoteComponentMetadata['type'] {\n return value && isComponentType(value) ? value : 'unknown';\n}\n\n/**\n * Applies default values to raw metadata attributes and returns a fully\n * resolved {@link RemoteComponentMetadata}. When no bundle is provided, falls\n * back to the `NEXT_PUBLIC_MFE_CURRENT_APPLICATION` env var (the host's\n * application name), then `DEFAULT_BUNDLE_NAME`.\n */\nexport function buildMetadata(\n attrs: RawMetadataAttrs,\n url: URL,\n): RemoteComponentMetadata {\n const id = attrs.id || DEFAULT_COMPONENT_NAME;\n const bundle =\n attrs.bundle ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n DEFAULT_BUNDLE_NAME;\n return {\n name: attrs.name || id.replace(/_ssr$/, ''),\n bundle,\n route: attrs.route || url.pathname || DEFAULT_ROUTE,\n runtime: toRuntime(attrs.runtime),\n id,\n type: toComponentType(attrs.type),\n };\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA+BP,MAAM,iBAA8B,oBAAI,IAAI,CAAC,WAAW,aAAa,QAAQ,CAAC;AAC9E,MAAM,cAA2B,oBAAI,IAAI;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,UAAU,OAA4D;AAC7E,SAAO,eAAe,IAAI,KAAK;AACjC;AAEA,SAAS,gBACP,OAC0C;AAC1C,SAAO,YAAY,IAAI,KAAK;AAC9B;AAEA,SAAS,UACP,OACoC;AACpC,SAAO,SAAS,UAAU,KAAK,IAAI,QAAQ;AAC7C;AAEA,SAAS,gBACP,OACiC;AACjC,SAAO,SAAS,gBAAgB,KAAK,IAAI,QAAQ;AACnD;AAQO,SAAS,cACd,OACA,KACyB;AACzB,QAAM,KAAK,MAAM,MAAM;AACvB,QAAM,SACJ,MAAM,UACN,QAAQ,IAAI,uCACZ;AACF,SAAO;AAAA,IACL,MAAM,MAAM,QAAQ,GAAG,QAAQ,SAAS,EAAE;AAAA,IAC1C;AAAA,IACA,OAAO,MAAM,SAAS,IAAI,YAAY;AAAA,IACtC,SAAS,UAAU,MAAM,OAAO;AAAA,IAChC;AAAA,IACA,MAAM,gBAAgB,MAAM,IAAI;AAAA,EAClC;AACF;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 patterns_exports = {};
|
|
20
|
+
__export(patterns_exports, {
|
|
21
|
+
NEXT_BUNDLE_PATH_RE: () => NEXT_BUNDLE_PATH_RE,
|
|
22
|
+
REMOTE_COMPONENT_REGEX: () => REMOTE_COMPONENT_REGEX,
|
|
23
|
+
collapseDoubleSlashes: () => collapseDoubleSlashes
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(patterns_exports);
|
|
26
|
+
const REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
27
|
+
const NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
28
|
+
const DOUBLE_SLASH_RE = /(?<!:)\/\//g;
|
|
29
|
+
function collapseDoubleSlashes(path) {
|
|
30
|
+
return path.replace(DOUBLE_SLASH_RE, "/");
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
NEXT_BUNDLE_PATH_RE,
|
|
35
|
+
REMOTE_COMPONENT_REGEX,
|
|
36
|
+
collapseDoubleSlashes
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=patterns.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/patterns.ts"],"sourcesContent":["export const REMOTE_COMPONENT_REGEX =\n /(?<prefix>.*?)\\[(?<bundle>[^\\]]+)\\](?:%20| )(?<id>.+)/;\n\n// Matches Next.js bundle-prefixed paths like /_next/[bundle-name] /static/...\n// Used to strip the bundle identifier before loading scripts via the standard /_next/ path.\nexport const NEXT_BUNDLE_PATH_RE = /\\/_next\\/\\[.+\\](?:%20| )/;\n\n/** Collapse duplicate path separators (`//`) while preserving protocol (`://`). */\nconst DOUBLE_SLASH_RE = /(?<!:)\\/\\//g;\nexport function collapseDoubleSlashes(path: string): string {\n return path.replace(DOUBLE_SLASH_RE, '/');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,yBACX;AAIK,MAAM,sBAAsB;AAGnC,MAAM,kBAAkB;AACjB,SAAS,sBAAsB,MAAsB;AAC1D,SAAO,KAAK,QAAQ,iBAAiB,GAAG;AAC1C;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
2
|
+
const NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
3
|
+
const DOUBLE_SLASH_RE = /(?<!:)\/\//g;
|
|
4
|
+
function collapseDoubleSlashes(path) {
|
|
5
|
+
return path.replace(DOUBLE_SLASH_RE, "/");
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
NEXT_BUNDLE_PATH_RE,
|
|
9
|
+
REMOTE_COMPONENT_REGEX,
|
|
10
|
+
collapseDoubleSlashes
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=patterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/patterns.ts"],"sourcesContent":["export const REMOTE_COMPONENT_REGEX =\n /(?<prefix>.*?)\\[(?<bundle>[^\\]]+)\\](?:%20| )(?<id>.+)/;\n\n// Matches Next.js bundle-prefixed paths like /_next/[bundle-name] /static/...\n// Used to strip the bundle identifier before loading scripts via the standard /_next/ path.\nexport const NEXT_BUNDLE_PATH_RE = /\\/_next\\/\\[.+\\](?:%20| )/;\n\n/** Collapse duplicate path separators (`//`) while preserving protocol (`://`). */\nconst DOUBLE_SLASH_RE = /(?<!:)\\/\\//g;\nexport function collapseDoubleSlashes(path: string): string {\n return path.replace(DOUBLE_SLASH_RE, '/');\n}\n"],"mappings":"AAAO,MAAM,yBACX;AAIK,MAAM,sBAAsB;AAGnC,MAAM,kBAAkB;AACjB,SAAS,sBAAsB,MAAsB;AAC1D,SAAO,KAAK,QAAQ,iBAAiB,GAAG;AAC1C;","names":[]}
|
|
@@ -22,10 +22,11 @@ __export(chunk_loader_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(chunk_loader_exports);
|
|
24
24
|
var import_constants = require("#internal/runtime/constants");
|
|
25
|
+
var import_patterns = require("#internal/runtime/patterns");
|
|
25
26
|
var import_protected_rc_fallback = require("#internal/runtime/url/protected-rc-fallback");
|
|
26
27
|
var import_error = require("#internal/utils/error");
|
|
27
28
|
var import_logger = require("#internal/utils/logger");
|
|
28
|
-
var
|
|
29
|
+
var import_patterns2 = require("./patterns");
|
|
29
30
|
function createChunkLoader(runtime, resolveClientUrl) {
|
|
30
31
|
return function __turbopack_chunk_load__(chunkId, scriptBundle) {
|
|
31
32
|
(0, import_logger.logDebug)("ChunkLoader", `Loading chunk: "${chunkId}"`);
|
|
@@ -34,7 +35,7 @@ function createChunkLoader(runtime, resolveClientUrl) {
|
|
|
34
35
|
bundle,
|
|
35
36
|
id: path,
|
|
36
37
|
prefix
|
|
37
|
-
} =
|
|
38
|
+
} = import_patterns.REMOTE_COMPONENT_REGEX.exec(chunkId)?.groups ?? {
|
|
38
39
|
bundle: scriptBundle ?? "",
|
|
39
40
|
id: chunkId
|
|
40
41
|
};
|
|
@@ -70,7 +71,7 @@ function createChunkLoader(runtime, resolveClientUrl) {
|
|
|
70
71
|
(0, import_logger.logDebug)("ChunkLoader", `Fetching chunk from: "${resolvedUrl}"`);
|
|
71
72
|
self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
|
|
72
73
|
fetch(resolvedUrl).then((res) => res.text()).then((code) => {
|
|
73
|
-
const hasTurbopack =
|
|
74
|
+
const hasTurbopack = import_patterns2.TURBOPACK_GLOBAL_RE.test(code);
|
|
74
75
|
if (hasTurbopack) {
|
|
75
76
|
return handleTurbopackChunk(code, bundle ?? "", url);
|
|
76
77
|
}
|