remote-components 0.0.46 → 0.0.47

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.
Files changed (74) hide show
  1. package/dist/html/host.cjs +50 -7
  2. package/dist/html/host.cjs.map +1 -1
  3. package/dist/html/host.js +50 -7
  4. package/dist/html/host.js.map +1 -1
  5. package/dist/html/remote.cjs.map +1 -1
  6. package/dist/html/remote.js.map +1 -1
  7. package/dist/internal/next/host/app-router-client.cjs +6 -6
  8. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  9. package/dist/internal/next/host/app-router-client.js +1 -1
  10. package/dist/internal/next/host/app-router-client.js.map +1 -1
  11. package/dist/internal/next/host/app-router-compat.cjs +5 -5
  12. package/dist/internal/next/host/app-router-compat.cjs.map +1 -1
  13. package/dist/internal/next/host/app-router-compat.js +1 -1
  14. package/dist/internal/next/host/app-router-compat.js.map +1 -1
  15. package/dist/internal/shared/client/polyfill.cjs +2 -2
  16. package/dist/internal/shared/client/polyfill.cjs.map +1 -1
  17. package/dist/internal/shared/client/polyfill.js +1 -1
  18. package/dist/internal/shared/client/polyfill.js.map +1 -1
  19. package/dist/internal/shared/client/remote-component.cjs +32 -1
  20. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  21. package/dist/internal/shared/client/remote-component.js +32 -1
  22. package/dist/internal/shared/client/remote-component.js.map +1 -1
  23. package/dist/internal/shared/ssr/fetch-remote-component.cjs +1 -6
  24. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  25. package/dist/internal/shared/ssr/fetch-remote-component.js +1 -6
  26. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  27. package/dist/internal/shared/ssr/fetch-with-hooks.cjs +9 -2
  28. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
  29. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +6 -1
  30. package/dist/internal/shared/ssr/fetch-with-hooks.js +9 -2
  31. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
  32. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs +57 -0
  33. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs.map +1 -0
  34. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.d.ts +11 -0
  35. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js +32 -0
  36. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js.map +1 -0
  37. package/dist/internal/shared/{logger.cjs → utils/logger.cjs} +5 -0
  38. package/dist/internal/shared/utils/logger.cjs.map +1 -0
  39. package/dist/internal/shared/{logger.d.ts → utils/logger.d.ts} +3 -2
  40. package/dist/internal/shared/{logger.js → utils/logger.js} +4 -0
  41. package/dist/internal/shared/utils/logger.js.map +1 -0
  42. package/dist/internal/shared/utils.cjs +2 -9
  43. package/dist/internal/shared/utils.cjs.map +1 -1
  44. package/dist/internal/shared/utils.d.ts +0 -2
  45. package/dist/internal/shared/utils.js +1 -5
  46. package/dist/internal/shared/utils.js.map +1 -1
  47. package/dist/next/config.cjs.map +1 -1
  48. package/dist/next/config.js.map +1 -1
  49. package/dist/next/host/client/index.cjs +51 -17
  50. package/dist/next/host/client/index.cjs.map +1 -1
  51. package/dist/next/host/client/index.js +51 -17
  52. package/dist/next/host/client/index.js.map +1 -1
  53. package/dist/next/proxy.cjs +128 -19
  54. package/dist/next/proxy.cjs.map +1 -1
  55. package/dist/next/proxy.d.ts +34 -6
  56. package/dist/next/proxy.js +125 -18
  57. package/dist/next/proxy.js.map +1 -1
  58. package/dist/react/index.cjs +51 -17
  59. package/dist/react/index.cjs.map +1 -1
  60. package/dist/react/index.js +51 -17
  61. package/dist/react/index.js.map +1 -1
  62. package/dist/shared/host/proxy.cjs +79 -0
  63. package/dist/shared/host/proxy.cjs.map +1 -0
  64. package/dist/shared/host/proxy.d.ts +29 -0
  65. package/dist/shared/host/proxy.js +54 -0
  66. package/dist/shared/host/proxy.js.map +1 -0
  67. package/dist/shared/remote/proxy.cjs +71 -0
  68. package/dist/shared/remote/proxy.cjs.map +1 -0
  69. package/dist/shared/remote/proxy.d.ts +38 -0
  70. package/dist/shared/remote/proxy.js +45 -0
  71. package/dist/shared/remote/proxy.js.map +1 -0
  72. package/package.json +10 -1
  73. package/dist/internal/shared/logger.cjs.map +0 -1
  74. package/dist/internal/shared/logger.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/ssr/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { getClientSrc } from '#internal/shared/client/get-client-src';\nimport {\n failedToFetchRemoteComponentError,\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/shared/error';\nimport { visit } from '#internal/shared/ssr/dom-flight';\nimport { remoteFetchHeaders } from '#internal/shared/ssr/fetch-headers';\nimport { fetchWithHooks } from '#internal/shared/ssr/fetch-with-hooks';\nimport { getSSRRelativePathBaseUrl } from '#internal/shared/ssr/get-ssr-relative-path-base-url';\nimport {\n getSkeletonHtml,\n getSkeletonMessage,\n} from '#internal/shared/ssr/skeleton';\nimport type {\n FetchRemoteComponentResponse,\n NextData,\n OnRequestHook,\n OnResponseHook,\n RemoteComponentMetadata,\n} from './types';\n\nconst CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;\n\nexport async function fetchRemoteComponent(\n src: string | URL,\n 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 rsc: false,\n },\n): Promise<FetchRemoteComponentResponse> {\n const ssrRelativePathBaseUrl = getSSRRelativePathBaseUrl();\n const serverUrl = new URL(src, ssrRelativePathBaseUrl);\n\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 = {\n method: 'GET',\n // pass all headers to the remote component\n headers: remoteFetchHeaders(),\n credentials: 'include',\n next: {\n tags,\n },\n } as const;\n\n const res = await fetchWithHooks(serverUrl, fetchInit, {\n onRequest: options.onRequest,\n onResponse: options.onResponse,\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.',\n );\n }\n\n if (res.status === 404) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'Check if you can open it in the browser.',\n );\n }\n\n // create a parser for the HTML response\n const parser = Parser.getFragmentParser<DefaultTreeAdapterMap>();\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 decoder = new TextDecoder();\n // read the response body as a stream and parse it using the parse5 fragment parser\n for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {\n parser.tokenizer.write(decoder.decode(chunk), false);\n }\n const fragment = parser.getFragment();\n\n let metadata: RemoteComponentMetadata = {\n bundle: CURRENT_ZONE ?? '__vercel_remote_component',\n route: '/',\n runtime: 'webpack',\n id: '__vercel_remote_component',\n type: 'unknown',\n };\n let remoteShared: Record<string, string> = {};\n const scripts: { src: string; textContent?: string }[] = [];\n const links: Record<string, string | boolean>[] = [];\n const hydrationData: string[] = [];\n let nextData: NextData | undefined;\n let html = '';\n\n const remoteName =\n options.name || (serverUrl.hash ? serverUrl.hash.substring(1) : undefined);\n // convert the parsed HTML fragment into an RSC flight data\n // and extract the metadata, scripts, links and remote component RSC flight data\n let hasRemoteComponent = false;\n let hasRSC = false;\n let hasShared = false;\n let hasMultipleRemoteComponents = false;\n let error: RemoteComponentsError | undefined;\n const rsc = visit(fragment, {\n url: serverUrl,\n name: remoteName,\n onMetadata(_metadata) {\n // Skip multiple component detection for Pages Router (__next) since it only supports one remote component per page\n if (\n hasRemoteComponent &&\n metadata.id !== _metadata.id &&\n _metadata.id !== '__next' &&\n metadata.id !== '__next' &&\n !nextData\n ) {\n hasMultipleRemoteComponents = true;\n }\n metadata = _metadata;\n hasRemoteComponent = true;\n },\n onScript(attrs) {\n const clientSrc = getClientSrc(attrs.src, serverUrl.href);\n if (\n !scripts.find(\n (it) =>\n it.src === clientSrc ||\n (attrs.textContent && it.textContent === attrs.textContent),\n )\n ) {\n scripts.push(\n typeof attrs.textContent === 'string'\n ? {\n src: '',\n textContent: attrs.textContent,\n }\n : {\n src: clientSrc,\n },\n );\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: getClientSrc(attrs.href, serverUrl.href),\n };\n if (\n !links.find(\n (it) => it.href === relativeAttrs.href && it.rel === attrs.rel,\n )\n ) {\n links.push(relativeAttrs);\n }\n },\n onRSC(chunk) {\n hydrationData.push(chunk);\n hasRSC = true;\n },\n onNextData(data) {\n nextData = data;\n\n // use the Next.js Pages Router props data to extract remote component metadata\n if (data.props.__REMOTE_COMPONENT__) {\n Object.assign(metadata, data.props.__REMOTE_COMPONENT__);\n // only a singleton remote component is supported per page when using the Next.js Pages Router\n metadata.id = '__next';\n metadata.route = data.page ?? '/';\n }\n },\n onHTML(_html) {\n if (!html.includes(_html)) {\n html += _html;\n }\n },\n onShared(_shared) {\n remoteShared = _shared;\n hasShared = true;\n },\n onError(message, stack) {\n error = new RemoteComponentsError(message);\n if (stack) {\n error.stack = stack;\n }\n },\n });\n\n if (error) {\n throw error;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!hasRemoteComponent) {\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 // If the remote component is part of a microfrontend, the src provided\n // will be relative.\n const isSSRRelativePathBase =\n serverUrl.host === new URL(ssrRelativePathBaseUrl).host;\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\n if (isSSGBuild && isSSRRelativePathBase && isPreview && options.appRouter) {\n const skeletonMessage = getSkeletonMessage();\n const skeletonHtml = getSkeletonHtml(serverUrl.href);\n\n let skeletonComponent: React.ReactNode | undefined;\n if (options.rsc) {\n const { createElement } = await import('react');\n skeletonComponent = createElement('div', {\n dangerouslySetInnerHTML: { __html: skeletonHtml },\n });\n }\n\n return {\n name: 'remote-component-skeleton',\n serverUrl,\n metadata: {\n ...metadata,\n type: 'remote-component',\n },\n rsc: skeletonMessage,\n scripts: [],\n links: [],\n hydrationData: [],\n nextData: undefined,\n component: skeletonComponent,\n html: skeletonHtml,\n remoteShared: {},\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (hasMultipleRemoteComponents && !remoteName) {\n throw multipleRemoteComponentsError(serverUrl.href);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n !hasShared &&\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 let component: React.ReactNode | undefined;\n\n // only create a React component if requested\n if (options.rsc) {\n // RSC flight data for the static HTML in a single RSC line\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n\n const { createFromReadableStream } = await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\n );\n\n // create a React tree from the RSC flight data\n component = await createFromReadableStream(\n new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n controller.enqueue(encoder.encode(componentRSC));\n controller.close();\n },\n }),\n {\n serverConsumerManifest: {\n moduleLoading: {\n prefix: serverUrl.origin,\n crossOrigin: true,\n },\n moduleMap: {},\n },\n },\n );\n }\n\n const name = metadata.id.replace(/_ssr$/, '');\n return {\n name,\n serverUrl,\n metadata,\n rsc,\n scripts,\n links,\n hydrationData,\n nextData,\n component,\n html,\n remoteShared: nextData?.props.__REMOTE_COMPONENT__?.shared ?? remoteShared,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmD;AACnD,4BAA6B;AAC7B,mBAIO;AACP,wBAAsB;AACtB,2BAAmC;AACnC,8BAA+B;AAC/B,4CAA0C;AAC1C,sBAGO;AASP,MAAM,eAAe,QAAQ,IAAI;AAEjC,eAAsB,qBACpB,KACA,UAOI;AAAA,EACF,KAAK;AACP,GACuC;AACvC,QAAM,6BAAyB,iEAA0B;AACzD,QAAM,YAAY,IAAI,IAAI,KAAK,sBAAsB;AAErD,QAAM,OAAO;AAAA,IACX;AAAA;AAAA,IAEA,UAAU,KAAK,MAAM,GAAG,GAAG;AAAA;AAAA;AAAA,KAG1B,OAAO,QAAQ,WAAW,MAAM,IAAI,MAAM,MAAM,IAAI;AAAA,EACvD;AACA,MAAI,QAAQ,MAAM;AAChB,SAAK,KAAK,QAAQ,KAAK,MAAM,IAAI,CAAC;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SAAS,SAAS,UAAU;AACtD,UAAM,IAAI;AAAA,MACR,4BAA4B,UAAU;AAAA,IACxC;AAAA,EACF;AAEA,MACE,SAAS,SAAS;AAAA,EAElB,CAAC,aACD,CAAC,UAAU,MAAM,sBAAsB,QACvC;AACA,UAAM,IAAI;AAAA,MACR,yDAAyD,UAAU;AAAA,IACrE;AAAA,EACF;AAEA,MAAI;AAGJ,MAAI,QAAQ,KAAK;AAEf,UAAM,eAAe,KAAK,KAAK,UAAU,GAAG;AAAA;AAE5C,UAAM,EAAE,yBAAyB,IAAI,MAAM,OACzC,yDACF;AAGA,gBAAY,MAAM;AAAA,MAChB,IAAI,eAAe;AAAA,QACjB,MAAM;AAAA,QACN,MAAM,YAAY;AAChB,gBAAM,UAAU,IAAI,YAAY;AAChC,qBAAW,QAAQ,QAAQ,OAAO,YAAY,CAAC;AAC/C,qBAAW,MAAM;AAAA,QACnB;AAAA,MACF,CAAC;AAAA,MACD;AAAA,QACE,wBAAwB;AAAA,UACtB,eAAe;AAAA,YACb,QAAQ,UAAU;AAAA,YAClB,aAAa;AAAA,UACf;AAAA,UACA,WAAW,CAAC;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,OAAO,SAAS,GAAG,QAAQ,SAAS,EAAE;AAC5C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,UAAU,MAAM,sBAAsB,UAAU;AAAA,EAChE;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/shared/ssr/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { getClientSrc } from '#internal/shared/client/get-client-src';\nimport {\n failedToFetchRemoteComponentError,\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/shared/error';\nimport { visit } from '#internal/shared/ssr/dom-flight';\nimport { fetchWithHooks } from '#internal/shared/ssr/fetch-with-hooks';\nimport { getSSRRelativePathBaseUrl } from '#internal/shared/ssr/get-ssr-relative-path-base-url';\nimport {\n getSkeletonHtml,\n getSkeletonMessage,\n} from '#internal/shared/ssr/skeleton';\nimport type {\n FetchRemoteComponentResponse,\n NextData,\n OnRequestHook,\n OnResponseHook,\n RemoteComponentMetadata,\n} from './types';\n\nconst CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;\n\nexport async function fetchRemoteComponent(\n src: string | URL,\n 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 rsc: false,\n },\n): Promise<FetchRemoteComponentResponse> {\n const ssrRelativePathBaseUrl = getSSRRelativePathBaseUrl();\n const serverUrl = new URL(src, ssrRelativePathBaseUrl);\n\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 = {\n next: {\n tags,\n },\n };\n\n const res = await fetchWithHooks(serverUrl, fetchInit, {\n onRequest: options.onRequest,\n onResponse: options.onResponse,\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 'Check if you can open it in the browser.',\n );\n }\n\n // create a parser for the HTML response\n const parser = Parser.getFragmentParser<DefaultTreeAdapterMap>();\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 decoder = new TextDecoder();\n // read the response body as a stream and parse it using the parse5 fragment parser\n for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {\n parser.tokenizer.write(decoder.decode(chunk), false);\n }\n const fragment = parser.getFragment();\n\n let metadata: RemoteComponentMetadata = {\n bundle: CURRENT_ZONE ?? '__vercel_remote_component',\n route: '/',\n runtime: 'webpack',\n id: '__vercel_remote_component',\n type: 'unknown',\n };\n let remoteShared: Record<string, string> = {};\n const scripts: { src: string; textContent?: string }[] = [];\n const links: Record<string, string | boolean>[] = [];\n const hydrationData: string[] = [];\n let nextData: NextData | undefined;\n let html = '';\n\n const remoteName =\n options.name || (serverUrl.hash ? serverUrl.hash.substring(1) : undefined);\n // convert the parsed HTML fragment into an RSC flight data\n // and extract the metadata, scripts, links and remote component RSC flight data\n let hasRemoteComponent = false;\n let hasRSC = false;\n let hasShared = false;\n let hasMultipleRemoteComponents = false;\n let error: RemoteComponentsError | undefined;\n const rsc = visit(fragment, {\n url: serverUrl,\n name: remoteName,\n onMetadata(_metadata) {\n // Skip multiple component detection for Pages Router (__next) since it only supports one remote component per page\n if (\n hasRemoteComponent &&\n metadata.id !== _metadata.id &&\n _metadata.id !== '__next' &&\n metadata.id !== '__next' &&\n !nextData\n ) {\n hasMultipleRemoteComponents = true;\n }\n metadata = _metadata;\n hasRemoteComponent = true;\n },\n onScript(attrs) {\n const clientSrc = getClientSrc(attrs.src, serverUrl.href);\n if (\n !scripts.find(\n (it) =>\n it.src === clientSrc ||\n (attrs.textContent && it.textContent === attrs.textContent),\n )\n ) {\n scripts.push(\n typeof attrs.textContent === 'string'\n ? {\n src: '',\n textContent: attrs.textContent,\n }\n : {\n src: clientSrc,\n },\n );\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: getClientSrc(attrs.href, serverUrl.href),\n };\n if (\n !links.find(\n (it) => it.href === relativeAttrs.href && it.rel === attrs.rel,\n )\n ) {\n links.push(relativeAttrs);\n }\n },\n onRSC(chunk) {\n hydrationData.push(chunk);\n hasRSC = true;\n },\n onNextData(data) {\n nextData = data;\n\n // use the Next.js Pages Router props data to extract remote component metadata\n if (data.props.__REMOTE_COMPONENT__) {\n Object.assign(metadata, data.props.__REMOTE_COMPONENT__);\n // only a singleton remote component is supported per page when using the Next.js Pages Router\n metadata.id = '__next';\n metadata.route = data.page ?? '/';\n }\n },\n onHTML(_html) {\n if (!html.includes(_html)) {\n html += _html;\n }\n },\n onShared(_shared) {\n remoteShared = _shared;\n hasShared = true;\n },\n onError(message, stack) {\n error = new RemoteComponentsError(message);\n if (stack) {\n error.stack = stack;\n }\n },\n });\n\n if (error) {\n throw error;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!hasRemoteComponent) {\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 // If the remote component is part of a microfrontend, the src provided\n // will be relative.\n const isSSRRelativePathBase =\n serverUrl.host === new URL(ssrRelativePathBaseUrl).host;\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\n if (isSSGBuild && isSSRRelativePathBase && isPreview && options.appRouter) {\n const skeletonMessage = getSkeletonMessage();\n const skeletonHtml = getSkeletonHtml(serverUrl.href);\n\n let skeletonComponent: React.ReactNode | undefined;\n if (options.rsc) {\n const { createElement } = await import('react');\n skeletonComponent = createElement('div', {\n dangerouslySetInnerHTML: { __html: skeletonHtml },\n });\n }\n\n return {\n name: 'remote-component-skeleton',\n serverUrl,\n metadata: {\n ...metadata,\n type: 'remote-component',\n },\n rsc: skeletonMessage,\n scripts: [],\n links: [],\n hydrationData: [],\n nextData: undefined,\n component: skeletonComponent,\n html: skeletonHtml,\n remoteShared: {},\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (hasMultipleRemoteComponents && !remoteName) {\n throw multipleRemoteComponentsError(serverUrl.href);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n !hasShared &&\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 let component: React.ReactNode | undefined;\n\n // only create a React component if requested\n if (options.rsc) {\n // RSC flight data for the static HTML in a single RSC line\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n\n const { createFromReadableStream } = await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\n );\n\n // create a React tree from the RSC flight data\n component = await createFromReadableStream(\n new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n controller.enqueue(encoder.encode(componentRSC));\n controller.close();\n },\n }),\n {\n serverConsumerManifest: {\n moduleLoading: {\n prefix: serverUrl.origin,\n crossOrigin: true,\n },\n moduleMap: {},\n },\n },\n );\n }\n\n const name = metadata.id.replace(/_ssr$/, '');\n return {\n name,\n serverUrl,\n metadata,\n rsc,\n scripts,\n links,\n hydrationData,\n nextData,\n component,\n html,\n remoteShared: nextData?.props.__REMOTE_COMPONENT__?.shared ?? remoteShared,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmD;AACnD,4BAA6B;AAC7B,mBAIO;AACP,wBAAsB;AACtB,8BAA+B;AAC/B,4CAA0C;AAC1C,sBAGO;AASP,MAAM,eAAe,QAAQ,IAAI;AAEjC,eAAsB,qBACpB,KACA,UAOI;AAAA,EACF,KAAK;AACP,GACuC;AACvC,QAAM,6BAAyB,iEAA0B;AACzD,QAAM,YAAY,IAAI,IAAI,KAAK,sBAAsB;AAErD,QAAM,OAAO;AAAA,IACX;AAAA;AAAA,IAEA,UAAU,KAAK,MAAM,GAAG,GAAG;AAAA;AAAA;AAAA,KAG1B,OAAO,QAAQ,WAAW,MAAM,IAAI,MAAM,MAAM,IAAI;AAAA,EACvD;AACA,MAAI,QAAQ,MAAM;AAChB,SAAK,KAAK,QAAQ,KAAK,MAAM,IAAI,CAAC;AAAA,EACpC;AAEA,QAAM,YAAY;AAAA,IAChB,MAAM;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AAEA,QAAM,MAAM,UAAM,wCAAe,WAAW,WAAW;AAAA,IACrD,WAAW,QAAQ;AAAA,IACnB,YAAY,QAAQ;AAAA,EACtB,CAAC;AAGD,MAAI,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM;AACxB,cAAM,gDAAkC,UAAU,MAAM,GAAG;AAAA,EAC7D;AAEA,MAAI,IAAI,WAAW,KAAK;AACtB,cAAM;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,IAAI,WAAW,KAAK;AACtB,cAAM;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAGA,QAAM,SAAS,qBAAO,kBAAyC;AAE/D,MAAI,CAAC,IAAI,MAAM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b,QAAQ,UAAU;AAAA,YAClB,aAAa;AAAA,UACf;AAAA,UACA,WAAW,CAAC;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,OAAO,SAAS,GAAG,QAAQ,SAAS,EAAE;AAC5C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,UAAU,MAAM,sBAAsB,UAAU;AAAA,EAChE;AACF;","names":[]}
@@ -6,7 +6,6 @@ import {
6
6
  RemoteComponentsError
7
7
  } from "#internal/shared/error";
8
8
  import { visit } from "#internal/shared/ssr/dom-flight";
9
- import { remoteFetchHeaders } from "#internal/shared/ssr/fetch-headers";
10
9
  import { fetchWithHooks } from "#internal/shared/ssr/fetch-with-hooks";
11
10
  import { getSSRRelativePathBaseUrl } from "#internal/shared/ssr/get-ssr-relative-path-base-url";
12
11
  import {
@@ -31,10 +30,6 @@ async function fetchRemoteComponent(src, options = {
31
30
  tags.push(options.name.slice(-256));
32
31
  }
33
32
  const fetchInit = {
34
- method: "GET",
35
- // pass all headers to the remote component
36
- headers: remoteFetchHeaders(),
37
- credentials: "include",
38
33
  next: {
39
34
  tags
40
35
  }
@@ -50,7 +45,7 @@ async function fetchRemoteComponent(src, options = {
50
45
  throw failedToFetchRemoteComponentError(
51
46
  serverUrl.href,
52
47
  res,
53
- "If you are using Deployment Protection, ensure the automation bypass environment variable secret in the host matches an automation bypass value in the remote."
48
+ "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."
54
49
  );
55
50
  }
56
51
  if (res.status === 404) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/ssr/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { getClientSrc } from '#internal/shared/client/get-client-src';\nimport {\n failedToFetchRemoteComponentError,\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/shared/error';\nimport { visit } from '#internal/shared/ssr/dom-flight';\nimport { remoteFetchHeaders } from '#internal/shared/ssr/fetch-headers';\nimport { fetchWithHooks } from '#internal/shared/ssr/fetch-with-hooks';\nimport { getSSRRelativePathBaseUrl } from '#internal/shared/ssr/get-ssr-relative-path-base-url';\nimport {\n getSkeletonHtml,\n getSkeletonMessage,\n} from '#internal/shared/ssr/skeleton';\nimport type {\n FetchRemoteComponentResponse,\n NextData,\n OnRequestHook,\n OnResponseHook,\n RemoteComponentMetadata,\n} from './types';\n\nconst CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;\n\nexport async function fetchRemoteComponent(\n src: string | URL,\n 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 rsc: false,\n },\n): Promise<FetchRemoteComponentResponse> {\n const ssrRelativePathBaseUrl = getSSRRelativePathBaseUrl();\n const serverUrl = new URL(src, ssrRelativePathBaseUrl);\n\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 = {\n method: 'GET',\n // pass all headers to the remote component\n headers: remoteFetchHeaders(),\n credentials: 'include',\n next: {\n tags,\n },\n } as const;\n\n const res = await fetchWithHooks(serverUrl, fetchInit, {\n onRequest: options.onRequest,\n onResponse: options.onResponse,\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.',\n );\n }\n\n if (res.status === 404) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'Check if you can open it in the browser.',\n );\n }\n\n // create a parser for the HTML response\n const parser = Parser.getFragmentParser<DefaultTreeAdapterMap>();\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 decoder = new TextDecoder();\n // read the response body as a stream and parse it using the parse5 fragment parser\n for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {\n parser.tokenizer.write(decoder.decode(chunk), false);\n }\n const fragment = parser.getFragment();\n\n let metadata: RemoteComponentMetadata = {\n bundle: CURRENT_ZONE ?? '__vercel_remote_component',\n route: '/',\n runtime: 'webpack',\n id: '__vercel_remote_component',\n type: 'unknown',\n };\n let remoteShared: Record<string, string> = {};\n const scripts: { src: string; textContent?: string }[] = [];\n const links: Record<string, string | boolean>[] = [];\n const hydrationData: string[] = [];\n let nextData: NextData | undefined;\n let html = '';\n\n const remoteName =\n options.name || (serverUrl.hash ? serverUrl.hash.substring(1) : undefined);\n // convert the parsed HTML fragment into an RSC flight data\n // and extract the metadata, scripts, links and remote component RSC flight data\n let hasRemoteComponent = false;\n let hasRSC = false;\n let hasShared = false;\n let hasMultipleRemoteComponents = false;\n let error: RemoteComponentsError | undefined;\n const rsc = visit(fragment, {\n url: serverUrl,\n name: remoteName,\n onMetadata(_metadata) {\n // Skip multiple component detection for Pages Router (__next) since it only supports one remote component per page\n if (\n hasRemoteComponent &&\n metadata.id !== _metadata.id &&\n _metadata.id !== '__next' &&\n metadata.id !== '__next' &&\n !nextData\n ) {\n hasMultipleRemoteComponents = true;\n }\n metadata = _metadata;\n hasRemoteComponent = true;\n },\n onScript(attrs) {\n const clientSrc = getClientSrc(attrs.src, serverUrl.href);\n if (\n !scripts.find(\n (it) =>\n it.src === clientSrc ||\n (attrs.textContent && it.textContent === attrs.textContent),\n )\n ) {\n scripts.push(\n typeof attrs.textContent === 'string'\n ? {\n src: '',\n textContent: attrs.textContent,\n }\n : {\n src: clientSrc,\n },\n );\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: getClientSrc(attrs.href, serverUrl.href),\n };\n if (\n !links.find(\n (it) => it.href === relativeAttrs.href && it.rel === attrs.rel,\n )\n ) {\n links.push(relativeAttrs);\n }\n },\n onRSC(chunk) {\n hydrationData.push(chunk);\n hasRSC = true;\n },\n onNextData(data) {\n nextData = data;\n\n // use the Next.js Pages Router props data to extract remote component metadata\n if (data.props.__REMOTE_COMPONENT__) {\n Object.assign(metadata, data.props.__REMOTE_COMPONENT__);\n // only a singleton remote component is supported per page when using the Next.js Pages Router\n metadata.id = '__next';\n metadata.route = data.page ?? '/';\n }\n },\n onHTML(_html) {\n if (!html.includes(_html)) {\n html += _html;\n }\n },\n onShared(_shared) {\n remoteShared = _shared;\n hasShared = true;\n },\n onError(message, stack) {\n error = new RemoteComponentsError(message);\n if (stack) {\n error.stack = stack;\n }\n },\n });\n\n if (error) {\n throw error;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!hasRemoteComponent) {\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 // If the remote component is part of a microfrontend, the src provided\n // will be relative.\n const isSSRRelativePathBase =\n serverUrl.host === new URL(ssrRelativePathBaseUrl).host;\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\n if (isSSGBuild && isSSRRelativePathBase && isPreview && options.appRouter) {\n const skeletonMessage = getSkeletonMessage();\n const skeletonHtml = getSkeletonHtml(serverUrl.href);\n\n let skeletonComponent: React.ReactNode | undefined;\n if (options.rsc) {\n const { createElement } = await import('react');\n skeletonComponent = createElement('div', {\n dangerouslySetInnerHTML: { __html: skeletonHtml },\n });\n }\n\n return {\n name: 'remote-component-skeleton',\n serverUrl,\n metadata: {\n ...metadata,\n type: 'remote-component',\n },\n rsc: skeletonMessage,\n scripts: [],\n links: [],\n hydrationData: [],\n nextData: undefined,\n component: skeletonComponent,\n html: skeletonHtml,\n remoteShared: {},\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (hasMultipleRemoteComponents && !remoteName) {\n throw multipleRemoteComponentsError(serverUrl.href);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n !hasShared &&\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 let component: React.ReactNode | undefined;\n\n // only create a React component if requested\n if (options.rsc) {\n // RSC flight data for the static HTML in a single RSC line\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n\n const { createFromReadableStream } = await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\n );\n\n // create a React tree from the RSC flight data\n component = await createFromReadableStream(\n new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n controller.enqueue(encoder.encode(componentRSC));\n controller.close();\n },\n }),\n {\n serverConsumerManifest: {\n moduleLoading: {\n prefix: serverUrl.origin,\n crossOrigin: true,\n },\n moduleMap: {},\n },\n },\n );\n }\n\n const name = metadata.id.replace(/_ssr$/, '');\n return {\n name,\n serverUrl,\n metadata,\n rsc,\n scripts,\n links,\n hydrationData,\n nextData,\n component,\n html,\n remoteShared: nextData?.props.__REMOTE_COMPONENT__?.shared ?? remoteShared,\n };\n}\n"],"mappings":"AAAA,SAAqC,cAAc;AACnD,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa;AACtB,SAAS,0BAA0B;AACnC,SAAS,sBAAsB;AAC/B,SAAS,iCAAiC;AAC1C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AASP,MAAM,eAAe,QAAQ,IAAI;AAEjC,eAAsB,qBACpB,KACA,UAOI;AAAA,EACF,KAAK;AACP,GACuC;AACvC,QAAM,yBAAyB,0BAA0B;AACzD,QAAM,YAAY,IAAI,IAAI,KAAK,sBAAsB;AAErD,QAAM,OAAO;AAAA,IACX;AAAA;AAAA,IAEA,UAAU,KAAK,MAAM,GAAG,GAAG;AAAA;AAAA;AAAA,KAG1B,OAAO,QAAQ,WAAW,MAAM,IAAI,MAAM,MAAM,IAAI;AAAA,EACvD;AACA,MAAI,QAAQ,MAAM;AAChB,SAAK,KAAK,QAAQ,KAAK,MAAM,IAAI,CAAC;AAAA,EACpC;AAEA,QAAM,YAAY;AAAA,IAChB,QAAQ;AAAA;AAAA,IAER,SAAS,mBAAmB;AAAA,IAC5B,aAAa;AAAA,IACb,MAAM;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AAEA,QAAM,MAAM,MAAM,eAAe,WAAW,WAAW;AAAA,IACrD,WAAW,QAAQ;AAAA,IACnB,YAAY,QAAQ;AAAA,EACtB,CAAC;AAGD,MAAI,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM;AACxB,UAAM,kCAAkC,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yB,IAAI,MAAM,OACzC,yDACF;AAGA,gBAAY,MAAM;AAAA,MAChB,IAAI,eAAe;AAAA,QACjB,MAAM;AAAA,QACN,MAAM,YAAY;AAChB,gBAAM,UAAU,IAAI,YAAY;AAChC,qBAAW,QAAQ,QAAQ,OAAO,YAAY,CAAC;AAC/C,qBAAW,MAAM;AAAA,QACnB;AAAA,MACF,CAAC;AAAA,MACD;AAAA,QACE,wBAAwB;AAAA,UACtB,eAAe;AAAA,YACb,QAAQ,UAAU;AAAA,YAClB,aAAa;AAAA,UACf;AAAA,UACA,WAAW,CAAC;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,OAAO,SAAS,GAAG,QAAQ,SAAS,EAAE;AAC5C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,UAAU,MAAM,sBAAsB,UAAU;AAAA,EAChE;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/shared/ssr/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { getClientSrc } from '#internal/shared/client/get-client-src';\nimport {\n failedToFetchRemoteComponentError,\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/shared/error';\nimport { visit } from '#internal/shared/ssr/dom-flight';\nimport { fetchWithHooks } from '#internal/shared/ssr/fetch-with-hooks';\nimport { getSSRRelativePathBaseUrl } from '#internal/shared/ssr/get-ssr-relative-path-base-url';\nimport {\n getSkeletonHtml,\n getSkeletonMessage,\n} from '#internal/shared/ssr/skeleton';\nimport type {\n FetchRemoteComponentResponse,\n NextData,\n OnRequestHook,\n OnResponseHook,\n RemoteComponentMetadata,\n} from './types';\n\nconst CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;\n\nexport async function fetchRemoteComponent(\n src: string | URL,\n 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 rsc: false,\n },\n): Promise<FetchRemoteComponentResponse> {\n const ssrRelativePathBaseUrl = getSSRRelativePathBaseUrl();\n const serverUrl = new URL(src, ssrRelativePathBaseUrl);\n\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 = {\n next: {\n tags,\n },\n };\n\n const res = await fetchWithHooks(serverUrl, fetchInit, {\n onRequest: options.onRequest,\n onResponse: options.onResponse,\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 'Check if you can open it in the browser.',\n );\n }\n\n // create a parser for the HTML response\n const parser = Parser.getFragmentParser<DefaultTreeAdapterMap>();\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 decoder = new TextDecoder();\n // read the response body as a stream and parse it using the parse5 fragment parser\n for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {\n parser.tokenizer.write(decoder.decode(chunk), false);\n }\n const fragment = parser.getFragment();\n\n let metadata: RemoteComponentMetadata = {\n bundle: CURRENT_ZONE ?? '__vercel_remote_component',\n route: '/',\n runtime: 'webpack',\n id: '__vercel_remote_component',\n type: 'unknown',\n };\n let remoteShared: Record<string, string> = {};\n const scripts: { src: string; textContent?: string }[] = [];\n const links: Record<string, string | boolean>[] = [];\n const hydrationData: string[] = [];\n let nextData: NextData | undefined;\n let html = '';\n\n const remoteName =\n options.name || (serverUrl.hash ? serverUrl.hash.substring(1) : undefined);\n // convert the parsed HTML fragment into an RSC flight data\n // and extract the metadata, scripts, links and remote component RSC flight data\n let hasRemoteComponent = false;\n let hasRSC = false;\n let hasShared = false;\n let hasMultipleRemoteComponents = false;\n let error: RemoteComponentsError | undefined;\n const rsc = visit(fragment, {\n url: serverUrl,\n name: remoteName,\n onMetadata(_metadata) {\n // Skip multiple component detection for Pages Router (__next) since it only supports one remote component per page\n if (\n hasRemoteComponent &&\n metadata.id !== _metadata.id &&\n _metadata.id !== '__next' &&\n metadata.id !== '__next' &&\n !nextData\n ) {\n hasMultipleRemoteComponents = true;\n }\n metadata = _metadata;\n hasRemoteComponent = true;\n },\n onScript(attrs) {\n const clientSrc = getClientSrc(attrs.src, serverUrl.href);\n if (\n !scripts.find(\n (it) =>\n it.src === clientSrc ||\n (attrs.textContent && it.textContent === attrs.textContent),\n )\n ) {\n scripts.push(\n typeof attrs.textContent === 'string'\n ? {\n src: '',\n textContent: attrs.textContent,\n }\n : {\n src: clientSrc,\n },\n );\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: getClientSrc(attrs.href, serverUrl.href),\n };\n if (\n !links.find(\n (it) => it.href === relativeAttrs.href && it.rel === attrs.rel,\n )\n ) {\n links.push(relativeAttrs);\n }\n },\n onRSC(chunk) {\n hydrationData.push(chunk);\n hasRSC = true;\n },\n onNextData(data) {\n nextData = data;\n\n // use the Next.js Pages Router props data to extract remote component metadata\n if (data.props.__REMOTE_COMPONENT__) {\n Object.assign(metadata, data.props.__REMOTE_COMPONENT__);\n // only a singleton remote component is supported per page when using the Next.js Pages Router\n metadata.id = '__next';\n metadata.route = data.page ?? '/';\n }\n },\n onHTML(_html) {\n if (!html.includes(_html)) {\n html += _html;\n }\n },\n onShared(_shared) {\n remoteShared = _shared;\n hasShared = true;\n },\n onError(message, stack) {\n error = new RemoteComponentsError(message);\n if (stack) {\n error.stack = stack;\n }\n },\n });\n\n if (error) {\n throw error;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!hasRemoteComponent) {\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 // If the remote component is part of a microfrontend, the src provided\n // will be relative.\n const isSSRRelativePathBase =\n serverUrl.host === new URL(ssrRelativePathBaseUrl).host;\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\n if (isSSGBuild && isSSRRelativePathBase && isPreview && options.appRouter) {\n const skeletonMessage = getSkeletonMessage();\n const skeletonHtml = getSkeletonHtml(serverUrl.href);\n\n let skeletonComponent: React.ReactNode | undefined;\n if (options.rsc) {\n const { createElement } = await import('react');\n skeletonComponent = createElement('div', {\n dangerouslySetInnerHTML: { __html: skeletonHtml },\n });\n }\n\n return {\n name: 'remote-component-skeleton',\n serverUrl,\n metadata: {\n ...metadata,\n type: 'remote-component',\n },\n rsc: skeletonMessage,\n scripts: [],\n links: [],\n hydrationData: [],\n nextData: undefined,\n component: skeletonComponent,\n html: skeletonHtml,\n remoteShared: {},\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (hasMultipleRemoteComponents && !remoteName) {\n throw multipleRemoteComponentsError(serverUrl.href);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n !hasShared &&\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 let component: React.ReactNode | undefined;\n\n // only create a React component if requested\n if (options.rsc) {\n // RSC flight data for the static HTML in a single RSC line\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n\n const { createFromReadableStream } = await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\n );\n\n // create a React tree from the RSC flight data\n component = await createFromReadableStream(\n new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n controller.enqueue(encoder.encode(componentRSC));\n controller.close();\n },\n }),\n {\n serverConsumerManifest: {\n moduleLoading: {\n prefix: serverUrl.origin,\n crossOrigin: true,\n },\n moduleMap: {},\n },\n },\n );\n }\n\n const name = metadata.id.replace(/_ssr$/, '');\n return {\n name,\n serverUrl,\n metadata,\n rsc,\n scripts,\n links,\n hydrationData,\n nextData,\n component,\n html,\n remoteShared: nextData?.props.__REMOTE_COMPONENT__?.shared ?? remoteShared,\n };\n}\n"],"mappings":"AAAA,SAAqC,cAAc;AACnD,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa;AACtB,SAAS,sBAAsB;AAC/B,SAAS,iCAAiC;AAC1C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AASP,MAAM,eAAe,QAAQ,IAAI;AAEjC,eAAsB,q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AU;AAAA,EAChE;AACF;","names":[]}
@@ -21,11 +21,18 @@ __export(fetch_with_hooks_exports, {
21
21
  fetchWithHooks: () => fetchWithHooks
22
22
  });
23
23
  module.exports = __toCommonJS(fetch_with_hooks_exports);
24
- async function fetchWithHooks(url, init, options = {}) {
24
+ var import_fetch_headers = require("./fetch-headers");
25
+ var import_fetch_with_protected_rc_fallback = require("./fetch-with-protected-rc-fallback");
26
+ async function fetchWithHooks(url, additionalInit, options = {}) {
25
27
  const { onRequest, onResponse } = options;
28
+ const init = {
29
+ method: "GET",
30
+ headers: (0, import_fetch_headers.remoteFetchHeaders)(),
31
+ ...additionalInit
32
+ };
26
33
  let res = await onRequest?.(url, init);
27
34
  if (!res) {
28
- res = await fetch(url, init);
35
+ res = await (0, import_fetch_with_protected_rc_fallback.fetchWithProtectedRcFallback)(url, init);
29
36
  }
30
37
  const transformedRes = await onResponse?.(url, res);
31
38
  if (transformedRes) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/ssr/fetch-with-hooks.ts"],"sourcesContent":["import type { OnRequestHook, OnResponseHook } from './types';\n\n/**\n * Options for fetching with request/response hooks.\n */\nexport interface FetchWithHooksOptions {\n /** Hook to intercept the request before fetching */\n onRequest?: OnRequestHook;\n /** Hook to process the response after fetching */\n onResponse?: OnResponseHook;\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 * @param url - The URL to fetch\n * @param init - The fetch init options\n * @param options - Optional hooks for request/response interception\n * @returns The final Response (either from onRequest, fetch, or transformed by onResponse)\n *\n * @example\n * const response = await fetchWithHooks(url, fetchInit, {\n * onRequest: async (url, init) => {\n * console.log('Fetching:', url.href);\n * },\n * onResponse: async (url, response) => {\n * if (response.redirected) {\n * console.log('Redirected to:', response.url);\n * }\n * },\n * });\n */\nexport async function fetchWithHooks(\n url: URL,\n init: RequestInit,\n options: FetchWithHooksOptions = {},\n): Promise<Response> {\n const { onRequest, onResponse } = options;\n\n // Call onRequest hook if provided - may return a Response to skip fetching\n let res = await onRequest?.(url, init);\n if (!res) {\n res = await fetch(url, init);\n }\n\n // Call onResponse hook if provided - may return a transformed Response\n const transformedRes = await onResponse?.(url, res);\n if (transformedRes) {\n res = transformedRes;\n }\n\n return res;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqCA,eAAsB,eACpB,KACA,MACA,UAAiC,CAAC,GACf;AACnB,QAAM,EAAE,WAAW,WAAW,IAAI;AAGlC,MAAI,MAAM,MAAM,YAAY,KAAK,IAAI;AACrC,MAAI,CAAC,KAAK;AACR,UAAM,MAAM,MAAM,KAAK,IAAI;AAAA,EAC7B;AAGA,QAAM,iBAAiB,MAAM,aAAa,KAAK,GAAG;AAClD,MAAI,gBAAgB;AAClB,UAAM;AAAA,EACR;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../src/shared/ssr/fetch-with-hooks.ts"],"sourcesContent":["import { remoteFetchHeaders } from './fetch-headers';\nimport { fetchWithProtectedRcFallback } from './fetch-with-protected-rc-fallback';\nimport type { OnRequestHook, OnResponseHook } from './types';\n\n/**\n * Options for fetching with request/response hooks.\n */\nexport interface FetchWithHooksOptions {\n /** Hook to intercept the request before fetching */\n onRequest?: OnRequestHook;\n /** Hook to process the response after fetching */\n onResponse?: OnResponseHook;\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 * @param url - The URL to fetch\n * @param init - The fetch init options\n * @param options - Optional hooks for request/response interception\n * @returns The final Response (either from onRequest, fetch, or transformed by onResponse)\n *\n * @example\n * const response = await fetchWithHooks(url, fetchInit, {\n * onRequest: async (url, init) => {\n * console.log('Fetching:', url.href);\n * },\n * onResponse: async (url, response) => {\n * if (response.redirected) {\n * console.log('Redirected to:', response.url);\n * }\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 { onRequest, onResponse } = options;\n\n // fetch the remote component\n const init = {\n method: 'GET',\n headers: remoteFetchHeaders(),\n ...additionalInit,\n };\n\n // Call onRequest hook if provided - may return a Response to skip fetching\n let res = await onRequest?.(url, init);\n if (!res) {\n res = await fetchWithProtectedRcFallback(url, init);\n }\n\n // Call onResponse hook if provided - may return a transformed Response\n const transformedRes = await onResponse?.(url, res);\n if (transformedRes) {\n res = transformedRes;\n }\n\n return res;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAmC;AACnC,8CAA6C;AAsC7C,eAAsB,eACpB,KACA,gBAMA,UAAiC,CAAC,GACf;AACnB,QAAM,EAAE,WAAW,WAAW,IAAI;AAGlC,QAAM,OAAO;AAAA,IACX,QAAQ;AAAA,IACR,aAAS,yCAAmB;AAAA,IAC5B,GAAG;AAAA,EACL;AAGA,MAAI,MAAM,MAAM,YAAY,KAAK,IAAI;AACrC,MAAI,CAAC,KAAK;AACR,UAAM,UAAM,sEAA6B,KAAK,IAAI;AAAA,EACpD;AAGA,QAAM,iBAAiB,MAAM,aAAa,KAAK,GAAG;AAClD,MAAI,gBAAgB;AAClB,UAAM;AAAA,EACR;AAEA,SAAO;AACT;","names":[]}
@@ -35,6 +35,11 @@ interface FetchWithHooksOptions {
35
35
  * },
36
36
  * });
37
37
  */
38
- declare function fetchWithHooks(url: URL, init: RequestInit, options?: FetchWithHooksOptions): Promise<Response>;
38
+ declare function fetchWithHooks(url: URL, additionalInit: {
39
+ credentials?: RequestCredentials;
40
+ next?: {
41
+ tags?: string[];
42
+ };
43
+ }, options?: FetchWithHooksOptions): Promise<Response>;
39
44
 
40
45
  export { FetchWithHooksOptions, fetchWithHooks };
@@ -1,8 +1,15 @@
1
- async function fetchWithHooks(url, init, options = {}) {
1
+ import { remoteFetchHeaders } from "./fetch-headers";
2
+ import { fetchWithProtectedRcFallback } from "./fetch-with-protected-rc-fallback";
3
+ async function fetchWithHooks(url, additionalInit, options = {}) {
2
4
  const { onRequest, onResponse } = options;
5
+ const init = {
6
+ method: "GET",
7
+ headers: remoteFetchHeaders(),
8
+ ...additionalInit
9
+ };
3
10
  let res = await onRequest?.(url, init);
4
11
  if (!res) {
5
- res = await fetch(url, init);
12
+ res = await fetchWithProtectedRcFallback(url, init);
6
13
  }
7
14
  const transformedRes = await onResponse?.(url, res);
8
15
  if (transformedRes) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/ssr/fetch-with-hooks.ts"],"sourcesContent":["import type { OnRequestHook, OnResponseHook } from './types';\n\n/**\n * Options for fetching with request/response hooks.\n */\nexport interface FetchWithHooksOptions {\n /** Hook to intercept the request before fetching */\n onRequest?: OnRequestHook;\n /** Hook to process the response after fetching */\n onResponse?: OnResponseHook;\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 * @param url - The URL to fetch\n * @param init - The fetch init options\n * @param options - Optional hooks for request/response interception\n * @returns The final Response (either from onRequest, fetch, or transformed by onResponse)\n *\n * @example\n * const response = await fetchWithHooks(url, fetchInit, {\n * onRequest: async (url, init) => {\n * console.log('Fetching:', url.href);\n * },\n * onResponse: async (url, response) => {\n * if (response.redirected) {\n * console.log('Redirected to:', response.url);\n * }\n * },\n * });\n */\nexport async function fetchWithHooks(\n url: URL,\n init: RequestInit,\n options: FetchWithHooksOptions = {},\n): Promise<Response> {\n const { onRequest, onResponse } = options;\n\n // Call onRequest hook if provided - may return a Response to skip fetching\n let res = await onRequest?.(url, init);\n if (!res) {\n res = await fetch(url, init);\n }\n\n // Call onResponse hook if provided - may return a transformed Response\n const transformedRes = await onResponse?.(url, res);\n if (transformedRes) {\n res = transformedRes;\n }\n\n return res;\n}\n"],"mappings":"AAqCA,eAAsB,eACpB,KACA,MACA,UAAiC,CAAC,GACf;AACnB,QAAM,EAAE,WAAW,WAAW,IAAI;AAGlC,MAAI,MAAM,MAAM,YAAY,KAAK,IAAI;AACrC,MAAI,CAAC,KAAK;AACR,UAAM,MAAM,MAAM,KAAK,IAAI;AAAA,EAC7B;AAGA,QAAM,iBAAiB,MAAM,aAAa,KAAK,GAAG;AAClD,MAAI,gBAAgB;AAClB,UAAM;AAAA,EACR;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../src/shared/ssr/fetch-with-hooks.ts"],"sourcesContent":["import { remoteFetchHeaders } from './fetch-headers';\nimport { fetchWithProtectedRcFallback } from './fetch-with-protected-rc-fallback';\nimport type { OnRequestHook, OnResponseHook } from './types';\n\n/**\n * Options for fetching with request/response hooks.\n */\nexport interface FetchWithHooksOptions {\n /** Hook to intercept the request before fetching */\n onRequest?: OnRequestHook;\n /** Hook to process the response after fetching */\n onResponse?: OnResponseHook;\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 * @param url - The URL to fetch\n * @param init - The fetch init options\n * @param options - Optional hooks for request/response interception\n * @returns The final Response (either from onRequest, fetch, or transformed by onResponse)\n *\n * @example\n * const response = await fetchWithHooks(url, fetchInit, {\n * onRequest: async (url, init) => {\n * console.log('Fetching:', url.href);\n * },\n * onResponse: async (url, response) => {\n * if (response.redirected) {\n * console.log('Redirected to:', response.url);\n * }\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 { onRequest, onResponse } = options;\n\n // fetch the remote component\n const init = {\n method: 'GET',\n headers: remoteFetchHeaders(),\n ...additionalInit,\n };\n\n // Call onRequest hook if provided - may return a Response to skip fetching\n let res = await onRequest?.(url, init);\n if (!res) {\n res = await fetchWithProtectedRcFallback(url, init);\n }\n\n // Call onResponse hook if provided - may return a transformed Response\n const transformedRes = await onResponse?.(url, res);\n if (transformedRes) {\n res = transformedRes;\n }\n\n return res;\n}\n"],"mappings":"AAAA,SAAS,0BAA0B;AACnC,SAAS,oCAAoC;AAsC7C,eAAsB,eACpB,KACA,gBAMA,UAAiC,CAAC,GACf;AACnB,QAAM,EAAE,WAAW,WAAW,IAAI;AAGlC,QAAM,OAAO;AAAA,IACX,QAAQ;AAAA,IACR,SAAS,mBAAmB;AAAA,IAC5B,GAAG;AAAA,EACL;AAGA,MAAI,MAAM,MAAM,YAAY,KAAK,IAAI;AACrC,MAAI,CAAC,KAAK;AACR,UAAM,MAAM,6BAA6B,KAAK,IAAI;AAAA,EACpD;AAGA,QAAM,iBAAiB,MAAM,aAAa,KAAK,GAAG;AAClD,MAAI,gBAAgB;AAClB,UAAM;AAAA,EACR;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,57 @@
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 fetch_with_protected_rc_fallback_exports = {};
20
+ __export(fetch_with_protected_rc_fallback_exports, {
21
+ RC_PROTECTED_REMOTE_FETCH_PATHNAME: () => RC_PROTECTED_REMOTE_FETCH_PATHNAME,
22
+ fetchWithProtectedRcFallback: () => fetchWithProtectedRcFallback
23
+ });
24
+ module.exports = __toCommonJS(fetch_with_protected_rc_fallback_exports);
25
+ var import_logger = require("#internal/shared/utils/logger");
26
+ const RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
27
+ async function fetchWithProtectedRcFallback(url, init) {
28
+ try {
29
+ const res = await fetch(url, init);
30
+ return res;
31
+ } catch (error) {
32
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
33
+ (0, import_logger.logInfo)(
34
+ "FetchRemoteComponent",
35
+ "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
36
+ );
37
+ const proxiedRes = await fetch(
38
+ `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`
39
+ );
40
+ if (proxiedRes.status === 200) {
41
+ return proxiedRes;
42
+ } else {
43
+ (0, import_logger.logError)(
44
+ "FetchRemoteComponent",
45
+ `Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
46
+ );
47
+ }
48
+ }
49
+ throw error;
50
+ }
51
+ }
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ RC_PROTECTED_REMOTE_FETCH_PATHNAME,
55
+ fetchWithProtectedRcFallback
56
+ });
57
+ //# sourceMappingURL=fetch-with-protected-rc-fallback.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/shared/ssr/fetch-with-protected-rc-fallback.ts"],"sourcesContent":["import { logError, logInfo } from '#internal/shared/utils/logger';\n\nexport const RC_PROTECTED_REMOTE_FETCH_PATHNAME = '/rc-fetch-protected-remote';\n\n/**\n * When a vercel host preview fetches a vercel protected remote preview on the\n * client, the request will reject as it's not possible to authenticate for the\n * protected deployment in a client side fetch - cookies cannot be shared across\n * domains. To enable previews, this request is proxied via the host where the\n * process.env.VERCEL_AUTOMATION_BYPASS_SECRET will be added.\n */\nexport async function fetchWithProtectedRcFallback(\n url: URL | string,\n init?: RequestInit,\n): Promise<Response> {\n try {\n const res = await fetch(url, init);\n return res;\n } catch (error) {\n if (\n typeof document === 'object' &&\n typeof document.location === 'object' &&\n document.location.origin !== new URL(url).origin\n ) {\n logInfo(\n 'FetchRemoteComponent',\n 'Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy.',\n );\n const proxiedRes = await fetch(\n `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`,\n );\n if (proxiedRes.status === 200) {\n return proxiedRes;\n } else {\n logError(\n 'FetchRemoteComponent',\n `Could not proxy remote: [response status ${\n proxiedRes.status\n }] ${await proxiedRes.text()}`,\n );\n }\n }\n\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAkC;AAE3B,MAAM,qCAAqC;AASlD,eAAsB,6BACpB,KACA,MACmB;AACnB,MAAI;AACF,UAAM,MAAM,MAAM,MAAM,KAAK,IAAI;AACjC,WAAO;AAAA,EACT,SAAS,OAAP;AACA,QACE,OAAO,aAAa,YACpB,OAAO,SAAS,aAAa,YAC7B,SAAS,SAAS,WAAW,IAAI,IAAI,GAAG,EAAE,QAC1C;AACA;AAAA,QACE;AAAA,QACA;AAAA,MACF;AACA,YAAM,aAAa,MAAM;AAAA,QACvB,GAAG,0CAA0C;AAAA,MAC/C;AACA,UAAI,WAAW,WAAW,KAAK;AAC7B,eAAO;AAAA,MACT,OAAO;AACL;AAAA,UACE;AAAA,UACA,4CACE,WAAW,WACR,MAAM,WAAW,KAAK;AAAA,QAC7B;AAAA,MACF;AAAA,IACF;AAEA,UAAM;AAAA,EACR;AACF;","names":[]}
@@ -0,0 +1,11 @@
1
+ declare const RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
2
+ /**
3
+ * When a vercel host preview fetches a vercel protected remote preview on the
4
+ * client, the request will reject as it's not possible to authenticate for the
5
+ * protected deployment in a client side fetch - cookies cannot be shared across
6
+ * domains. To enable previews, this request is proxied via the host where the
7
+ * process.env.VERCEL_AUTOMATION_BYPASS_SECRET will be added.
8
+ */
9
+ declare function fetchWithProtectedRcFallback(url: URL | string, init?: RequestInit): Promise<Response>;
10
+
11
+ export { RC_PROTECTED_REMOTE_FETCH_PATHNAME, fetchWithProtectedRcFallback };
@@ -0,0 +1,32 @@
1
+ import { logError, logInfo } from "#internal/shared/utils/logger";
2
+ const RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
3
+ async function fetchWithProtectedRcFallback(url, init) {
4
+ try {
5
+ const res = await fetch(url, init);
6
+ return res;
7
+ } catch (error) {
8
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
9
+ logInfo(
10
+ "FetchRemoteComponent",
11
+ "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
12
+ );
13
+ const proxiedRes = await fetch(
14
+ `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`
15
+ );
16
+ if (proxiedRes.status === 200) {
17
+ return proxiedRes;
18
+ } else {
19
+ logError(
20
+ "FetchRemoteComponent",
21
+ `Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
22
+ );
23
+ }
24
+ }
25
+ throw error;
26
+ }
27
+ }
28
+ export {
29
+ RC_PROTECTED_REMOTE_FETCH_PATHNAME,
30
+ fetchWithProtectedRcFallback
31
+ };
32
+ //# sourceMappingURL=fetch-with-protected-rc-fallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/shared/ssr/fetch-with-protected-rc-fallback.ts"],"sourcesContent":["import { logError, logInfo } from '#internal/shared/utils/logger';\n\nexport const RC_PROTECTED_REMOTE_FETCH_PATHNAME = '/rc-fetch-protected-remote';\n\n/**\n * When a vercel host preview fetches a vercel protected remote preview on the\n * client, the request will reject as it's not possible to authenticate for the\n * protected deployment in a client side fetch - cookies cannot be shared across\n * domains. To enable previews, this request is proxied via the host where the\n * process.env.VERCEL_AUTOMATION_BYPASS_SECRET will be added.\n */\nexport async function fetchWithProtectedRcFallback(\n url: URL | string,\n init?: RequestInit,\n): Promise<Response> {\n try {\n const res = await fetch(url, init);\n return res;\n } catch (error) {\n if (\n typeof document === 'object' &&\n typeof document.location === 'object' &&\n document.location.origin !== new URL(url).origin\n ) {\n logInfo(\n 'FetchRemoteComponent',\n 'Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy.',\n );\n const proxiedRes = await fetch(\n `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`,\n );\n if (proxiedRes.status === 200) {\n return proxiedRes;\n } else {\n logError(\n 'FetchRemoteComponent',\n `Could not proxy remote: [response status ${\n proxiedRes.status\n }] ${await proxiedRes.text()}`,\n );\n }\n }\n\n throw error;\n }\n}\n"],"mappings":"AAAA,SAAS,UAAU,eAAe;AAE3B,MAAM,qCAAqC;AASlD,eAAsB,6BACpB,KACA,MACmB;AACnB,MAAI;AACF,UAAM,MAAM,MAAM,MAAM,KAAK,IAAI;AACjC,WAAO;AAAA,EACT,SAAS,OAAP;AACA,QACE,OAAO,aAAa,YACpB,OAAO,SAAS,aAAa,YAC7B,SAAS,SAAS,WAAW,IAAI,IAAI,GAAG,EAAE,QAC1C;AACA;AAAA,QACE;AAAA,QACA;AAAA,MACF;AACA,YAAM,aAAa,MAAM;AAAA,QACvB,GAAG,0CAA0C;AAAA,MAC/C;AACA,UAAI,WAAW,WAAW,KAAK;AAC7B,eAAO;AAAA,MACT,OAAO;AACL;AAAA,UACE;AAAA,UACA,4CACE,WAAW,WACR,MAAM,WAAW,KAAK;AAAA,QAC7B;AAAA,MACF;AAAA,IACF;AAEA,UAAM;AAAA,EACR;AACF;","names":[]}
@@ -20,6 +20,7 @@ var logger_exports = {};
20
20
  __export(logger_exports, {
21
21
  logDebug: () => logDebug,
22
22
  logError: () => logError,
23
+ logInfo: () => logInfo,
23
24
  logWarn: () => logWarn
24
25
  });
25
26
  module.exports = __toCommonJS(logger_exports);
@@ -31,6 +32,9 @@ function logDebug(location, message) {
31
32
  console.debug(`[${PREFIX}:${location}]: ${message}`);
32
33
  }
33
34
  }
35
+ function logInfo(location, message) {
36
+ console.info(`[${PREFIX}:${location}]: ${message}`);
37
+ }
34
38
  function logWarn(location, message) {
35
39
  console.warn(`[${PREFIX}:${location}]: ${message}`);
36
40
  }
@@ -45,6 +49,7 @@ function logError(location, message, cause) {
45
49
  0 && (module.exports = {
46
50
  logDebug,
47
51
  logError,
52
+ logInfo,
48
53
  logWarn
49
54
  });
50
55
  //# sourceMappingURL=logger.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/shared/utils/logger.ts"],"sourcesContent":["import { RemoteComponentsError } from '#internal/shared/error';\n\ntype LogLocation =\n | 'ChunkLoader'\n | 'ComponentLoader'\n | 'SharedModules'\n | 'WebpackAdapter'\n | 'TurbopackModule'\n | 'StaticLoader'\n | 'Polyfill'\n | 'HtmlRemote'\n | 'HtmlHost'\n | 'Config'\n | 'NextAppRouter'\n | 'NextAppRouterCompat'\n | 'FetchRemoteComponent';\n\nconst PREFIX = 'remote-components';\nconst DEBUG =\n typeof window !== 'undefined' && localStorage.getItem('RC_DEBUG') === 'true';\n\nexport function logDebug(location: LogLocation, message: string) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.debug(`[${PREFIX}:${location}]: ${message}`);\n }\n}\n\nexport function logInfo(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.info(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logWarn(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.warn(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logError(\n location: LogLocation,\n message: string,\n cause?: unknown,\n) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(`[${PREFIX}:${location}]: ${message}`, {\n cause,\n }),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsC;AAiBtC,MAAM,SAAS;AACf,MAAM,QACJ,OAAO,WAAW,eAAe,aAAa,QAAQ,UAAU,MAAM;AAEjE,SAAS,SAAS,UAAuB,SAAiB;AAC/D,MAAI,OAAO;AAET,YAAQ,MAAM,IAAI,UAAU,cAAc,SAAS;AAAA,EACrD;AACF;AAEO,SAAS,QAAQ,UAAuB,SAAiB;AAE9D,UAAQ,KAAK,IAAI,UAAU,cAAc,SAAS;AACpD;AAEO,SAAS,QAAQ,UAAuB,SAAiB;AAE9D,UAAQ,KAAK,IAAI,UAAU,cAAc,SAAS;AACpD;AAEO,SAAS,SACd,UACA,SACA,OACA;AAEA,UAAQ;AAAA,IACN,IAAI,mCAAsB,IAAI,UAAU,cAAc,WAAW;AAAA,MAC/D;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1,6 +1,7 @@
1
- type LogLocation = 'ChunkLoader' | 'ComponentLoader' | 'SharedModules' | 'WebpackAdapter' | 'TurbopackModule' | 'StaticLoader' | 'Polyfill' | 'HtmlRemote' | 'HtmlHost' | 'Config' | 'NextAppRouter' | 'NextAppRouterCompat';
1
+ type LogLocation = 'ChunkLoader' | 'ComponentLoader' | 'SharedModules' | 'WebpackAdapter' | 'TurbopackModule' | 'StaticLoader' | 'Polyfill' | 'HtmlRemote' | 'HtmlHost' | 'Config' | 'NextAppRouter' | 'NextAppRouterCompat' | 'FetchRemoteComponent';
2
2
  declare function logDebug(location: LogLocation, message: string): void;
3
+ declare function logInfo(location: LogLocation, message: string): void;
3
4
  declare function logWarn(location: LogLocation, message: string): void;
4
5
  declare function logError(location: LogLocation, message: string, cause?: unknown): void;
5
6
 
6
- export { logDebug, logError, logWarn };
7
+ export { logDebug, logError, logInfo, logWarn };
@@ -6,6 +6,9 @@ function logDebug(location, message) {
6
6
  console.debug(`[${PREFIX}:${location}]: ${message}`);
7
7
  }
8
8
  }
9
+ function logInfo(location, message) {
10
+ console.info(`[${PREFIX}:${location}]: ${message}`);
11
+ }
9
12
  function logWarn(location, message) {
10
13
  console.warn(`[${PREFIX}:${location}]: ${message}`);
11
14
  }
@@ -19,6 +22,7 @@ function logError(location, message, cause) {
19
22
  export {
20
23
  logDebug,
21
24
  logError,
25
+ logInfo,
22
26
  logWarn
23
27
  };
24
28
  //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/shared/utils/logger.ts"],"sourcesContent":["import { RemoteComponentsError } from '#internal/shared/error';\n\ntype LogLocation =\n | 'ChunkLoader'\n | 'ComponentLoader'\n | 'SharedModules'\n | 'WebpackAdapter'\n | 'TurbopackModule'\n | 'StaticLoader'\n | 'Polyfill'\n | 'HtmlRemote'\n | 'HtmlHost'\n | 'Config'\n | 'NextAppRouter'\n | 'NextAppRouterCompat'\n | 'FetchRemoteComponent';\n\nconst PREFIX = 'remote-components';\nconst DEBUG =\n typeof window !== 'undefined' && localStorage.getItem('RC_DEBUG') === 'true';\n\nexport function logDebug(location: LogLocation, message: string) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.debug(`[${PREFIX}:${location}]: ${message}`);\n }\n}\n\nexport function logInfo(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.info(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logWarn(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.warn(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logError(\n location: LogLocation,\n message: string,\n cause?: unknown,\n) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(`[${PREFIX}:${location}]: ${message}`, {\n cause,\n }),\n );\n}\n"],"mappings":"AAAA,SAAS,6BAA6B;AAiBtC,MAAM,SAAS;AACf,MAAM,QACJ,OAAO,WAAW,eAAe,aAAa,QAAQ,UAAU,MAAM;AAEjE,SAAS,SAAS,UAAuB,SAAiB;AAC/D,MAAI,OAAO;AAET,YAAQ,MAAM,IAAI,UAAU,cAAc,SAAS;AAAA,EACrD;AACF;AAEO,SAAS,QAAQ,UAAuB,SAAiB;AAE9D,UAAQ,KAAK,IAAI,UAAU,cAAc,SAAS;AACpD;AAEO,SAAS,QAAQ,UAAuB,SAAiB;AAE9D,UAAQ,KAAK,IAAI,UAAU,cAAc,SAAS;AACpD;AAEO,SAAS,SACd,UACA,SACA,OACA;AAEA,UAAQ;AAAA,IACN,IAAI,sBAAsB,IAAI,UAAU,cAAc,WAAW;AAAA,MAC/D;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -19,13 +19,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var utils_exports = {};
20
20
  __export(utils_exports, {
21
21
  attrToProp: () => attrToProp,
22
- escapeString: () => escapeString,
23
- logDebug: () => import_logger.logDebug,
24
- logError: () => import_logger.logError,
25
- logWarn: () => import_logger.logWarn
22
+ escapeString: () => escapeString
26
23
  });
27
24
  module.exports = __toCommonJS(utils_exports);
28
- var import_logger = require("./logger");
29
25
  function escapeString(str) {
30
26
  return str.replace(/[^a-z0-9]/g, "_");
31
27
  }
@@ -39,9 +35,6 @@ const attrToProp = {
39
35
  // Annotate the CommonJS export names for ESM import in node:
40
36
  0 && (module.exports = {
41
37
  attrToProp,
42
- escapeString,
43
- logDebug,
44
- logError,
45
- logWarn
38
+ escapeString
46
39
  });
47
40
  //# sourceMappingURL=utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/shared/utils/index.ts"],"sourcesContent":["export { logDebug, logError, logWarn } from './logger';\n\nexport function escapeString(str: string) {\n return str.replace(/[^a-z0-9]/g, '_');\n}\n\nexport const attrToProp = {\n fetchpriority: 'fetchPriority',\n crossorigin: 'crossOrigin',\n imagesrcset: 'imageSrcSet',\n imagesizes: 'imageSizes',\n srcset: 'srcSet',\n} as Record<string, string>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4C;AAErC,SAAS,aAAa,KAAa;AACxC,SAAO,IAAI,QAAQ,cAAc,GAAG;AACtC;AAEO,MAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AACV;","names":[]}
1
+ {"version":3,"sources":["../../../src/shared/utils/index.ts"],"sourcesContent":["export function escapeString(str: string) {\n return str.replace(/[^a-z0-9]/g, '_');\n}\n\nexport const attrToProp = {\n fetchpriority: 'fetchPriority',\n crossorigin: 'crossOrigin',\n imagesrcset: 'imageSrcSet',\n imagesizes: 'imageSizes',\n srcset: 'srcSet',\n} as Record<string, string>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,aAAa,KAAa;AACxC,SAAO,IAAI,QAAQ,cAAc,GAAG;AACtC;AAEO,MAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AACV;","names":[]}
@@ -1,5 +1,3 @@
1
- export { logDebug, logError, logWarn } from './logger.js';
2
-
3
1
  declare function escapeString(str: string): string;
4
2
  declare const attrToProp: Record<string, string>;
5
3
 
@@ -1,4 +1,3 @@
1
- import { logDebug, logError, logWarn } from "./logger";
2
1
  function escapeString(str) {
3
2
  return str.replace(/[^a-z0-9]/g, "_");
4
3
  }
@@ -11,9 +10,6 @@ const attrToProp = {
11
10
  };
12
11
  export {
13
12
  attrToProp,
14
- escapeString,
15
- logDebug,
16
- logError,
17
- logWarn
13
+ escapeString
18
14
  };
19
15
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/shared/utils/index.ts"],"sourcesContent":["export { logDebug, logError, logWarn } from './logger';\n\nexport function escapeString(str: string) {\n return str.replace(/[^a-z0-9]/g, '_');\n}\n\nexport const attrToProp = {\n fetchpriority: 'fetchPriority',\n crossorigin: 'crossOrigin',\n imagesrcset: 'imageSrcSet',\n imagesizes: 'imageSizes',\n srcset: 'srcSet',\n} as Record<string, string>;\n"],"mappings":"AAAA,SAAS,UAAU,UAAU,eAAe;AAErC,SAAS,aAAa,KAAa;AACxC,SAAO,IAAI,QAAQ,cAAc,GAAG;AACtC;AAEO,MAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AACV;","names":[]}
1
+ {"version":3,"sources":["../../../src/shared/utils/index.ts"],"sourcesContent":["export function escapeString(str: string) {\n return str.replace(/[^a-z0-9]/g, '_');\n}\n\nexport const attrToProp = {\n fetchpriority: 'fetchPriority',\n crossorigin: 'crossOrigin',\n imagesrcset: 'imageSrcSet',\n imagesizes: 'imageSizes',\n srcset: 'srcSet',\n} as Record<string, string>;\n"],"mappings":"AAAO,SAAS,aAAa,KAAa;AACxC,SAAO,IAAI,QAAQ,cAAc,GAAG;AACtC;AAEO,MAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AACV;","names":[]}