remote-components 0.4.13 → 0.4.14
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/{chunk-CLB2ATH2.js → chunk-EIEIT5PG.js} +3 -3
- package/dist/{chunk-5BBEO4SE.js → chunk-GG32LZD3.js} +2 -2
- package/dist/{chunk-KP544TQH.cjs → chunk-JKDPK6L5.cjs} +23 -23
- package/dist/{chunk-KMG54QXV.cjs → chunk-MAVMKFFL.cjs} +3 -3
- package/dist/{chunk-XEO3XD67.js → chunk-PNKSHWZ3.js} +5 -5
- package/dist/{chunk-OI37BBBU.cjs → chunk-T2JJIQUJ.cjs} +22 -22
- package/dist/{chunk-OVD7BRLD.cjs → chunk-TIS6PXSQ.cjs} +18 -18
- package/dist/{chunk-W7RJUCZQ.cjs → chunk-WCZKEWRM.cjs} +19 -19
- package/dist/{chunk-3DR4Z24C.js → chunk-WWHNG5YP.js} +36 -23
- package/dist/chunk-WWHNG5YP.js.map +1 -0
- package/dist/{chunk-IE7FXNFJ.js → chunk-XLGLCKZZ.js} +2 -2
- package/dist/{chunk-CBEDRGC7.js → chunk-YKCU7RFM.js} +3 -3
- package/dist/{chunk-OZCVXVKU.cjs → chunk-ZPJ5J24T.cjs} +45 -32
- package/dist/chunk-ZPJ5J24T.cjs.map +1 -0
- package/dist/config/nextjs.cjs +5 -5
- package/dist/config/nextjs.js +1 -1
- package/dist/host/html.cjs +19 -19
- package/dist/host/html.js +7 -7
- package/dist/host/nextjs/app/client-only.cjs +20 -11
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +17 -8
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/nextjs/app.cjs +2 -0
- package/dist/host/nextjs/app.cjs.map +1 -1
- package/dist/host/nextjs/app.js +2 -0
- package/dist/host/nextjs/app.js.map +1 -1
- package/dist/host/nextjs/pages.cjs +14 -7
- package/dist/host/nextjs/pages.cjs.map +1 -1
- package/dist/host/nextjs/pages.d.ts +2 -0
- package/dist/host/nextjs/pages.js +14 -7
- package/dist/host/nextjs/pages.js.map +1 -1
- package/dist/host/react.cjs +7 -7
- package/dist/host/react.js +6 -6
- package/dist/internal/host/nextjs/app-client.cjs +8 -3
- package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
- package/dist/internal/host/nextjs/app-client.d.ts +3 -2
- package/dist/internal/host/nextjs/app-client.js +8 -3
- package/dist/internal/host/nextjs/app-client.js.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.cjs +1 -0
- package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.d.ts +1 -0
- package/dist/internal/host/nextjs/dom-flight.js +1 -0
- package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
- package/dist/internal/host/nextjs/image-shared.cjs +11 -2
- package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
- package/dist/internal/host/nextjs/image-shared.d.ts +3 -1
- package/dist/internal/host/nextjs/image-shared.js +11 -2
- package/dist/internal/host/nextjs/image-shared.js.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.cjs +58 -3
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.d.ts +1 -0
- package/dist/internal/host/server/fetch-remote-component.js +61 -3
- package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
- package/dist/internal/host/server/types.cjs.map +1 -1
- package/dist/internal/host/server/types.d.ts +2 -0
- package/dist/internal/host/shared/next-image-deployment-id.cjs +50 -0
- package/dist/internal/host/shared/next-image-deployment-id.cjs.map +1 -0
- package/dist/internal/host/shared/next-image-deployment-id.d.ts +14 -0
- package/dist/internal/host/shared/next-image-deployment-id.js +25 -0
- package/dist/internal/host/shared/next-image-deployment-id.js.map +1 -0
- package/dist/internal/host/shared/pipeline.d.ts +2 -1
- package/dist/internal/host/shared/remote-image-loader.cjs +15 -23
- package/dist/internal/host/shared/remote-image-loader.cjs.map +1 -1
- package/dist/internal/host/shared/remote-image-loader.d.ts +2 -1
- package/dist/internal/host/shared/remote-image-loader.js +17 -22
- package/dist/internal/host/shared/remote-image-loader.js.map +1 -1
- package/dist/internal/runtime/html/parse-remote-html.d.ts +1 -0
- package/dist/internal/runtime/loaders/component-loader.d.ts +2 -1
- package/dist/{server-handoff-9e905049.d.ts → server-handoff-006f9cb5.d.ts} +2 -0
- package/dist/{turbopack-Z744H3T4.js → turbopack-HK7DVYUG.js} +4 -4
- package/dist/{turbopack-5WAY6QIC.cjs → turbopack-YZOIO55D.cjs} +11 -11
- package/dist/{webpack-IQKPPBGH.js → webpack-2HP73JL7.js} +4 -4
- package/dist/{webpack-3GSL5AZJ.cjs → webpack-W2MODB73.cjs} +11 -11
- package/package.json +1 -1
- package/dist/chunk-3DR4Z24C.js.map +0 -1
- package/dist/chunk-OZCVXVKU.cjs.map +0 -1
- /package/dist/{chunk-CLB2ATH2.js.map → chunk-EIEIT5PG.js.map} +0 -0
- /package/dist/{chunk-5BBEO4SE.js.map → chunk-GG32LZD3.js.map} +0 -0
- /package/dist/{chunk-KP544TQH.cjs.map → chunk-JKDPK6L5.cjs.map} +0 -0
- /package/dist/{chunk-KMG54QXV.cjs.map → chunk-MAVMKFFL.cjs.map} +0 -0
- /package/dist/{chunk-XEO3XD67.js.map → chunk-PNKSHWZ3.js.map} +0 -0
- /package/dist/{chunk-OI37BBBU.cjs.map → chunk-T2JJIQUJ.cjs.map} +0 -0
- /package/dist/{chunk-OVD7BRLD.cjs.map → chunk-TIS6PXSQ.cjs.map} +0 -0
- /package/dist/{chunk-W7RJUCZQ.cjs.map → chunk-WCZKEWRM.cjs.map} +0 -0
- /package/dist/{chunk-IE7FXNFJ.js.map → chunk-XLGLCKZZ.js.map} +0 -0
- /package/dist/{chunk-CBEDRGC7.js.map → chunk-YKCU7RFM.js.map} +0 -0
- /package/dist/{turbopack-Z744H3T4.js.map → turbopack-HK7DVYUG.js.map} +0 -0
- /package/dist/{turbopack-5WAY6QIC.cjs.map → turbopack-YZOIO55D.cjs.map} +0 -0
- /package/dist/{webpack-IQKPPBGH.js.map → webpack-2HP73JL7.js.map} +0 -0
- /package/dist/{webpack-3GSL5AZJ.cjs.map → webpack-W2MODB73.cjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/server/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { type RSC, visit } from '#internal/host/nextjs/dom-flight';\nimport {\n getSkeletonHtml,\n getSkeletonMessage,\n} from '#internal/host/nextjs/skeleton';\nimport { fetchWithHooks } from '#internal/host/server/fetch-with-hooks';\nimport { getClientSrc } from '#internal/host/server/get-client-src';\nimport {\n DEPLOYMENT_URL,\n getSSRRelativePathBaseUrl,\n PRODUCTION_URL,\n} from '#internal/host/server/get-ssr-relative-path-base-url';\nimport type {\n LinkDescriptor,\n ScriptDescriptor,\n} from '#internal/host/shared/asset-descriptors';\nimport type {\n OnRequestHook,\n OnResponseHook,\n} from '#internal/host/shared/fetch-interceptors';\nimport type { RemoteSharedModules } from '#internal/host/shared/shared-broker';\nimport {\n buildMetadata,\n type RawMetadataAttrs,\n type RemoteComponentMetadata,\n} from '#internal/runtime/metadata';\nimport { importRSCClientEdge } from '#internal/runtime/rsc-imports';\nimport {\n failedToFetchRemoteComponentError,\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport type { FetchRemoteComponentResponse, NextData } from './types';\n\n/**\n * Converts RSC flight data into a React element tree using the edge streaming\n * runtime. The manifest tells React how to resolve module references back to\n * the remote origin.\n */\nasync function buildRscComponent(\n rsc: RSC | RSC[] | string | null,\n serverUrl: URL,\n): Promise<React.ReactNode> {\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n const { createFromReadableStream } = await importRSCClientEdge();\n return createFromReadableStream(\n new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n controller.enqueue(encoder.encode(componentRSC));\n controller.close();\n },\n }),\n {\n serverConsumerManifest: {\n moduleLoading: {\n prefix: serverUrl.origin,\n crossOrigin: true,\n },\n moduleMap: {},\n },\n },\n );\n}\n\nfunction buildSkeletonResponse(\n serverUrl: URL,\n metadata: RemoteComponentMetadata,\n skeletonComponent: React.ReactNode | undefined,\n): FetchRemoteComponentResponse {\n return {\n name: 'remote-component-skeleton',\n serverUrl,\n metadata: {\n ...metadata,\n type: 'remote-component',\n },\n rsc: getSkeletonMessage(),\n scripts: [],\n links: [],\n hydrationData: [],\n nextData: undefined,\n component: skeletonComponent,\n html: getSkeletonHtml(serverUrl.href),\n remoteShared: {},\n };\n}\n\n/**\n * Walks the parsed HTML fragment and extracts all remote component data:\n * metadata, scripts, links, hydration data, Next.js data, shared deps, and HTML.\n */\nfunction visitFragment(\n fragment: DefaultTreeAdapterMap['documentFragment'],\n serverUrl: URL,\n remoteName: string | undefined,\n) {\n const scriptSrcSet = new Set<string>();\n const scriptTextSet = new Set<string>();\n const scripts: ScriptDescriptor[] = [];\n\n const linkKeySet = new Set<string>();\n const links: LinkDescriptor[] = [];\n\n const hydrationData: string[] = [];\n const htmlChunks = new Set<string>();\n\n let metadata: RemoteComponentMetadata | undefined;\n let nextData: NextData | undefined;\n let remoteShared: RemoteSharedModules = {};\n let hasRSC = false;\n let hasShared = false;\n let error: RemoteComponentsError | undefined;\n\n const rawRscChunks: string[] = [];\n\n const rsc = visit(fragment, {\n url: serverUrl,\n name: remoteName,\n onMetadata(attrs: RawMetadataAttrs) {\n const incoming = buildMetadata(attrs, serverUrl);\n // Skip multiple component detection for Pages Router (__next) since\n // it only supports one remote component per page\n if (\n !remoteName &&\n metadata &&\n metadata.id !== incoming.id &&\n incoming.id !== '__next' &&\n metadata.id !== '__next' &&\n !nextData\n ) {\n throw multipleRemoteComponentsError(serverUrl.href);\n }\n metadata = incoming;\n },\n onScript(attrs) {\n const clientSrc = getClientSrc(attrs.src, serverUrl.href);\n const textContent =\n typeof attrs.textContent === 'string' ? attrs.textContent : undefined;\n\n if (textContent) {\n if (!scriptTextSet.has(textContent)) {\n scriptTextSet.add(textContent);\n scripts.push({ src: '', textContent });\n }\n } else if (!scriptSrcSet.has(clientSrc)) {\n scriptSrcSet.add(clientSrc);\n scripts.push({ src: clientSrc });\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: getClientSrc(attrs.href, serverUrl.href),\n };\n const linkKey = `${relativeAttrs.href}::${attrs.rel}`;\n if (!linkKeySet.has(linkKey)) {\n linkKeySet.add(linkKey);\n links.push(relativeAttrs);\n }\n },\n onRSC(chunk) {\n rawRscChunks.push(chunk);\n hasRSC = true;\n },\n onNextData(data) {\n nextData = data;\n },\n onHTML(chunk) {\n if (!htmlChunks.has(chunk)) {\n htmlChunks.add(chunk);\n }\n },\n onShared(_shared) {\n remoteShared = _shared;\n hasShared = true;\n },\n onError(message, stack) {\n error = new RemoteComponentsError(message);\n if (stack) {\n error.stack = stack;\n }\n },\n });\n\n hydrationData.push(...rawRscChunks);\n\n if (error) {\n throw error;\n }\n\n if (metadata) {\n if (!hasRSC && !nextData && metadata.type === 'nextjs') {\n throw new RemoteComponentsError(\n `The Remote Component at \"${serverUrl.href}\" seems to be a Next.js component but it does not contain any RSC flight data or Next.js props data. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n if (\n metadata.type === 'nextjs' &&\n !hasShared &&\n !nextData?.props.__REMOTE_COMPONENT__?.sharedManifest &&\n !nextData?.props.__REMOTE_COMPONENT__?.shared\n ) {\n throw new RemoteComponentsError(\n `No shared dependencies found for Remote Component at \"${serverUrl.href}\". Make sure the remote URL is correct and contains a Remote Component with shared dependencies.`,\n );\n }\n }\n\n const resolvedShared =\n nextData?.props.__REMOTE_COMPONENT__?.sharedManifest ??\n // @legacy(remote-components<=0.4.x): keep accepting the Pages Router\n // shared map until remotes on 0.4.x are outside the compatibility window.\n nextData?.props.__REMOTE_COMPONENT__?.shared ??\n remoteShared;\n\n return {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared: resolvedShared,\n html: Array.from(htmlChunks).join(''),\n };\n}\n\ninterface Options {\n name?: string;\n rsc?: boolean;\n /** Whether this is being called from Next.js App Router. Used to enable skeleton fallback during SSG builds. */\n appRouter?: boolean;\n onRequest?: OnRequestHook;\n onResponse?: OnResponseHook;\n}\n\nasync function fetchWithTags(\n src: string | URL,\n relativePathBaseUrl: string,\n options: Options,\n) {\n const serverUrl = new URL(src, relativePathBaseUrl);\n const tags = [\n '_vc_rc:fetch-remote-component',\n // the max size of a next cache tag is 256 characters\n serverUrl.host.slice(0, 256),\n // use the suffix so this tag is unique if multiple remote\n // components have the same host, but unique pathnames / query params\n (typeof src === 'string' ? src : src.href).slice(-256),\n ];\n if (options.name) {\n tags.push(options.name.slice(-256));\n }\n\n const fetchInit = { next: { tags } };\n\n const res = await fetchWithHooks(serverUrl, fetchInit, {\n onRequest: options.onRequest,\n onResponse: options.onResponse,\n });\n\n return {\n res,\n serverUrl,\n // If the remote component is part of a microfrontend, the src provided will be relative.\n isMfeRelativeSrc: serverUrl.host === new URL(relativePathBaseUrl).host,\n };\n}\n\nexport async function fetchRemoteComponent(\n src: string | URL,\n options: Options = {},\n): Promise<FetchRemoteComponentResponse> {\n let { res, isMfeRelativeSrc, serverUrl } = await fetchWithTags(\n src,\n getSSRRelativePathBaseUrl(),\n options,\n );\n\n const maybeFirstMfeProductionDeployment =\n isMfeRelativeSrc && serverUrl.host === PRODUCTION_URL;\n\n // When deploying a microfrontend with remote components to production for the first time, the fetch with the\n // production URL will fail if the production URL is not already an MFE alias. The URL becomes an MFE alias\n // on the first MFE deployment. For this fetch, use the deployment URL which is an MFE alias.\n if (\n res.status === 404 &&\n maybeFirstMfeProductionDeployment &&\n DEPLOYMENT_URL\n ) {\n ({ res, isMfeRelativeSrc, serverUrl } = await fetchWithTags(\n src,\n `https://${DEPLOYMENT_URL}`,\n options,\n ));\n }\n\n // If there is an error in the remote, parse and extract the remote error (except 404 and 401).\n if (!res.ok && !res.body) {\n throw failedToFetchRemoteComponentError(serverUrl.href, res);\n }\n\n if (res.status === 401) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'If you are using Deployment Protection, ensure the automation bypass environment variable secret in the host matches an automation bypass value in the remote. See https://remote-components-docs.vercel.sh/docs/concepts/cors-external-urls#deployment-protection for details.',\n );\n }\n\n if (res.status === 404) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n maybeFirstMfeProductionDeployment\n ? `If this is the first production build of a microfrontends setup, try redeploying once the remote is deployed to production. Once deployed, this error will not re-occur, and ISR revalidation will happen automatically for remote components once they deploy. https://remote-components-docs.vercel.sh/docs/concepts/isr-deployment`\n : `Check if you can open it in the browser.`,\n );\n }\n\n if (!res.body) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `Response body is empty. Check if you can open it in the browser and you see the Remote Component content.`,\n );\n }\n\n const parser = Parser.getFragmentParser<DefaultTreeAdapterMap>();\n const decoder = new TextDecoder();\n // read the response body as a stream and parse it using the parse5 fragment parser\n for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {\n parser.tokenizer.write(decoder.decode(chunk), false);\n }\n const fragment = parser.getFragment();\n\n const remoteName =\n options.name || (serverUrl.hash ? serverUrl.hash.substring(1) : undefined);\n\n const {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared,\n html,\n } = visitFragment(fragment, serverUrl, remoteName);\n\n if (!metadata) {\n // For microfrontend builds during run time, the host and remote build\n // may be happening concurrently. In this case, the request will 404.\n // We want to allow the build to continue with a placeholder remote\n // component. Once the build completes, vercel will automatically revalidate\n // ISR and fetch the built remote component.\n const isSSGBuild = process.env.NEXT_PHASE === 'phase-production-build';\n // Only want this skeleton behaviour in previews to unblock development.\n // For production, the remote component should already be built.\n const isPreview = process.env.VERCEL_TARGET_ENV === 'preview';\n // For app router previews, the host and remote build at the same time, to allow this, render a skeleton\n // in the host if the remote is not found, which will revalidate when the remote deploys, or give a helpful error in the UI\n if (isSSGBuild && isMfeRelativeSrc && isPreview && options.appRouter) {\n let skeletonComponent: React.ReactNode | undefined;\n if (options.rsc) {\n const { createElement } = await import('react');\n skeletonComponent = createElement('div', {\n dangerouslySetInnerHTML: {\n __html: getSkeletonHtml(serverUrl.href),\n },\n });\n }\n\n return buildSkeletonResponse(\n serverUrl,\n buildMetadata({}, serverUrl),\n skeletonComponent,\n );\n }\n\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `No Remote Component found. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n const name = remoteName || metadata.name;\n const component = options.rsc\n ? await buildRscComponent(rsc, serverUrl)\n : undefined;\n\n return {\n name,\n serverUrl,\n metadata,\n rsc,\n scripts,\n links,\n hydrationData,\n nextData,\n component,\n html,\n remoteShared,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmD;AACnD,wBAAgC;AAChC,sBAGO;AACP,8BAA+B;AAC/B,4BAA6B;AAC7B,4CAIO;AAUP,sBAIO;AACP,yBAAoC;AACpC,mBAIO;AAQP,eAAe,kBACb,KACA,WAC0B;AAC1B,QAAM,eAAe,KAAK,KAAK,UAAU,GAAG;AAAA;AAC5C,QAAM,EAAE,yBAAyB,IAAI,UAAM,wCAAoB;AAC/D,SAAO;AAAA,IACL,IAAI,eAAe;AAAA,MACjB,MAAM;AAAA,MACN,MAAM,YAAY;AAChB,cAAM,UAAU,IAAI,YAAY;AAChC,mBAAW,QAAQ,QAAQ,OAAO,YAAY,CAAC;AAC/C,mBAAW,MAAM;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,IACD;AAAA,MACE,wBAAwB;AAAA,QACtB,eAAe;AAAA,UACb,QAAQ,UAAU;AAAA,UAClB,aAAa;AAAA,QACf;AAAA,QACA,WAAW,CAAC;AAAA,MACd;AAAA,IACF;AAAA,EACF;AACF;AA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;AAAA,YACA,+BAAc,CAAC,GAAG,SAAS;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AAEA,cAAM;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,OAAO,cAAc,SAAS;AACpC,QAAM,YAAY,QAAQ,MACtB,MAAM,kBAAkB,KAAK,SAAS,IACtC;AAEJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/server/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { type RSC, visit } from '#internal/host/nextjs/dom-flight';\nimport {\n getSkeletonHtml,\n getSkeletonMessage,\n} from '#internal/host/nextjs/skeleton';\nimport { fetchWithHooks } from '#internal/host/server/fetch-with-hooks';\nimport { getClientSrc } from '#internal/host/server/get-client-src';\nimport {\n DEPLOYMENT_URL,\n getSSRRelativePathBaseUrl,\n PRODUCTION_URL,\n} from '#internal/host/server/get-ssr-relative-path-base-url';\nimport type {\n LinkDescriptor,\n ScriptDescriptor,\n} from '#internal/host/shared/asset-descriptors';\nimport type {\n OnRequestHook,\n OnResponseHook,\n} from '#internal/host/shared/fetch-interceptors';\nimport {\n extractDeploymentIdFromSrc,\n isNextDeploymentAssetSrc,\n type NextImageDeploymentId,\n} from '#internal/host/shared/next-image-deployment-id';\nimport type { RemoteSharedModules } from '#internal/host/shared/shared-broker';\nimport {\n buildMetadata,\n type RawMetadataAttrs,\n type RemoteComponentMetadata,\n} from '#internal/runtime/metadata';\nimport { importRSCClientEdge } from '#internal/runtime/rsc-imports';\nimport {\n failedToFetchRemoteComponentError,\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport type { FetchRemoteComponentResponse, NextData } from './types';\n\nconst NEXT_IMAGE_PATHNAME = '/_next/image';\n/**\n * Converts RSC flight data into a React element tree using the edge streaming\n * runtime. The manifest tells React how to resolve module references back to\n * the remote origin.\n */\nasync function buildRscComponent(\n rsc: RSC | RSC[] | string | null,\n serverUrl: URL,\n): Promise<React.ReactNode> {\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n const { createFromReadableStream } = await importRSCClientEdge();\n return createFromReadableStream(\n new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n controller.enqueue(encoder.encode(componentRSC));\n controller.close();\n },\n }),\n {\n serverConsumerManifest: {\n moduleLoading: {\n prefix: serverUrl.origin,\n crossOrigin: true,\n },\n moduleMap: {},\n },\n },\n );\n}\n\nfunction buildSkeletonResponse(\n serverUrl: URL,\n metadata: RemoteComponentMetadata,\n skeletonComponent: React.ReactNode | undefined,\n): FetchRemoteComponentResponse {\n return {\n name: 'remote-component-skeleton',\n serverUrl,\n metadata: {\n ...metadata,\n type: 'remote-component',\n },\n rsc: getSkeletonMessage(),\n scripts: [],\n links: [],\n hydrationData: [],\n nextData: undefined,\n component: skeletonComponent,\n html: getSkeletonHtml(serverUrl.href),\n remoteShared: {},\n ssrImageDeploymentIds: [],\n };\n}\n\nfunction getNextImageDeploymentId(\n value: string,\n base: URL,\n): NextImageDeploymentId | undefined {\n try {\n const parsed = new URL(value.replace(/&/g, '&'), base);\n const imageSrc = parsed.searchParams.get('url');\n if (\n !parsed.pathname.endsWith(NEXT_IMAGE_PATHNAME) ||\n !isNextDeploymentAssetSrc(imageSrc)\n ) {\n return undefined;\n }\n\n const extracted = extractDeploymentIdFromSrc(imageSrc);\n const deploymentId =\n parsed.searchParams.get('dpl') || extracted.deploymentId;\n\n return deploymentId ? { src: extracted.src, deploymentId } : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction addNextImageDeploymentId(\n value: string | undefined,\n serverUrl: URL,\n result: Map<string, string>,\n) {\n if (!value) {\n return;\n }\n\n const image = getNextImageDeploymentId(value, serverUrl);\n if (image) {\n result.set(image.src, image.deploymentId);\n }\n}\n\nfunction addNextImageDeploymentIdsFromSrcset(\n value: string | undefined,\n serverUrl: URL,\n result: Map<string, string>,\n) {\n if (!value) return;\n for (const candidate of value.split(',')) {\n addNextImageDeploymentId(\n candidate.trim().split(/\\s+/)[0],\n serverUrl,\n result,\n );\n }\n}\n\n/**\n * Walks the parsed HTML fragment and extracts all remote component data:\n * metadata, scripts, links, hydration data, Next.js data, shared deps, and HTML.\n */\nfunction visitFragment(\n fragment: DefaultTreeAdapterMap['documentFragment'],\n serverUrl: URL,\n remoteName: string | undefined,\n) {\n const scriptSrcSet = new Set<string>();\n const scriptTextSet = new Set<string>();\n const scripts: ScriptDescriptor[] = [];\n\n const linkKeySet = new Set<string>();\n const links: LinkDescriptor[] = [];\n\n const hydrationData: string[] = [];\n const htmlChunks = new Set<string>();\n const ssrImageDeploymentIdMap = new Map<string, string>();\n\n let metadata: RemoteComponentMetadata | undefined;\n let nextData: NextData | undefined;\n let remoteShared: RemoteSharedModules = {};\n let hasRSC = false;\n let hasShared = false;\n let error: RemoteComponentsError | undefined;\n\n const rawRscChunks: string[] = [];\n\n const rsc = visit(fragment, {\n url: serverUrl,\n name: remoteName,\n onMetadata(attrs: RawMetadataAttrs) {\n const incoming = buildMetadata(attrs, serverUrl);\n // Skip multiple component detection for Pages Router (__next) since\n // it only supports one remote component per page\n if (\n !remoteName &&\n metadata &&\n metadata.id !== incoming.id &&\n incoming.id !== '__next' &&\n metadata.id !== '__next' &&\n !nextData\n ) {\n throw multipleRemoteComponentsError(serverUrl.href);\n }\n metadata = incoming;\n },\n onScript(attrs) {\n const clientSrc = getClientSrc(attrs.src, serverUrl.href);\n const textContent =\n typeof attrs.textContent === 'string' ? attrs.textContent : undefined;\n\n if (textContent) {\n if (!scriptTextSet.has(textContent)) {\n scriptTextSet.add(textContent);\n scripts.push({ src: '', textContent });\n }\n } else if (!scriptSrcSet.has(clientSrc)) {\n scriptSrcSet.add(clientSrc);\n scripts.push({ src: clientSrc });\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: getClientSrc(attrs.href, serverUrl.href),\n };\n const linkKey = `${relativeAttrs.href}::${attrs.rel}`;\n if (!linkKeySet.has(linkKey)) {\n linkKeySet.add(linkKey);\n links.push(relativeAttrs);\n }\n },\n onRSC(chunk) {\n rawRscChunks.push(chunk);\n hasRSC = true;\n },\n onNextData(data) {\n nextData = data;\n },\n onHTML(chunk) {\n if (!htmlChunks.has(chunk)) {\n htmlChunks.add(chunk);\n }\n },\n onShared(_shared) {\n remoteShared = _shared;\n hasShared = true;\n },\n onError(message, stack) {\n error = new RemoteComponentsError(message);\n if (stack) {\n error.stack = stack;\n }\n },\n onElement(nodeName, attrs) {\n if (nodeName !== 'img') {\n return;\n }\n\n addNextImageDeploymentId(attrs.src, serverUrl, ssrImageDeploymentIdMap);\n addNextImageDeploymentIdsFromSrcset(\n attrs.srcset,\n serverUrl,\n ssrImageDeploymentIdMap,\n );\n },\n });\n\n hydrationData.push(...rawRscChunks);\n\n if (error) {\n throw error;\n }\n\n if (metadata) {\n if (!hasRSC && !nextData && metadata.type === 'nextjs') {\n throw new RemoteComponentsError(\n `The Remote Component at \"${serverUrl.href}\" seems to be a Next.js component but it does not contain any RSC flight data or Next.js props data. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n if (\n metadata.type === 'nextjs' &&\n !hasShared &&\n !nextData?.props.__REMOTE_COMPONENT__?.sharedManifest &&\n !nextData?.props.__REMOTE_COMPONENT__?.shared\n ) {\n throw new RemoteComponentsError(\n `No shared dependencies found for Remote Component at \"${serverUrl.href}\". Make sure the remote URL is correct and contains a Remote Component with shared dependencies.`,\n );\n }\n }\n\n const resolvedShared =\n nextData?.props.__REMOTE_COMPONENT__?.sharedManifest ??\n // @legacy(remote-components<=0.4.x): keep accepting the Pages Router\n // shared map until remotes on 0.4.x are outside the compatibility window.\n nextData?.props.__REMOTE_COMPONENT__?.shared ??\n remoteShared;\n\n return {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared: resolvedShared,\n ssrImageDeploymentIds: Array.from(\n ssrImageDeploymentIdMap,\n ([src, deploymentId]) => ({ src, deploymentId }),\n ),\n html: Array.from(htmlChunks).join(''),\n };\n}\n\ninterface Options {\n name?: string;\n rsc?: boolean;\n /** Whether this is being called from Next.js App Router. Used to enable skeleton fallback during SSG builds. */\n appRouter?: boolean;\n onRequest?: OnRequestHook;\n onResponse?: OnResponseHook;\n}\n\nasync function fetchWithTags(\n src: string | URL,\n relativePathBaseUrl: string,\n options: Options,\n) {\n const serverUrl = new URL(src, relativePathBaseUrl);\n const tags = [\n '_vc_rc:fetch-remote-component',\n // the max size of a next cache tag is 256 characters\n serverUrl.host.slice(0, 256),\n // use the suffix so this tag is unique if multiple remote\n // components have the same host, but unique pathnames / query params\n (typeof src === 'string' ? src : src.href).slice(-256),\n ];\n if (options.name) {\n tags.push(options.name.slice(-256));\n }\n\n const fetchInit = { next: { tags } };\n\n const res = await fetchWithHooks(serverUrl, fetchInit, {\n onRequest: options.onRequest,\n onResponse: options.onResponse,\n });\n\n return {\n res,\n serverUrl,\n // If the remote component is part of a microfrontend, the src provided will be relative.\n isMfeRelativeSrc: serverUrl.host === new URL(relativePathBaseUrl).host,\n };\n}\n\nexport async function fetchRemoteComponent(\n src: string | URL,\n options: Options = {},\n): Promise<FetchRemoteComponentResponse> {\n let { res, isMfeRelativeSrc, serverUrl } = await fetchWithTags(\n src,\n getSSRRelativePathBaseUrl(),\n options,\n );\n\n const maybeFirstMfeProductionDeployment =\n isMfeRelativeSrc && serverUrl.host === PRODUCTION_URL;\n\n // When deploying a microfrontend with remote components to production for the first time, the fetch with the\n // production URL will fail if the production URL is not already an MFE alias. The URL becomes an MFE alias\n // on the first MFE deployment. For this fetch, use the deployment URL which is an MFE alias.\n if (\n res.status === 404 &&\n maybeFirstMfeProductionDeployment &&\n DEPLOYMENT_URL\n ) {\n ({ res, isMfeRelativeSrc, serverUrl } = await fetchWithTags(\n src,\n `https://${DEPLOYMENT_URL}`,\n options,\n ));\n }\n\n // If there is an error in the remote, parse and extract the remote error (except 404 and 401).\n if (!res.ok && !res.body) {\n throw failedToFetchRemoteComponentError(serverUrl.href, res);\n }\n\n if (res.status === 401) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'If you are using Deployment Protection, ensure the automation bypass environment variable secret in the host matches an automation bypass value in the remote. See https://remote-components-docs.vercel.sh/docs/concepts/cors-external-urls#deployment-protection for details.',\n );\n }\n\n if (res.status === 404) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n maybeFirstMfeProductionDeployment\n ? `If this is the first production build of a microfrontends setup, try redeploying once the remote is deployed to production. Once deployed, this error will not re-occur, and ISR revalidation will happen automatically for remote components once they deploy. https://remote-components-docs.vercel.sh/docs/concepts/isr-deployment`\n : `Check if you can open it in the browser.`,\n );\n }\n\n if (!res.body) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `Response body is empty. Check if you can open it in the browser and you see the Remote Component content.`,\n );\n }\n\n const parser = Parser.getFragmentParser<DefaultTreeAdapterMap>();\n const decoder = new TextDecoder();\n // read the response body as a stream and parse it using the parse5 fragment parser\n for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {\n parser.tokenizer.write(decoder.decode(chunk), false);\n }\n const fragment = parser.getFragment();\n\n const remoteName =\n options.name || (serverUrl.hash ? serverUrl.hash.substring(1) : undefined);\n\n const {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared,\n html,\n ssrImageDeploymentIds,\n } = visitFragment(fragment, serverUrl, remoteName);\n\n if (!metadata) {\n // For microfrontend builds during run time, the host and remote build\n // may be happening concurrently. In this case, the request will 404.\n // We want to allow the build to continue with a placeholder remote\n // component. Once the build completes, vercel will automatically revalidate\n // ISR and fetch the built remote component.\n const isSSGBuild = process.env.NEXT_PHASE === 'phase-production-build';\n // Only want this skeleton behaviour in previews to unblock development.\n // For production, the remote component should already be built.\n const isPreview = process.env.VERCEL_TARGET_ENV === 'preview';\n // For app router previews, the host and remote build at the same time, to allow this, render a skeleton\n // in the host if the remote is not found, which will revalidate when the remote deploys, or give a helpful error in the UI\n if (isSSGBuild && isMfeRelativeSrc && isPreview && options.appRouter) {\n let skeletonComponent: React.ReactNode | undefined;\n if (options.rsc) {\n const { createElement } = await import('react');\n skeletonComponent = createElement('div', {\n dangerouslySetInnerHTML: {\n __html: getSkeletonHtml(serverUrl.href),\n },\n });\n }\n\n return buildSkeletonResponse(\n serverUrl,\n buildMetadata({}, serverUrl),\n skeletonComponent,\n );\n }\n\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `No Remote Component found. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n const name = remoteName || metadata.name;\n const component = options.rsc\n ? await buildRscComponent(rsc, serverUrl)\n : undefined;\n\n return {\n name,\n serverUrl,\n metadata,\n rsc,\n scripts,\n links,\n hydrationData,\n nextData,\n component,\n html,\n remoteShared,\n ssrImageDeploymentIds,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmD;AACnD,wBAAgC;AAChC,sBAGO;AACP,8BAA+B;AAC/B,4BAA6B;AAC7B,4CAIO;AASP,sCAIO;AAEP,sBAIO;AACP,yBAAoC;AACpC,mBAIO;AAGP,MAAM,sBAAsB;AAM5B,eAAe,kBACb,KACA,WAC0B;AAC1B,QAAM,eAAe,KAAK,KAAK,UAAU,GAAG;AAAA;AAC5C,QAAM,EAAE,yBAAyB,IAAI,UAAM,wCAAoB;AAC/D,SAAO;AAAA,IACL,IAAI,eAAe;AAAA,MACjB,MAAM;AAAA,MACN,MAAM,YAAY;AAChB,cAAM,UAAU,IAAI,YAAY;AAChC,mBAAW,QAAQ,QAAQ,OAAO,YAAY,CAAC;AAC/C,mBAAW,MAAM;AAAA,MACnB;AAAA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B,cAAc,OAAO;AAAA,UACvC,yBAAyB;AAAA,YACvB,YAAQ,iCAAgB,UAAU,IAAI;AAAA,UACxC;AAAA,QACF,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,QACL;AAAA,YACA,+BAAc,CAAC,GAAG,SAAS;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AAEA,cAAM;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,OAAO,cAAc,SAAS;AACpC,QAAM,YAAY,QAAQ,MACtB,MAAM,kBAAkB,KAAK,SAAS,IACtC;AAEJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -6,6 +6,7 @@ import '../shared/shared-broker.js';
|
|
|
6
6
|
import '../../utils/logger.js';
|
|
7
7
|
import '../../runtime/metadata.js';
|
|
8
8
|
import '../shared/asset-descriptors.js';
|
|
9
|
+
import '../shared/next-image-deployment-id.js';
|
|
9
10
|
import '../../runtime/url/resolve-client-url.js';
|
|
10
11
|
|
|
11
12
|
interface Options {
|
|
@@ -11,6 +11,10 @@ import {
|
|
|
11
11
|
getSSRRelativePathBaseUrl,
|
|
12
12
|
PRODUCTION_URL
|
|
13
13
|
} from "#internal/host/server/get-ssr-relative-path-base-url";
|
|
14
|
+
import {
|
|
15
|
+
extractDeploymentIdFromSrc,
|
|
16
|
+
isNextDeploymentAssetSrc
|
|
17
|
+
} from "#internal/host/shared/next-image-deployment-id";
|
|
14
18
|
import {
|
|
15
19
|
buildMetadata
|
|
16
20
|
} from "#internal/runtime/metadata";
|
|
@@ -20,6 +24,7 @@ import {
|
|
|
20
24
|
multipleRemoteComponentsError,
|
|
21
25
|
RemoteComponentsError
|
|
22
26
|
} from "#internal/utils/error";
|
|
27
|
+
const NEXT_IMAGE_PATHNAME = "/_next/image";
|
|
23
28
|
async function buildRscComponent(rsc, serverUrl) {
|
|
24
29
|
const componentRSC = `0:${JSON.stringify(rsc)}
|
|
25
30
|
`;
|
|
@@ -59,9 +64,44 @@ function buildSkeletonResponse(serverUrl, metadata, skeletonComponent) {
|
|
|
59
64
|
nextData: void 0,
|
|
60
65
|
component: skeletonComponent,
|
|
61
66
|
html: getSkeletonHtml(serverUrl.href),
|
|
62
|
-
remoteShared: {}
|
|
67
|
+
remoteShared: {},
|
|
68
|
+
ssrImageDeploymentIds: []
|
|
63
69
|
};
|
|
64
70
|
}
|
|
71
|
+
function getNextImageDeploymentId(value, base) {
|
|
72
|
+
try {
|
|
73
|
+
const parsed = new URL(value.replace(/&/g, "&"), base);
|
|
74
|
+
const imageSrc = parsed.searchParams.get("url");
|
|
75
|
+
if (!parsed.pathname.endsWith(NEXT_IMAGE_PATHNAME) || !isNextDeploymentAssetSrc(imageSrc)) {
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
const extracted = extractDeploymentIdFromSrc(imageSrc);
|
|
79
|
+
const deploymentId = parsed.searchParams.get("dpl") || extracted.deploymentId;
|
|
80
|
+
return deploymentId ? { src: extracted.src, deploymentId } : void 0;
|
|
81
|
+
} catch {
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function addNextImageDeploymentId(value, serverUrl, result) {
|
|
86
|
+
if (!value) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const image = getNextImageDeploymentId(value, serverUrl);
|
|
90
|
+
if (image) {
|
|
91
|
+
result.set(image.src, image.deploymentId);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function addNextImageDeploymentIdsFromSrcset(value, serverUrl, result) {
|
|
95
|
+
if (!value)
|
|
96
|
+
return;
|
|
97
|
+
for (const candidate of value.split(",")) {
|
|
98
|
+
addNextImageDeploymentId(
|
|
99
|
+
candidate.trim().split(/\s+/)[0],
|
|
100
|
+
serverUrl,
|
|
101
|
+
result
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
65
105
|
function visitFragment(fragment, serverUrl, remoteName) {
|
|
66
106
|
const scriptSrcSet = /* @__PURE__ */ new Set();
|
|
67
107
|
const scriptTextSet = /* @__PURE__ */ new Set();
|
|
@@ -70,6 +110,7 @@ function visitFragment(fragment, serverUrl, remoteName) {
|
|
|
70
110
|
const links = [];
|
|
71
111
|
const hydrationData = [];
|
|
72
112
|
const htmlChunks = /* @__PURE__ */ new Set();
|
|
113
|
+
const ssrImageDeploymentIdMap = /* @__PURE__ */ new Map();
|
|
73
114
|
let metadata;
|
|
74
115
|
let nextData;
|
|
75
116
|
let remoteShared = {};
|
|
@@ -132,6 +173,17 @@ function visitFragment(fragment, serverUrl, remoteName) {
|
|
|
132
173
|
if (stack) {
|
|
133
174
|
error.stack = stack;
|
|
134
175
|
}
|
|
176
|
+
},
|
|
177
|
+
onElement(nodeName, attrs) {
|
|
178
|
+
if (nodeName !== "img") {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
addNextImageDeploymentId(attrs.src, serverUrl, ssrImageDeploymentIdMap);
|
|
182
|
+
addNextImageDeploymentIdsFromSrcset(
|
|
183
|
+
attrs.srcset,
|
|
184
|
+
serverUrl,
|
|
185
|
+
ssrImageDeploymentIdMap
|
|
186
|
+
);
|
|
135
187
|
}
|
|
136
188
|
});
|
|
137
189
|
hydrationData.push(...rawRscChunks);
|
|
@@ -161,6 +213,10 @@ function visitFragment(fragment, serverUrl, remoteName) {
|
|
|
161
213
|
hydrationData,
|
|
162
214
|
nextData,
|
|
163
215
|
remoteShared: resolvedShared,
|
|
216
|
+
ssrImageDeploymentIds: Array.from(
|
|
217
|
+
ssrImageDeploymentIdMap,
|
|
218
|
+
([src, deploymentId]) => ({ src, deploymentId })
|
|
219
|
+
),
|
|
164
220
|
html: Array.from(htmlChunks).join("")
|
|
165
221
|
};
|
|
166
222
|
}
|
|
@@ -242,7 +298,8 @@ async function fetchRemoteComponent(src, options = {}) {
|
|
|
242
298
|
hydrationData,
|
|
243
299
|
nextData,
|
|
244
300
|
remoteShared,
|
|
245
|
-
html
|
|
301
|
+
html,
|
|
302
|
+
ssrImageDeploymentIds
|
|
246
303
|
} = visitFragment(fragment, serverUrl, remoteName);
|
|
247
304
|
if (!metadata) {
|
|
248
305
|
const isSSGBuild = process.env.NEXT_PHASE === "phase-production-build";
|
|
@@ -282,7 +339,8 @@ async function fetchRemoteComponent(src, options = {}) {
|
|
|
282
339
|
nextData,
|
|
283
340
|
component,
|
|
284
341
|
html,
|
|
285
|
-
remoteShared
|
|
342
|
+
remoteShared,
|
|
343
|
+
ssrImageDeploymentIds
|
|
286
344
|
};
|
|
287
345
|
}
|
|
288
346
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/server/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { type RSC, visit } from '#internal/host/nextjs/dom-flight';\nimport {\n getSkeletonHtml,\n getSkeletonMessage,\n} from '#internal/host/nextjs/skeleton';\nimport { fetchWithHooks } from '#internal/host/server/fetch-with-hooks';\nimport { getClientSrc } from '#internal/host/server/get-client-src';\nimport {\n DEPLOYMENT_URL,\n getSSRRelativePathBaseUrl,\n PRODUCTION_URL,\n} from '#internal/host/server/get-ssr-relative-path-base-url';\nimport type {\n LinkDescriptor,\n ScriptDescriptor,\n} from '#internal/host/shared/asset-descriptors';\nimport type {\n OnRequestHook,\n OnResponseHook,\n} from '#internal/host/shared/fetch-interceptors';\nimport type { RemoteSharedModules } from '#internal/host/shared/shared-broker';\nimport {\n buildMetadata,\n type RawMetadataAttrs,\n type RemoteComponentMetadata,\n} from '#internal/runtime/metadata';\nimport { importRSCClientEdge } from '#internal/runtime/rsc-imports';\nimport {\n failedToFetchRemoteComponentError,\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport type { FetchRemoteComponentResponse, NextData } from './types';\n\n/**\n * Converts RSC flight data into a React element tree using the edge streaming\n * runtime. The manifest tells React how to resolve module references back to\n * the remote origin.\n */\nasync function buildRscComponent(\n rsc: RSC | RSC[] | string | null,\n serverUrl: URL,\n): Promise<React.ReactNode> {\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n const { createFromReadableStream } = await importRSCClientEdge();\n return createFromReadableStream(\n new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n controller.enqueue(encoder.encode(componentRSC));\n controller.close();\n },\n }),\n {\n serverConsumerManifest: {\n moduleLoading: {\n prefix: serverUrl.origin,\n crossOrigin: true,\n },\n moduleMap: {},\n },\n },\n );\n}\n\nfunction buildSkeletonResponse(\n serverUrl: URL,\n metadata: RemoteComponentMetadata,\n skeletonComponent: React.ReactNode | undefined,\n): FetchRemoteComponentResponse {\n return {\n name: 'remote-component-skeleton',\n serverUrl,\n metadata: {\n ...metadata,\n type: 'remote-component',\n },\n rsc: getSkeletonMessage(),\n scripts: [],\n links: [],\n hydrationData: [],\n nextData: undefined,\n component: skeletonComponent,\n html: getSkeletonHtml(serverUrl.href),\n remoteShared: {},\n };\n}\n\n/**\n * Walks the parsed HTML fragment and extracts all remote component data:\n * metadata, scripts, links, hydration data, Next.js data, shared deps, and HTML.\n */\nfunction visitFragment(\n fragment: DefaultTreeAdapterMap['documentFragment'],\n serverUrl: URL,\n remoteName: string | undefined,\n) {\n const scriptSrcSet = new Set<string>();\n const scriptTextSet = new Set<string>();\n const scripts: ScriptDescriptor[] = [];\n\n const linkKeySet = new Set<string>();\n const links: LinkDescriptor[] = [];\n\n const hydrationData: string[] = [];\n const htmlChunks = new Set<string>();\n\n let metadata: RemoteComponentMetadata | undefined;\n let nextData: NextData | undefined;\n let remoteShared: RemoteSharedModules = {};\n let hasRSC = false;\n let hasShared = false;\n let error: RemoteComponentsError | undefined;\n\n const rawRscChunks: string[] = [];\n\n const rsc = visit(fragment, {\n url: serverUrl,\n name: remoteName,\n onMetadata(attrs: RawMetadataAttrs) {\n const incoming = buildMetadata(attrs, serverUrl);\n // Skip multiple component detection for Pages Router (__next) since\n // it only supports one remote component per page\n if (\n !remoteName &&\n metadata &&\n metadata.id !== incoming.id &&\n incoming.id !== '__next' &&\n metadata.id !== '__next' &&\n !nextData\n ) {\n throw multipleRemoteComponentsError(serverUrl.href);\n }\n metadata = incoming;\n },\n onScript(attrs) {\n const clientSrc = getClientSrc(attrs.src, serverUrl.href);\n const textContent =\n typeof attrs.textContent === 'string' ? attrs.textContent : undefined;\n\n if (textContent) {\n if (!scriptTextSet.has(textContent)) {\n scriptTextSet.add(textContent);\n scripts.push({ src: '', textContent });\n }\n } else if (!scriptSrcSet.has(clientSrc)) {\n scriptSrcSet.add(clientSrc);\n scripts.push({ src: clientSrc });\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: getClientSrc(attrs.href, serverUrl.href),\n };\n const linkKey = `${relativeAttrs.href}::${attrs.rel}`;\n if (!linkKeySet.has(linkKey)) {\n linkKeySet.add(linkKey);\n links.push(relativeAttrs);\n }\n },\n onRSC(chunk) {\n rawRscChunks.push(chunk);\n hasRSC = true;\n },\n onNextData(data) {\n nextData = data;\n },\n onHTML(chunk) {\n if (!htmlChunks.has(chunk)) {\n htmlChunks.add(chunk);\n }\n },\n onShared(_shared) {\n remoteShared = _shared;\n hasShared = true;\n },\n onError(message, stack) {\n error = new RemoteComponentsError(message);\n if (stack) {\n error.stack = stack;\n }\n },\n });\n\n hydrationData.push(...rawRscChunks);\n\n if (error) {\n throw error;\n }\n\n if (metadata) {\n if (!hasRSC && !nextData && metadata.type === 'nextjs') {\n throw new RemoteComponentsError(\n `The Remote Component at \"${serverUrl.href}\" seems to be a Next.js component but it does not contain any RSC flight data or Next.js props data. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n if (\n metadata.type === 'nextjs' &&\n !hasShared &&\n !nextData?.props.__REMOTE_COMPONENT__?.sharedManifest &&\n !nextData?.props.__REMOTE_COMPONENT__?.shared\n ) {\n throw new RemoteComponentsError(\n `No shared dependencies found for Remote Component at \"${serverUrl.href}\". Make sure the remote URL is correct and contains a Remote Component with shared dependencies.`,\n );\n }\n }\n\n const resolvedShared =\n nextData?.props.__REMOTE_COMPONENT__?.sharedManifest ??\n // @legacy(remote-components<=0.4.x): keep accepting the Pages Router\n // shared map until remotes on 0.4.x are outside the compatibility window.\n nextData?.props.__REMOTE_COMPONENT__?.shared ??\n remoteShared;\n\n return {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared: resolvedShared,\n html: Array.from(htmlChunks).join(''),\n };\n}\n\ninterface Options {\n name?: string;\n rsc?: boolean;\n /** Whether this is being called from Next.js App Router. Used to enable skeleton fallback during SSG builds. */\n appRouter?: boolean;\n onRequest?: OnRequestHook;\n onResponse?: OnResponseHook;\n}\n\nasync function fetchWithTags(\n src: string | URL,\n relativePathBaseUrl: string,\n options: Options,\n) {\n const serverUrl = new URL(src, relativePathBaseUrl);\n const tags = [\n '_vc_rc:fetch-remote-component',\n // the max size of a next cache tag is 256 characters\n serverUrl.host.slice(0, 256),\n // use the suffix so this tag is unique if multiple remote\n // components have the same host, but unique pathnames / query params\n (typeof src === 'string' ? src : src.href).slice(-256),\n ];\n if (options.name) {\n tags.push(options.name.slice(-256));\n }\n\n const fetchInit = { next: { tags } };\n\n const res = await fetchWithHooks(serverUrl, fetchInit, {\n onRequest: options.onRequest,\n onResponse: options.onResponse,\n });\n\n return {\n res,\n serverUrl,\n // If the remote component is part of a microfrontend, the src provided will be relative.\n isMfeRelativeSrc: serverUrl.host === new URL(relativePathBaseUrl).host,\n };\n}\n\nexport async function fetchRemoteComponent(\n src: string | URL,\n options: Options = {},\n): Promise<FetchRemoteComponentResponse> {\n let { res, isMfeRelativeSrc, serverUrl } = await fetchWithTags(\n src,\n getSSRRelativePathBaseUrl(),\n options,\n );\n\n const maybeFirstMfeProductionDeployment =\n isMfeRelativeSrc && serverUrl.host === PRODUCTION_URL;\n\n // When deploying a microfrontend with remote components to production for the first time, the fetch with the\n // production URL will fail if the production URL is not already an MFE alias. The URL becomes an MFE alias\n // on the first MFE deployment. For this fetch, use the deployment URL which is an MFE alias.\n if (\n res.status === 404 &&\n maybeFirstMfeProductionDeployment &&\n DEPLOYMENT_URL\n ) {\n ({ res, isMfeRelativeSrc, serverUrl } = await fetchWithTags(\n src,\n `https://${DEPLOYMENT_URL}`,\n options,\n ));\n }\n\n // If there is an error in the remote, parse and extract the remote error (except 404 and 401).\n if (!res.ok && !res.body) {\n throw failedToFetchRemoteComponentError(serverUrl.href, res);\n }\n\n if (res.status === 401) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'If you are using Deployment Protection, ensure the automation bypass environment variable secret in the host matches an automation bypass value in the remote. See https://remote-components-docs.vercel.sh/docs/concepts/cors-external-urls#deployment-protection for details.',\n );\n }\n\n if (res.status === 404) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n maybeFirstMfeProductionDeployment\n ? `If this is the first production build of a microfrontends setup, try redeploying once the remote is deployed to production. Once deployed, this error will not re-occur, and ISR revalidation will happen automatically for remote components once they deploy. https://remote-components-docs.vercel.sh/docs/concepts/isr-deployment`\n : `Check if you can open it in the browser.`,\n );\n }\n\n if (!res.body) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `Response body is empty. Check if you can open it in the browser and you see the Remote Component content.`,\n );\n }\n\n const parser = Parser.getFragmentParser<DefaultTreeAdapterMap>();\n const decoder = new TextDecoder();\n // read the response body as a stream and parse it using the parse5 fragment parser\n for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {\n parser.tokenizer.write(decoder.decode(chunk), false);\n }\n const fragment = parser.getFragment();\n\n const remoteName =\n options.name || (serverUrl.hash ? serverUrl.hash.substring(1) : undefined);\n\n const {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared,\n html,\n } = visitFragment(fragment, serverUrl, remoteName);\n\n if (!metadata) {\n // For microfrontend builds during run time, the host and remote build\n // may be happening concurrently. In this case, the request will 404.\n // We want to allow the build to continue with a placeholder remote\n // component. Once the build completes, vercel will automatically revalidate\n // ISR and fetch the built remote component.\n const isSSGBuild = process.env.NEXT_PHASE === 'phase-production-build';\n // Only want this skeleton behaviour in previews to unblock development.\n // For production, the remote component should already be built.\n const isPreview = process.env.VERCEL_TARGET_ENV === 'preview';\n // For app router previews, the host and remote build at the same time, to allow this, render a skeleton\n // in the host if the remote is not found, which will revalidate when the remote deploys, or give a helpful error in the UI\n if (isSSGBuild && isMfeRelativeSrc && isPreview && options.appRouter) {\n let skeletonComponent: React.ReactNode | undefined;\n if (options.rsc) {\n const { createElement } = await import('react');\n skeletonComponent = createElement('div', {\n dangerouslySetInnerHTML: {\n __html: getSkeletonHtml(serverUrl.href),\n },\n });\n }\n\n return buildSkeletonResponse(\n serverUrl,\n buildMetadata({}, serverUrl),\n skeletonComponent,\n );\n }\n\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `No Remote Component found. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n const name = remoteName || metadata.name;\n const component = options.rsc\n ? await buildRscComponent(rsc, serverUrl)\n : undefined;\n\n return {\n name,\n serverUrl,\n metadata,\n rsc,\n scripts,\n links,\n hydrationData,\n nextData,\n component,\n html,\n remoteShared,\n };\n}\n"],"mappings":"AAAA,SAAqC,cAAc;AACnD,SAAmB,aAAa;AAChC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUP;AAAA,EACE;AAAA,OAGK;AACP,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQP,eAAe,kBACb,KACA,WAC0B;AAC1B,QAAM,eAAe,KAAK,KAAK,UAAU,GAAG;AAAA;AAC5C,QAAM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W,UAAU;AAEjD,MAAI,CAAC,UAAU;AAMb,UAAM,aAAa,QAAQ,IAAI,eAAe;AAG9C,UAAM,YAAY,QAAQ,IAAI,sBAAsB;AAGpD,QAAI,cAAc,oBAAoB,aAAa,QAAQ,WAAW;AACpE,UAAI;AACJ,UAAI,QAAQ,KAAK;AACf,cAAM,EAAE,cAAc,IAAI,MAAM,OAAO,OAAO;AAC9C,4BAAoB,cAAc,OAAO;AAAA,UACvC,yBAAyB;AAAA,YACvB,QAAQ,gBAAgB,UAAU,IAAI;AAAA,UACxC;AAAA,QACF,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,QACL;AAAA,QACA,cAAc,CAAC,GAAG,SAAS;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AAEA,UAAM;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,OAAO,cAAc,SAAS;AACpC,QAAM,YAAY,QAAQ,MACtB,MAAM,kBAAkB,KAAK,SAAS,IACtC;AAEJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/server/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { type RSC, visit } from '#internal/host/nextjs/dom-flight';\nimport {\n getSkeletonHtml,\n getSkeletonMessage,\n} from '#internal/host/nextjs/skeleton';\nimport { fetchWithHooks } from '#internal/host/server/fetch-with-hooks';\nimport { getClientSrc } from '#internal/host/server/get-client-src';\nimport {\n DEPLOYMENT_URL,\n getSSRRelativePathBaseUrl,\n PRODUCTION_URL,\n} from '#internal/host/server/get-ssr-relative-path-base-url';\nimport type {\n LinkDescriptor,\n ScriptDescriptor,\n} from '#internal/host/shared/asset-descriptors';\nimport type {\n OnRequestHook,\n OnResponseHook,\n} from '#internal/host/shared/fetch-interceptors';\nimport {\n extractDeploymentIdFromSrc,\n isNextDeploymentAssetSrc,\n type NextImageDeploymentId,\n} from '#internal/host/shared/next-image-deployment-id';\nimport type { RemoteSharedModules } from '#internal/host/shared/shared-broker';\nimport {\n buildMetadata,\n type RawMetadataAttrs,\n type RemoteComponentMetadata,\n} from '#internal/runtime/metadata';\nimport { importRSCClientEdge } from '#internal/runtime/rsc-imports';\nimport {\n failedToFetchRemoteComponentError,\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport type { FetchRemoteComponentResponse, NextData } from './types';\n\nconst NEXT_IMAGE_PATHNAME = '/_next/image';\n/**\n * Converts RSC flight data into a React element tree using the edge streaming\n * runtime. The manifest tells React how to resolve module references back to\n * the remote origin.\n */\nasync function buildRscComponent(\n rsc: RSC | RSC[] | string | null,\n serverUrl: URL,\n): Promise<React.ReactNode> {\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n const { createFromReadableStream } = await importRSCClientEdge();\n return createFromReadableStream(\n new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n controller.enqueue(encoder.encode(componentRSC));\n controller.close();\n },\n }),\n {\n serverConsumerManifest: {\n moduleLoading: {\n prefix: serverUrl.origin,\n crossOrigin: true,\n },\n moduleMap: {},\n },\n },\n );\n}\n\nfunction buildSkeletonResponse(\n serverUrl: URL,\n metadata: RemoteComponentMetadata,\n skeletonComponent: React.ReactNode | undefined,\n): FetchRemoteComponentResponse {\n return {\n name: 'remote-component-skeleton',\n serverUrl,\n metadata: {\n ...metadata,\n type: 'remote-component',\n },\n rsc: getSkeletonMessage(),\n scripts: [],\n links: [],\n hydrationData: [],\n nextData: undefined,\n component: skeletonComponent,\n html: getSkeletonHtml(serverUrl.href),\n remoteShared: {},\n ssrImageDeploymentIds: [],\n };\n}\n\nfunction getNextImageDeploymentId(\n value: string,\n base: URL,\n): NextImageDeploymentId | undefined {\n try {\n const parsed = new URL(value.replace(/&/g, '&'), base);\n const imageSrc = parsed.searchParams.get('url');\n if (\n !parsed.pathname.endsWith(NEXT_IMAGE_PATHNAME) ||\n !isNextDeploymentAssetSrc(imageSrc)\n ) {\n return undefined;\n }\n\n const extracted = extractDeploymentIdFromSrc(imageSrc);\n const deploymentId =\n parsed.searchParams.get('dpl') || extracted.deploymentId;\n\n return deploymentId ? { src: extracted.src, deploymentId } : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction addNextImageDeploymentId(\n value: string | undefined,\n serverUrl: URL,\n result: Map<string, string>,\n) {\n if (!value) {\n return;\n }\n\n const image = getNextImageDeploymentId(value, serverUrl);\n if (image) {\n result.set(image.src, image.deploymentId);\n }\n}\n\nfunction addNextImageDeploymentIdsFromSrcset(\n value: string | undefined,\n serverUrl: URL,\n result: Map<string, string>,\n) {\n if (!value) return;\n for (const candidate of value.split(',')) {\n addNextImageDeploymentId(\n candidate.trim().split(/\\s+/)[0],\n serverUrl,\n result,\n );\n }\n}\n\n/**\n * Walks the parsed HTML fragment and extracts all remote component data:\n * metadata, scripts, links, hydration data, Next.js data, shared deps, and HTML.\n */\nfunction visitFragment(\n fragment: DefaultTreeAdapterMap['documentFragment'],\n serverUrl: URL,\n remoteName: string | undefined,\n) {\n const scriptSrcSet = new Set<string>();\n const scriptTextSet = new Set<string>();\n const scripts: ScriptDescriptor[] = [];\n\n const linkKeySet = new Set<string>();\n const links: LinkDescriptor[] = [];\n\n const hydrationData: string[] = [];\n const htmlChunks = new Set<string>();\n const ssrImageDeploymentIdMap = new Map<string, string>();\n\n let metadata: RemoteComponentMetadata | undefined;\n let nextData: NextData | undefined;\n let remoteShared: RemoteSharedModules = {};\n let hasRSC = false;\n let hasShared = false;\n let error: RemoteComponentsError | undefined;\n\n const rawRscChunks: string[] = [];\n\n const rsc = visit(fragment, {\n url: serverUrl,\n name: remoteName,\n onMetadata(attrs: RawMetadataAttrs) {\n const incoming = buildMetadata(attrs, serverUrl);\n // Skip multiple component detection for Pages Router (__next) since\n // it only supports one remote component per page\n if (\n !remoteName &&\n metadata &&\n metadata.id !== incoming.id &&\n incoming.id !== '__next' &&\n metadata.id !== '__next' &&\n !nextData\n ) {\n throw multipleRemoteComponentsError(serverUrl.href);\n }\n metadata = incoming;\n },\n onScript(attrs) {\n const clientSrc = getClientSrc(attrs.src, serverUrl.href);\n const textContent =\n typeof attrs.textContent === 'string' ? attrs.textContent : undefined;\n\n if (textContent) {\n if (!scriptTextSet.has(textContent)) {\n scriptTextSet.add(textContent);\n scripts.push({ src: '', textContent });\n }\n } else if (!scriptSrcSet.has(clientSrc)) {\n scriptSrcSet.add(clientSrc);\n scripts.push({ src: clientSrc });\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: getClientSrc(attrs.href, serverUrl.href),\n };\n const linkKey = `${relativeAttrs.href}::${attrs.rel}`;\n if (!linkKeySet.has(linkKey)) {\n linkKeySet.add(linkKey);\n links.push(relativeAttrs);\n }\n },\n onRSC(chunk) {\n rawRscChunks.push(chunk);\n hasRSC = true;\n },\n onNextData(data) {\n nextData = data;\n },\n onHTML(chunk) {\n if (!htmlChunks.has(chunk)) {\n htmlChunks.add(chunk);\n }\n },\n onShared(_shared) {\n remoteShared = _shared;\n hasShared = true;\n },\n onError(message, stack) {\n error = new RemoteComponentsError(message);\n if (stack) {\n error.stack = stack;\n }\n },\n onElement(nodeName, attrs) {\n if (nodeName !== 'img') {\n return;\n }\n\n addNextImageDeploymentId(attrs.src, serverUrl, ssrImageDeploymentIdMap);\n addNextImageDeploymentIdsFromSrcset(\n attrs.srcset,\n serverUrl,\n ssrImageDeploymentIdMap,\n );\n },\n });\n\n hydrationData.push(...rawRscChunks);\n\n if (error) {\n throw error;\n }\n\n if (metadata) {\n if (!hasRSC && !nextData && metadata.type === 'nextjs') {\n throw new RemoteComponentsError(\n `The Remote Component at \"${serverUrl.href}\" seems to be a Next.js component but it does not contain any RSC flight data or Next.js props data. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n if (\n metadata.type === 'nextjs' &&\n !hasShared &&\n !nextData?.props.__REMOTE_COMPONENT__?.sharedManifest &&\n !nextData?.props.__REMOTE_COMPONENT__?.shared\n ) {\n throw new RemoteComponentsError(\n `No shared dependencies found for Remote Component at \"${serverUrl.href}\". Make sure the remote URL is correct and contains a Remote Component with shared dependencies.`,\n );\n }\n }\n\n const resolvedShared =\n nextData?.props.__REMOTE_COMPONENT__?.sharedManifest ??\n // @legacy(remote-components<=0.4.x): keep accepting the Pages Router\n // shared map until remotes on 0.4.x are outside the compatibility window.\n nextData?.props.__REMOTE_COMPONENT__?.shared ??\n remoteShared;\n\n return {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared: resolvedShared,\n ssrImageDeploymentIds: Array.from(\n ssrImageDeploymentIdMap,\n ([src, deploymentId]) => ({ src, deploymentId }),\n ),\n html: Array.from(htmlChunks).join(''),\n };\n}\n\ninterface Options {\n name?: string;\n rsc?: boolean;\n /** Whether this is being called from Next.js App Router. Used to enable skeleton fallback during SSG builds. */\n appRouter?: boolean;\n onRequest?: OnRequestHook;\n onResponse?: OnResponseHook;\n}\n\nasync function fetchWithTags(\n src: string | URL,\n relativePathBaseUrl: string,\n options: Options,\n) {\n const serverUrl = new URL(src, relativePathBaseUrl);\n const tags = [\n '_vc_rc:fetch-remote-component',\n // the max size of a next cache tag is 256 characters\n serverUrl.host.slice(0, 256),\n // use the suffix so this tag is unique if multiple remote\n // components have the same host, but unique pathnames / query params\n (typeof src === 'string' ? src : src.href).slice(-256),\n ];\n if (options.name) {\n tags.push(options.name.slice(-256));\n }\n\n const fetchInit = { next: { tags } };\n\n const res = await fetchWithHooks(serverUrl, fetchInit, {\n onRequest: options.onRequest,\n onResponse: options.onResponse,\n });\n\n return {\n res,\n serverUrl,\n // If the remote component is part of a microfrontend, the src provided will be relative.\n isMfeRelativeSrc: serverUrl.host === new URL(relativePathBaseUrl).host,\n };\n}\n\nexport async function fetchRemoteComponent(\n src: string | URL,\n options: Options = {},\n): Promise<FetchRemoteComponentResponse> {\n let { res, isMfeRelativeSrc, serverUrl } = await fetchWithTags(\n src,\n getSSRRelativePathBaseUrl(),\n options,\n );\n\n const maybeFirstMfeProductionDeployment =\n isMfeRelativeSrc && serverUrl.host === PRODUCTION_URL;\n\n // When deploying a microfrontend with remote components to production for the first time, the fetch with the\n // production URL will fail if the production URL is not already an MFE alias. The URL becomes an MFE alias\n // on the first MFE deployment. For this fetch, use the deployment URL which is an MFE alias.\n if (\n res.status === 404 &&\n maybeFirstMfeProductionDeployment &&\n DEPLOYMENT_URL\n ) {\n ({ res, isMfeRelativeSrc, serverUrl } = await fetchWithTags(\n src,\n `https://${DEPLOYMENT_URL}`,\n options,\n ));\n }\n\n // If there is an error in the remote, parse and extract the remote error (except 404 and 401).\n if (!res.ok && !res.body) {\n throw failedToFetchRemoteComponentError(serverUrl.href, res);\n }\n\n if (res.status === 401) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'If you are using Deployment Protection, ensure the automation bypass environment variable secret in the host matches an automation bypass value in the remote. See https://remote-components-docs.vercel.sh/docs/concepts/cors-external-urls#deployment-protection for details.',\n );\n }\n\n if (res.status === 404) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n maybeFirstMfeProductionDeployment\n ? `If this is the first production build of a microfrontends setup, try redeploying once the remote is deployed to production. Once deployed, this error will not re-occur, and ISR revalidation will happen automatically for remote components once they deploy. https://remote-components-docs.vercel.sh/docs/concepts/isr-deployment`\n : `Check if you can open it in the browser.`,\n );\n }\n\n if (!res.body) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `Response body is empty. Check if you can open it in the browser and you see the Remote Component content.`,\n );\n }\n\n const parser = Parser.getFragmentParser<DefaultTreeAdapterMap>();\n const decoder = new TextDecoder();\n // read the response body as a stream and parse it using the parse5 fragment parser\n for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {\n parser.tokenizer.write(decoder.decode(chunk), false);\n }\n const fragment = parser.getFragment();\n\n const remoteName =\n options.name || (serverUrl.hash ? serverUrl.hash.substring(1) : undefined);\n\n const {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared,\n html,\n ssrImageDeploymentIds,\n } = visitFragment(fragment, serverUrl, remoteName);\n\n if (!metadata) {\n // For microfrontend builds during run time, the host and remote build\n // may be happening concurrently. In this case, the request will 404.\n // We want to allow the build to continue with a placeholder remote\n // component. Once the build completes, vercel will automatically revalidate\n // ISR and fetch the built remote component.\n const isSSGBuild = process.env.NEXT_PHASE === 'phase-production-build';\n // Only want this skeleton behaviour in previews to unblock development.\n // For production, the remote component should already be built.\n const isPreview = process.env.VERCEL_TARGET_ENV === 'preview';\n // For app router previews, the host and remote build at the same time, to allow this, render a skeleton\n // in the host if the remote is not found, which will revalidate when the remote deploys, or give a helpful error in the UI\n if (isSSGBuild && isMfeRelativeSrc && isPreview && options.appRouter) {\n let skeletonComponent: React.ReactNode | undefined;\n if (options.rsc) {\n const { createElement } = await import('react');\n skeletonComponent = createElement('div', {\n dangerouslySetInnerHTML: {\n __html: getSkeletonHtml(serverUrl.href),\n },\n });\n }\n\n return buildSkeletonResponse(\n serverUrl,\n buildMetadata({}, serverUrl),\n skeletonComponent,\n );\n }\n\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `No Remote Component found. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n const name = remoteName || metadata.name;\n const component = options.rsc\n ? await buildRscComponent(rsc, serverUrl)\n : undefined;\n\n return {\n name,\n serverUrl,\n metadata,\n rsc,\n scripts,\n links,\n hydrationData,\n nextData,\n component,\n html,\n remoteShared,\n ssrImageDeploymentIds,\n };\n}\n"],"mappings":"AAAA,SAAqC,cAAc;AACnD,SAAmB,aAAa;AAChC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;A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AAO,YAAY;AAEpC,QAAM,aACJ,QAAQ,SAAS,UAAU,OAAO,UAAU,KAAK,UAAU,CAAC,IAAI;AAElE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,cAAc,UAAU,WAAW,UAAU;AAEjD,MAAI,CAAC,UAAU;AAMb,UAAM,aAAa,QAAQ,IAAI,eAAe;AAG9C,UAAM,YAAY,QAAQ,IAAI,sBAAsB;AAGpD,QAAI,cAAc,oBAAoB,aAAa,QAAQ,WAAW;AACpE,UAAI;AACJ,UAAI,QAAQ,KAAK;AACf,cAAM,EAAE,cAAc,IAAI,MAAM,OAAO,OAAO;AAC9C,4BAAoB,cAAc,OAAO;AAAA,UACvC,yBAAyB;AAAA,YACvB,QAAQ,gBAAgB,UAAU,IAAI;AAAA,UACxC;AAAA,QACF,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,QACL;AAAA,QACA,cAAc,CAAC,GAAG,SAAS;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AAEA,UAAM;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,OAAO,cAAc,SAAS;AACpC,QAAM,YAAY,QAAQ,MACtB,MAAM,kBAAkB,KAAK,SAAS,IACtC;AAEJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/server/types.ts"],"sourcesContent":["import type {\n LinkDescriptor,\n ScriptDescriptor,\n} from '#internal/host/shared/asset-descriptors';\nimport type {\n RemoteSharedModules,\n SharedModuleManifest,\n} from '#internal/host/shared/shared-broker';\nimport type { RemoteComponentMetadata } from '#internal/runtime/metadata';\n\nexport type {\n InternalResolveClientUrl,\n ResolveClientUrl,\n} from '#internal/runtime/url/resolve-client-url';\n\nexport interface NextData {\n props: {\n pageProps: Record<string, unknown>;\n __REMOTE_COMPONENT__?: {\n bundle: string;\n runtime: string;\n shared?: Record<string, string>;\n sharedManifest?: SharedModuleManifest;\n };\n };\n page?: string;\n buildId?: string;\n}\n\nexport interface FetchRemoteComponentResponse {\n name: string;\n serverUrl: URL;\n metadata: RemoteComponentMetadata;\n rsc:\n | import('#internal/host/nextjs/dom-flight').RSC\n | import('#internal/host/nextjs/dom-flight').RSC[]\n | string\n | null;\n scripts: ScriptDescriptor[];\n links: LinkDescriptor[];\n hydrationData: string[];\n nextData: NextData | undefined;\n component: React.ReactNode | undefined;\n html: string;\n remoteShared: RemoteSharedModules;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/server/types.ts"],"sourcesContent":["import type {\n LinkDescriptor,\n ScriptDescriptor,\n} from '#internal/host/shared/asset-descriptors';\nimport type { NextImageDeploymentId } from '#internal/host/shared/next-image-deployment-id';\nimport type {\n RemoteSharedModules,\n SharedModuleManifest,\n} from '#internal/host/shared/shared-broker';\nimport type { RemoteComponentMetadata } from '#internal/runtime/metadata';\n\nexport type {\n InternalResolveClientUrl,\n ResolveClientUrl,\n} from '#internal/runtime/url/resolve-client-url';\n\nexport interface NextData {\n props: {\n pageProps: Record<string, unknown>;\n __REMOTE_COMPONENT__?: {\n bundle: string;\n runtime: string;\n shared?: Record<string, string>;\n sharedManifest?: SharedModuleManifest;\n };\n };\n page?: string;\n buildId?: string;\n}\n\nexport interface FetchRemoteComponentResponse {\n name: string;\n serverUrl: URL;\n metadata: RemoteComponentMetadata;\n rsc:\n | import('#internal/host/nextjs/dom-flight').RSC\n | import('#internal/host/nextjs/dom-flight').RSC[]\n | string\n | null;\n scripts: ScriptDescriptor[];\n links: LinkDescriptor[];\n hydrationData: string[];\n nextData: NextData | undefined;\n component: React.ReactNode | undefined;\n html: string;\n remoteShared: RemoteSharedModules;\n ssrImageDeploymentIds: NextImageDeploymentId[];\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RSC } from '../nextjs/dom-flight.js';
|
|
2
2
|
import { ScriptDescriptor, LinkDescriptor } from '../shared/asset-descriptors.js';
|
|
3
|
+
import { NextImageDeploymentId } from '../shared/next-image-deployment-id.js';
|
|
3
4
|
import { SharedModuleManifest, RemoteSharedModules } from '../shared/shared-broker.js';
|
|
4
5
|
import { RemoteComponentMetadata } from '../../runtime/metadata.js';
|
|
5
6
|
export { InternalResolveClientUrl, ResolveClientUrl } from '../../runtime/url/resolve-client-url.js';
|
|
@@ -31,6 +32,7 @@ interface FetchRemoteComponentResponse {
|
|
|
31
32
|
component: React.ReactNode | undefined;
|
|
32
33
|
html: string;
|
|
33
34
|
remoteShared: RemoteSharedModules;
|
|
35
|
+
ssrImageDeploymentIds: NextImageDeploymentId[];
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
export { FetchRemoteComponentResponse, NextData };
|
|
@@ -0,0 +1,50 @@
|
|
|
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 next_image_deployment_id_exports = {};
|
|
20
|
+
__export(next_image_deployment_id_exports, {
|
|
21
|
+
extractDeploymentIdFromSrc: () => extractDeploymentIdFromSrc,
|
|
22
|
+
isNextDeploymentAssetSrc: () => isNextDeploymentAssetSrc
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(next_image_deployment_id_exports);
|
|
25
|
+
function isNextDeploymentAssetSrc(src) {
|
|
26
|
+
return typeof src === "string" && src.startsWith("/") && !src.startsWith("//");
|
|
27
|
+
}
|
|
28
|
+
function extractDeploymentIdFromSrc(src) {
|
|
29
|
+
const queryIndex = src.indexOf("?");
|
|
30
|
+
if (queryIndex === -1) {
|
|
31
|
+
return { deploymentId: void 0, src };
|
|
32
|
+
}
|
|
33
|
+
const params = new URLSearchParams(src.slice(queryIndex + 1));
|
|
34
|
+
const deploymentId = params.get("dpl") || void 0;
|
|
35
|
+
if (!deploymentId) {
|
|
36
|
+
return { deploymentId: void 0, src };
|
|
37
|
+
}
|
|
38
|
+
params.delete("dpl");
|
|
39
|
+
const remaining = params.toString();
|
|
40
|
+
return {
|
|
41
|
+
deploymentId,
|
|
42
|
+
src: `${src.slice(0, queryIndex)}${remaining ? `?${remaining}` : ""}`
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
extractDeploymentIdFromSrc,
|
|
48
|
+
isNextDeploymentAssetSrc
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=next-image-deployment-id.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/next-image-deployment-id.ts"],"sourcesContent":["export interface NextImageDeploymentId {\n src: string;\n deploymentId: string;\n}\n\nexport function isNextDeploymentAssetSrc(src: string | null): src is string {\n return (\n typeof src === 'string' && src.startsWith('/') && !src.startsWith('//')\n );\n}\n\nexport function extractDeploymentIdFromSrc(src: string) {\n const queryIndex = src.indexOf('?');\n if (queryIndex === -1) {\n return { deploymentId: undefined, src };\n }\n\n const params = new URLSearchParams(src.slice(queryIndex + 1));\n const deploymentId = params.get('dpl') || undefined;\n if (!deploymentId) {\n return { deploymentId: undefined, src };\n }\n\n params.delete('dpl');\n const remaining = params.toString();\n return {\n deploymentId,\n src: `${src.slice(0, queryIndex)}${remaining ? `?${remaining}` : ''}`,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,SAAS,yBAAyB,KAAmC;AAC1E,SACE,OAAO,QAAQ,YAAY,IAAI,WAAW,GAAG,KAAK,CAAC,IAAI,WAAW,IAAI;AAE1E;AAEO,SAAS,2BAA2B,KAAa;AACtD,QAAM,aAAa,IAAI,QAAQ,GAAG;AAClC,MAAI,eAAe,IAAI;AACrB,WAAO,EAAE,cAAc,QAAW,IAAI;AAAA,EACxC;AAEA,QAAM,SAAS,IAAI,gBAAgB,IAAI,MAAM,aAAa,CAAC,CAAC;AAC5D,QAAM,eAAe,OAAO,IAAI,KAAK,KAAK;AAC1C,MAAI,CAAC,cAAc;AACjB,WAAO,EAAE,cAAc,QAAW,IAAI;AAAA,EACxC;AAEA,SAAO,OAAO,KAAK;AACnB,QAAM,YAAY,OAAO,SAAS;AAClC,SAAO;AAAA,IACL;AAAA,IACA,KAAK,GAAG,IAAI,MAAM,GAAG,UAAU,IAAI,YAAY,IAAI,cAAc;AAAA,EACnE;AACF;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface NextImageDeploymentId {
|
|
2
|
+
src: string;
|
|
3
|
+
deploymentId: string;
|
|
4
|
+
}
|
|
5
|
+
declare function isNextDeploymentAssetSrc(src: string | null): src is string;
|
|
6
|
+
declare function extractDeploymentIdFromSrc(src: string): {
|
|
7
|
+
deploymentId: undefined;
|
|
8
|
+
src: string;
|
|
9
|
+
} | {
|
|
10
|
+
deploymentId: string;
|
|
11
|
+
src: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { NextImageDeploymentId, extractDeploymentIdFromSrc, isNextDeploymentAssetSrc };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function isNextDeploymentAssetSrc(src) {
|
|
2
|
+
return typeof src === "string" && src.startsWith("/") && !src.startsWith("//");
|
|
3
|
+
}
|
|
4
|
+
function extractDeploymentIdFromSrc(src) {
|
|
5
|
+
const queryIndex = src.indexOf("?");
|
|
6
|
+
if (queryIndex === -1) {
|
|
7
|
+
return { deploymentId: void 0, src };
|
|
8
|
+
}
|
|
9
|
+
const params = new URLSearchParams(src.slice(queryIndex + 1));
|
|
10
|
+
const deploymentId = params.get("dpl") || void 0;
|
|
11
|
+
if (!deploymentId) {
|
|
12
|
+
return { deploymentId: void 0, src };
|
|
13
|
+
}
|
|
14
|
+
params.delete("dpl");
|
|
15
|
+
const remaining = params.toString();
|
|
16
|
+
return {
|
|
17
|
+
deploymentId,
|
|
18
|
+
src: `${src.slice(0, queryIndex)}${remaining ? `?${remaining}` : ""}`
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
extractDeploymentIdFromSrc,
|
|
23
|
+
isNextDeploymentAssetSrc
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=next-image-deployment-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/next-image-deployment-id.ts"],"sourcesContent":["export interface NextImageDeploymentId {\n src: string;\n deploymentId: string;\n}\n\nexport function isNextDeploymentAssetSrc(src: string | null): src is string {\n return (\n typeof src === 'string' && src.startsWith('/') && !src.startsWith('//')\n );\n}\n\nexport function extractDeploymentIdFromSrc(src: string) {\n const queryIndex = src.indexOf('?');\n if (queryIndex === -1) {\n return { deploymentId: undefined, src };\n }\n\n const params = new URLSearchParams(src.slice(queryIndex + 1));\n const deploymentId = params.get('dpl') || undefined;\n if (!deploymentId) {\n return { deploymentId: undefined, src };\n }\n\n params.delete('dpl');\n const remaining = params.toString();\n return {\n deploymentId,\n src: `${src.slice(0, queryIndex)}${remaining ? `?${remaining}` : ''}`,\n };\n}\n"],"mappings":"AAKO,SAAS,yBAAyB,KAAmC;AAC1E,SACE,OAAO,QAAQ,YAAY,IAAI,WAAW,GAAG,KAAK,CAAC,IAAI,WAAW,IAAI;AAE1E;AAEO,SAAS,2BAA2B,KAAa;AACtD,QAAM,aAAa,IAAI,QAAQ,GAAG;AAClC,MAAI,eAAe,IAAI;AACrB,WAAO,EAAE,cAAc,QAAW,IAAI;AAAA,EACxC;AAEA,QAAM,SAAS,IAAI,gBAAgB,IAAI,MAAM,aAAa,CAAC,CAAC;AAC5D,QAAM,eAAe,OAAO,IAAI,KAAK,KAAK;AAC1C,MAAI,CAAC,cAAc;AACjB,WAAO,EAAE,cAAc,QAAW,IAAI;AAAA,EACxC;AAEA,SAAO,OAAO,KAAK;AACnB,QAAM,YAAY,OAAO,SAAS;AAClC,SAAO;AAAA,IACL;AAAA,IACA,KAAK,GAAG,IAAI,MAAM,GAAG,UAAU,IAAI,YAAY,IAAI,cAAc;AAAA,EACnE;AACF;","names":[]}
|
|
@@ -2,13 +2,14 @@ import { RemoteSharedModules } from './shared-broker.js';
|
|
|
2
2
|
import { RemoteComponentMetadata } from '../../runtime/metadata.js';
|
|
3
3
|
import { ScriptDescriptor } from './asset-descriptors.js';
|
|
4
4
|
import { InternalResolveClientUrl } from '../../runtime/url/resolve-client-url.js';
|
|
5
|
-
import { a as ConsumeLoaderPayload } from '../../../server-handoff-
|
|
5
|
+
import { a as ConsumeLoaderPayload } from '../../../server-handoff-006f9cb5.js';
|
|
6
6
|
import { ParsedRemoteComponent } from '../../runtime/html/parse-remote-html.js';
|
|
7
7
|
import { M as MountOrUnmountFunction } from '../../../types-bd7be268.js';
|
|
8
8
|
import '../../utils/logger.js';
|
|
9
9
|
import 'react';
|
|
10
10
|
import './config.js';
|
|
11
11
|
import './fetch-interceptors.js';
|
|
12
|
+
import './next-image-deployment-id.js';
|
|
12
13
|
import '../server/types.js';
|
|
13
14
|
import '../nextjs/dom-flight.js';
|
|
14
15
|
import 'parse5/dist/tree-adapters/default';
|
|
@@ -21,28 +21,15 @@ __export(remote_image_loader_exports, {
|
|
|
21
21
|
createRemoteImageLoader: () => createRemoteImageLoader
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(remote_image_loader_exports);
|
|
24
|
+
var import_next_image_deployment_id = require("#internal/host/shared/next-image-deployment-id");
|
|
24
25
|
var import_remote_scope = require("#internal/runtime/turbopack/remote-scope");
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
const params = new URLSearchParams(src.slice(queryIndex + 1));
|
|
34
|
-
const deploymentId = params.get("dpl") || void 0;
|
|
35
|
-
if (!deploymentId) {
|
|
36
|
-
return { deploymentId: void 0, src };
|
|
37
|
-
}
|
|
38
|
-
params.delete("dpl");
|
|
39
|
-
const remaining = params.toString();
|
|
40
|
-
return {
|
|
41
|
-
deploymentId,
|
|
42
|
-
src: `${src.slice(0, queryIndex)}${remaining ? `?${remaining}` : ""}`
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
26
|
+
function createRemoteImageLoader(bundle, resolveClientUrl, ssrImageDeploymentIds) {
|
|
27
|
+
const ssrImageDeploymentIdMap = ssrImageDeploymentIds ? new Map(
|
|
28
|
+
ssrImageDeploymentIds.map(({ src, deploymentId }) => [
|
|
29
|
+
src,
|
|
30
|
+
deploymentId
|
|
31
|
+
])
|
|
32
|
+
) : void 0;
|
|
46
33
|
const loader = Object.assign(
|
|
47
34
|
({
|
|
48
35
|
config,
|
|
@@ -54,8 +41,13 @@ function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
|
54
41
|
const remoteOrigin = (0, import_remote_scope.getScope)(bundle)?.url.origin ?? "";
|
|
55
42
|
const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;
|
|
56
43
|
const basePath = isCrossOrigin ? `${remoteOrigin}${config.path ?? "/_next/image"}` : config.path ?? `${remoteOrigin}/_next/image`;
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
if (!(0, import_next_image_deployment_id.isNextDeploymentAssetSrc)(src)) {
|
|
45
|
+
const url2 = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;
|
|
46
|
+
return resolveClientUrl?.(url2) ?? url2;
|
|
47
|
+
}
|
|
48
|
+
const extracted = (0, import_next_image_deployment_id.extractDeploymentIdFromSrc)(src);
|
|
49
|
+
const deploymentId = extracted.deploymentId ?? ssrImageDeploymentIdMap?.get(extracted.src);
|
|
50
|
+
const deploymentParam = deploymentId ? `&dpl=${encodeURIComponent(deploymentId)}` : "";
|
|
59
51
|
const url = `${basePath}?url=${encodeURIComponent(extracted.src)}&w=${width}&q=${q}${deploymentParam}`;
|
|
60
52
|
return resolveClientUrl?.(url) ?? url;
|
|
61
53
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/shared/remote-image-loader.ts"],"sourcesContent":["import { getScope } from '#internal/runtime/turbopack/remote-scope';\nimport type { InternalResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\n\
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/remote-image-loader.ts"],"sourcesContent":["import {\n extractDeploymentIdFromSrc,\n isNextDeploymentAssetSrc,\n type NextImageDeploymentId,\n} from '#internal/host/shared/next-image-deployment-id';\nimport { getScope } from '#internal/runtime/turbopack/remote-scope';\nimport type { InternalResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\n\n/**\n * Replacement for `next/dist/shared/lib/image-loader`.\n *\n * Uses `config.path` (which includes the remote's asset prefix, e.g.\n * `/vc-ap-xxx/_next/image`) to generate URLs that match the server-rendered\n * HTML and avoid hydration mismatches. Under the microfrontends proxy these\n * relative paths are routed to the correct app.\n *\n * For cross-origin deployments (standalone host on a different domain),\n * `config.path` is a relative path that would incorrectly resolve to the host\n * origin, so we prefix it with the remote origin to produce an absolute URL\n * pointing at the remote's optimizer.\n *\n * When `resolveClientUrl` is provided (deployment protection), the final URL\n * is routed through the host's proxy.\n */\nexport function createRemoteImageLoader(\n bundle: string,\n resolveClientUrl?: InternalResolveClientUrl,\n ssrImageDeploymentIds?: readonly NextImageDeploymentId[],\n) {\n const ssrImageDeploymentIdMap = ssrImageDeploymentIds\n ? new Map(\n ssrImageDeploymentIds.map(({ src, deploymentId }) => [\n src,\n deploymentId,\n ]),\n )\n : undefined;\n const loader = Object.assign(\n ({\n config,\n src,\n width,\n quality,\n }: {\n config: { path?: string };\n src: string;\n width: number;\n quality?: number;\n }) => {\n const q = quality ?? 75;\n const remoteOrigin = getScope(bundle)?.url.origin ?? '';\n const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;\n const basePath = isCrossOrigin\n ? `${remoteOrigin}${config.path ?? '/_next/image'}`\n : (config.path ?? `${remoteOrigin}/_next/image`);\n\n if (!isNextDeploymentAssetSrc(src)) {\n const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;\n return resolveClientUrl?.(url) ?? url;\n }\n\n const extracted = extractDeploymentIdFromSrc(src);\n const deploymentId =\n extracted.deploymentId ?? ssrImageDeploymentIdMap?.get(extracted.src);\n const deploymentParam = deploymentId\n ? `&dpl=${encodeURIComponent(deploymentId)}`\n : '';\n const url = `${basePath}?url=${encodeURIComponent(extracted.src)}&w=${width}&q=${q}${deploymentParam}`;\n return resolveClientUrl?.(url) ?? url;\n },\n // Signals to getImgProps that this is a default loader (not a user-defined\n // one), enabling srcSet generation with device/image sizes from the config.\n { __next_img_default: true as const },\n );\n return loader;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAIO;AACP,0BAAyB;AAmBlB,SAAS,wBACd,QACA,kBACA,uBACA;AACA,QAAM,0BAA0B,wBAC5B,IAAI;AAAA,IACF,sBAAsB,IAAI,CAAC,EAAE,KAAK,aAAa,MAAM;AAAA,MACnD;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,IACA;AACJ,QAAM,SAAS,OAAO;AAAA,IACpB,CAAC;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,MAKM;AACJ,YAAM,IAAI,WAAW;AACrB,YAAM,mBAAe,8BAAS,MAAM,GAAG,IAAI,UAAU;AACrD,YAAM,gBAAgB,gBAAgB,iBAAiB,SAAS;AAChE,YAAM,WAAW,gBACb,GAAG,eAAe,OAAO,QAAQ,mBAChC,OAAO,QAAQ,GAAG;AAEvB,UAAI,KAAC,0DAAyB,GAAG,GAAG;AAClC,cAAMA,OAAM,GAAG,gBAAgB,mBAAmB,GAAG,OAAO,WAAW;AACvE,eAAO,mBAAmBA,IAAG,KAAKA;AAAA,MACpC;AAEA,YAAM,gBAAY,4DAA2B,GAAG;AAChD,YAAM,eACJ,UAAU,gBAAgB,yBAAyB,IAAI,UAAU,GAAG;AACtE,YAAM,kBAAkB,eACpB,QAAQ,mBAAmB,YAAY,MACvC;AACJ,YAAM,MAAM,GAAG,gBAAgB,mBAAmB,UAAU,GAAG,OAAO,WAAW,IAAI;AACrF,aAAO,mBAAmB,GAAG,KAAK;AAAA,IACpC;AAAA;AAAA;AAAA,IAGA,EAAE,oBAAoB,KAAc;AAAA,EACtC;AACA,SAAO;AACT;","names":["url"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NextImageDeploymentId } from './next-image-deployment-id.js';
|
|
1
2
|
import { InternalResolveClientUrl } from '../../runtime/url/resolve-client-url.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -16,7 +17,7 @@ import { InternalResolveClientUrl } from '../../runtime/url/resolve-client-url.j
|
|
|
16
17
|
* When `resolveClientUrl` is provided (deployment protection), the final URL
|
|
17
18
|
* is routed through the host's proxy.
|
|
18
19
|
*/
|
|
19
|
-
declare function createRemoteImageLoader(bundle: string, resolveClientUrl?: InternalResolveClientUrl): (({ config, src, width, quality, }: {
|
|
20
|
+
declare function createRemoteImageLoader(bundle: string, resolveClientUrl?: InternalResolveClientUrl, ssrImageDeploymentIds?: readonly NextImageDeploymentId[]): (({ config, src, width, quality, }: {
|
|
20
21
|
config: {
|
|
21
22
|
path?: string;
|
|
22
23
|
};
|
|
@@ -1,25 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
extractDeploymentIdFromSrc,
|
|
3
|
+
isNextDeploymentAssetSrc
|
|
4
|
+
} from "#internal/host/shared/next-image-deployment-id";
|
|
1
5
|
import { getScope } from "#internal/runtime/turbopack/remote-scope";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
const params = new URLSearchParams(src.slice(queryIndex + 1));
|
|
11
|
-
const deploymentId = params.get("dpl") || void 0;
|
|
12
|
-
if (!deploymentId) {
|
|
13
|
-
return { deploymentId: void 0, src };
|
|
14
|
-
}
|
|
15
|
-
params.delete("dpl");
|
|
16
|
-
const remaining = params.toString();
|
|
17
|
-
return {
|
|
18
|
-
deploymentId,
|
|
19
|
-
src: `${src.slice(0, queryIndex)}${remaining ? `?${remaining}` : ""}`
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
6
|
+
function createRemoteImageLoader(bundle, resolveClientUrl, ssrImageDeploymentIds) {
|
|
7
|
+
const ssrImageDeploymentIdMap = ssrImageDeploymentIds ? new Map(
|
|
8
|
+
ssrImageDeploymentIds.map(({ src, deploymentId }) => [
|
|
9
|
+
src,
|
|
10
|
+
deploymentId
|
|
11
|
+
])
|
|
12
|
+
) : void 0;
|
|
23
13
|
const loader = Object.assign(
|
|
24
14
|
({
|
|
25
15
|
config,
|
|
@@ -31,8 +21,13 @@ function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
|
31
21
|
const remoteOrigin = getScope(bundle)?.url.origin ?? "";
|
|
32
22
|
const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;
|
|
33
23
|
const basePath = isCrossOrigin ? `${remoteOrigin}${config.path ?? "/_next/image"}` : config.path ?? `${remoteOrigin}/_next/image`;
|
|
24
|
+
if (!isNextDeploymentAssetSrc(src)) {
|
|
25
|
+
const url2 = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;
|
|
26
|
+
return resolveClientUrl?.(url2) ?? url2;
|
|
27
|
+
}
|
|
34
28
|
const extracted = extractDeploymentIdFromSrc(src);
|
|
35
|
-
const
|
|
29
|
+
const deploymentId = extracted.deploymentId ?? ssrImageDeploymentIdMap?.get(extracted.src);
|
|
30
|
+
const deploymentParam = deploymentId ? `&dpl=${encodeURIComponent(deploymentId)}` : "";
|
|
36
31
|
const url = `${basePath}?url=${encodeURIComponent(extracted.src)}&w=${width}&q=${q}${deploymentParam}`;
|
|
37
32
|
return resolveClientUrl?.(url) ?? url;
|
|
38
33
|
},
|