remote-components 0.3.4 → 0.3.6
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/app-63L5THIQ.js +12 -0
- package/dist/app-63L5THIQ.js.map +1 -0
- package/dist/app-A5QE7XRH.cjs +12 -0
- package/dist/app-A5QE7XRH.cjs.map +1 -0
- package/dist/chunk-2VQGCACH.js +190 -0
- package/dist/chunk-2VQGCACH.js.map +1 -0
- package/dist/chunk-42N2ZLE2.js +703 -0
- package/dist/chunk-42N2ZLE2.js.map +1 -0
- package/dist/chunk-6IUP26UK.cjs +57 -0
- package/dist/chunk-6IUP26UK.cjs.map +1 -0
- package/dist/chunk-7MVFHOIP.cjs +60 -0
- package/dist/chunk-7MVFHOIP.cjs.map +1 -0
- package/dist/chunk-CREXMFMF.cjs +155 -0
- package/dist/chunk-CREXMFMF.cjs.map +1 -0
- package/dist/chunk-CTUJSWCM.js +215 -0
- package/dist/chunk-CTUJSWCM.js.map +1 -0
- package/dist/chunk-ENYGL5CO.js +11 -0
- package/dist/chunk-ENYGL5CO.js.map +1 -0
- package/dist/chunk-ER73O65F.cjs +703 -0
- package/dist/chunk-ER73O65F.cjs.map +1 -0
- package/dist/chunk-F44NODUS.cjs +709 -0
- package/dist/chunk-F44NODUS.cjs.map +1 -0
- package/dist/chunk-GAXJTFBV.js +20 -0
- package/dist/chunk-GAXJTFBV.js.map +1 -0
- package/dist/chunk-HNZVEIKN.js +358 -0
- package/dist/chunk-HNZVEIKN.js.map +1 -0
- package/dist/chunk-KE7QPAQ4.cjs +21 -0
- package/dist/chunk-KE7QPAQ4.cjs.map +1 -0
- package/dist/chunk-KEPHL25S.js +60 -0
- package/dist/chunk-KEPHL25S.js.map +1 -0
- package/dist/chunk-KKBEMQU7.cjs +670 -0
- package/dist/chunk-KKBEMQU7.cjs.map +1 -0
- package/dist/chunk-KYJWRZ2B.js +709 -0
- package/dist/chunk-KYJWRZ2B.js.map +1 -0
- package/dist/chunk-N5VQR2PW.cjs +215 -0
- package/dist/chunk-N5VQR2PW.cjs.map +1 -0
- package/dist/chunk-OO4AMJWO.js +155 -0
- package/dist/chunk-OO4AMJWO.js.map +1 -0
- package/dist/chunk-R4QFK5TN.cjs +358 -0
- package/dist/chunk-R4QFK5TN.cjs.map +1 -0
- package/dist/chunk-RUWR74XQ.cjs +152 -0
- package/dist/chunk-RUWR74XQ.cjs.map +1 -0
- package/dist/chunk-S2A4TFLS.js +152 -0
- package/dist/chunk-S2A4TFLS.js.map +1 -0
- package/dist/chunk-SHFJ5OQA.cjs +11 -0
- package/dist/chunk-SHFJ5OQA.cjs.map +1 -0
- package/dist/chunk-TCFLEBQM.cjs +20 -0
- package/dist/chunk-TCFLEBQM.cjs.map +1 -0
- package/dist/chunk-W5ESPGHH.js +670 -0
- package/dist/chunk-W5ESPGHH.js.map +1 -0
- package/dist/chunk-X6YKUJKH.js +21 -0
- package/dist/chunk-X6YKUJKH.js.map +1 -0
- package/dist/chunk-XCFYWSLD.cjs +190 -0
- package/dist/chunk-XCFYWSLD.cjs.map +1 -0
- package/dist/chunk-ZPMTZ3KJ.js +57 -0
- package/dist/chunk-ZPMTZ3KJ.js.map +1 -0
- package/dist/config/nextjs.cjs +76 -351
- package/dist/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.js +26 -266
- package/dist/config/nextjs.js.map +1 -1
- package/dist/config/webpack.cjs +12 -240
- package/dist/config/webpack.cjs.map +1 -1
- package/dist/config/webpack.js +6 -207
- package/dist/config/webpack.js.map +1 -1
- package/dist/host/html.cjs +139 -2447
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +66 -2345
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +53 -2825
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +31 -2780
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/nextjs/app.cjs +34 -2
- package/dist/host/nextjs/app.cjs.map +1 -1
- package/dist/host/nextjs/app.js +35 -3
- package/dist/host/nextjs/app.js.map +1 -1
- package/dist/host/proxy/client.cjs +8 -38
- package/dist/host/proxy/client.cjs.map +1 -1
- package/dist/host/proxy/client.js +4 -7
- package/dist/host/proxy/client.js.map +1 -1
- package/dist/host/proxy.cjs +19 -56
- package/dist/host/proxy.cjs.map +1 -1
- package/dist/host/proxy.js +8 -20
- package/dist/host/proxy.js.map +1 -1
- package/dist/host/react.cjs +17 -2756
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +13 -2723
- package/dist/host/react.js.map +1 -1
- package/dist/internal/host/nextjs/app-client.cjs +38 -24
- package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
- package/dist/internal/host/nextjs/app-client.js +38 -24
- package/dist/internal/host/nextjs/app-client.js.map +1 -1
- package/dist/internal/host/nextjs/remote-component-links.cjs +24 -13
- package/dist/internal/host/nextjs/remote-component-links.cjs.map +1 -1
- package/dist/internal/host/nextjs/remote-component-links.d.ts +3 -0
- package/dist/internal/host/nextjs/remote-component-links.js +24 -13
- package/dist/internal/host/nextjs/remote-component-links.js.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.cjs +1 -18
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.js +1 -18
- package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
- package/dist/internal/host/shared/lifecycle.cjs +69 -0
- package/dist/internal/host/shared/lifecycle.cjs.map +1 -0
- package/dist/internal/host/shared/lifecycle.d.ts +34 -0
- package/dist/internal/host/shared/lifecycle.js +44 -0
- package/dist/internal/host/shared/lifecycle.js.map +1 -0
- package/dist/internal/host/shared/pipeline.cjs +222 -0
- package/dist/internal/host/shared/pipeline.cjs.map +1 -0
- package/dist/internal/host/shared/pipeline.d.ts +153 -0
- package/dist/internal/host/shared/pipeline.js +200 -0
- package/dist/internal/host/shared/pipeline.js.map +1 -0
- package/dist/internal/runtime/loaders/component-loader.cjs +5 -2
- package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/component-loader.js +5 -2
- package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/patterns.cjs +1 -1
- package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/patterns.js +1 -1
- package/dist/internal/runtime/turbopack/patterns.js.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope.cjs +1 -5
- package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope.js +1 -5
- package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
- package/dist/internal/utils.cjs +1 -1
- package/dist/internal/utils.cjs.map +1 -1
- package/dist/internal/utils.d.ts +5 -5
- package/dist/internal/utils.js +1 -1
- package/dist/internal/utils.js.map +1 -1
- package/dist/remote/html.cjs +15 -314
- package/dist/remote/html.cjs.map +1 -1
- package/dist/remote/html.js +7 -305
- package/dist/remote/html.js.map +1 -1
- package/dist/remote/middleware.cjs +16 -41
- package/dist/remote/middleware.cjs.map +1 -1
- package/dist/script-6W5JRBZK.cjs +26 -0
- package/dist/script-6W5JRBZK.cjs.map +1 -0
- package/dist/script-IFEBOLIA.js +26 -0
- package/dist/script-IFEBOLIA.js.map +1 -0
- package/dist/static-loader-X4TSF5KW.js +11 -0
- package/dist/static-loader-X4TSF5KW.js.map +1 -0
- package/dist/static-loader-ZYD5BO4D.cjs +11 -0
- package/dist/static-loader-ZYD5BO4D.cjs.map +1 -0
- package/dist/turbopack-NPGO3MWS.js +55 -0
- package/dist/turbopack-NPGO3MWS.js.map +1 -0
- package/dist/turbopack-WRMKPNN4.cjs +55 -0
- package/dist/turbopack-WRMKPNN4.cjs.map +1 -0
- package/dist/webpack-DUBHPYD6.js +92 -0
- package/dist/webpack-DUBHPYD6.js.map +1 -0
- package/dist/webpack-KSCMCL7M.cjs +92 -0
- package/dist/webpack-KSCMCL7M.cjs.map +1 -0
- package/package.json +10 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/host/server/fetch-with-hooks.ts","../src/host/server/get-client-or-server-url.ts","../src/host/shared/lifecycle.ts","../src/runtime/rsc.ts","../src/runtime/html/html-spec.ts","../src/runtime/html/rewrite-srcset.ts","../src/runtime/html/apply-origin.ts","../src/runtime/metadata.ts","../src/runtime/html/parse-remote-html.ts","../src/runtime/loaders/component-loader.ts","../src/runtime/rsc-imports.ts","../src/host/shared/pipeline.ts","../src/host/shared/state.ts","../src/host/utils/resolve-name-from-src.ts","../src/runtime/url/resolve-client-url.ts","../src/runtime/url/default-resolve-client-url.ts"],"sourcesContent":["import type {\n HookOptions,\n OnRequestHook,\n OnResponseHook,\n} from '#internal/host/shared/fetch-interceptors';\nimport { warnCrossOriginFetchError } from '#internal/utils/logger';\nimport { remoteFetchHeaders } from './fetch-headers';\n\n/**\n * Options for fetching with request/response hooks.\n */\ninterface FetchWithHooksOptions {\n /** Hook to intercept the request before fetching */\n onRequest?: OnRequestHook;\n /** Hook to process the response after fetching */\n onResponse?: OnResponseHook;\n /** AbortController to cancel loading - aborts will throw AbortError */\n abortController?: AbortController;\n}\n\n/**\n * Performs a fetch with optional request and response lifecycle hooks.\n *\n * This utility centralizes the logic for:\n * 1. Calling onRequest hook - if it returns a Response, use it instead of fetching\n * 2. Performing the actual fetch if onRequest didn't provide a response\n * 3. Calling onResponse hook - if it returns a Response, use that transformed response\n *\n * Hooks receive an AbortSignal and abort function to cancel loading at any point.\n * When aborted, throws AbortError (DOMException with name 'AbortError').\n *\n * @param url - The URL to fetch\n * @param init - The fetch init options\n * @param options - Optional hooks for request/response interception and AbortController\n * @returns The response (never null - throws on abort)\n * @throws DOMException with name 'AbortError' if loading is aborted\n *\n * @example\n * const controller = new AbortController();\n * try {\n * const response = await fetchWithHooks(url, fetchInit, {\n * abortController: controller,\n * onResponse: async (url, response, { abort }) => {\n * if (response.redirected) {\n * abort(); // Throws AbortError\n * }\n * },\n * });\n * } catch (error) {\n * if (error.name === 'AbortError') {\n * console.log('Loading was aborted');\n * }\n * }\n */\nasync function fetchWithWarning(\n url: URL,\n init: RequestInit,\n): Promise<Response> {\n try {\n return await fetch(url, init);\n } catch (error) {\n warnCrossOriginFetchError('FetchRemoteComponent', url);\n throw error;\n }\n}\n\nexport async function fetchWithHooks(\n url: URL,\n additionalInit: {\n credentials?: RequestCredentials;\n next?: {\n tags?: string[];\n };\n },\n options: FetchWithHooksOptions = {},\n): Promise<Response> {\n const {\n onRequest,\n onResponse,\n abortController = new AbortController(),\n } = options;\n const signal = abortController.signal;\n\n const hookOptions: HookOptions = {\n signal,\n abort: (reason?: unknown) => abortController.abort(reason),\n };\n\n // Include signal in fetch init for reactive abort support\n const init: RequestInit = {\n method: 'GET',\n headers: remoteFetchHeaders(),\n signal,\n ...additionalInit,\n };\n\n // Call onRequest hook if provided - may return a Response to skip fetching\n const res =\n (await onRequest?.(url, init, hookOptions)) ??\n (await fetchWithWarning(url, init));\n\n // Call onResponse hook if provided - may return a transformed Response\n return (await onResponse?.(url, res, hookOptions)) ?? res;\n}\n","export function getClientOrServerUrl(\n src: string | URL | undefined,\n serverFallback: string,\n): URL {\n const fallback =\n typeof location !== 'undefined' ? location.href : serverFallback;\n\n if (!src) {\n return new URL(fallback);\n }\n\n return typeof src === 'string' ? new URL(src, fallback) : src;\n}\n","import type { ChangeInfo, ConsumeLifecycleCallbacks } from './config';\n\n/**\n * Unified lifecycle event emitter used by the host loading pipeline.\n *\n * Hosts create an emitter that matches their eventing model — React hosts\n * wrap callback props via {@link makeReactEmitter}, while the HTML custom\n * element dispatches DOM events via {@link makeEventEmitter}. The pipeline\n * calls emitter methods at the appropriate phases without knowing which\n * host is driving the load.\n */\nexport interface LifecycleEmitter {\n beforeLoad(src: string | URL): void;\n load(src: string | URL): void;\n error(error: unknown, src?: string | URL): void;\n change(info: ChangeInfo): void;\n}\n\n/**\n * Wraps React-style callback props into a {@link LifecycleEmitter}.\n *\n * Missing callbacks are silently ignored — this is the normal case for\n * hosts that only subscribe to a subset of events.\n */\nexport function makeReactEmitter(\n callbacks: ConsumeLifecycleCallbacks,\n): LifecycleEmitter {\n return {\n beforeLoad(src) {\n callbacks.onBeforeLoad?.(src);\n },\n load(src) {\n callbacks.onLoad?.(src);\n },\n error(error, _src?) {\n callbacks.onError?.(error);\n },\n change(info) {\n callbacks.onChange?.(info);\n },\n };\n}\n\n/**\n * Wraps a DOM element into a {@link LifecycleEmitter} by dispatching\n * `CustomEvent`s with `bubbles: true` and `composed: true` (crosses\n * Shadow DOM boundaries).\n */\nexport function makeEventEmitter(element: HTMLElement): LifecycleEmitter {\n function dispatch(\n type: 'beforeload' | 'load' | 'error' | 'change',\n detail?: Record<string, unknown>,\n ) {\n const event = new Event(type, { bubbles: true, composed: true });\n if (detail) {\n Object.assign(event, detail);\n }\n element.dispatchEvent(event);\n }\n\n return {\n beforeLoad(src) {\n dispatch('beforeload', { src });\n },\n load(src) {\n dispatch('load', { src });\n },\n error(error, src?) {\n dispatch('error', src != null ? { error, src } : { error });\n },\n change(info) {\n dispatch('change', info as unknown as Record<string, unknown>);\n },\n };\n}\n","import { ReadableStream } from 'web-streams-polyfill';\n\n/**\n * Fixes RSC payload arrays to be compatible with React JSX development runtime.\n * React elements in the wire format are 4-element arrays (`['$', type, key, props]`);\n * the dev runtime expects 7 elements with debug info in positions 4-6.\n */\nexport function fixPayload(payload: unknown): void {\n if (Array.isArray(payload)) {\n if (payload[0] === '$') {\n // React element — fix props recursively, then pad to 7 elements\n fixPayload(payload[3]);\n if (payload.length === 4) {\n payload.push(null, null, 1);\n }\n } else {\n for (const item of payload) {\n fixPayload(item);\n }\n }\n } else if (typeof payload === 'object' && payload !== null) {\n for (const key in payload) {\n fixPayload((payload as Record<string, unknown>)[key]);\n }\n }\n}\n\n/**\n * Parses raw RSC script chunks (the `self[\"name\"].push(\"...\")` format produced\n * by `<RemoteComponentData>`) into a flat array of flight-data strings.\n *\n * This is a pure function — it reads from `data` only, never from `globalThis`.\n */\nexport function buildRSCChunks(rscName: string, data: string[]): string[] {\n const chunks: string[] = [];\n\n for (const chunk of data) {\n for (const line of chunk.split('\\n')) {\n const match = /\\.push\\(\"(?<rsc>.*)\"\\);$/.exec(line);\n if (match?.groups?.rsc) {\n chunks.push(JSON.parse(`\"${match.groups.rsc}\"`) as string);\n }\n }\n }\n\n return chunks;\n}\n\n/**\n * Processes RSC flight data and creates a ReadableStream.\n *\n * First checks `data` for inline script chunks (parsed via {@link buildRSCChunks}),\n * merging them onto `globalThis[rscName]`. Then consumes the global array\n * (or falls back to an empty RSC payload) and pipes fixed chunks into the stream.\n */\nexport function createRSCStream(\n rscName: string,\n data: string[],\n): ReadableStream<Uint8Array> {\n return new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n const self = globalThis as typeof globalThis &\n Record<string, string[] | null>;\n\n // Parse inline script chunks and merge onto the global array\n if (data.length > 0) {\n const parsed = buildRSCChunks(rscName, data);\n if (parsed.length > 0) {\n self[rscName] = self[rscName] ?? [];\n self[rscName].push(...parsed);\n }\n }\n\n // Consume the global RSC flight data, falling back to an empty payload\n const allChunks = (self[rscName] ?? [`0:[null]\\n`]).join('');\n self[rscName] = null;\n\n // Process each line in the RSC flight data\n allChunks.split('\\n').forEach((chunk) => {\n if (chunk.length > 0) {\n const { before, id, prefix, payload } =\n /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\\[.*\\])/.exec(\n chunk,\n )?.groups ?? {};\n\n if (payload) {\n const jsonPayload = JSON.parse(payload) as unknown[];\n fixPayload(jsonPayload);\n const reconstruct = `${before ?? ''}${id}:${prefix ?? ''}${JSON.stringify(jsonPayload)}`;\n controller.enqueue(encoder.encode(`${reconstruct}\\n`));\n } else {\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n } else {\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n });\n controller.close();\n },\n });\n}\n","/**\n * Pure constants for HTML element names, data attributes, and ID suffixes\n * used across both server-side (parse5) and browser (DOM) HTML processing.\n *\n * No imports, no runtime code — safe to use in any context.\n */\n\n/** Elements whose `src`, `href`, `srcset`, and `imagesrcset` need origin rewriting. */\nexport const ORIGIN_REWRITE_TAGS = [\n 'img',\n 'source',\n 'video',\n 'audio',\n 'track',\n 'iframe',\n 'embed',\n 'script',\n 'link',\n] as const;\n\n// ID suffixes appended to the component name to form element IDs.\nexport const ID_SUFFIX_RSC = '_rsc';\nexport const ID_SUFFIX_SSR = '_ssr';\nexport const ID_SUFFIX_SHARED = '_shared';\n\n// Data attributes written on the remote component wrapper element.\nexport const DATA_BUNDLE = 'data-bundle';\nexport const DATA_ROUTE = 'data-route';\nexport const DATA_RUNTIME = 'data-runtime';\nexport const DATA_TYPE = 'data-type';\nexport const DATA_SRC = 'data-src';\nexport const DATA_REMOTE_COMPONENTS_SHARED = 'data-remote-components-shared';\n\n// Well-known element identifiers.\nexport const TAG_REMOTE_COMPONENT = 'remote-component';\nexport const NEXT_DATA_ID = '__NEXT_DATA__';\nexport const REMOTE_NEXT_DATA_ID = '__REMOTE_NEXT_DATA__';\nexport const NEXT_CONTAINER_ID = '__next';\n","/**\n * Rewrites relative URLs in an HTML `srcset` or `imagesrcset` attribute value\n * to absolute URLs. Works identically in server (parse5) and browser (DOM) contexts.\n *\n * @param srcset - The raw srcset attribute value (comma-separated entries).\n * @param base - Base URL or origin to resolve relative URLs against.\n * @param resolve - Optional callback applied to each absolute URL (e.g. to proxy through a CDN).\n * @returns The rewritten srcset string with absolute (and optionally resolved) URLs.\n */\nexport function rewriteSrcset(\n srcset: string,\n base: URL | string,\n resolve?: (absoluteUrl: string) => string,\n): string {\n return srcset\n .split(',')\n .map((entry) => {\n const [url, descriptor] = entry.trim().split(/\\s+/);\n if (!url) return entry;\n\n const absoluteUrl = new URL(url, base).href;\n const resolvedUrl = resolve ? resolve(absoluteUrl) : absoluteUrl;\n return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;\n })\n .join(', ');\n}\n","import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { ORIGIN_REWRITE_TAGS } from './html-spec';\nimport { rewriteSrcset } from './rewrite-srcset';\n\nexport function applyOriginToNodes(\n doc: Document | HTMLElement,\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n if (url.origin !== location.origin) {\n const nodes = doc.querySelectorAll<HTMLImageElement>(\n ORIGIN_REWRITE_TAGS.map(\n (type) =>\n `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`,\n ).join(','),\n );\n nodes.forEach((node) => {\n if (\n node.hasAttribute('src') &&\n /^[./]+\\/?/.test(node.getAttribute('src') ?? '')\n ) {\n const absoluteSrc = new URL(node.getAttribute('src') ?? '/', url).href;\n // Script elements are handled by the loaders (script-loader, static-loader)\n // which apply the callback themselves. Only apply it here for non-script elements.\n const isScript = node.tagName.toLowerCase() === 'script';\n node.src = isScript\n ? absoluteSrc\n : (resolveClientUrl?.(absoluteSrc) ?? absoluteSrc);\n }\n if (\n node.hasAttribute('href') &&\n /^[./]+\\/?/.test(node.getAttribute('href') ?? '')\n ) {\n const absoluteHref = new URL(node.getAttribute('href') ?? '/', url)\n .href;\n node.setAttribute(\n 'href',\n resolveClientUrl?.(absoluteHref) ?? absoluteHref,\n );\n }\n if (node.hasAttribute('srcset')) {\n const raw = node.getAttribute('srcset');\n if (raw) {\n const resolve = resolveClientUrl\n ? (abs: string) => resolveClientUrl(abs) ?? abs\n : undefined;\n node.setAttribute('srcset', rewriteSrcset(raw, url, resolve));\n }\n }\n if (node.hasAttribute('imagesrcset')) {\n const raw = node.getAttribute('imagesrcset');\n if (raw) {\n const resolve = resolveClientUrl\n ? (abs: string) => resolveClientUrl(abs) ?? abs\n : undefined;\n node.setAttribute('imagesrcset', rewriteSrcset(raw, url, resolve));\n }\n }\n });\n }\n}\n","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","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';\nimport {\n DATA_BUNDLE,\n DATA_REMOTE_COMPONENTS_SHARED,\n DATA_ROUTE,\n DATA_RUNTIME,\n DATA_SRC,\n DATA_TYPE,\n ID_SUFFIX_RSC,\n ID_SUFFIX_SHARED,\n ID_SUFFIX_SSR,\n NEXT_CONTAINER_ID,\n NEXT_DATA_ID,\n REMOTE_NEXT_DATA_ID,\n TAG_REMOTE_COMPONENT,\n} from './html-spec';\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(\n `div[${DATA_BUNDLE}][${DATA_ROUTE}][id^=\"${name}\"]`,\n )) ||\n (doc.querySelectorAll(`${TAG_REMOTE_COMPONENT}:not([src])`).length > 1 &&\n !doc.querySelector(`${TAG_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_CONTAINER_ID}`) ??\n doc.querySelector(`${TAG_REMOTE_COMPONENT}[name=\"${name}\"]:not([src])`) ??\n doc.querySelector(`${TAG_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_ID}`) ??\n doc.querySelector(`#${REMOTE_NEXT_DATA_ID}`)\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() === TAG_REMOTE_COMPONENT;\n\n const name =\n component\n ?.getAttribute('id')\n ?.replace(new RegExp(`${ID_SUFFIX_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}${ID_SUFFIX_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}${ID_SUFFIX_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","import * as React from 'react';\nimport * as JSXDevRuntime from 'react/jsx-dev-runtime';\nimport * as JSXRuntime from 'react/jsx-runtime';\nimport * as ReactDOM from 'react-dom';\nimport * as ReactDOMClient from 'react-dom/client';\nimport { applySharedModules } from '#internal/config/webpack/apply-shared-modules';\nimport { nextClientPagesLoader } from '#internal/config/webpack/next-client-pages-loader';\nimport type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type { ConsumeLoaderPayload } from '#internal/host/shared/server-handoff';\nimport {\n buildCoreShared,\n buildWebpackResolve,\n} from '#internal/host/shared/shared-module-resolver';\nimport { createRSCStream } from '#internal/runtime/rsc';\nimport { importRSCClientBrowser } from '#internal/runtime/rsc-imports';\nimport { setupRemoteScope } from '#internal/runtime/turbopack/remote-scope-setup';\nimport { initializeSharedModules } from '#internal/runtime/turbopack/shared-modules';\nimport type { GlobalScope, LoaderResult } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { loadScripts } from './script-loader';\n\n/**\n * Props accepted by {@link loadRemoteComponent}.\n *\n * Extends {@link ConsumeLoaderPayload} (the SSR-resolved fields needed for\n * hydration) with loader-specific fields (`url`, `shared`, `container`, etc.).\n * `remoteShared` is narrowed from optional to required (defaults to `{}` at\n * the call site).\n */\nexport interface ConsumeLoaderProps extends ConsumeLoaderPayload {\n url: URL;\n shared:\n | Promise<Record<string, (bundle?: string) => Promise<unknown>>>\n | Record<string, (bundle?: string) => Promise<unknown>>;\n remoteShared: Record<string, string>;\n container?: HTMLHeadElement | ShadowRoot | null;\n rscName?: string;\n resolveClientUrl?: InternalResolveClientUrl;\n}\n\n/**\n * Main loader function that orchestrates the component loading process\n */\nexport async function loadRemoteComponent({\n url,\n name,\n rscName,\n bundle,\n route = '/',\n runtime = 'webpack',\n data,\n nextData,\n scripts = [],\n shared = Promise.resolve({}),\n remoteShared = {},\n container,\n resolveClientUrl,\n}: ConsumeLoaderProps): Promise<LoaderResult> {\n try {\n // Load scripts if using webpack runtime\n if (runtime === 'webpack') {\n const self = globalThis as GlobalScope;\n // disable webpack entrypoint execution for the remote\n if (!self.__DISABLE_WEBPACK_EXEC__) {\n self.__DISABLE_WEBPACK_EXEC__ = {};\n }\n // disable webpack entrypoint execution for the current remote bundle\n self.__DISABLE_WEBPACK_EXEC__[bundle] = true;\n await loadScripts(scripts, resolveClientUrl);\n }\n\n const hostShared = await shared;\n logDebug(\n 'ComponentLoader',\n `loadRemoteComponent: bundle=\"${bundle}\", name=\"${name}\"`,\n );\n logDebug(\n 'ComponentLoader',\n `Host shared modules available: ${Object.keys(hostShared)}`,\n );\n logDebug(\n 'ComponentLoader',\n `Remote shared modules requested: ${JSON.stringify(remoteShared)}`,\n );\n\n // Setup remote scope and load turbopack chunks\n const scope = await setupRemoteScope(\n runtime,\n scripts,\n url,\n bundle,\n resolveClientUrl,\n );\n\n // Initialize turbopack shared modules (React, etc.) now that chunks are loaded\n if (runtime === 'turbopack') {\n await initializeSharedModules(\n scope,\n buildCoreShared(hostShared),\n remoteShared,\n );\n }\n\n // Setup shared modules\n if (bundle) {\n const resolve = await buildWebpackResolve(\n hostShared,\n remoteShared,\n bundle,\n {\n '/react/index.js': React,\n '/react/jsx-dev-runtime.js': JSXDevRuntime,\n '/react/jsx-runtime.js': JSXRuntime,\n '/react-dom/index.js': ReactDOM,\n '/react-dom/client.js': ReactDOMClient,\n },\n 'ComponentLoader',\n );\n applySharedModules(bundle, resolve);\n } else {\n logWarn(\n 'ComponentLoader',\n 'No bundle specified, skipping shared module setup',\n );\n }\n\n // Rewrite plain bundle references in RSC data to the scoped name so\n // the client dispatchers resolve the correct scope.\n const scopedData = data.map((chunk) =>\n chunk.replaceAll(`[${bundle}]`, `[${scope.scopedName}]`),\n );\n\n // Load component based on data type\n if (scopedData.length > 0) {\n return await loadRSCComponent(rscName ?? name, scopedData);\n } else if (nextData) {\n return loadNextPagesComponent(bundle, route, nextData, name, container);\n }\n\n return loadRSCComponent(rscName ?? name, [`0:[null]\\n`]); // Fallback to empty RSC payload\n } catch (error) {\n return {\n component: null,\n error: new RemoteComponentsError(\n `Failed to load remote component \"${name}\".`,\n {\n cause: error instanceof Error ? error : new Error(String(error)),\n },\n ),\n };\n }\n}\n\n/**\n * Loads RSC (React Server Components) based component\n */\nasync function loadRSCComponent(\n rscName: string,\n data: string[],\n): Promise<LoaderResult> {\n const { createFromReadableStream } = await importRSCClientBrowser();\n if (typeof createFromReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'Failed to import \"react-server-dom-webpack\". Is Next.js installed correctly?',\n );\n }\n\n const stream = createRSCStream(rscName, data);\n const component = createFromReadableStream(stream);\n\n return { component };\n}\n\n/**\n * Loads Next.js Pages Router based component\n */\nfunction loadNextPagesComponent(\n bundle: string,\n route: string,\n nextData: NonNullable<ConsumeLoaderPayload['nextData']>,\n name: string,\n container?: HTMLHeadElement | ShadowRoot | null,\n): LoaderResult {\n const { Component, App } = nextClientPagesLoader(bundle, route, container);\n\n if (!Component) {\n throw new RemoteComponentsError(\n `Remote Component \"${name}\" is trying to load the component for route \"${route}\" but it is not available.`,\n );\n }\n\n // error tolerance when app component is not found\n const component = App\n ? React.createElement(App, { Component, ...nextData.props })\n : React.createElement(Component, nextData.props);\n\n return { component };\n}\n","/**\n * Single import hub for all React Server Components runtime modules.\n *\n * Each function encapsulates the try/catch fallback chain that probes\n * Next.js internal paths first, then falls back to the public\n * `react-server-dom-webpack` / `react-server-dom-turbopack` packages.\n * This keeps version-specific import paths out of business logic.\n */\n\nimport type {\n RSCClientBrowserRuntime,\n RSCClientEdgeRuntime,\n RSCServerRuntime,\n} from './rsc-runtime';\n\n/**\n * Imports the RSC client for the **edge** runtime (server-side).\n * Used by `fetch-remote-component.ts` to deserialise RSC flight data.\n *\n * Tries the Next.js compiled path first, falls back to the bare\n * `react-server-dom-webpack/client.edge` module.\n */\nexport async function importRSCClientEdge(): Promise<RSCClientEdgeRuntime> {\n try {\n return await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\n );\n } catch {\n return await import('react-server-dom-webpack/client.edge');\n }\n}\n\n/**\n * Imports the RSC client for the **browser** runtime (client-side hydration).\n * Used by `component-loader.ts` to hydrate RSC streams in the browser.\n *\n * Tries the Next.js compiled path first, falls back to the bare\n * `react-server-dom-webpack/client.browser` module (which may use a\n * default export depending on the package version).\n */\nexport async function importRSCClientBrowser(): Promise<RSCClientBrowserRuntime> {\n try {\n return await import(\n 'next/dist/compiled/react-server-dom-webpack/client.browser'\n );\n } catch {\n const mod = await import('react-server-dom-webpack/client.browser');\n // Some versions export `createFromReadableStream` as a default export\n return (mod.default ?? mod) as RSCClientBrowserRuntime;\n }\n}\n\n/**\n * Imports the RSC **server** renderer for `ExposeRemoteComponent`.\n *\n * When `TURBOPACK` is set in the environment, imports from\n * `react-server-dom-turbopack`; otherwise uses `react-server-dom-webpack`.\n * Each variant tries the primary path first (`/server`), falling back to\n * the `.edge` entry point.\n */\nexport async function importRSCServer(): Promise<RSCServerRuntime> {\n const [primary, fallback] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n\n return {\n renderToReadableStream:\n primary.renderToReadableStream ?? fallback.renderToReadableStream,\n };\n}\n\nasync function tryImport<T>(importer: () => Promise<T>): Promise<T> {\n try {\n return await importer();\n } catch {\n return {} as T;\n }\n}\n","import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type { ScriptDescriptor } from '#internal/host/shared/asset-descriptors';\nimport type { ConsumeLoaderPayload } from '#internal/host/shared/server-handoff';\nimport { buildHostShared } from '#internal/host/shared/shared-module-resolver';\nimport { applyOriginToNodes } from '#internal/runtime/html/apply-origin';\nimport {\n type ParsedRemoteComponent,\n parseRemoteComponentDocument,\n} from '#internal/runtime/html/parse-remote-html';\nimport { loadRemoteComponent } from '#internal/runtime/loaders/component-loader';\nimport { loadStaticRemoteComponent } from '#internal/runtime/loaders/static-loader';\nimport type { RemoteComponentMetadata } from '#internal/runtime/metadata';\nimport {\n collapseDoubleSlashes,\n REMOTE_COMPONENT_REGEX,\n} from '#internal/runtime/patterns';\nimport type { MountOrUnmountFunction } from '#internal/runtime/types';\nimport { escapeString } from '#internal/utils';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\ntype SharedModuleMap = Record<string, (bundle?: string) => Promise<unknown>>;\n\n/**\n * Input for {@link runPipeline} — the full post-fetch pipeline that starts\n * from raw HTML.\n */\nexport interface PipelineInput {\n /** Resolved URL of the remote component. */\n url: URL;\n /** Raw HTML string returned by the remote. */\n html: string;\n /** Component name hint (may be refined during parsing). */\n name: string;\n /** Abort signal — the pipeline checks this between async steps. */\n signal: AbortSignal;\n /** Host-provided shared module factories (resolved or promise). */\n shared: Promise<SharedModuleMap> | SharedModuleMap;\n /** URL rewriter for client-side asset URLs. */\n resolveClientUrl?: InternalResolveClientUrl;\n /** Shadow root or element to mount into (for script-based components). */\n container?: ShadowRoot | HTMLElement | null;\n}\n\n/**\n * Input for {@link runPipelineFromParsed} — the pipeline entry point for\n * hosts that receive pre-parsed SSR data (e.g. the App Router client).\n */\nexport interface ParsedPipelineInput {\n /** Resolved URL of the remote component. */\n url: URL;\n /** Component name. */\n name: string;\n /** Abort signal. */\n signal: AbortSignal;\n /** Pre-resolved loader payload from the server component. */\n payload: ConsumeLoaderPayload;\n /** Host-provided shared module factories (resolved or promise). */\n shared: Promise<SharedModuleMap> | SharedModuleMap;\n /** Remote-requested shared modules. */\n remoteShared?: Record<string, string>;\n /** URL rewriter for client-side asset URLs. */\n resolveClientUrl?: InternalResolveClientUrl;\n /** Shadow root or element to mount into. */\n container?: ShadowRoot | HTMLElement | null;\n /** Optional RSC name override (used by App Router for scoped RSC data). */\n rscName?: string;\n}\n\n/**\n * Successful dynamic component load — the component is a React element tree\n * ready to render.\n */\nexport interface PipelineLoaded {\n status: 'loaded';\n component: React.ReactNode;\n metadata: RemoteComponentMetadata;\n parsed: ParsedRemoteComponent;\n doc: Document;\n}\n\n/**\n * Successful static component load — mount/unmount functions are returned\n * for the host to call.\n */\nexport interface PipelineStatic {\n status: 'static';\n mount: Set<MountOrUnmountFunction>;\n unmount: Set<MountOrUnmountFunction>;\n metadata: RemoteComponentMetadata;\n parsed: ParsedRemoteComponent;\n doc: Document;\n}\n\n/** The load was aborted before it could complete. */\nexport interface PipelineAborted {\n status: 'aborted';\n}\n\n/** The load failed with an error. */\nexport interface PipelineError {\n status: 'error';\n error: Error;\n}\n\nexport type PipelineResult =\n | PipelineLoaded\n | PipelineStatic\n | PipelineAborted\n | PipelineError;\n\n/**\n * Intermediate result from {@link preparePipeline}. Hosts that need to run\n * framework-specific logic between parse and load (e.g. inline script\n * execution in the React host) use this to split the pipeline into two\n * phases.\n */\nexport interface PreparedPipeline {\n doc: Document;\n parsed: ParsedRemoteComponent;\n /** Script descriptors ready to pass to `loadRemoteComponent`. */\n scriptDescriptors: ScriptDescriptor[];\n}\n\n// ---------------------------------------------------------------------------\n// Pipeline phases\n// ---------------------------------------------------------------------------\n\n/**\n * Phase 1: Parse HTML, validate shared modules, and normalize URLs.\n *\n * This is the synchronous/cheap portion of the pipeline. Hosts that need to\n * inject logic between parse and load (e.g. executing inline scripts) call\n * this directly, then call {@link loadPrepared} when ready.\n */\nexport function preparePipeline(input: {\n html: string;\n name: string;\n url: URL;\n shared: SharedModuleMap;\n remoteShared?: Record<string, string>;\n resolveClientUrl?: InternalResolveClientUrl;\n}): PreparedPipeline {\n const parser = new DOMParser();\n const doc = parser.parseFromString(input.html, 'text/html');\n\n const parsed = parseRemoteComponentDocument(doc, input.name, input.url);\n\n // Validate shared modules — surface errors early before any script loading.\n // Only check *remote* shared modules here. The host-side marker\n // (`__remote_components_missing_shared__` in `input.shared`) is a callable\n // error signal that the host may intentionally leave in place when\n // `withRemoteComponentsConfig` is not used — blocking on it would break\n // framework-agnostic hosts that don't configure shared modules.\n const remoteShared = input.remoteShared ?? parsed.remoteShared;\n if ('__remote_components_missing_shared__' in remoteShared) {\n throw new RemoteComponentsError(\n remoteShared.__remote_components_missing_shared__,\n );\n }\n\n applyOriginToNodes(doc, input.url, input.resolveClientUrl);\n\n const scriptDescriptors = buildScriptDescriptors(parsed.scripts, input.url);\n\n return { doc, parsed, scriptDescriptors };\n}\n\n/**\n * Phase 2: Load the component from a prepared pipeline result.\n *\n * For dynamic components, delegates to `loadRemoteComponent`. For static\n * components (`isRemoteComponent`), delegates to `loadStaticRemoteComponent`.\n */\nexport async function loadPrepared(input: {\n prepared: PreparedPipeline;\n url: URL;\n signal: AbortSignal;\n shared: Promise<SharedModuleMap> | SharedModuleMap;\n resolveClientUrl?: InternalResolveClientUrl;\n container?: ShadowRoot | HTMLElement | null;\n rscName?: string;\n}): Promise<PipelineResult> {\n const { prepared, url, signal, resolveClientUrl, container, rscName } = input;\n const { doc, parsed, scriptDescriptors } = prepared;\n\n if (signal.aborted) {\n return { status: 'aborted' };\n }\n\n const userShared = await input.shared;\n if (signal.aborted) {\n return { status: 'aborted' };\n }\n\n if (parsed.isRemoteComponent) {\n return loadStaticPath({\n parsed,\n doc,\n url,\n resolveClientUrl,\n });\n }\n\n return loadDynamicPath({\n parsed,\n doc,\n url,\n scriptDescriptors,\n shared: userShared,\n resolveClientUrl,\n container,\n rscName,\n });\n}\n\n// ---------------------------------------------------------------------------\n// Full pipeline entry points\n// ---------------------------------------------------------------------------\n\n/**\n * Full post-fetch pipeline: parse → validate → normalize → load.\n *\n * Use this when starting from a raw HTML string (React host, HTML host).\n */\nexport async function runPipeline(\n input: PipelineInput,\n): Promise<PipelineResult> {\n try {\n const userShared = await input.shared;\n if (input.signal.aborted) {\n return { status: 'aborted' };\n }\n\n const prepared = preparePipeline({\n html: input.html,\n name: input.name,\n url: input.url,\n shared: userShared,\n resolveClientUrl: input.resolveClientUrl,\n });\n\n return await loadPrepared({\n prepared,\n url: input.url,\n signal: input.signal,\n shared: userShared,\n resolveClientUrl: input.resolveClientUrl,\n container: input.container,\n });\n } catch (error) {\n return {\n status: 'error',\n error:\n error instanceof Error\n ? error\n : new RemoteComponentsError(String(error)),\n };\n }\n}\n\n/**\n * Pipeline entry point for pre-parsed SSR data (App Router client).\n *\n * Skips HTML parsing and goes straight to `loadRemoteComponent` with the\n * pre-resolved payload from the server component.\n */\nexport async function runPipelineFromParsed(\n input: ParsedPipelineInput,\n): Promise<\n | { status: 'loaded'; component: React.ReactNode }\n | PipelineAborted\n | PipelineError\n> {\n try {\n if (input.signal.aborted) {\n return { status: 'aborted' };\n }\n\n const remoteShared = input.remoteShared ?? input.payload.remoteShared ?? {};\n\n if ('__remote_components_missing_shared__' in remoteShared) {\n throw new RemoteComponentsError(\n remoteShared.__remote_components_missing_shared__,\n );\n }\n\n const result = await loadRemoteComponent({\n url: input.url,\n name: input.name,\n rscName: input.rscName,\n bundle: input.payload.bundle,\n route: input.payload.route,\n runtime: input.payload.runtime,\n data: input.payload.data,\n nextData: input.payload.nextData,\n scripts: input.payload.scripts,\n shared: input.shared,\n remoteShared,\n container: input.container,\n resolveClientUrl: input.resolveClientUrl,\n });\n\n if (input.signal.aborted) {\n return { status: 'aborted' };\n }\n\n if (result.error) {\n return { status: 'error', error: result.error };\n }\n return { status: 'loaded', component: result.component };\n } catch (error) {\n return {\n status: 'error',\n error:\n error instanceof Error\n ? error\n : new RemoteComponentsError(String(error)),\n };\n }\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Converts parsed `<script>` elements into the `ScriptDescriptor[]` format\n * expected by `loadRemoteComponent`. Handles the `[bundle] id` URL format\n * and collapses double slashes.\n */\nfunction buildScriptDescriptors(\n scripts: HTMLScriptElement[],\n url: URL,\n): ScriptDescriptor[] {\n return scripts.map((script) => {\n const scriptSrc =\n script.getAttribute('data-src') ||\n script.getAttribute('src') ||\n script.src;\n const { prefix, id: path } = REMOTE_COMPONENT_REGEX.exec(scriptSrc)\n ?.groups ?? {\n prefix: undefined,\n id: scriptSrc,\n };\n return {\n src: new URL(collapseDoubleSlashes(`${prefix ?? ''}${path}`), url).href,\n };\n });\n}\n\nasync function loadStaticPath(input: {\n parsed: ParsedRemoteComponent;\n doc: Document;\n url: URL;\n resolveClientUrl?: InternalResolveClientUrl;\n}): Promise<PipelineStatic> {\n const { parsed, doc, url, resolveClientUrl } = input;\n const scripts = Array.from(\n parsed.component.querySelectorAll<HTMLScriptElement>('script'),\n );\n const { mount, unmount } = await loadStaticRemoteComponent(\n scripts,\n url,\n resolveClientUrl,\n );\n return {\n status: 'static',\n mount,\n unmount,\n metadata: parsed.metadata,\n parsed,\n doc,\n };\n}\n\nasync function loadDynamicPath(input: {\n parsed: ParsedRemoteComponent;\n doc: Document;\n url: URL;\n scriptDescriptors: ScriptDescriptor[];\n shared: SharedModuleMap;\n resolveClientUrl?: InternalResolveClientUrl;\n container?: ShadowRoot | HTMLElement | null;\n rscName?: string;\n}): Promise<PipelineLoaded | PipelineError> {\n const {\n parsed,\n doc,\n url,\n scriptDescriptors,\n shared,\n resolveClientUrl,\n container,\n } = input;\n\n const rscName =\n input.rscName ??\n (parsed.rsc\n ? `__remote_component_rsc_${escapeString(url.href)}_${escapeString(parsed.name)}`\n : undefined);\n\n const rscData = parsed.rsc\n ? (parsed.rsc.textContent || '').split('\\n').filter(Boolean)\n : [];\n\n const result = await loadRemoteComponent({\n url,\n name: parsed.name,\n rscName,\n bundle: parsed.metadata.bundle,\n route: parsed.metadata.route,\n runtime: parsed.metadata.runtime,\n data: rscData,\n nextData: parsed.nextData,\n scripts: scriptDescriptors,\n shared: buildHostShared(shared, resolveClientUrl),\n remoteShared: parsed.remoteShared,\n container,\n resolveClientUrl,\n });\n\n if (result.error) {\n return { status: 'error', error: result.error };\n }\n return {\n status: 'loaded',\n component: result.component,\n metadata: parsed.metadata,\n parsed,\n doc,\n };\n}\n","/**\n * The lifecycle stages a host progresses through during a load cycle.\n *\n * ```\n * ┌─────────────────────────┐\n * │ (new load) │\n * ▼ │\n * idle ──▶ loading ──▶ loaded ─────────┘\n * ▲ │ │\n * │ ▼ │ (new load)\n * │ error ─────────┘\n * │\n * └── loading (abandoned / aborted)\n * ```\n *\n * - `idle` — No load has started, or a previous load was abandoned.\n * - `loading` — A fetch or hydration is in progress.\n * - `loaded` — The remote component rendered successfully.\n * - `error` — The load failed (the error itself is surfaced separately).\n *\n * Any non-idle stage transitions directly to `loading` when a new load starts.\n */\nexport type HostStage = 'idle' | 'loading' | 'loaded' | 'error';\n\n/**\n * Mutable state shared by every host implementation (HTML, React, Next.js\n * App Router).\n *\n * Each host stores a single `HostState` instance rather than scattering\n * individual properties/refs. This keeps the \"what changed since the last\n * load?\" tracking consistent across frameworks and makes it easy to test\n * state transitions in isolation.\n */\nexport interface HostState {\n /** Current lifecycle stage. */\n stage: HostStage;\n\n /** Source from the most-recent load. `undefined` before the first load. */\n prevSrc: string | URL | undefined;\n\n /** Resolved URL from the most-recent load. `undefined` before the first load. */\n prevUrl: URL | undefined;\n\n /** Component name from the most-recent load. `undefined` before the first load. */\n prevName: string | undefined;\n\n /** Whether the most-recent load was a remote component (vs. a plain page). */\n prevIsRemoteComponent: boolean;\n\n /**\n * `AbortController` for the in-flight load. Abort it to cancel a\n * superseded fetch. `undefined` when no load is active.\n */\n abortController: AbortController | undefined;\n}\n\n/** Creates a fresh `HostState` with all fields at their initial values. */\nexport function createHostState(): HostState {\n return {\n stage: 'idle',\n prevSrc: undefined,\n prevUrl: undefined,\n prevName: undefined,\n prevIsRemoteComponent: false,\n abortController: undefined,\n };\n}\n","/**\n * Extracts a component name from the URL hash of `src`, falling back to\n * `defaultName` when no hash is present.\n *\n * Both the HTML and React hosts use this to derive the component name\n * from patterns like `/components/header#my-component`.\n *\n * Parses the hash directly from the string rather than constructing a\n * full `URL`, so no SSR fallback base is needed.\n */\nexport function resolveNameFromSrc(\n src: string | URL | undefined,\n defaultName: string,\n): string {\n if (!src) {\n return defaultName;\n }\n\n const hash = typeof src === 'string' ? src : src.hash;\n const hashIndex = hash.indexOf('#');\n if (hashIndex < 0) {\n return defaultName;\n }\n\n const name = hash.slice(hashIndex + 1);\n return name || defaultName;\n}\n","/**\n * Intercepts client-side URL resolution for remote component resources.\n * Called before each asset (script, stylesheet, chunk, module, image) is fetched.\n *\n * Return a new URL string to redirect the fetch (e.g., through a proxy),\n * or undefined to use the original URL.\n *\n * @param remoteSrc - The `src` of the remote component being loaded\n * @param url - The asset URL about to be fetched\n *\n * @example\n * // Proxy all assets from the remote's origin through the host\n * const resolveClientUrl = (remoteSrc, url) => {\n * const remoteOrigin = new URL(remoteSrc).origin;\n * const parsed = new URL(url);\n * if (parsed.origin !== location.origin && parsed.origin === remoteOrigin) {\n * return `/rc-fetch-protected-remote?url=${encodeURIComponent(url)}`;\n * }\n * };\n */\nexport type ResolveClientUrl = (\n remoteSrc: string,\n url: string,\n) => string | undefined;\n\n/**\n * Internal bound resolver — `ResolveClientUrl` with `remoteSrc` already applied.\n * Used by internal loaders that don't need to know the remote src.\n */\nexport type InternalResolveClientUrl = (url: string) => string | undefined;\n\n/**\n * Binds a `ResolveClientUrl` to a specific `remoteSrc`, producing an\n * `InternalResolveClientUrl` that only needs the asset URL.\n *\n * Only invokes the callback for URLs whose origin matches the remote\n * component's origin. Third-party scripts (e.g. `vercel.live` toolbar)\n * are left untouched. To proxy additional domains in the future, a\n * field or flag can be added to the host configuration.\n */\nexport function withRemoteSrc(\n resolveClientUrl: ResolveClientUrl,\n remoteSrc: string,\n): InternalResolveClientUrl {\n const remoteOrigin = parseOrigin(remoteSrc);\n return (url) => {\n const urlOrigin = parseOrigin(url);\n if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {\n return undefined;\n }\n return resolveClientUrl(remoteSrc, url);\n };\n}\n\nfunction parseOrigin(url: string): string | undefined {\n try {\n return new URL(url).origin;\n } catch {\n return undefined;\n }\n}\n","import {\n type InternalResolveClientUrl,\n type ResolveClientUrl,\n withRemoteSrc,\n} from './resolve-client-url';\n\nexport function bindResolveClientUrl(\n prop: ResolveClientUrl | undefined,\n remoteSrc: string,\n): InternalResolveClientUrl | undefined {\n return prop ? withRemoteSrc(prop, remoteSrc) : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,eAAe,iBACb,KACA,MACmB;AACnB,MAAI;AACF,WAAO,MAAM,MAAM,KAAK,IAAI;AAAA,EAC9B,SAAS,OAAP;AACA,8BAA0B,wBAAwB,GAAG;AACr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ACtDO,SAAS,qBACd,MACA,WACsC;AACtC,SAAO,OAAO,cAAc,MAAM,SAAS,IAAI;AACjD;","names":[]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkR4QFK5TNcjs = require('./chunk-R4QFK5TN.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkRUWR74XQcjs = require('./chunk-RUWR74XQ.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkKE7QPAQ4cjs = require('./chunk-KE7QPAQ4.cjs');
|
|
12
|
+
|
|
13
|
+
// src/runtime/loaders/script-loader.ts
|
|
14
|
+
async function loadScripts(scripts, resolveClientUrl) {
|
|
15
|
+
await Promise.all(
|
|
16
|
+
scripts.map((script) => {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const newSrc = new URL(
|
|
19
|
+
// remove the remote component bundle name identifier from the script src
|
|
20
|
+
script.src.replace(_chunkR4QFK5TNcjs.NEXT_BUNDLE_PATH_RE, "/_next/"),
|
|
21
|
+
location.origin
|
|
22
|
+
).href;
|
|
23
|
+
const resolvedSrc = _nullishCoalesce(_optionalChain([resolveClientUrl, 'optionalCall', _ => _(newSrc)]), () => ( newSrc));
|
|
24
|
+
const alreadyLoaded = Array.from(
|
|
25
|
+
document.querySelectorAll("script[src]")
|
|
26
|
+
).some((s) => s.src === resolvedSrc);
|
|
27
|
+
if (alreadyLoaded) {
|
|
28
|
+
resolve();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const newScript = document.createElement("script");
|
|
32
|
+
newScript.onload = () => resolve();
|
|
33
|
+
newScript.onerror = () => {
|
|
34
|
+
const isProxied = _chunkKE7QPAQ4cjs.isProxiedUrl.call(void 0, resolvedSrc);
|
|
35
|
+
if (isProxied) {
|
|
36
|
+
reject(_chunkRUWR74XQcjs.failedProxiedAssetError.call(void 0, "script", newSrc, resolvedSrc));
|
|
37
|
+
} else {
|
|
38
|
+
_chunkRUWR74XQcjs.warnCrossOriginFetchError.call(void 0, "ScriptLoader", newSrc);
|
|
39
|
+
reject(
|
|
40
|
+
new (0, _chunkRUWR74XQcjs.RemoteComponentsError)(
|
|
41
|
+
`Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
newScript.src = resolvedSrc;
|
|
47
|
+
newScript.async = true;
|
|
48
|
+
document.head.appendChild(newScript);
|
|
49
|
+
});
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
exports.loadScripts = loadScripts;
|
|
57
|
+
//# sourceMappingURL=chunk-6IUP26UK.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime/loaders/script-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAYA,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,gBAAgB,MAAM;AAAA,UAC1B,SAAS,iBAAoC,aAAa;AAAA,QAC5D,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,WAAW;AACnC,YAAI,eAAe;AACjB,kBAAQ;AACR;AAAA,QACF;AAEA,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","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 alreadyLoaded = Array.from(\n document.querySelectorAll<HTMLScriptElement>('script[src]'),\n ).some((s) => s.src === resolvedSrc);\n if (alreadyLoaded) {\n resolve();\n return;\n }\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"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/runtime/namespace.ts
|
|
2
|
+
var SHADOW_ROOT_PREFIX = "__remote_components_shadowroot_";
|
|
3
|
+
var LEGACY_ALIASES = [
|
|
4
|
+
{ global: "__remote_component_scopes__", prop: "scopes" },
|
|
5
|
+
{
|
|
6
|
+
global: "__remote_components_turbopack_chunk_loader_promise__",
|
|
7
|
+
prop: "chunkCache"
|
|
8
|
+
},
|
|
9
|
+
{ global: "__remote_script_entrypoint_mount__", prop: "mountFns" },
|
|
10
|
+
{ global: "__remote_script_entrypoint_unmount__", prop: "unmountFns" },
|
|
11
|
+
{ global: "__remote_bundle_url__", prop: "bundleUrls" },
|
|
12
|
+
{ global: "__rc_module_registry__", prop: "moduleRegistry" },
|
|
13
|
+
{
|
|
14
|
+
global: "__remote_component_host_shared_modules__",
|
|
15
|
+
prop: "hostSharedModules"
|
|
16
|
+
},
|
|
17
|
+
{ global: "__remote_next_css__", prop: "cssCache" }
|
|
18
|
+
];
|
|
19
|
+
function getNamespace() {
|
|
20
|
+
const g = globalThis;
|
|
21
|
+
const existing = g.__remote_components__;
|
|
22
|
+
if (existing) {
|
|
23
|
+
return existing;
|
|
24
|
+
}
|
|
25
|
+
const ns = {
|
|
26
|
+
scopes: /* @__PURE__ */ new Map(),
|
|
27
|
+
chunkCache: {},
|
|
28
|
+
mountFns: {},
|
|
29
|
+
unmountFns: {},
|
|
30
|
+
bundleUrls: {},
|
|
31
|
+
moduleRegistry: {},
|
|
32
|
+
dispatcherRuntime: void 0,
|
|
33
|
+
hostSharedModules: {},
|
|
34
|
+
cssCache: {},
|
|
35
|
+
shadowRoots: {}
|
|
36
|
+
};
|
|
37
|
+
const nsRecord = ns;
|
|
38
|
+
for (const { global, prop } of LEGACY_ALIASES) {
|
|
39
|
+
const legacyValue = g[global];
|
|
40
|
+
if (legacyValue != null) {
|
|
41
|
+
nsRecord[prop] = legacyValue;
|
|
42
|
+
}
|
|
43
|
+
g[global] = ns[prop];
|
|
44
|
+
}
|
|
45
|
+
const gRecord = g;
|
|
46
|
+
for (const key of Object.keys(gRecord)) {
|
|
47
|
+
if (key.startsWith(SHADOW_ROOT_PREFIX)) {
|
|
48
|
+
const suffix = key.slice(SHADOW_ROOT_PREFIX.length);
|
|
49
|
+
ns.shadowRoots[suffix] = gRecord[key];
|
|
50
|
+
delete gRecord[key];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
g.__remote_components__ = ns;
|
|
54
|
+
return ns;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
exports.getNamespace = getNamespace;
|
|
60
|
+
//# sourceMappingURL=chunk-7MVFHOIP.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime/namespace.ts"],"names":[],"mappings":";AAyCA,IAAM,qBAAqB;AAS3B,IAAM,iBAGD;AAAA,EACH,EAAE,QAAQ,+BAA+B,MAAM,SAAS;AAAA,EACxD;AAAA,IACE,QAAQ;AAAA,IACR,MAAM;AAAA,EACR;AAAA,EACA,EAAE,QAAQ,sCAAsC,MAAM,WAAW;AAAA,EACjE,EAAE,QAAQ,wCAAwC,MAAM,aAAa;AAAA,EACrE,EAAE,QAAQ,yBAAyB,MAAM,aAAa;AAAA,EACtD,EAAE,QAAQ,0BAA0B,MAAM,iBAAiB;AAAA,EAC3D;AAAA,IACE,QAAQ;AAAA,IACR,MAAM;AAAA,EACR;AAAA,EACA,EAAE,QAAQ,uBAAuB,MAAM,WAAW;AACpD;AAeO,SAAS,eAA0C;AACxD,QAAM,IAAI;AACV,QAAM,WAAW,EAAE;AACnB,MAAI,UAAU;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,KAAgC;AAAA,IACpC,QAAQ,oBAAI,IAAI;AAAA,IAChB,YAAY,CAAC;AAAA,IACb,UAAU,CAAC;AAAA,IACX,YAAY,CAAC;AAAA,IACb,YAAY,CAAC;AAAA,IACb,gBAAgB,CAAC;AAAA,IACjB,mBAAmB;AAAA,IACnB,mBAAmB,CAAC;AAAA,IACpB,UAAU,CAAC;AAAA,IACX,aAAa,CAAC;AAAA,EAChB;AAGA,QAAM,WAAW;AACjB,aAAW,EAAE,QAAQ,KAAK,KAAK,gBAAgB;AAC7C,UAAM,cAAe,EAA8B,MAAM;AACzD,QAAI,eAAe,MAAM;AACvB,eAAS,IAAI,IAAI;AAAA,IACnB;AACA,IAAC,EAA8B,MAAM,IAAI,GAAG,IAAI;AAAA,EAClD;AAIA,QAAM,UAAU;AAChB,aAAW,OAAO,OAAO,KAAK,OAAO,GAAG;AACtC,QAAI,IAAI,WAAW,kBAAkB,GAAG;AACtC,YAAM,SAAS,IAAI,MAAM,mBAAmB,MAAM;AAClD,SAAG,YAAY,MAAM,IAAI,QAAQ,GAAG;AACpC,aAAO,QAAQ,GAAG;AAAA,IACpB;AAAA,EACF;AAEA,IAAE,wBAAwB;AAC1B,SAAO;AACT","sourcesContent":["import type { RemoteScope } from '#internal/runtime/turbopack/remote-scope';\nimport type {\n GlobalScope,\n MountOrUnmountFunction,\n MountUnmountFunctions,\n} from '#internal/runtime/types';\n\n/**\n * Typed namespace for all remote-components runtime state.\n *\n * Consolidates scattered `globalThis` globals into a single object at\n * `globalThis.__remote_components__`. Each property corresponds to a\n * previously independent global — see inline `@see` tags for the original\n * global name. Code that previously read from those globals still works\n * because each migration writes through to both the namespace and the\n * legacy global (pointing at the same underlying object).\n */\nexport interface RemoteComponentsNamespace {\n /** @see `__remote_component_scopes__` */\n scopes: Map<string, RemoteScope>;\n /** @see `__remote_components_turbopack_chunk_loader_promise__` */\n chunkCache: Record<string, Promise<unknown>>;\n /** @see `__remote_script_entrypoint_mount__` */\n mountFns: Record<string, Set<MountOrUnmountFunction>>;\n /** @see `__remote_script_entrypoint_unmount__` */\n unmountFns: Record<string, Set<MountOrUnmountFunction>>;\n /** @see `__remote_bundle_url__` */\n bundleUrls: Record<string, string | URL>;\n /** @see `__rc_module_registry__` */\n moduleRegistry: Record<string, unknown>;\n /** @see `__webpack_require_type__` */\n dispatcherRuntime: string | undefined;\n /** @see `__remote_component_host_shared_modules__` */\n hostSharedModules: Record<string, () => Promise<unknown>>;\n /** @see `__remote_next_css__` */\n cssCache: Record<string, ChildNode[]>;\n /** @see `__remote_components_shadowroot_*` */\n shadowRoots: Record<string, ShadowRoot | null>;\n}\n\n/** Prefix for legacy per-key shadow root globals (`__remote_components_shadowroot_*`). */\nconst SHADOW_ROOT_PREFIX = '__remote_components_shadowroot_';\n\n/**\n * Backward-compat aliases for globals used in <=0.3.3.\n *\n * Only includes object/Map values that can be aliased by reference.\n * Primitives (`dispatcherRuntime`) must use write-through at their call sites.\n * Dynamic-key shadow root globals are adopted separately in `getNamespace()`.\n */\nconst LEGACY_ALIASES: ReadonlyArray<{\n global: string;\n prop: keyof RemoteComponentsNamespace;\n}> = [\n { global: '__remote_component_scopes__', prop: 'scopes' },\n {\n global: '__remote_components_turbopack_chunk_loader_promise__',\n prop: 'chunkCache',\n },\n { global: '__remote_script_entrypoint_mount__', prop: 'mountFns' },\n { global: '__remote_script_entrypoint_unmount__', prop: 'unmountFns' },\n { global: '__remote_bundle_url__', prop: 'bundleUrls' },\n { global: '__rc_module_registry__', prop: 'moduleRegistry' },\n {\n global: '__remote_component_host_shared_modules__',\n prop: 'hostSharedModules',\n },\n { global: '__remote_next_css__', prop: 'cssCache' },\n];\n\n/**\n * Returns the single shared `RemoteComponentsNamespace` instance, creating\n * it on first access. The namespace lives at `globalThis.__remote_components__`\n * so every module in the page shares the same state regardless of how many\n * copies of the library are loaded.\n *\n * On first initialization this function also handles backward compatibility\n * with legacy globals:\n * 1. **Adopt**: if a legacy global already exists (written by older code before\n * the namespace was created), its value becomes the initial namespace value.\n * 2. **Alias**: legacy globals are assigned to point at the namespace's objects,\n * so older code that reads the legacy global sees the same reference.\n */\nexport function getNamespace(): RemoteComponentsNamespace {\n const g = globalThis as GlobalScope & MountUnmountFunctions;\n const existing = g.__remote_components__;\n if (existing) {\n return existing;\n }\n\n const ns: RemoteComponentsNamespace = {\n scopes: new Map(),\n chunkCache: {},\n mountFns: {},\n unmountFns: {},\n bundleUrls: {},\n moduleRegistry: {},\n dispatcherRuntime: undefined,\n hostSharedModules: {},\n cssCache: {},\n shadowRoots: {},\n };\n\n // Adopt any pre-existing legacy globals, then alias them to the namespace.\n const nsRecord = ns as unknown as Record<string, unknown>;\n for (const { global, prop } of LEGACY_ALIASES) {\n const legacyValue = (g as Record<string, unknown>)[global];\n if (legacyValue != null) {\n nsRecord[prop] = legacyValue;\n }\n (g as Record<string, unknown>)[global] = ns[prop];\n }\n\n // Adopt per-key shadow root globals used in <=0.3.3\n // (e.g. `globalThis.__remote_components_shadowroot_<key> = root`).\n const gRecord = g as Record<string, unknown>;\n for (const key of Object.keys(gRecord)) {\n if (key.startsWith(SHADOW_ROOT_PREFIX)) {\n const suffix = key.slice(SHADOW_ROOT_PREFIX.length);\n ns.shadowRoots[suffix] = gRecord[key] as ShadowRoot | null;\n delete gRecord[key];\n }\n }\n\n g.__remote_components__ = ns;\n return ns;\n}\n"]}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunk7MVFHOIPcjs = require('./chunk-7MVFHOIP.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkRUWR74XQcjs = require('./chunk-RUWR74XQ.cjs');
|
|
8
|
+
|
|
9
|
+
// src/runtime/loaders/static-loader.ts
|
|
10
|
+
async function importViaCallback(absoluteSrc, resolveClientUrl) {
|
|
11
|
+
const resolvedUrl = _nullishCoalesce(resolveClientUrl(absoluteSrc), () => ( absoluteSrc));
|
|
12
|
+
const fetchUrl = new URL(resolvedUrl, location.href).href;
|
|
13
|
+
const response = await fetch(fetchUrl);
|
|
14
|
+
if (!response.ok)
|
|
15
|
+
throw new Error(`Proxied fetch failed: ${response.status}`);
|
|
16
|
+
const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
|
|
17
|
+
/\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
|
|
18
|
+
(_, keyword, quote, relativePath) => {
|
|
19
|
+
const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
|
|
20
|
+
const resolvedImportUrl = new URL(
|
|
21
|
+
_nullishCoalesce(resolveClientUrl(absoluteImportUrl), () => ( absoluteImportUrl)),
|
|
22
|
+
location.href
|
|
23
|
+
).href;
|
|
24
|
+
return `${keyword} ${quote}${resolvedImportUrl}${quote}`;
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
const moduleBlobUrl = URL.createObjectURL(
|
|
28
|
+
new Blob([content], { type: "text/javascript" })
|
|
29
|
+
);
|
|
30
|
+
const wrapperContent = [
|
|
31
|
+
`import*as m from${JSON.stringify(moduleBlobUrl)};`,
|
|
32
|
+
`globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
|
|
33
|
+
`globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
|
|
34
|
+
].join("");
|
|
35
|
+
const wrapperBlobUrl = URL.createObjectURL(
|
|
36
|
+
new Blob([wrapperContent], { type: "text/javascript" })
|
|
37
|
+
);
|
|
38
|
+
const scriptEl = document.createElement("script");
|
|
39
|
+
scriptEl.type = "module";
|
|
40
|
+
scriptEl.src = wrapperBlobUrl;
|
|
41
|
+
try {
|
|
42
|
+
await new Promise((resolve, reject) => {
|
|
43
|
+
scriptEl.onload = () => resolve();
|
|
44
|
+
scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
|
|
45
|
+
document.head.appendChild(scriptEl);
|
|
46
|
+
});
|
|
47
|
+
} finally {
|
|
48
|
+
scriptEl.remove();
|
|
49
|
+
URL.revokeObjectURL(moduleBlobUrl);
|
|
50
|
+
URL.revokeObjectURL(wrapperBlobUrl);
|
|
51
|
+
}
|
|
52
|
+
const registry = _chunk7MVFHOIPcjs.getNamespace.call(void 0, ).moduleRegistry;
|
|
53
|
+
const mod = _nullishCoalesce(registry[absoluteSrc], () => ( {}));
|
|
54
|
+
delete registry[absoluteSrc];
|
|
55
|
+
return mod;
|
|
56
|
+
}
|
|
57
|
+
async function importDirectly(absoluteSrc) {
|
|
58
|
+
try {
|
|
59
|
+
return await Promise.resolve().then(() => _interopRequireWildcard(require(
|
|
60
|
+
/* @vite-ignore */
|
|
61
|
+
/* webpackIgnore: true */
|
|
62
|
+
absoluteSrc
|
|
63
|
+
)));
|
|
64
|
+
} catch (importError) {
|
|
65
|
+
if (!absoluteSrc.startsWith("blob:")) {
|
|
66
|
+
_chunkRUWR74XQcjs.warnCrossOriginFetchError.call(void 0, "StaticLoader", absoluteSrc);
|
|
67
|
+
}
|
|
68
|
+
throw importError;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function resolveScriptSrc(script, url) {
|
|
72
|
+
const rawSrc = typeof script.getAttribute === "function" ? _nullishCoalesce(script.getAttribute("src"), () => ( script.src)) : script.src;
|
|
73
|
+
if (!rawSrc && script.textContent) {
|
|
74
|
+
return URL.createObjectURL(
|
|
75
|
+
new Blob(
|
|
76
|
+
[script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
|
|
77
|
+
{ type: "text/javascript" }
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return rawSrc;
|
|
82
|
+
}
|
|
83
|
+
async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
|
|
84
|
+
const ns = _chunk7MVFHOIPcjs.getNamespace.call(void 0, );
|
|
85
|
+
if (ns.mountFns[url.href]) {
|
|
86
|
+
ns.mountFns[url.href] = /* @__PURE__ */ new Set();
|
|
87
|
+
}
|
|
88
|
+
if (ns.unmountFns[url.href]) {
|
|
89
|
+
ns.unmountFns[url.href] = /* @__PURE__ */ new Set();
|
|
90
|
+
}
|
|
91
|
+
const mountUnmountSets = await Promise.all(
|
|
92
|
+
scripts.map(async (script) => {
|
|
93
|
+
try {
|
|
94
|
+
const src = resolveScriptSrc(script, url);
|
|
95
|
+
const absoluteSrc = new URL(src, url).href;
|
|
96
|
+
const mod = resolveClientUrl ? await importViaCallback(absoluteSrc, resolveClientUrl) : await importDirectly(absoluteSrc);
|
|
97
|
+
if (src.startsWith("blob:")) {
|
|
98
|
+
URL.revokeObjectURL(src);
|
|
99
|
+
}
|
|
100
|
+
if (typeof mod.mount === "function" || typeof _optionalChain([mod, 'access', _2 => _2.default, 'optionalAccess', _3 => _3.mount]) === "function") {
|
|
101
|
+
if (!ns.mountFns[url.href]) {
|
|
102
|
+
ns.mountFns[url.href] = /* @__PURE__ */ new Set();
|
|
103
|
+
}
|
|
104
|
+
_optionalChain([ns, 'access', _4 => _4.mountFns, 'access', _5 => _5[url.href], 'optionalAccess', _6 => _6.add, 'call', _7 => _7(
|
|
105
|
+
mod.mount || _optionalChain([mod, 'access', _8 => _8.default, 'optionalAccess', _9 => _9.mount]) || (() => {
|
|
106
|
+
})
|
|
107
|
+
)]);
|
|
108
|
+
}
|
|
109
|
+
if (typeof mod.unmount === "function" || typeof _optionalChain([mod, 'access', _10 => _10.default, 'optionalAccess', _11 => _11.unmount]) === "function") {
|
|
110
|
+
if (!ns.unmountFns[url.href]) {
|
|
111
|
+
ns.unmountFns[url.href] = /* @__PURE__ */ new Set();
|
|
112
|
+
}
|
|
113
|
+
_optionalChain([ns, 'access', _12 => _12.unmountFns, 'access', _13 => _13[url.href], 'optionalAccess', _14 => _14.add, 'call', _15 => _15(
|
|
114
|
+
mod.unmount || _optionalChain([mod, 'access', _16 => _16.default, 'optionalAccess', _17 => _17.unmount]) || (() => {
|
|
115
|
+
})
|
|
116
|
+
)]);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
mount: mod.mount || _optionalChain([mod, 'access', _18 => _18.default, 'optionalAccess', _19 => _19.mount]),
|
|
120
|
+
unmount: mod.unmount || _optionalChain([mod, 'access', _20 => _20.default, 'optionalAccess', _21 => _21.unmount])
|
|
121
|
+
};
|
|
122
|
+
} catch (e) {
|
|
123
|
+
_chunkRUWR74XQcjs.logError.call(void 0,
|
|
124
|
+
"StaticLoader",
|
|
125
|
+
`Error loading remote component script from "${script.src || url.href}".`,
|
|
126
|
+
e
|
|
127
|
+
);
|
|
128
|
+
return {
|
|
129
|
+
mount: void 0,
|
|
130
|
+
unmount: void 0
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
);
|
|
135
|
+
return mountUnmountSets.reduce(
|
|
136
|
+
(acc, { mount, unmount }) => {
|
|
137
|
+
if (typeof mount === "function") {
|
|
138
|
+
acc.mount.add(mount);
|
|
139
|
+
}
|
|
140
|
+
if (typeof unmount === "function") {
|
|
141
|
+
acc.unmount.add(unmount);
|
|
142
|
+
}
|
|
143
|
+
return acc;
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
mount: /* @__PURE__ */ new Set(),
|
|
147
|
+
unmount: /* @__PURE__ */ new Set()
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
exports.loadStaticRemoteComponent = loadStaticRemoteComponent;
|
|
155
|
+
//# sourceMappingURL=chunk-CREXMFMF.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime/loaders/static-loader.ts"],"names":[],"mappings":";;;;;;;;;AAyBA,eAAe,kBACb,aACA,kBACY;AACZ,QAAM,cAAc,iBAAiB,WAAW,KAAK;AACrD,QAAM,WAAW,IAAI,IAAI,aAAa,SAAS,IAAI,EAAE;AACrD,QAAM,WAAW,MAAM,MAAM,QAAQ;AACrC,MAAI,CAAC,SAAS;AAAI,UAAM,IAAI,MAAM,yBAAyB,SAAS,QAAQ;AAM5E,QAAM,WAAW,MAAM,SAAS,KAAK,GAClC,QAAQ,sBAAsB,KAAK,UAAU,WAAW,CAAC,EACzD;AAAA,IACC;AAAA,IACA,CAAC,GAAG,SAAS,OAAO,iBAAiB;AACnC,YAAM,oBAAoB,IAAI,IAAI,cAAc,WAAW,EAAE;AAC7D,YAAM,oBAAoB,IAAI;AAAA,QAC5B,iBAAiB,iBAAiB,KAAK;AAAA,QACvC,SAAS;AAAA,MACX,EAAE;AACF,aAAO,GAAG,WAAW,QAAQ,oBAAoB;AAAA,IACnD;AAAA,EACF;AACF,QAAM,gBAAgB,IAAI;AAAA,IACxB,IAAI,KAAK,CAAC,OAAO,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAAA,EACjD;AACA,QAAM,iBAAiB;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AA,UACL,OAAO,IAAI,SAAS,IAAI,SAAS;AAAA,UACjC,SAAS,IAAI,WAAW,IAAI,SAAS;AAAA,QACvC;AAAA,MACF,SAAS,GAAP;AACA;AAAA,UACE;AAAA,UACA,+CAA+C,OAAO,OAAO,IAAI;AAAA,UACjE;AAAA,QACF;AACA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,iBAAiB;AAAA,IACtB,CAAC,KAAK,EAAE,OAAO,QAAQ,MAAM;AAC3B,UAAI,OAAO,UAAU,YAAY;AAC/B,YAAI,MAAM,IAAI,KAAK;AAAA,MACrB;AACA,UAAI,OAAO,YAAY,YAAY;AACjC,YAAI,QAAQ,IAAI,OAAO;AAAA,MACzB;AACA,aAAO;AAAA,IACT;AAAA,IACA;AAAA,MACE,OAAO,oBAAI,IAA4B;AAAA,MACvC,SAAS,oBAAI,IAA4B;AAAA,IAC3C;AAAA,EACF;AACF","sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport type { MountOrUnmountFunction } from '#internal/runtime/types';\nimport { logError, warnCrossOriginFetchError } from '#internal/utils/logger';\n\ntype ScriptMod = {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n};\n\n/**\n * Fetches an ES module via the resolveClientUrl callback, rewrites its\n * relative imports to also go through the callback, then loads it by injecting a\n * wrapper <script type=\"module\"> tag. The module's namespace is captured via\n * a temporary global and returned.\n *\n * This is needed when a direct import() of a cross-origin module fails due to\n * CORS restrictions or Vercel preview-deployment auth. A simple URL rewrite\n * doesn't work for import() because relative imports inside the module would\n * resolve against the rewritten URL instead of the original remote origin.\n */\nasync function importViaCallback<T>(\n absoluteSrc: string,\n resolveClientUrl: InternalResolveClientUrl,\n): Promise<T> {\n const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;\n const fetchUrl = new URL(resolvedUrl, location.href).href;\n const response = await fetch(fetchUrl);\n if (!response.ok) throw new Error(`Proxied fetch failed: ${response.status}`);\n\n // Restore import.meta.url to the original module URL so any code that\n // relies on it (e.g. for asset resolution) gets the right value.\n // Rewrite relative imports to absolute URLs resolved through the callback so\n // that transitive dependencies also bypass CORS/auth.\n const content = (await response.text())\n .replace(/import\\.meta\\.url/g, JSON.stringify(absoluteSrc))\n .replace(\n /\\b(from|import)\\s*([\"'])(\\.\\.?\\/[^\"']+)\\2/g,\n (_, keyword, quote, relativePath) => {\n const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;\n const resolvedImportUrl = new URL(\n resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,\n location.href,\n ).href;\n return `${keyword} ${quote}${resolvedImportUrl}${quote}`;\n },\n );\n const moduleBlobUrl = URL.createObjectURL(\n new Blob([content], { type: 'text/javascript' }),\n );\n const wrapperContent = [\n `import*as m from${JSON.stringify(moduleBlobUrl)};`,\n `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,\n `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`,\n ].join('');\n const wrapperBlobUrl = URL.createObjectURL(\n new Blob([wrapperContent], { type: 'text/javascript' }),\n );\n const scriptEl = document.createElement('script');\n scriptEl.type = 'module';\n scriptEl.src = wrapperBlobUrl;\n try {\n await new Promise<void>((resolve, reject) => {\n scriptEl.onload = () => resolve();\n scriptEl.onerror = () =>\n reject(new Error(`Failed to load module for ${absoluteSrc}`));\n document.head.appendChild(scriptEl);\n });\n } finally {\n scriptEl.remove();\n URL.revokeObjectURL(moduleBlobUrl);\n URL.revokeObjectURL(wrapperBlobUrl);\n }\n const registry = getNamespace().moduleRegistry as Record<string, T>;\n const mod = registry[absoluteSrc] ?? ({} as T);\n delete registry[absoluteSrc];\n return mod;\n}\n\nasync function importDirectly<T>(absoluteSrc: string): Promise<T> {\n try {\n return (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ absoluteSrc\n )) as T;\n } catch (importError) {\n if (!absoluteSrc.startsWith('blob:')) {\n warnCrossOriginFetchError('StaticLoader', absoluteSrc);\n }\n throw importError;\n }\n}\n\nfunction resolveScriptSrc(script: HTMLScriptElement, url: URL): string {\n const rawSrc =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n if (!rawSrc && script.textContent) {\n return URL.createObjectURL(\n new Blob(\n [script.textContent.replace(/import\\.meta\\.url/g, JSON.stringify(url))],\n { type: 'text/javascript' },\n ),\n );\n }\n return rawSrc;\n}\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const ns = getNamespace();\n\n if (ns.mountFns[url.href]) {\n ns.mountFns[url.href] = new Set();\n }\n if (ns.unmountFns[url.href]) {\n ns.unmountFns[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n const src = resolveScriptSrc(script, url);\n const absoluteSrc = new URL(src, url).href;\n const mod: ScriptMod = resolveClientUrl\n ? await importViaCallback<ScriptMod>(absoluteSrc, resolveClientUrl)\n : await importDirectly<ScriptMod>(absoluteSrc);\n // revoke the object URL if we created one for inline script content\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!ns.mountFns[url.href]) {\n ns.mountFns[url.href] = new Set();\n }\n ns.mountFns[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!ns.unmountFns[url.href]) {\n ns.unmountFns[url.href] = new Set();\n }\n ns.unmountFns[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n logError(\n 'StaticLoader',\n `Error loading remote component script from \"${script.src || url.href}\".`,\n e,\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmountFunction>(),\n },\n );\n}\n"]}
|