remote-components 0.2.2 → 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/config/nextjs.cjs +2 -4
- package/dist/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.d.ts +1 -1
- package/dist/config/nextjs.js +2 -4
- package/dist/config/nextjs.js.map +1 -1
- package/dist/host/html.cjs +128 -112
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +128 -115
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +233 -259
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +234 -260
- 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 +7 -19
- package/dist/host/nextjs/pages.cjs.map +1 -1
- package/dist/host/nextjs/pages.js +11 -20
- package/dist/host/nextjs/pages.js.map +1 -1
- package/dist/host/react.cjs +101 -93
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +101 -93
- package/dist/host/react.js.map +1 -1
- package/dist/internal/host/nextjs/app-client.cjs +3 -8
- package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
- package/dist/internal/host/nextjs/app-client.js +4 -9
- package/dist/internal/host/nextjs/app-client.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/nextjs/image-shared.cjs +25 -15
- package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
- package/dist/internal/host/nextjs/image-shared.d.ts +19 -6
- package/dist/internal/host/nextjs/image-shared.js +24 -14
- package/dist/internal/host/nextjs/image-shared.js.map +1 -1
- package/dist/internal/host/react/hooks/use-resolve-client-url.cjs +1 -5
- package/dist/internal/host/react/hooks/use-resolve-client-url.cjs.map +1 -1
- package/dist/internal/host/react/hooks/use-resolve-client-url.d.ts +1 -4
- package/dist/internal/host/react/hooks/use-resolve-client-url.js +1 -5
- package/dist/internal/host/react/hooks/use-resolve-client-url.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/host/shared/polyfill.cjs +10 -65
- package/dist/internal/host/shared/polyfill.cjs.map +1 -1
- package/dist/internal/host/shared/polyfill.d.ts +1 -3
- package/dist/internal/host/shared/polyfill.js +9 -63
- package/dist/internal/host/shared/polyfill.js.map +1 -1
- package/dist/internal/host/shared/remote-image-loader.cjs +53 -0
- package/dist/internal/host/shared/remote-image-loader.cjs.map +1 -0
- package/dist/internal/host/shared/remote-image-loader.d.ts +30 -0
- package/dist/internal/host/shared/remote-image-loader.js +29 -0
- package/dist/internal/host/shared/remote-image-loader.js.map +1 -0
- 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
- package/dist/internal/host/nextjs/image-impl.cjs +0 -64
- package/dist/internal/host/nextjs/image-impl.cjs.map +0 -1
- package/dist/internal/host/nextjs/image-impl.d.ts +0 -10
- package/dist/internal/host/nextjs/image-impl.js +0 -40
- package/dist/internal/host/nextjs/image-impl.js.map +0 -1
|
@@ -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 remote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A,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","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":"AACA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AA2BA,SAAS,wBACd,KACA,MACA,KACM;AACN,MACG,IAAI,iBAAiB,8BAA8B,EAAE,SAAS,KAC7D,CAAC,IAAI,cAAc,qCAAqC,QAAQ,KACjE,IAAI,iBAAiB,6BAA6B,EAAE,SAAS,KAC5D,CAAC,IAAI,cAAc,0BAA0B,QAAQ,GACvD;AACA,UAAM,8BAA8B,GAAG;AAAA,EACzC;AACF;AAMO,SAAS,qBACd,KACA,MACgB;AAChB,SACE,IAAI,cAAc,qCAAqC,QAAQ,KAC/D,IAAI,cAAc,8BAA8B,KAChD,IAAI,cAAc,YAAY,KAC9B,IAAI,cAAc,0BAA0B,mBAAmB,KAC/D,IAAI,cAAc,6BAA6B;AAEnD;AAKO,SAAS,cAAc,KAAgC;AAC5D,SAAO,KAAK;AAAA,KAER,IAAI,cAAc,gBAAgB,KAClC,IAAI,cAAc,uBAAuB,IACxC,eAAe;AAAA,EACpB;AACF;AAOO,SAAS,qBACd,WACA,UACA,cAC8C;AAC9C,QAAM,oBACJ,WAAW,QAAQ,YAAY,MAAM;AAEvC,QAAM,OACJ,WAAW,aAAa,IAAI,GAAG,QAAQ,SAAS,EAAE,KACjD,qBAAqB,WAAW,aAAa,MAAM,MACnD,WAAW,WAAW;AAEzB,SAAO,EAAE,MAAM,kBAAkB;AACnC;AAMO,SAAS,oBACd,KACA,MACA,UACwB;AACxB,QAAM,iBAAiB,IAAI;AAAA,IACzB,IAAI;AAAA,EACN;AACA,QAAM,eACJ,UAAU,MAAM,sBAAsB,WACpC,KAAK,MAAM,gBAAgB,eAAe,IAAI,KAAK,CAAC;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,IACJ;AAAA,EACF;AAEA,QAAM,QAAQ,aAAa,KAAK,SAAS;AACzC,QAAM,UAAU,eAAe,KAAK,WAAW,iBAAiB;AAEhE,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","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
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/turbopack/chunk-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n getBundleKey,\n REMOTE_COMPONENT_REGEX,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport { logDebug, warnCrossOriginFetchError } from '#internal/utils/logger';\nimport { TURBOPACK_GLOBAL_RE } from './patterns';\n\n/**\n * Creates chunk loader function for webpack runtime.\n * This function is responsible for loading JavaScript chunks from remote applications\n * and transforming Turbopack-specific code to work in the host environment.\n */\nexport function createChunkLoader(\n runtime: Runtime,\n resolveClientUrl?: InternalResolveClientUrl,\n): (chunkId: string, scriptBundle?: string) => Promise<unknown> | undefined {\n return function __turbopack_chunk_load__(\n chunkId: string,\n scriptBundle?: string,\n ) {\n logDebug('ChunkLoader', `Loading chunk: \"${chunkId}\"`);\n const self = globalThis as GlobalScope;\n const {\n bundle,\n id: path,\n prefix,\n } = REMOTE_COMPONENT_REGEX.exec(chunkId)?.groups ?? {\n bundle: scriptBundle ?? '',\n id: chunkId,\n };\n logDebug(\n 'ChunkLoader',\n `Parsed chunk - bundle: \"${bundle}\", path: \"${path}\", prefix: \"${prefix}\"`,\n );\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : runtime;\n logDebug('ChunkLoader', `Remote runtime: \"${remoteRuntime}\"`);\n if (remoteRuntime === RUNTIME_WEBPACK) {\n logDebug('ChunkLoader', 'Skipping chunk load - webpack runtime detected');\n return Promise.resolve(undefined);\n }\n\n const url = new URL(\n path\n ? `${prefix ?? ''}${path}`.replace(\n /(?<char>[^:])(?<double>\\/\\/)/g,\n '$1/',\n )\n : '/',\n self.__remote_bundle_url__?.[bundle ?? 'default'] ??\n new URL(location.origin),\n ).href;\n if (url.endsWith('.css')) {\n logDebug('ChunkLoader', `Skipping CSS file: \"${url}\"`);\n return;\n }\n\n if (!self.__remote_components_turbopack_chunk_loader_promise__) {\n self.__remote_components_turbopack_chunk_loader_promise__ = {};\n }\n if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {\n logDebug('ChunkLoader', `Returning cached promise for: \"${url}\"`);\n return self.__remote_components_turbopack_chunk_loader_promise__[url];\n }\n\n const resolvedUrl = resolveClientUrl?.(url) ?? url;\n logDebug('ChunkLoader', `Fetching chunk from: \"${resolvedUrl}\"`);\n self.__remote_components_turbopack_chunk_loader_promise__[url] =\n new Promise((resolve, reject) => {\n fetch(resolvedUrl)\n .then((res) => res.text())\n .then((code) => {\n // Turbopack runtime uses either dot-notation or bracket-notation globals.\n const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);\n if (hasTurbopack) {\n return handleTurbopackChunk(code, bundle ?? '', url);\n }\n logDebug(\n 'ChunkLoader',\n `Chunk does not contain globalThis.TURBOPACK or self.TURBOPACK: \"${url}\"`,\n );\n logDebug(\n 'ChunkLoader',\n `First 500 chars of chunk: ${code.slice(0, 500)}`,\n );\n })\n .then(resolve)\n .catch((error) => {\n const isProxied = isProxiedUrl(resolvedUrl);\n if (isProxied) {\n reject(failedProxiedAssetError('chunk', url, resolvedUrl));\n } else {\n warnCrossOriginFetchError('ChunkLoader', url);\n reject(error);\n }\n });\n });\n\n return self.__remote_components_turbopack_chunk_loader_promise__[url];\n };\n}\n\n/**\n * Handles Turbopack chunk loading by transforming the chunk code to isolate\n * global variables per bundle and dynamically loading the transformed script.\n */\nasync function handleTurbopackChunk(\n code: string,\n bundle: string,\n url: string,\n): Promise<void> {\n logDebug(\n 'ChunkLoader',\n `Handling Turbopack chunk - bundle: \"${bundle}\", url: \"${url}\"`,\n );\n // skip this chunk as it is not needed for remote components\n if (/importScripts\\(\\.\\.\\.self.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {\n logDebug('ChunkLoader', `Skipping worker chunk: \"${url}\"`);\n // remove preload links for this chunk\n const preloadLinks = document.querySelectorAll(\n `link[rel=\"preload\"][href=\"${new URL(url).pathname}\"]`,\n );\n preloadLinks.forEach((preloadLink) => preloadLink.remove());\n return;\n }\n\n const self = globalThis as GlobalScope;\n const bundleKey = getBundleKey(bundle);\n logDebug('ChunkLoader', `Bundle key: \"${bundleKey}\"`);\n\n // replace global variables with bundle-specific ones to prevent collisions\n // between multiple remote component bundles\n const transformedCode = code\n // Turbopack runtime can reference TURBOPACK via bracket-notation (common in newer Next.js)\n // e.g. globalThis[\"TURBOPACK\"] / self['TURBOPACK']\n .replace(\n /globalThis\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `globalThis[\"TURBOPACK_${bundleKey}\"]`,\n )\n .replace(\n /self\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `self[\"TURBOPACK_${bundleKey}\"]`,\n )\n .replace(/globalThis\\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`)\n .replace(/self\\.TURBOPACK(?!_)/g, `self.TURBOPACK_${bundleKey}`)\n .replace(\n /TURBOPACK_WORKER_LOCATION/g,\n `TURBOPACK_WORKER_LOCATION_${bundleKey}`,\n )\n .replace(\n /TURBOPACK_NEXT_CHUNK_URLS/g,\n `TURBOPACK_NEXT_CHUNK_URLS_${bundleKey}`,\n )\n .replace(\n /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,\n `TURBOPACK_CHUNK_UPDATE_LISTENERS_${bundleKey}`,\n )\n .replace(/__next_require__/g, `__${bundleKey}_next_require__`)\n .replace(\n /\\/\\/# sourceMappingURL=(?<name>.+)(?<optional>\\._)?\\.js\\.map/g,\n `//# sourceMappingURL=${\n new URL(\n '.',\n new URL(\n url,\n self.__remote_bundle_url__?.[bundle] ?? new URL(location.origin),\n ),\n ).href\n }$1$2.js.map`,\n );\n\n // Initialize TURBOPACK bundle with push interceptor for Next.js 16.2.0-canary\n // Use webpack-style chunk loading pattern\n if (!self[`TURBOPACK_${bundleKey}`]) {\n const chunkData: unknown[][] = [];\n const turbopackObject = {\n push: (item: unknown) => {\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey}.push() called with item type: ${Array.isArray(item) ? 'array' : typeof item}`,\n );\n if (Array.isArray(item)) {\n chunkData.push(item);\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey} now has ${chunkData.length} chunks`,\n );\n } else {\n chunkData.push([item]);\n }\n return chunkData.length;\n },\n // Store chunks for later access\n __chunks__: chunkData,\n };\n self[`TURBOPACK_${bundleKey}`] = turbopackObject as unknown as Record<\n string,\n unknown\n >;\n }\n\n // load the script dynamically using a Blob URL\n logDebug('ChunkLoader', `Creating blob script for: \"${url}\"`);\n await new Promise<void>((scriptResolve, scriptReject) => {\n const blob = new Blob([transformedCode], {\n type: 'application/javascript; charset=UTF-8',\n });\n const scriptUrl = URL.createObjectURL(blob);\n const script = document.createElement('script');\n script.setAttribute('data-turbopack-src', url);\n script.src = scriptUrl;\n script.async = true;\n script.onload = () => {\n URL.revokeObjectURL(scriptUrl);\n logDebug(\n 'ChunkLoader',\n `Script loaded successfully for bundle \"${bundle}\"`,\n );\n const turbopackBundle = self[`TURBOPACK_${bundleKey}`];\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey} type: ${typeof turbopackBundle}, isArray: ${Array.isArray(turbopackBundle)}, keys: ${\n turbopackBundle\n ? Object.keys(turbopackBundle as object)\n .slice(0, 10)\n .join(', ')\n : 'none'\n }`,\n );\n if (turbopackBundle && typeof turbopackBundle === 'object') {\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey} length/size: ${Array.isArray(turbopackBundle) ? turbopackBundle.length : Object.keys(turbopackBundle as object).length}`,\n );\n }\n scriptResolve(undefined);\n script.remove();\n };\n script.onerror = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptReject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${script.src}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n script.remove();\n };\n document.head.appendChild(script);\n });\n\n // process any additional chunks that were registered during script execution\n const chunkLists = self[`TURBOPACK_${bundleKey}_CHUNK_LISTS`] as\n | { chunks: string[] }[]\n | undefined;\n logDebug(\n 'ChunkLoader',\n `Processing chunk lists for bundle \"${bundle}\": ${chunkLists?.length ?? 0} lists`,\n );\n const loadChunkLists = [] as (Promise<unknown> | undefined)[];\n while (chunkLists?.length) {\n const { chunks } = chunkLists.shift() ?? { chunks: [] };\n if (chunks.length > 0) {\n logDebug(\n 'ChunkLoader',\n `Loading ${chunks.length} additional chunks for bundle \"${bundle}\": [${chunks.join(', ')}]`,\n );\n chunks.forEach((id: string) => {\n const chunkLoadResult = self.__webpack_chunk_load__?.(\n `[${bundle}] ${url.slice(0, url.indexOf('/_next'))}/_next/${id}`,\n );\n if (chunkLoadResult) {\n loadChunkLists.push(chunkLoadResult);\n }\n });\n }\n }\n if (loadChunkLists.length > 0) {\n logDebug(\n 'ChunkLoader',\n `Waiting for ${loadChunkLists.length} additional chunks to load`,\n );\n await Promise.all(loadChunkLists);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAKO;AAEP,mCAA6B;AAC7B,mBAGO;AACP,oBAAoD;AACpD,sBAAoC;AAO7B,SAAS,kBACd,SACA,kBAC0E;AAC1E,SAAO,SAAS,yBACd,SACA,cACA;AACA,gCAAS,eAAe,mBAAmB,UAAU;AACrD,UAAM,OAAO;AACb,UAAM;AAAA,MACJ;AAAA,MACA,IAAI;AAAA,MACJ;AAAA,IACF,IAAI,wCAAuB,KAAK,OAAO,GAAG,UAAU;AAAA,MAClD,QAAQ,gBAAgB;AAAA,MACxB,IAAI;AAAA,IACN;AACA;AAAA,MACE;AAAA,MACA,2BAA2B,mBAAmB,mBAAmB;AAAA,IACnE;AACA,UAAM,gBAAgB,KAAK,6BAA6B,UAAU,SAAS,IACvE,KAAK,2BAA2B,UAAU,SAAS,GAAG,QAAQ,YAC9D;AACJ,gCAAS,eAAe,oBAAoB,gBAAgB;AAC5D,QAAI,kBAAkB,kCAAiB;AACrC,kCAAS,eAAe,gDAAgD;AACxE,aAAO,QAAQ,QAAQ,MAAS;AAAA,IAClC;AAEA,UAAM,MAAM,IAAI;AAAA,MACd,OACI,GAAG,UAAU,KAAK,OAAO;AAAA,QACvB;AAAA,QACA;AAAA,MACF,IACA;AAAA,MACJ,KAAK,wBAAwB,UAAU,SAAS,KAC9C,IAAI,IAAI,SAAS,MAAM;AAAA,IAC3B,EAAE;AACF,QAAI,IAAI,SAAS,MAAM,GAAG;AACxB,kCAAS,eAAe,uBAAuB,MAAM;AACrD;AAAA,IACF;AAEA,QAAI,CAAC,KAAK,sDAAsD;AAC9D,WAAK,uDAAuD,CAAC;AAAA,IAC/D;AACA,QAAI,KAAK,qDAAqD,GAAG,GAAG;AAClE,kCAAS,eAAe,kCAAkC,MA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B,KAAK;AAAA,UAC3B,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,QAAQ,QAAQ,CAAC,WAAW;AAAA,QAC9D;AACA,YAAI,iBAAiB;AACnB,yBAAe,KAAK,eAAe;AAAA,QACrC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACA,MAAI,eAAe,SAAS,GAAG;AAC7B;AAAA,MACE;AAAA,MACA,eAAe,eAAe;AAAA,IAChC;AACA,UAAM,QAAQ,IAAI,cAAc;AAAA,EAClC;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/turbopack/chunk-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n getBundleKey,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport { logDebug, warnCrossOriginFetchError } from '#internal/utils/logger';\nimport { TURBOPACK_GLOBAL_RE } from './patterns';\n\n/**\n * Creates chunk loader function for webpack runtime.\n * This function is responsible for loading JavaScript chunks from remote applications\n * and transforming Turbopack-specific code to work in the host environment.\n */\nexport function createChunkLoader(\n runtime: Runtime,\n resolveClientUrl?: InternalResolveClientUrl,\n): (chunkId: string, scriptBundle?: string) => Promise<unknown> | undefined {\n return function __turbopack_chunk_load__(\n chunkId: string,\n scriptBundle?: string,\n ) {\n logDebug('ChunkLoader', `Loading chunk: \"${chunkId}\"`);\n const self = globalThis as GlobalScope;\n const {\n bundle,\n id: path,\n prefix,\n } = REMOTE_COMPONENT_REGEX.exec(chunkId)?.groups ?? {\n bundle: scriptBundle ?? '',\n id: chunkId,\n };\n logDebug(\n 'ChunkLoader',\n `Parsed chunk - bundle: \"${bundle}\", path: \"${path}\", prefix: \"${prefix}\"`,\n );\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : runtime;\n logDebug('ChunkLoader', `Remote runtime: \"${remoteRuntime}\"`);\n if (remoteRuntime === RUNTIME_WEBPACK) {\n logDebug('ChunkLoader', 'Skipping chunk load - webpack runtime detected');\n return Promise.resolve(undefined);\n }\n\n const url = new URL(\n path\n ? `${prefix ?? ''}${path}`.replace(\n /(?<char>[^:])(?<double>\\/\\/)/g,\n '$1/',\n )\n : '/',\n self.__remote_bundle_url__?.[bundle ?? 'default'] ??\n new URL(location.origin),\n ).href;\n if (url.endsWith('.css')) {\n logDebug('ChunkLoader', `Skipping CSS file: \"${url}\"`);\n return;\n }\n\n if (!self.__remote_components_turbopack_chunk_loader_promise__) {\n self.__remote_components_turbopack_chunk_loader_promise__ = {};\n }\n if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {\n logDebug('ChunkLoader', `Returning cached promise for: \"${url}\"`);\n return self.__remote_components_turbopack_chunk_loader_promise__[url];\n }\n\n const resolvedUrl = resolveClientUrl?.(url) ?? url;\n logDebug('ChunkLoader', `Fetching chunk from: \"${resolvedUrl}\"`);\n self.__remote_components_turbopack_chunk_loader_promise__[url] =\n new Promise((resolve, reject) => {\n fetch(resolvedUrl)\n .then((res) => res.text())\n .then((code) => {\n // Turbopack runtime uses either dot-notation or bracket-notation globals.\n const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);\n if (hasTurbopack) {\n return handleTurbopackChunk(code, bundle ?? '', url);\n }\n logDebug(\n 'ChunkLoader',\n `Chunk does not contain globalThis.TURBOPACK or self.TURBOPACK: \"${url}\"`,\n );\n logDebug(\n 'ChunkLoader',\n `First 500 chars of chunk: ${code.slice(0, 500)}`,\n );\n })\n .then(resolve)\n .catch((error) => {\n const isProxied = isProxiedUrl(resolvedUrl);\n if (isProxied) {\n reject(failedProxiedAssetError('chunk', url, resolvedUrl));\n } else {\n warnCrossOriginFetchError('ChunkLoader', url);\n reject(error);\n }\n });\n });\n\n return self.__remote_components_turbopack_chunk_loader_promise__[url];\n };\n}\n\n/**\n * Handles Turbopack chunk loading by transforming the chunk code to isolate\n * global variables per bundle and dynamically loading the transformed script.\n */\nasync function handleTurbopackChunk(\n code: string,\n bundle: string,\n url: string,\n): Promise<void> {\n logDebug(\n 'ChunkLoader',\n `Handling Turbopack chunk - bundle: \"${bundle}\", url: \"${url}\"`,\n );\n // skip this chunk as it is not needed for remote components\n if (/importScripts\\(\\.\\.\\.self.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {\n logDebug('ChunkLoader', `Skipping worker chunk: \"${url}\"`);\n // remove preload links for this chunk\n const preloadLinks = document.querySelectorAll(\n `link[rel=\"preload\"][href=\"${new URL(url).pathname}\"]`,\n );\n preloadLinks.forEach((preloadLink) => preloadLink.remove());\n return;\n }\n\n const self = globalThis as GlobalScope;\n const bundleKey = getBundleKey(bundle);\n logDebug('ChunkLoader', `Bundle key: \"${bundleKey}\"`);\n\n // replace global variables with bundle-specific ones to prevent collisions\n // between multiple remote component bundles\n const transformedCode = code\n // Turbopack runtime can reference TURBOPACK via bracket-notation (common in newer Next.js)\n // e.g. globalThis[\"TURBOPACK\"] / self['TURBOPACK']\n .replace(\n /globalThis\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `globalThis[\"TURBOPACK_${bundleKey}\"]`,\n )\n .replace(\n /self\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `self[\"TURBOPACK_${bundleKey}\"]`,\n )\n .replace(/globalThis\\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`)\n .replace(/self\\.TURBOPACK(?!_)/g, `self.TURBOPACK_${bundleKey}`)\n .replace(\n /TURBOPACK_WORKER_LOCATION/g,\n `TURBOPACK_WORKER_LOCATION_${bundleKey}`,\n )\n .replace(\n /TURBOPACK_NEXT_CHUNK_URLS/g,\n `TURBOPACK_NEXT_CHUNK_URLS_${bundleKey}`,\n )\n .replace(\n /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,\n `TURBOPACK_CHUNK_UPDATE_LISTENERS_${bundleKey}`,\n )\n .replace(/__next_require__/g, `__${bundleKey}_next_require__`)\n .replace(\n /\\/\\/# sourceMappingURL=(?<name>.+)(?<optional>\\._)?\\.js\\.map/g,\n `//# sourceMappingURL=${\n new URL(\n '.',\n new URL(\n url,\n self.__remote_bundle_url__?.[bundle] ?? new URL(location.origin),\n ),\n ).href\n }$1$2.js.map`,\n );\n\n // Initialize TURBOPACK bundle with push interceptor for Next.js 16.2.0-canary\n // Use webpack-style chunk loading pattern\n if (!self[`TURBOPACK_${bundleKey}`]) {\n const chunkData: unknown[][] = [];\n const turbopackObject = {\n push: (item: unknown) => {\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey}.push() called with item type: ${Array.isArray(item) ? 'array' : typeof item}`,\n );\n if (Array.isArray(item)) {\n chunkData.push(item);\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey} now has ${chunkData.length} chunks`,\n );\n } else {\n chunkData.push([item]);\n }\n return chunkData.length;\n },\n // Store chunks for later access\n __chunks__: chunkData,\n };\n self[`TURBOPACK_${bundleKey}`] = turbopackObject as unknown as Record<\n string,\n unknown\n >;\n }\n\n // load the script dynamically using a Blob URL\n logDebug('ChunkLoader', `Creating blob script for: \"${url}\"`);\n await new Promise<void>((scriptResolve, scriptReject) => {\n const blob = new Blob([transformedCode], {\n type: 'application/javascript; charset=UTF-8',\n });\n const scriptUrl = URL.createObjectURL(blob);\n const script = document.createElement('script');\n script.setAttribute('data-turbopack-src', url);\n script.src = scriptUrl;\n script.async = true;\n script.onload = () => {\n URL.revokeObjectURL(scriptUrl);\n logDebug(\n 'ChunkLoader',\n `Script loaded successfully for bundle \"${bundle}\"`,\n );\n const turbopackBundle = self[`TURBOPACK_${bundleKey}`];\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey} type: ${typeof turbopackBundle}, isArray: ${Array.isArray(turbopackBundle)}, keys: ${\n turbopackBundle\n ? Object.keys(turbopackBundle as object)\n .slice(0, 10)\n .join(', ')\n : 'none'\n }`,\n );\n if (turbopackBundle && typeof turbopackBundle === 'object') {\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey} length/size: ${Array.isArray(turbopackBundle) ? turbopackBundle.length : Object.keys(turbopackBundle as object).length}`,\n );\n }\n scriptResolve(undefined);\n script.remove();\n };\n script.onerror = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptReject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${script.src}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n script.remove();\n };\n document.head.appendChild(script);\n });\n\n // process any additional chunks that were registered during script execution\n const chunkLists = self[`TURBOPACK_${bundleKey}_CHUNK_LISTS`] as\n | { chunks: string[] }[]\n | undefined;\n logDebug(\n 'ChunkLoader',\n `Processing chunk lists for bundle \"${bundle}\": ${chunkLists?.length ?? 0} lists`,\n );\n const loadChunkLists = [] as (Promise<unknown> | undefined)[];\n while (chunkLists?.length) {\n const { chunks } = chunkLists.shift() ?? { chunks: [] };\n if (chunks.length > 0) {\n logDebug(\n 'ChunkLoader',\n `Loading ${chunks.length} additional chunks for bundle \"${bundle}\": [${chunks.join(', ')}]`,\n );\n chunks.forEach((id: string) => {\n const chunkLoadResult = self.__webpack_chunk_load__?.(\n `[${bundle}] ${url.slice(0, url.indexOf('/_next'))}/_next/${id}`,\n );\n if (chunkLoadResult) {\n loadChunkLists.push(chunkLoadResult);\n }\n });\n }\n }\n if (loadChunkLists.length > 0) {\n logDebug(\n 'ChunkLoader',\n `Waiting for ${loadChunkLists.length} additional chunks to load`,\n );\n await Promise.all(loadChunkLists);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAIO;AACP,sBAAuC;AAEvC,mCAA6B;AAC7B,mBAGO;AACP,oBAAoD;AACpD,IAAAA,mBAAoC;AAO7B,SAAS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eAAe,eAAe;AAAA,IAChC;AACA,UAAM,QAAQ,IAAI,cAAc;AAAA,EAClC;AACF;","names":["import_patterns"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getBundleKey,
|
|
3
|
-
REMOTE_COMPONENT_REGEX,
|
|
4
3
|
RUNTIME_WEBPACK
|
|
5
4
|
} from "#internal/runtime/constants";
|
|
5
|
+
import { REMOTE_COMPONENT_REGEX } from "#internal/runtime/patterns";
|
|
6
6
|
import { isProxiedUrl } from "#internal/runtime/url/protected-rc-fallback";
|
|
7
7
|
import {
|
|
8
8
|
failedProxiedAssetError,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/turbopack/chunk-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n getBundleKey,\n REMOTE_COMPONENT_REGEX,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport { logDebug, warnCrossOriginFetchError } from '#internal/utils/logger';\nimport { TURBOPACK_GLOBAL_RE } from './patterns';\n\n/**\n * Creates chunk loader function for webpack runtime.\n * This function is responsible for loading JavaScript chunks from remote applications\n * and transforming Turbopack-specific code to work in the host environment.\n */\nexport function createChunkLoader(\n runtime: Runtime,\n resolveClientUrl?: InternalResolveClientUrl,\n): (chunkId: string, scriptBundle?: string) => Promise<unknown> | undefined {\n return function __turbopack_chunk_load__(\n chunkId: string,\n scriptBundle?: string,\n ) {\n logDebug('ChunkLoader', `Loading chunk: \"${chunkId}\"`);\n const self = globalThis as GlobalScope;\n const {\n bundle,\n id: path,\n prefix,\n } = REMOTE_COMPONENT_REGEX.exec(chunkId)?.groups ?? {\n bundle: scriptBundle ?? '',\n id: chunkId,\n };\n logDebug(\n 'ChunkLoader',\n `Parsed chunk - bundle: \"${bundle}\", path: \"${path}\", prefix: \"${prefix}\"`,\n );\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : runtime;\n logDebug('ChunkLoader', `Remote runtime: \"${remoteRuntime}\"`);\n if (remoteRuntime === RUNTIME_WEBPACK) {\n logDebug('ChunkLoader', 'Skipping chunk load - webpack runtime detected');\n return Promise.resolve(undefined);\n }\n\n const url = new URL(\n path\n ? `${prefix ?? ''}${path}`.replace(\n /(?<char>[^:])(?<double>\\/\\/)/g,\n '$1/',\n )\n : '/',\n self.__remote_bundle_url__?.[bundle ?? 'default'] ??\n new URL(location.origin),\n ).href;\n if (url.endsWith('.css')) {\n logDebug('ChunkLoader', `Skipping CSS file: \"${url}\"`);\n return;\n }\n\n if (!self.__remote_components_turbopack_chunk_loader_promise__) {\n self.__remote_components_turbopack_chunk_loader_promise__ = {};\n }\n if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {\n logDebug('ChunkLoader', `Returning cached promise for: \"${url}\"`);\n return self.__remote_components_turbopack_chunk_loader_promise__[url];\n }\n\n const resolvedUrl = resolveClientUrl?.(url) ?? url;\n logDebug('ChunkLoader', `Fetching chunk from: \"${resolvedUrl}\"`);\n self.__remote_components_turbopack_chunk_loader_promise__[url] =\n new Promise((resolve, reject) => {\n fetch(resolvedUrl)\n .then((res) => res.text())\n .then((code) => {\n // Turbopack runtime uses either dot-notation or bracket-notation globals.\n const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);\n if (hasTurbopack) {\n return handleTurbopackChunk(code, bundle ?? '', url);\n }\n logDebug(\n 'ChunkLoader',\n `Chunk does not contain globalThis.TURBOPACK or self.TURBOPACK: \"${url}\"`,\n );\n logDebug(\n 'ChunkLoader',\n `First 500 chars of chunk: ${code.slice(0, 500)}`,\n );\n })\n .then(resolve)\n .catch((error) => {\n const isProxied = isProxiedUrl(resolvedUrl);\n if (isProxied) {\n reject(failedProxiedAssetError('chunk', url, resolvedUrl));\n } else {\n warnCrossOriginFetchError('ChunkLoader', url);\n reject(error);\n }\n });\n });\n\n return self.__remote_components_turbopack_chunk_loader_promise__[url];\n };\n}\n\n/**\n * Handles Turbopack chunk loading by transforming the chunk code to isolate\n * global variables per bundle and dynamically loading the transformed script.\n */\nasync function handleTurbopackChunk(\n code: string,\n bundle: string,\n url: string,\n): Promise<void> {\n logDebug(\n 'ChunkLoader',\n `Handling Turbopack chunk - bundle: \"${bundle}\", url: \"${url}\"`,\n );\n // skip this chunk as it is not needed for remote components\n if (/importScripts\\(\\.\\.\\.self.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {\n logDebug('ChunkLoader', `Skipping worker chunk: \"${url}\"`);\n // remove preload links for this chunk\n const preloadLinks = document.querySelectorAll(\n `link[rel=\"preload\"][href=\"${new URL(url).pathname}\"]`,\n );\n preloadLinks.forEach((preloadLink) => preloadLink.remove());\n return;\n }\n\n const self = globalThis as GlobalScope;\n const bundleKey = getBundleKey(bundle);\n logDebug('ChunkLoader', `Bundle key: \"${bundleKey}\"`);\n\n // replace global variables with bundle-specific ones to prevent collisions\n // between multiple remote component bundles\n const transformedCode = code\n // Turbopack runtime can reference TURBOPACK via bracket-notation (common in newer Next.js)\n // e.g. globalThis[\"TURBOPACK\"] / self['TURBOPACK']\n .replace(\n /globalThis\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `globalThis[\"TURBOPACK_${bundleKey}\"]`,\n )\n .replace(\n /self\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `self[\"TURBOPACK_${bundleKey}\"]`,\n )\n .replace(/globalThis\\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`)\n .replace(/self\\.TURBOPACK(?!_)/g, `self.TURBOPACK_${bundleKey}`)\n .replace(\n /TURBOPACK_WORKER_LOCATION/g,\n `TURBOPACK_WORKER_LOCATION_${bundleKey}`,\n )\n .replace(\n /TURBOPACK_NEXT_CHUNK_URLS/g,\n `TURBOPACK_NEXT_CHUNK_URLS_${bundleKey}`,\n )\n .replace(\n /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,\n `TURBOPACK_CHUNK_UPDATE_LISTENERS_${bundleKey}`,\n )\n .replace(/__next_require__/g, `__${bundleKey}_next_require__`)\n .replace(\n /\\/\\/# sourceMappingURL=(?<name>.+)(?<optional>\\._)?\\.js\\.map/g,\n `//# sourceMappingURL=${\n new URL(\n '.',\n new URL(\n url,\n self.__remote_bundle_url__?.[bundle] ?? new URL(location.origin),\n ),\n ).href\n }$1$2.js.map`,\n );\n\n // Initialize TURBOPACK bundle with push interceptor for Next.js 16.2.0-canary\n // Use webpack-style chunk loading pattern\n if (!self[`TURBOPACK_${bundleKey}`]) {\n const chunkData: unknown[][] = [];\n const turbopackObject = {\n push: (item: unknown) => {\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey}.push() called with item type: ${Array.isArray(item) ? 'array' : typeof item}`,\n );\n if (Array.isArray(item)) {\n chunkData.push(item);\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey} now has ${chunkData.length} chunks`,\n );\n } else {\n chunkData.push([item]);\n }\n return chunkData.length;\n },\n // Store chunks for later access\n __chunks__: chunkData,\n };\n self[`TURBOPACK_${bundleKey}`] = turbopackObject as unknown as Record<\n string,\n unknown\n >;\n }\n\n // load the script dynamically using a Blob URL\n logDebug('ChunkLoader', `Creating blob script for: \"${url}\"`);\n await new Promise<void>((scriptResolve, scriptReject) => {\n const blob = new Blob([transformedCode], {\n type: 'application/javascript; charset=UTF-8',\n });\n const scriptUrl = URL.createObjectURL(blob);\n const script = document.createElement('script');\n script.setAttribute('data-turbopack-src', url);\n script.src = scriptUrl;\n script.async = true;\n script.onload = () => {\n URL.revokeObjectURL(scriptUrl);\n logDebug(\n 'ChunkLoader',\n `Script loaded successfully for bundle \"${bundle}\"`,\n );\n const turbopackBundle = self[`TURBOPACK_${bundleKey}`];\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey} type: ${typeof turbopackBundle}, isArray: ${Array.isArray(turbopackBundle)}, keys: ${\n turbopackBundle\n ? Object.keys(turbopackBundle as object)\n .slice(0, 10)\n .join(', ')\n : 'none'\n }`,\n );\n if (turbopackBundle && typeof turbopackBundle === 'object') {\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey} length/size: ${Array.isArray(turbopackBundle) ? turbopackBundle.length : Object.keys(turbopackBundle as object).length}`,\n );\n }\n scriptResolve(undefined);\n script.remove();\n };\n script.onerror = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptReject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${script.src}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n script.remove();\n };\n document.head.appendChild(script);\n });\n\n // process any additional chunks that were registered during script execution\n const chunkLists = self[`TURBOPACK_${bundleKey}_CHUNK_LISTS`] as\n | { chunks: string[] }[]\n | undefined;\n logDebug(\n 'ChunkLoader',\n `Processing chunk lists for bundle \"${bundle}\": ${chunkLists?.length ?? 0} lists`,\n );\n const loadChunkLists = [] as (Promise<unknown> | undefined)[];\n while (chunkLists?.length) {\n const { chunks } = chunkLists.shift() ?? { chunks: [] };\n if (chunks.length > 0) {\n logDebug(\n 'ChunkLoader',\n `Loading ${chunks.length} additional chunks for bundle \"${bundle}\": [${chunks.join(', ')}]`,\n );\n chunks.forEach((id: string) => {\n const chunkLoadResult = self.__webpack_chunk_load__?.(\n `[${bundle}] ${url.slice(0, url.indexOf('/_next'))}/_next/${id}`,\n );\n if (chunkLoadResult) {\n loadChunkLists.push(chunkLoadResult);\n }\n });\n }\n }\n if (loadChunkLists.length > 0) {\n logDebug(\n 'ChunkLoader',\n `Waiting for ${loadChunkLists.length} additional chunks to load`,\n );\n await Promise.all(loadChunkLists);\n }\n}\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,oBAAoB;AAC7B;AAAA,EACE;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,EACF;AACA,MAAI,eAAe,SAAS,GAAG;AAC7B;AAAA,MACE;AAAA,MACA,eAAe,eAAe;AAAA,IAChC;AACA,UAAM,QAAQ,IAAI,cAAc;AAAA,EAClC;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/turbopack/chunk-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n getBundleKey,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport {\n failedProxiedAssetError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport { logDebug, warnCrossOriginFetchError } from '#internal/utils/logger';\nimport { TURBOPACK_GLOBAL_RE } from './patterns';\n\n/**\n * Creates chunk loader function for webpack runtime.\n * This function is responsible for loading JavaScript chunks from remote applications\n * and transforming Turbopack-specific code to work in the host environment.\n */\nexport function createChunkLoader(\n runtime: Runtime,\n resolveClientUrl?: InternalResolveClientUrl,\n): (chunkId: string, scriptBundle?: string) => Promise<unknown> | undefined {\n return function __turbopack_chunk_load__(\n chunkId: string,\n scriptBundle?: string,\n ) {\n logDebug('ChunkLoader', `Loading chunk: \"${chunkId}\"`);\n const self = globalThis as GlobalScope;\n const {\n bundle,\n id: path,\n prefix,\n } = REMOTE_COMPONENT_REGEX.exec(chunkId)?.groups ?? {\n bundle: scriptBundle ?? '',\n id: chunkId,\n };\n logDebug(\n 'ChunkLoader',\n `Parsed chunk - bundle: \"${bundle}\", path: \"${path}\", prefix: \"${prefix}\"`,\n );\n const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? 'default']\n ? self.__remote_webpack_require__[bundle ?? 'default']?.type || 'webpack'\n : runtime;\n logDebug('ChunkLoader', `Remote runtime: \"${remoteRuntime}\"`);\n if (remoteRuntime === RUNTIME_WEBPACK) {\n logDebug('ChunkLoader', 'Skipping chunk load - webpack runtime detected');\n return Promise.resolve(undefined);\n }\n\n const url = new URL(\n path\n ? `${prefix ?? ''}${path}`.replace(\n /(?<char>[^:])(?<double>\\/\\/)/g,\n '$1/',\n )\n : '/',\n self.__remote_bundle_url__?.[bundle ?? 'default'] ??\n new URL(location.origin),\n ).href;\n if (url.endsWith('.css')) {\n logDebug('ChunkLoader', `Skipping CSS file: \"${url}\"`);\n return;\n }\n\n if (!self.__remote_components_turbopack_chunk_loader_promise__) {\n self.__remote_components_turbopack_chunk_loader_promise__ = {};\n }\n if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {\n logDebug('ChunkLoader', `Returning cached promise for: \"${url}\"`);\n return self.__remote_components_turbopack_chunk_loader_promise__[url];\n }\n\n const resolvedUrl = resolveClientUrl?.(url) ?? url;\n logDebug('ChunkLoader', `Fetching chunk from: \"${resolvedUrl}\"`);\n self.__remote_components_turbopack_chunk_loader_promise__[url] =\n new Promise((resolve, reject) => {\n fetch(resolvedUrl)\n .then((res) => res.text())\n .then((code) => {\n // Turbopack runtime uses either dot-notation or bracket-notation globals.\n const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);\n if (hasTurbopack) {\n return handleTurbopackChunk(code, bundle ?? '', url);\n }\n logDebug(\n 'ChunkLoader',\n `Chunk does not contain globalThis.TURBOPACK or self.TURBOPACK: \"${url}\"`,\n );\n logDebug(\n 'ChunkLoader',\n `First 500 chars of chunk: ${code.slice(0, 500)}`,\n );\n })\n .then(resolve)\n .catch((error) => {\n const isProxied = isProxiedUrl(resolvedUrl);\n if (isProxied) {\n reject(failedProxiedAssetError('chunk', url, resolvedUrl));\n } else {\n warnCrossOriginFetchError('ChunkLoader', url);\n reject(error);\n }\n });\n });\n\n return self.__remote_components_turbopack_chunk_loader_promise__[url];\n };\n}\n\n/**\n * Handles Turbopack chunk loading by transforming the chunk code to isolate\n * global variables per bundle and dynamically loading the transformed script.\n */\nasync function handleTurbopackChunk(\n code: string,\n bundle: string,\n url: string,\n): Promise<void> {\n logDebug(\n 'ChunkLoader',\n `Handling Turbopack chunk - bundle: \"${bundle}\", url: \"${url}\"`,\n );\n // skip this chunk as it is not needed for remote components\n if (/importScripts\\(\\.\\.\\.self.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {\n logDebug('ChunkLoader', `Skipping worker chunk: \"${url}\"`);\n // remove preload links for this chunk\n const preloadLinks = document.querySelectorAll(\n `link[rel=\"preload\"][href=\"${new URL(url).pathname}\"]`,\n );\n preloadLinks.forEach((preloadLink) => preloadLink.remove());\n return;\n }\n\n const self = globalThis as GlobalScope;\n const bundleKey = getBundleKey(bundle);\n logDebug('ChunkLoader', `Bundle key: \"${bundleKey}\"`);\n\n // replace global variables with bundle-specific ones to prevent collisions\n // between multiple remote component bundles\n const transformedCode = code\n // Turbopack runtime can reference TURBOPACK via bracket-notation (common in newer Next.js)\n // e.g. globalThis[\"TURBOPACK\"] / self['TURBOPACK']\n .replace(\n /globalThis\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `globalThis[\"TURBOPACK_${bundleKey}\"]`,\n )\n .replace(\n /self\\[\\s*[\"']TURBOPACK[\"']\\s*\\]/g,\n `self[\"TURBOPACK_${bundleKey}\"]`,\n )\n .replace(/globalThis\\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`)\n .replace(/self\\.TURBOPACK(?!_)/g, `self.TURBOPACK_${bundleKey}`)\n .replace(\n /TURBOPACK_WORKER_LOCATION/g,\n `TURBOPACK_WORKER_LOCATION_${bundleKey}`,\n )\n .replace(\n /TURBOPACK_NEXT_CHUNK_URLS/g,\n `TURBOPACK_NEXT_CHUNK_URLS_${bundleKey}`,\n )\n .replace(\n /TURBOPACK_CHUNK_UPDATE_LISTENERS/g,\n `TURBOPACK_CHUNK_UPDATE_LISTENERS_${bundleKey}`,\n )\n .replace(/__next_require__/g, `__${bundleKey}_next_require__`)\n .replace(\n /\\/\\/# sourceMappingURL=(?<name>.+)(?<optional>\\._)?\\.js\\.map/g,\n `//# sourceMappingURL=${\n new URL(\n '.',\n new URL(\n url,\n self.__remote_bundle_url__?.[bundle] ?? new URL(location.origin),\n ),\n ).href\n }$1$2.js.map`,\n );\n\n // Initialize TURBOPACK bundle with push interceptor for Next.js 16.2.0-canary\n // Use webpack-style chunk loading pattern\n if (!self[`TURBOPACK_${bundleKey}`]) {\n const chunkData: unknown[][] = [];\n const turbopackObject = {\n push: (item: unknown) => {\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey}.push() called with item type: ${Array.isArray(item) ? 'array' : typeof item}`,\n );\n if (Array.isArray(item)) {\n chunkData.push(item);\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey} now has ${chunkData.length} chunks`,\n );\n } else {\n chunkData.push([item]);\n }\n return chunkData.length;\n },\n // Store chunks for later access\n __chunks__: chunkData,\n };\n self[`TURBOPACK_${bundleKey}`] = turbopackObject as unknown as Record<\n string,\n unknown\n >;\n }\n\n // load the script dynamically using a Blob URL\n logDebug('ChunkLoader', `Creating blob script for: \"${url}\"`);\n await new Promise<void>((scriptResolve, scriptReject) => {\n const blob = new Blob([transformedCode], {\n type: 'application/javascript; charset=UTF-8',\n });\n const scriptUrl = URL.createObjectURL(blob);\n const script = document.createElement('script');\n script.setAttribute('data-turbopack-src', url);\n script.src = scriptUrl;\n script.async = true;\n script.onload = () => {\n URL.revokeObjectURL(scriptUrl);\n logDebug(\n 'ChunkLoader',\n `Script loaded successfully for bundle \"${bundle}\"`,\n );\n const turbopackBundle = self[`TURBOPACK_${bundleKey}`];\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey} type: ${typeof turbopackBundle}, isArray: ${Array.isArray(turbopackBundle)}, keys: ${\n turbopackBundle\n ? Object.keys(turbopackBundle as object)\n .slice(0, 10)\n .join(', ')\n : 'none'\n }`,\n );\n if (turbopackBundle && typeof turbopackBundle === 'object') {\n logDebug(\n 'ChunkLoader',\n `TURBOPACK_${bundleKey} length/size: ${Array.isArray(turbopackBundle) ? turbopackBundle.length : Object.keys(turbopackBundle as object).length}`,\n );\n }\n scriptResolve(undefined);\n script.remove();\n };\n script.onerror = () => {\n URL.revokeObjectURL(scriptUrl);\n scriptReject(\n new RemoteComponentsError(\n `Failed to load <script src=\"${script.src}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n script.remove();\n };\n document.head.appendChild(script);\n });\n\n // process any additional chunks that were registered during script execution\n const chunkLists = self[`TURBOPACK_${bundleKey}_CHUNK_LISTS`] as\n | { chunks: string[] }[]\n | undefined;\n logDebug(\n 'ChunkLoader',\n `Processing chunk lists for bundle \"${bundle}\": ${chunkLists?.length ?? 0} lists`,\n );\n const loadChunkLists = [] as (Promise<unknown> | undefined)[];\n while (chunkLists?.length) {\n const { chunks } = chunkLists.shift() ?? { chunks: [] };\n if (chunks.length > 0) {\n logDebug(\n 'ChunkLoader',\n `Loading ${chunks.length} additional chunks for bundle \"${bundle}\": [${chunks.join(', ')}]`,\n );\n chunks.forEach((id: string) => {\n const chunkLoadResult = self.__webpack_chunk_load__?.(\n `[${bundle}] ${url.slice(0, url.indexOf('/_next'))}/_next/${id}`,\n );\n if (chunkLoadResult) {\n loadChunkLists.push(chunkLoadResult);\n }\n });\n }\n }\n if (loadChunkLists.length > 0) {\n logDebug(\n 'ChunkLoader',\n `Waiting for ${loadChunkLists.length} additional chunks to load`,\n );\n await Promise.all(loadChunkLists);\n }\n}\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,8BAA8B;AAEvC,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAU,iCAAiC;AACpD,SAAS,2BAA2B;AAO7B,SAAS,kBACd,SACA,kBAC0E;AAC1E,SAAO,SAAS,yBACd,SACA,cACA;AACA,aAAS,eAAe,mBAAmB,UAAU;AACrD,UAAM,OAAO;AACb,UAAM;AAAA,MACJ;AAAA,MACA,IAAI;AAAA,MACJ;AAAA,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ports);
|
|
34
34
|
var import_constants = require("#internal/runtime/constants");
|
|
35
|
+
var import_patterns = require("#internal/runtime/patterns");
|
|
35
36
|
var import_error = require("#internal/utils/error");
|
|
36
37
|
var import_logger = require("#internal/utils/logger");
|
|
37
38
|
var import_chunk_loader = require("./chunk-loader");
|
|
@@ -59,7 +60,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
if (runtime === import_constants.RUNTIME_TURBOPACK) {
|
|
62
|
-
await Promise.
|
|
63
|
+
const results = await Promise.allSettled(
|
|
63
64
|
scripts.map((script) => {
|
|
64
65
|
if (script.src) {
|
|
65
66
|
return self.__webpack_chunk_load__?.(script.src, bundle);
|
|
@@ -67,6 +68,14 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
67
68
|
return Promise.resolve(void 0);
|
|
68
69
|
})
|
|
69
70
|
);
|
|
71
|
+
for (const result of results) {
|
|
72
|
+
if (result.status === "rejected") {
|
|
73
|
+
(0, import_logger.logWarn)(
|
|
74
|
+
"WebpackRuntime",
|
|
75
|
+
`Initial chunk load failed: ${String(result.reason)}`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
70
79
|
}
|
|
71
80
|
const coreShared = {
|
|
72
81
|
react: async () => (await import("react")).default,
|
|
@@ -86,7 +95,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
86
95
|
function createModuleRequire(runtime) {
|
|
87
96
|
return (id) => {
|
|
88
97
|
const self = globalThis;
|
|
89
|
-
const { bundle, id: moduleId } = id.match(
|
|
98
|
+
const { bundle, id: moduleId } = id.match(import_patterns.REMOTE_COMPONENT_REGEX)?.groups ?? {
|
|
90
99
|
bundle: "default",
|
|
91
100
|
id
|
|
92
101
|
};
|