remote-components 0.0.34 → 0.0.36

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 (66) hide show
  1. package/dist/html/host.cjs +127 -117
  2. package/dist/html/host.cjs.map +1 -1
  3. package/dist/html/host.js +127 -117
  4. package/dist/html/host.js.map +1 -1
  5. package/dist/html/remote.cjs +4 -3
  6. package/dist/html/remote.cjs.map +1 -1
  7. package/dist/html/remote.js +4 -3
  8. package/dist/html/remote.js.map +1 -1
  9. package/dist/internal/next/host/app-router-client.cjs +4 -15
  10. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  11. package/dist/internal/next/host/app-router-client.js +10 -21
  12. package/dist/internal/next/host/app-router-client.js.map +1 -1
  13. package/dist/internal/next/host/app-router-compat.cjs.map +1 -1
  14. package/dist/internal/next/host/app-router-compat.d.ts +1 -1
  15. package/dist/internal/next/host/app-router-compat.js.map +1 -1
  16. package/dist/internal/next/remote/render-server.cjs +1 -1
  17. package/dist/internal/next/remote/render-server.cjs.map +1 -1
  18. package/dist/internal/next/remote/render-server.js +1 -1
  19. package/dist/internal/next/remote/render-server.js.map +1 -1
  20. package/dist/internal/shared/client/polyfill.cjs.map +1 -1
  21. package/dist/internal/shared/client/polyfill.js.map +1 -1
  22. package/dist/internal/shared/client/remote-component.cjs +179 -174
  23. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  24. package/dist/internal/shared/client/remote-component.d.ts +23 -23
  25. package/dist/internal/shared/client/remote-component.js +179 -174
  26. package/dist/internal/shared/client/remote-component.js.map +1 -1
  27. package/dist/internal/shared/error.cjs +1 -1
  28. package/dist/internal/shared/error.cjs.map +1 -1
  29. package/dist/internal/shared/error.js +1 -1
  30. package/dist/internal/shared/error.js.map +1 -1
  31. package/dist/internal/shared/ssr/dom-flight.cjs +7 -3
  32. package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
  33. package/dist/internal/shared/ssr/dom-flight.js +7 -3
  34. package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
  35. package/dist/internal/shared/ssr/fetch-remote-component.cjs +4 -4
  36. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  37. package/dist/internal/shared/ssr/fetch-remote-component.js +5 -5
  38. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  39. package/dist/next/config.cjs +100 -86
  40. package/dist/next/config.cjs.map +1 -1
  41. package/dist/next/config.js +100 -86
  42. package/dist/next/config.js.map +1 -1
  43. package/dist/next/host/app-router-server.cjs.map +1 -1
  44. package/dist/next/host/app-router-server.js +1 -1
  45. package/dist/next/host/app-router-server.js.map +1 -1
  46. package/dist/next/host/client/index.cjs +723 -718
  47. package/dist/next/host/client/index.cjs.map +1 -1
  48. package/dist/next/host/client/index.js +727 -722
  49. package/dist/next/host/client/index.js.map +1 -1
  50. package/dist/next/host/pages-router-server.cjs +4 -4
  51. package/dist/next/host/pages-router-server.cjs.map +1 -1
  52. package/dist/next/host/pages-router-server.js +4 -4
  53. package/dist/next/host/pages-router-server.js.map +1 -1
  54. package/dist/next/{middleware.cjs → proxy.cjs} +24 -14
  55. package/dist/next/proxy.cjs.map +1 -0
  56. package/dist/next/proxy.d.ts +29 -0
  57. package/dist/next/{middleware.js → proxy.js} +21 -11
  58. package/dist/next/proxy.js.map +1 -0
  59. package/dist/react/index.cjs +4 -4
  60. package/dist/react/index.cjs.map +1 -1
  61. package/dist/react/index.js +11 -11
  62. package/dist/react/index.js.map +1 -1
  63. package/package.json +15 -9
  64. package/dist/next/middleware.cjs.map +0 -1
  65. package/dist/next/middleware.d.ts +0 -29
  66. package/dist/next/middleware.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/remote/render-server.tsx"],"sourcesContent":["import { Suspense } from 'react';\nimport { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport { RemoteComponentSharedRemote } from '#internal/next/remote/render-client';\nimport { RemoteComponentsError } from '#internal/shared/error';\nimport type { Manifest } from './types';\n\n// internal Next.js symbol to access the manifest which is stored in the global scope\nconst SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nasync function tryImport<T>(importer: () => Promise<T>) {\n try {\n return (await importer()) as T;\n } catch {\n return {} as T;\n }\n}\n\n// inject the RSC flight data into the HTML response using <script>\n// the RSC flight data is used to hydrate the remote component on the host\n// this approach is similar to an island architecture on the host\n// the remote component is static HTML until it is hydrated using this RSC flight data\nfunction RemoteComponentData({ name, data }: { name: string; data: string[] }) {\n return (\n <script id={`${name}_rsc`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''}self[\"${name}\"].push(${JSON.stringify(\n chunk,\n )});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\nexport interface RemoteComponentProps {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * RemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<RemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { RemoteComponent } from 'remote-components/next';\n *\n * export default function MyPage() {\n * return (\n * <RemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </RemoteComponent>\n * );\n * }\n * ```\n */\nexport async function RemoteComponent({\n name = '__vercel_remote_component',\n children,\n}: RemoteComponentProps): Promise<React.ReactElement> {\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? {\n page: '/',\n route: '/',\n };\n\n // get reference to the manifests from the global scope\n const manifests = (\n globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n }\n )[SERVER_ACTION_MANIFESTS_SINGLETON];\n const manifest = manifests.clientReferenceManifestsPerPage?.[route];\n\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n };\n\n // manually handle the internal Next.js manifest\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\n let clientModules = manifest?.clientModules ?? {};\n const ssrModuleMapping = { ...manifest?.ssrModuleMapping };\n\n // if the remote component is used in a hosting application, we need to mutate the module map to include the zone\n clientModules = Object.fromEntries(\n Object.entries(clientModules).map(([key, value]) => {\n // append a prefix to each entry in the module map to include the zone of the remote component\n const remoteId = `[${PROJECT_ID}] ${value.id}`;\n ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];\n // override the original id with the new remote id\n return [\n key,\n {\n ...value,\n id: remoteId,\n // prepend the current zone to the chunks to handle remote component chunk loading in Webpack\n // this is required to avoid loading the wrong chunk in the host application\n chunks: value.chunks.map((chunk) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [\n { renderToReadableStream: nextRenderToReadableStream },\n { renderToReadableStream: legacyRenderToReadableStream },\n ] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n const renderToReadableStream =\n nextRenderToReadableStream ?? legacyRenderToReadableStream;\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\n\n const data = [];\n const decoder = new TextDecoder();\n\n // convert the stream to an array for safe passing to the client\n for await (const chunk of stream as unknown as AsyncIterable<Uint8Array>) {\n data.push(decoder.decode(chunk));\n }\n\n const runtime = process.env.TURBOPACK ? 'turbopack' : 'webpack';\n const remoteComponentName = `${name}_${route.replace(/[/[\\].]/g, '_')}`;\n\n return (\n // wrap the remote component content into a div to know which part of the HTML belongs to the remote component\n <div\n data-bundle={PROJECT_ID}\n data-route={route}\n data-runtime={runtime}\n data-type=\"nextjs\"\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BI;AA9BJ,mBAAyB;AACzB,gCAAiC;AACjC,2BAA4C;AAC5C,mBAAsC;AAItC,MAAM,oCAAoC,OAAO;AAAA,EAC/C;AACF;AAEA,MAAM,aACJ,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI;AAEd,eAAe,UAAa,UAA4B;AACtD,MAA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AA,UAGF,4CAAC,uBAAoB,MAAY,MAAM,qBAAqB;AAAA;AAAA;AAAA,IAC9D;AAAA;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/next/remote/render-server.tsx"],"sourcesContent":["import { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport { Suspense } from 'react';\nimport { RemoteComponentSharedRemote } from '#internal/next/remote/render-client';\nimport { RemoteComponentsError } from '#internal/shared/error';\nimport type { Manifest } from './types';\n\n// internal Next.js symbol to access the manifest which is stored in the global scope\nconst SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nasync function tryImport<T>(importer: () => Promise<T>) {\n try {\n return (await importer()) as T;\n } catch {\n return {} as T;\n }\n}\n\n// inject the RSC flight data into the HTML response using <script>\n// the RSC flight data is used to hydrate the remote component on the host\n// this approach is similar to an island architecture on the host\n// the remote component is static HTML until it is hydrated using this RSC flight data\nfunction RemoteComponentData({ name, data }: { name: string; data: string[] }) {\n return (\n <script id={`${name}_rsc`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''}self[\"${name}\"].push(${JSON.stringify(\n chunk,\n )});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\nexport interface RemoteComponentProps {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * RemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<RemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { RemoteComponent } from 'remote-components/next';\n *\n * export default function MyPage() {\n * return (\n * <RemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </RemoteComponent>\n * );\n * }\n * ```\n */\nexport async function RemoteComponent({\n name = '__vercel_remote_component',\n children,\n}: RemoteComponentProps): Promise<React.ReactElement> {\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? {\n page: '/',\n route: '/',\n };\n\n // get reference to the manifests from the global scope\n const manifests = (\n globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n }\n )[SERVER_ACTION_MANIFESTS_SINGLETON];\n const manifest = manifests.clientReferenceManifestsPerPage?.[route];\n\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n };\n\n // manually handle the internal Next.js manifest\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\n let clientModules = manifest?.clientModules ?? {};\n const ssrModuleMapping = { ...manifest?.ssrModuleMapping };\n\n // if the remote component is used in a hosting application, we need to mutate the module map to include the zone\n clientModules = Object.fromEntries(\n Object.entries(clientModules).map(([key, value]) => {\n // append a prefix to each entry in the module map to include the zone of the remote component\n const remoteId = `[${PROJECT_ID}] ${value.id}`;\n ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];\n // override the original id with the new remote id\n return [\n key,\n {\n ...value,\n id: remoteId,\n // prepend the current zone to the chunks to handle remote component chunk loading in Webpack\n // this is required to avoid loading the wrong chunk in the host application\n chunks: value.chunks.map((chunk) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [\n { renderToReadableStream: nextRenderToReadableStream },\n { renderToReadableStream: legacyRenderToReadableStream },\n ] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n const renderToReadableStream =\n nextRenderToReadableStream ?? legacyRenderToReadableStream;\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\n\n const data = [];\n const decoder = new TextDecoder();\n\n // convert the stream to an array for safe passing to the client\n for await (const chunk of stream as unknown as AsyncIterable<Uint8Array>) {\n data.push(decoder.decode(chunk));\n }\n\n const runtime = process.env.TURBOPACK ? 'turbopack' : 'webpack';\n const remoteComponentName = `${name}_${route.replace(/[/[\\].]/g, '_')}`;\n\n return (\n // wrap the remote component content into a div to know which part of the HTML belongs to the remote component\n <div\n data-bundle={PROJECT_ID}\n data-route={route}\n data-runtime={runtime}\n data-type=\"nextjs\"\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],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AAAA,sDAAC,oDAA4B,MAAM,qBAAqB;AAAA,UACvD,OAAO,UAAU,cAChB,4EACE;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,2BACE,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,gBAEvD,yBACE,iBAAiB,QAAS,MAAM,SAAS,KAAM;AAAA;AAAA,YAEnD;AAAA,YACA,4CAAC,yBAAS,UAAU,MAAO,UAAS;AAAA,aACtC,IAEA;AAAA,UAGF,4CAAC,uBAAoB,MAAY,MAAM,qBAAqB;AAAA;AAAA;AAAA,IAC9D;AAAA;AAEJ;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { Suspense } from "react";
3
2
  import { workAsyncStorage } from "next/dist/server/app-render/work-async-storage.external";
3
+ import { Suspense } from "react";
4
4
  import { RemoteComponentSharedRemote } from "#internal/next/remote/render-client";
5
5
  import { RemoteComponentsError } from "#internal/shared/error";
6
6
  const SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/remote/render-server.tsx"],"sourcesContent":["import { Suspense } from 'react';\nimport { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport { RemoteComponentSharedRemote } from '#internal/next/remote/render-client';\nimport { RemoteComponentsError } from '#internal/shared/error';\nimport type { Manifest } from './types';\n\n// internal Next.js symbol to access the manifest which is stored in the global scope\nconst SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nasync function tryImport<T>(importer: () => Promise<T>) {\n try {\n return (await importer()) as T;\n } catch {\n return {} as T;\n }\n}\n\n// inject the RSC flight data into the HTML response using <script>\n// the RSC flight data is used to hydrate the remote component on the host\n// this approach is similar to an island architecture on the host\n// the remote component is static HTML until it is hydrated using this RSC flight data\nfunction RemoteComponentData({ name, data }: { name: string; data: string[] }) {\n return (\n <script id={`${name}_rsc`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''}self[\"${name}\"].push(${JSON.stringify(\n chunk,\n )});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\nexport interface RemoteComponentProps {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * RemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<RemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { RemoteComponent } from 'remote-components/next';\n *\n * export default function MyPage() {\n * return (\n * <RemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </RemoteComponent>\n * );\n * }\n * ```\n */\nexport async function RemoteComponent({\n name = '__vercel_remote_component',\n children,\n}: RemoteComponentProps): Promise<React.ReactElement> {\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? {\n page: '/',\n route: '/',\n };\n\n // get reference to the manifests from the global scope\n const manifests = (\n globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n }\n )[SERVER_ACTION_MANIFESTS_SINGLETON];\n const manifest = manifests.clientReferenceManifestsPerPage?.[route];\n\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n };\n\n // manually handle the internal Next.js manifest\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\n let clientModules = manifest?.clientModules ?? {};\n const ssrModuleMapping = { ...manifest?.ssrModuleMapping };\n\n // if the remote component is used in a hosting application, we need to mutate the module map to include the zone\n clientModules = Object.fromEntries(\n Object.entries(clientModules).map(([key, value]) => {\n // append a prefix to each entry in the module map to include the zone of the remote component\n const remoteId = `[${PROJECT_ID}] ${value.id}`;\n ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];\n // override the original id with the new remote id\n return [\n key,\n {\n ...value,\n id: remoteId,\n // prepend the current zone to the chunks to handle remote component chunk loading in Webpack\n // this is required to avoid loading the wrong chunk in the host application\n chunks: value.chunks.map((chunk) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [\n { renderToReadableStream: nextRenderToReadableStream },\n { renderToReadableStream: legacyRenderToReadableStream },\n ] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n const renderToReadableStream =\n nextRenderToReadableStream ?? legacyRenderToReadableStream;\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\n\n const data = [];\n const decoder = new TextDecoder();\n\n // convert the stream to an array for safe passing to the client\n for await (const chunk of stream as unknown as AsyncIterable<Uint8Array>) {\n data.push(decoder.decode(chunk));\n }\n\n const runtime = process.env.TURBOPACK ? 'turbopack' : 'webpack';\n const remoteComponentName = `${name}_${route.replace(/[/[\\].]/g, '_')}`;\n\n return (\n // wrap the remote component content into a div to know which part of the HTML belongs to the remote component\n <div\n data-bundle={PROJECT_ID}\n data-route={route}\n data-runtime={runtime}\n data-type=\"nextjs\"\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":"AA8BI,SAmKI,UAnKJ,KAmKI,YAnKJ;AA9BJ,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AACjC,SAAS,mCAAmC;AAC5C,SAAS,6BAA6B;AAItC,MAAM,oCAAoC,OAAO;AAAA,EAC/C;AACF;AAEA,MAAM,aACJ,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI;AAEd,eAAe,UAAa,UAA4B;AACtD,MAAI;AACF,WAAQ,MAAM,SAAS;AAAA,EACzB,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAMA,SAAS,oBAAoB,EAAE,MAAM,KAAK,GAAqC;AAC7E,SACE,oBAAC,YAAO,IAAI,GAAG,YACZ,eACE;AAAA,IACC,CAAC,OAAO;AAAA;AAAA,MAEN,GAAG,MAAM,IAAI,SAAS,gBAAgB,gBAAgB,WAAW,eAAe,KAAK;AAAA,QACnF;AAAA,MACF;AAAA;AAAA,EACJ,EACC,KAAK,IAAI,GACd;AAEJ;AAkCA,eAAsB,gBAAgB;AAAA,EACpC,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AA2B,YAAY;AAChD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,MAAI;AAEJ,QAAM,SAAS,uBAAuB,UAAU,eAAe;AAAA,IAC7D,QAAQ,GAAG;AACT,cAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,OAAO,CAAC;AACd,QAAM,UAAU,IAAI,YAAY;AAGhC,mBAAiB,SAAS,QAAgD;AACxE,SAAK,KAAK,QAAQ,OAAO,KAAK,CAAC;AAAA,EACjC;AAEA,QAAM,UAAU,QAAQ,IAAI,YAAY,cAAc;AACtD,QAAM,sBAAsB,GAAG,QAAQ,MAAM,QAAQ,YAAY,GAAG;AAEpE;AAAA;AAAA,IAEE;AAAA,MAAC;AAAA;AAAA,QACC,eAAa;AAAA,QACb,cAAY;AAAA,QACZ,gBAAc;AAAA,QACd,aAAU;AAAA,QACV,IAAI,GAAG;AAAA,QAEP;AAAA,8BAAC,+BAA4B,MAAM,qBAAqB;AAAA,UACvD,OAAO,UAAU,cAChB,iCACE;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,2BACE,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,gBAEvD,yBACE,iBAAiB,QAAS,MAAM,SAAS,KAAM;AAAA;AAAA,YAEnD;AAAA,YACA,oBAAC,YAAS,UAAU,MAAO,UAAS;AAAA,aACtC,IAEA;AAAA,UAGF,oBAAC,uBAAoB,MAAY,MAAM,qBAAqB;AAAA;AAAA;AAAA,IAC9D;AAAA;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/next/remote/render-server.tsx"],"sourcesContent":["import { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport { Suspense } from 'react';\nimport { RemoteComponentSharedRemote } from '#internal/next/remote/render-client';\nimport { RemoteComponentsError } from '#internal/shared/error';\nimport type { Manifest } from './types';\n\n// internal Next.js symbol to access the manifest which is stored in the global scope\nconst SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nasync function tryImport<T>(importer: () => Promise<T>) {\n try {\n return (await importer()) as T;\n } catch {\n return {} as T;\n }\n}\n\n// inject the RSC flight data into the HTML response using <script>\n// the RSC flight data is used to hydrate the remote component on the host\n// this approach is similar to an island architecture on the host\n// the remote component is static HTML until it is hydrated using this RSC flight data\nfunction RemoteComponentData({ name, data }: { name: string; data: string[] }) {\n return (\n <script id={`${name}_rsc`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''}self[\"${name}\"].push(${JSON.stringify(\n chunk,\n )});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\nexport interface RemoteComponentProps {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * RemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<RemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { RemoteComponent } from 'remote-components/next';\n *\n * export default function MyPage() {\n * return (\n * <RemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </RemoteComponent>\n * );\n * }\n * ```\n */\nexport async function RemoteComponent({\n name = '__vercel_remote_component',\n children,\n}: RemoteComponentProps): Promise<React.ReactElement> {\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? {\n page: '/',\n route: '/',\n };\n\n // get reference to the manifests from the global scope\n const manifests = (\n globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n }\n )[SERVER_ACTION_MANIFESTS_SINGLETON];\n const manifest = manifests.clientReferenceManifestsPerPage?.[route];\n\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n };\n\n // manually handle the internal Next.js manifest\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\n let clientModules = manifest?.clientModules ?? {};\n const ssrModuleMapping = { ...manifest?.ssrModuleMapping };\n\n // if the remote component is used in a hosting application, we need to mutate the module map to include the zone\n clientModules = Object.fromEntries(\n Object.entries(clientModules).map(([key, value]) => {\n // append a prefix to each entry in the module map to include the zone of the remote component\n const remoteId = `[${PROJECT_ID}] ${value.id}`;\n ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];\n // override the original id with the new remote id\n return [\n key,\n {\n ...value,\n id: remoteId,\n // prepend the current zone to the chunks to handle remote component chunk loading in Webpack\n // this is required to avoid loading the wrong chunk in the host application\n chunks: value.chunks.map((chunk) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [\n { renderToReadableStream: nextRenderToReadableStream },\n { renderToReadableStream: legacyRenderToReadableStream },\n ] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n const renderToReadableStream =\n nextRenderToReadableStream ?? legacyRenderToReadableStream;\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\n\n const data = [];\n const decoder = new TextDecoder();\n\n // convert the stream to an array for safe passing to the client\n for await (const chunk of stream as unknown as AsyncIterable<Uint8Array>) {\n data.push(decoder.decode(chunk));\n }\n\n const runtime = process.env.TURBOPACK ? 'turbopack' : 'webpack';\n const remoteComponentName = `${name}_${route.replace(/[/[\\].]/g, '_')}`;\n\n return (\n // wrap the remote component content into a div to know which part of the HTML belongs to the remote component\n <div\n data-bundle={PROJECT_ID}\n data-route={route}\n data-runtime={runtime}\n data-type=\"nextjs\"\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":"AA8BI,SAmKI,UAnKJ,KAmKI,YAnKJ;AA9BJ,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;AACzB,SAAS,mCAAmC;AAC5C,SAAS,6BAA6B;AAItC,MAAM,oCAAoC,OAAO;AAAA,EAC/C;AACF;AAEA,MAAM,aACJ,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI;AAEd,eAAe,UAAa,UAA4B;AACtD,MAAI;AACF,WAAQ,MAAM,SAAS;AAAA,EACzB,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAMA,SAAS,oBAA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 -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/client/polyfill.tsx"],"sourcesContent":["import { type LinkProps } from 'next/link';\nimport type { ImageProps, StaticImageData } from 'next/image';\n\nfunction applyBundleUrlToSrc(bundle: string, src: string) {\n const self = globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n };\n\n if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {\n return src;\n }\n\n const { assetPrefix, path } =\n /^(?<assetPrefix>.*?)\\/_next\\/(?<path>.*)/.exec(src)?.groups ?? {};\n if (!path) {\n return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;\n }\n return `${\n self.__remote_bundle_url__?.[bundle]?.origin ?? ''\n }${assetPrefix}/_next/${path}`;\n}\n\nexport function applyBundleUrlToImagePropsSrc(\n bundle: string,\n src: ImageProps['src'],\n) {\n if (typeof src === 'string') {\n return applyBundleUrlToSrc(bundle, src);\n }\n const propSrc = src as StaticImageData;\n return applyBundleUrlToSrc(bundle, propSrc.src);\n}\n\nconst imageImpl = (bundle: string) =>\n function RemoteImage({\n fill: _fill,\n loader: _loader,\n quality: _quality,\n priority: _priority,\n loading: _loading,\n placeholder: _placeholder,\n blurDataURL: _blurDataURL,\n unoptimized: _unoptimized,\n overrideSrc: _overrideSrc,\n src,\n ...props\n }: ImageProps) {\n const newSrc = applyBundleUrlToImagePropsSrc(\n bundle,\n typeof src === 'string' ? src : (src as StaticImageData).src,\n );\n\n return (\n // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text\n <img\n decoding=\"async\"\n style={{ color: 'transparent' }}\n {...props}\n src={newSrc}\n suppressHydrationWarning\n />\n );\n };\n\n// polyfill Next.js App Router client API (minimal)\n// implementations are minimal and do not cover all use cases\n// developer can override these shared modules from configuration\nexport function sharedPolyfills(\n shared?: Record<string, () => Promise<unknown>>,\n) {\n const self = globalThis as typeof globalThis & {\n __remote_component_host_shared_modules__?: Record<\n string,\n () => Promise<unknown>\n >;\n };\n const polyfill = {\n 'next/dist/client/components/navigation':\n self.__remote_component_host_shared_modules__?.['next/navigation'] ??\n shared?.['next/navigation'] ??\n (() =>\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n usePathname() {\n return location.pathname;\n },\n useParams() {\n return {};\n },\n useSearchParams() {\n return new URLSearchParams(location.search);\n },\n useSelectedLayoutSegment() {\n return null;\n },\n useSelectedLayoutSegments() {\n return [];\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/link':\n self.__remote_component_host_shared_modules__?.['next/link'] ??\n shared?.['next/link'] ??\n (() =>\n Promise.resolve({\n default: ({\n scroll: _,\n replace,\n prefetch,\n onNavigate,\n children,\n ...props\n }: React.PropsWithChildren<LinkProps>) => {\n if (prefetch) {\n // eslint-disable-next-line no-console\n console.warn(\n 'Next.js Link prefetch is not supported in remote components',\n );\n }\n return (\n <a\n {...props}\n href={props.href as string}\n onClick={(e) => {\n e.preventDefault();\n let preventDefaulted = false;\n e.preventDefault = () => {\n preventDefaulted = true;\n e.defaultPrevented = true;\n };\n if (typeof props.onClick === 'function') {\n props.onClick(e);\n }\n onNavigate?.(e);\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (preventDefaulted) {\n return;\n }\n if (replace) {\n history.replaceState({}, '', props.href as string);\n } else {\n history.pushState({}, '', props.href as string);\n }\n }}\n suppressHydrationWarning\n >\n {children ?? null}\n </a>\n );\n },\n useLinkStatus() {\n return { pending: false };\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/form':\n self.__remote_component_host_shared_modules__?.['next/form'] ??\n shared?.['next/form'] ??\n (() =>\n Promise.resolve({\n default: () => {\n // TODO: implement <Form> component for non-Next.js host applications\n throw new Error('Next.js <Form> component not implemented');\n },\n __esModule: true,\n })),\n 'next/dist/client/image-component':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n Image: imageImpl(bundle),\n __esModule: true,\n })),\n 'next/image':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n default: imageImpl(bundle),\n getImageProps: (_imgProps: ImageProps) => {\n throw new Error(\n 'Next.js getImageProps() is not implemented in remote components',\n );\n },\n __esModule: true,\n })),\n 'next/dist/client/script':\n self.__remote_component_host_shared_modules__?.['next/script'] ??\n shared?.['next/script'] ??\n (() =>\n Promise.resolve({\n // TODO: implement <Script> component for non-Next.js host applications\n // do not throw an error for now\n default: () => null,\n __esModule: true,\n })),\n 'next/router':\n self.__remote_component_host_shared_modules__?.['next/router'] ??\n shared?.['next/router'] ??\n (() =>\n // TODO: incomplete implementation\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n __esModule: true,\n })),\n 'next/dist/build/polyfills/process': () =>\n Promise.resolve({\n default: {\n env: {\n NODE_ENV: 'production',\n },\n },\n __esModule: true,\n }),\n } as Record<string, () => Promise<unknown>>;\n\n polyfill['next/navigation'] = polyfill[\n 'next/dist/client/components/navigation'\n ] as () => Promise<unknown>;\n polyfill['next/link'] = polyfill[\n 'next/dist/client/app-dir/link'\n ] as () => Promise<unknown>;\n polyfill['next/form'] = polyfill[\n 'next/dist/client/app-dir/form'\n ] as () => Promise<unknown>;\n polyfill['next/dist/api/image'] = polyfill[\n 'next/dist/client/image-component'\n ] as () => Promise<unknown>;\n polyfill['next/script'] = polyfill[\n 'next/dist/client/script'\n ] as () => Promise<unknown>;\n\n return polyfill;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsDM;AAAA;AAAA;AAAA;AAnDN,SAAS,oBAAoB,QAAgB,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AAQ,KAAK;AAAA,YACf;AAAA,UACF;AAAA,QACF;AAAA,QACA,YAAY;AAAA,MACd,CAAC;AAAA;AAAA,IACL,qCAAqC,MACnC,QAAQ,QAAQ;AAAA,MACd,SAAS;AAAA,QACP,KAAK;AAAA,UACH,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,MACA,YAAY;AAAA,IACd,CAAC;AAAA,EACL;AAEA,WAAS,iBAAiB,IAAI,SAC5B,wCACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,qBAAqB,IAAI,SAChC,kCACF;AACA,WAAS,aAAa,IAAI,SACxB,yBACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../src/shared/client/polyfill.tsx"],"sourcesContent":["import type { ImageProps, StaticImageData } from 'next/image';\nimport type { LinkProps } from 'next/link';\n\nfunction applyBundleUrlToSrc(bundle: string, src: string) {\n const self = globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n };\n\n if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {\n return src;\n }\n\n const { assetPrefix, path } =\n /^(?<assetPrefix>.*?)\\/_next\\/(?<path>.*)/.exec(src)?.groups ?? {};\n if (!path) {\n return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;\n }\n return `${self.__remote_bundle_url__?.[bundle]?.origin ?? ''}${assetPrefix}/_next/${path}`;\n}\n\nexport function applyBundleUrlToImagePropsSrc(\n bundle: string,\n src: ImageProps['src'],\n) {\n if (typeof src === 'string') {\n return applyBundleUrlToSrc(bundle, src);\n }\n const propSrc = src as StaticImageData;\n return applyBundleUrlToSrc(bundle, propSrc.src);\n}\n\nconst imageImpl = (bundle: string) =>\n function RemoteImage({\n fill: _fill,\n loader: _loader,\n quality: _quality,\n priority: _priority,\n loading: _loading,\n placeholder: _placeholder,\n blurDataURL: _blurDataURL,\n unoptimized: _unoptimized,\n overrideSrc: _overrideSrc,\n src,\n ...props\n }: ImageProps) {\n const newSrc = applyBundleUrlToImagePropsSrc(\n bundle,\n typeof src === 'string' ? src : (src as StaticImageData).src,\n );\n\n return (\n // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text\n <img\n decoding=\"async\"\n style={{ color: 'transparent' }}\n {...props}\n src={newSrc}\n suppressHydrationWarning\n />\n );\n };\n\n// polyfill Next.js App Router client API (minimal)\n// implementations are minimal and do not cover all use cases\n// developer can override these shared modules from configuration\nexport function sharedPolyfills(\n shared?: Record<string, () => Promise<unknown>>,\n) {\n const self = globalThis as typeof globalThis & {\n __remote_component_host_shared_modules__?: Record<\n string,\n () => Promise<unknown>\n >;\n };\n const polyfill = {\n 'next/dist/client/components/navigation':\n self.__remote_component_host_shared_modules__?.['next/navigation'] ??\n shared?.['next/navigation'] ??\n (() =>\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n usePathname() {\n return location.pathname;\n },\n useParams() {\n return {};\n },\n useSearchParams() {\n return new URLSearchParams(location.search);\n },\n useSelectedLayoutSegment() {\n return null;\n },\n useSelectedLayoutSegments() {\n return [];\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/link':\n self.__remote_component_host_shared_modules__?.['next/link'] ??\n shared?.['next/link'] ??\n (() =>\n Promise.resolve({\n default: ({\n scroll: _,\n replace,\n prefetch,\n onNavigate,\n children,\n ...props\n }: React.PropsWithChildren<LinkProps>) => {\n if (prefetch) {\n // eslint-disable-next-line no-console\n console.warn(\n 'Next.js Link prefetch is not supported in remote components',\n );\n }\n return (\n <a\n {...props}\n href={props.href as string}\n onClick={(e) => {\n e.preventDefault();\n let preventDefaulted = false;\n e.preventDefault = () => {\n preventDefaulted = true;\n e.defaultPrevented = true;\n };\n if (typeof props.onClick === 'function') {\n props.onClick(e);\n }\n onNavigate?.(e);\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (preventDefaulted) {\n return;\n }\n if (replace) {\n history.replaceState({}, '', props.href as string);\n } else {\n history.pushState({}, '', props.href as string);\n }\n }}\n suppressHydrationWarning\n >\n {children ?? null}\n </a>\n );\n },\n useLinkStatus() {\n return { pending: false };\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/form':\n self.__remote_component_host_shared_modules__?.['next/form'] ??\n shared?.['next/form'] ??\n (() =>\n Promise.resolve({\n default: () => {\n // TODO: implement <Form> component for non-Next.js host applications\n throw new Error('Next.js <Form> component not implemented');\n },\n __esModule: true,\n })),\n 'next/dist/client/image-component':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n Image: imageImpl(bundle),\n __esModule: true,\n })),\n 'next/image':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n default: imageImpl(bundle),\n getImageProps: (_imgProps: ImageProps) => {\n throw new Error(\n 'Next.js getImageProps() is not implemented in remote components',\n );\n },\n __esModule: true,\n })),\n 'next/dist/client/script':\n self.__remote_component_host_shared_modules__?.['next/script'] ??\n shared?.['next/script'] ??\n (() =>\n Promise.resolve({\n // TODO: implement <Script> component for non-Next.js host applications\n // do not throw an error for now\n default: () => null,\n __esModule: true,\n })),\n 'next/router':\n self.__remote_component_host_shared_modules__?.['next/router'] ??\n shared?.['next/router'] ??\n (() =>\n // TODO: incomplete implementation\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n __esModule: true,\n })),\n 'next/dist/build/polyfills/process': () =>\n Promise.resolve({\n default: {\n env: {\n NODE_ENV: 'production',\n },\n },\n __esModule: true,\n }),\n } as Record<string, () => Promise<unknown>>;\n\n polyfill['next/navigation'] = polyfill[\n 'next/dist/client/components/navigation'\n ] as () => Promise<unknown>;\n polyfill['next/link'] = polyfill[\n 'next/dist/client/app-dir/link'\n ] as () => Promise<unknown>;\n polyfill['next/form'] = polyfill[\n 'next/dist/client/app-dir/form'\n ] as () => Promise<unknown>;\n polyfill['next/dist/api/image'] = polyfill[\n 'next/dist/client/image-component'\n ] as () => Promise<unknown>;\n polyfill['next/script'] = polyfill[\n 'next/dist/client/script'\n ] as () => Promise<unknown>;\n\n return polyfill;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoDM;AAAA;AAAA;AAAA;AAjDN,SAAS,oBAAoB,QAAgB,KAAa;AACxD,QAAM,OAAO;AAIb,MAAI,KAAK,wBAAwB,MAAM,GAAG,WAAW,SAAS,QAAQ;AACpE,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,aAAa,KAAK,IACxB,2CAA2C,KAAK,GAAG,GAAG,UAAU,CAAC;AACnE,MAAI,CAAC,MAAM;AACT,WAAO,IAAI,IAAI,KAAK,KAAK,wBAAwB,MAAM,GAAG,MAAM,EAAE;AAAA,EACpE;AACA,SAAO,GAAG,KAAK,wBAAwB,MAAM,GAAG,UAAU,KAAK,qBAAqB;AACtF;AAEO,SAAS,8BACd,QACA,KACA;AACA,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO,oBAAoB,QAAQ,GAAG;AAAA,EACxC;AACA,QAAM,UAAU;AAChB,SAAO,oBAAoB,QAAQ,QAAQ,GAAG;AAChD;AAEA,MAAM,YAAY,CAAC,WACjB,SAAS,YAAY;AAAA,EACnB,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AAAA,EACV,SAAS;AAAA,EACT,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb;AAAA,EACA,GAAG;AACL,GAAe;AACb,QAAM,SAAS;AAAA,IACb;AAAA,IACA,OAAO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S,aAAa,MACrB,MACC,QAAQ,QAAQ;AAAA;AAAA;AAAA,MAGd,SAAS,MAAM;AAAA,MACf,YAAY;AAAA,IACd,CAAC;AAAA,IACL,eACE,KAAK,2CAA2C,aAAa,KAC7D,SAAS,aAAa,MACrB;AAAA;AAAA,MAEC,QAAQ,QAAQ;AAAA,QACd,YAAY;AACV,iBAAO;AAAA,YACL,MAAM,CAAC,cAAsB;AAC3B,sBAAQ,UAAU,CAAC,GAAG,IAAI,SAAS;AAAA,YACrC;AAAA,YACA,SAAS,CAAC,cAAsB;AAC9B,sBAAQ,aAAa,CAAC,GAAG,IAAI,SAAS;AAAA,YACxC;AAAA,YACA,MAAM,MAAM;AACV,sBAAQ,KAAK;AAAA,YACf;AAAA,UACF;AAAA,QACF;AAAA,QACA,YAAY;AAAA,MACd,CAAC;AAAA;AAAA,IACL,qCAAqC,MACnC,QAAQ,QAAQ;AAAA,MACd,SAAS;AAAA,QACP,KAAK;AAAA,UACH,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,MACA,YAAY;AAAA,IACd,CAAC;AAAA,EACL;AAEA,WAAS,iBAAiB,IAAI,SAC5B,wCACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,qBAAqB,IAAI,SAChC,kCACF;AACA,WAAS,aAAa,IAAI,SACxB,yBACF;AAEA,SAAO;AACT;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/client/polyfill.tsx"],"sourcesContent":["import { type LinkProps } from 'next/link';\nimport type { ImageProps, StaticImageData } from 'next/image';\n\nfunction applyBundleUrlToSrc(bundle: string, src: string) {\n const self = globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n };\n\n if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {\n return src;\n }\n\n const { assetPrefix, path } =\n /^(?<assetPrefix>.*?)\\/_next\\/(?<path>.*)/.exec(src)?.groups ?? {};\n if (!path) {\n return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;\n }\n return `${\n self.__remote_bundle_url__?.[bundle]?.origin ?? ''\n }${assetPrefix}/_next/${path}`;\n}\n\nexport function applyBundleUrlToImagePropsSrc(\n bundle: string,\n src: ImageProps['src'],\n) {\n if (typeof src === 'string') {\n return applyBundleUrlToSrc(bundle, src);\n }\n const propSrc = src as StaticImageData;\n return applyBundleUrlToSrc(bundle, propSrc.src);\n}\n\nconst imageImpl = (bundle: string) =>\n function RemoteImage({\n fill: _fill,\n loader: _loader,\n quality: _quality,\n priority: _priority,\n loading: _loading,\n placeholder: _placeholder,\n blurDataURL: _blurDataURL,\n unoptimized: _unoptimized,\n overrideSrc: _overrideSrc,\n src,\n ...props\n }: ImageProps) {\n const newSrc = applyBundleUrlToImagePropsSrc(\n bundle,\n typeof src === 'string' ? src : (src as StaticImageData).src,\n );\n\n return (\n // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text\n <img\n decoding=\"async\"\n style={{ color: 'transparent' }}\n {...props}\n src={newSrc}\n suppressHydrationWarning\n />\n );\n };\n\n// polyfill Next.js App Router client API (minimal)\n// implementations are minimal and do not cover all use cases\n// developer can override these shared modules from configuration\nexport function sharedPolyfills(\n shared?: Record<string, () => Promise<unknown>>,\n) {\n const self = globalThis as typeof globalThis & {\n __remote_component_host_shared_modules__?: Record<\n string,\n () => Promise<unknown>\n >;\n };\n const polyfill = {\n 'next/dist/client/components/navigation':\n self.__remote_component_host_shared_modules__?.['next/navigation'] ??\n shared?.['next/navigation'] ??\n (() =>\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n usePathname() {\n return location.pathname;\n },\n useParams() {\n return {};\n },\n useSearchParams() {\n return new URLSearchParams(location.search);\n },\n useSelectedLayoutSegment() {\n return null;\n },\n useSelectedLayoutSegments() {\n return [];\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/link':\n self.__remote_component_host_shared_modules__?.['next/link'] ??\n shared?.['next/link'] ??\n (() =>\n Promise.resolve({\n default: ({\n scroll: _,\n replace,\n prefetch,\n onNavigate,\n children,\n ...props\n }: React.PropsWithChildren<LinkProps>) => {\n if (prefetch) {\n // eslint-disable-next-line no-console\n console.warn(\n 'Next.js Link prefetch is not supported in remote components',\n );\n }\n return (\n <a\n {...props}\n href={props.href as string}\n onClick={(e) => {\n e.preventDefault();\n let preventDefaulted = false;\n e.preventDefault = () => {\n preventDefaulted = true;\n e.defaultPrevented = true;\n };\n if (typeof props.onClick === 'function') {\n props.onClick(e);\n }\n onNavigate?.(e);\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (preventDefaulted) {\n return;\n }\n if (replace) {\n history.replaceState({}, '', props.href as string);\n } else {\n history.pushState({}, '', props.href as string);\n }\n }}\n suppressHydrationWarning\n >\n {children ?? null}\n </a>\n );\n },\n useLinkStatus() {\n return { pending: false };\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/form':\n self.__remote_component_host_shared_modules__?.['next/form'] ??\n shared?.['next/form'] ??\n (() =>\n Promise.resolve({\n default: () => {\n // TODO: implement <Form> component for non-Next.js host applications\n throw new Error('Next.js <Form> component not implemented');\n },\n __esModule: true,\n })),\n 'next/dist/client/image-component':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n Image: imageImpl(bundle),\n __esModule: true,\n })),\n 'next/image':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n default: imageImpl(bundle),\n getImageProps: (_imgProps: ImageProps) => {\n throw new Error(\n 'Next.js getImageProps() is not implemented in remote components',\n );\n },\n __esModule: true,\n })),\n 'next/dist/client/script':\n self.__remote_component_host_shared_modules__?.['next/script'] ??\n shared?.['next/script'] ??\n (() =>\n Promise.resolve({\n // TODO: implement <Script> component for non-Next.js host applications\n // do not throw an error for now\n default: () => null,\n __esModule: true,\n })),\n 'next/router':\n self.__remote_component_host_shared_modules__?.['next/router'] ??\n shared?.['next/router'] ??\n (() =>\n // TODO: incomplete implementation\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n __esModule: true,\n })),\n 'next/dist/build/polyfills/process': () =>\n Promise.resolve({\n default: {\n env: {\n NODE_ENV: 'production',\n },\n },\n __esModule: true,\n }),\n } as Record<string, () => Promise<unknown>>;\n\n polyfill['next/navigation'] = polyfill[\n 'next/dist/client/components/navigation'\n ] as () => Promise<unknown>;\n polyfill['next/link'] = polyfill[\n 'next/dist/client/app-dir/link'\n ] as () => Promise<unknown>;\n polyfill['next/form'] = polyfill[\n 'next/dist/client/app-dir/form'\n ] as () => Promise<unknown>;\n polyfill['next/dist/api/image'] = polyfill[\n 'next/dist/client/image-component'\n ] as () => Promise<unknown>;\n polyfill['next/script'] = polyfill[\n 'next/dist/client/script'\n ] as () => Promise<unknown>;\n\n return polyfill;\n}\n"],"mappings":"AAsDM;AAnDN,SAAS,oBAAoB,QAAgB,KAAa;AACxD,QAAM,OAAO;AAIb,MAAI,KAAK,wBAAwB,MAAM,GAAG,WAAW,SAAS,QAAQ;AACpE,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,aAAa,KAAK,IACxB,2CAA2C,KAAK,GAAG,GAAG,UAAU,CAAC;AACnE,MAAI,CAAC,MAAM;AACT,WAAO,IAAI,IAAI,KAAK,KAAK,wBAAwB,MAAM,GAAG,MAAM,EAAE;AAAA,EACpE;AACA,SAAO,GACL,KAAK,wBAAwB,MAAM,GAAG,UAAU,KAC/C,qBAAqB;AAC1B;AAEO,SAAS,8BACd,QACA,KACA;AACA,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO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IAAI,SACxB,yBACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../src/shared/client/polyfill.tsx"],"sourcesContent":["import type { ImageProps, StaticImageData } from 'next/image';\nimport type { LinkProps } from 'next/link';\n\nfunction applyBundleUrlToSrc(bundle: string, src: string) {\n const self = globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n };\n\n if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {\n return src;\n }\n\n const { assetPrefix, path } =\n /^(?<assetPrefix>.*?)\\/_next\\/(?<path>.*)/.exec(src)?.groups ?? {};\n if (!path) {\n return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;\n }\n return `${self.__remote_bundle_url__?.[bundle]?.origin ?? ''}${assetPrefix}/_next/${path}`;\n}\n\nexport function applyBundleUrlToImagePropsSrc(\n bundle: string,\n src: ImageProps['src'],\n) {\n if (typeof src === 'string') {\n return applyBundleUrlToSrc(bundle, src);\n }\n const propSrc = src as StaticImageData;\n return applyBundleUrlToSrc(bundle, propSrc.src);\n}\n\nconst imageImpl = (bundle: string) =>\n function RemoteImage({\n fill: _fill,\n loader: _loader,\n quality: _quality,\n priority: _priority,\n loading: _loading,\n placeholder: _placeholder,\n blurDataURL: _blurDataURL,\n unoptimized: _unoptimized,\n overrideSrc: _overrideSrc,\n src,\n ...props\n }: ImageProps) {\n const newSrc = applyBundleUrlToImagePropsSrc(\n bundle,\n typeof src === 'string' ? src : (src as StaticImageData).src,\n );\n\n return (\n // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text\n <img\n decoding=\"async\"\n style={{ color: 'transparent' }}\n {...props}\n src={newSrc}\n suppressHydrationWarning\n />\n );\n };\n\n// polyfill Next.js App Router client API (minimal)\n// implementations are minimal and do not cover all use cases\n// developer can override these shared modules from configuration\nexport function sharedPolyfills(\n shared?: Record<string, () => Promise<unknown>>,\n) {\n const self = globalThis as typeof globalThis & {\n __remote_component_host_shared_modules__?: Record<\n string,\n () => Promise<unknown>\n >;\n };\n const polyfill = {\n 'next/dist/client/components/navigation':\n self.__remote_component_host_shared_modules__?.['next/navigation'] ??\n shared?.['next/navigation'] ??\n (() =>\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n usePathname() {\n return location.pathname;\n },\n useParams() {\n return {};\n },\n useSearchParams() {\n return new URLSearchParams(location.search);\n },\n useSelectedLayoutSegment() {\n return null;\n },\n useSelectedLayoutSegments() {\n return [];\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/link':\n self.__remote_component_host_shared_modules__?.['next/link'] ??\n shared?.['next/link'] ??\n (() =>\n Promise.resolve({\n default: ({\n scroll: _,\n replace,\n prefetch,\n onNavigate,\n children,\n ...props\n }: React.PropsWithChildren<LinkProps>) => {\n if (prefetch) {\n // eslint-disable-next-line no-console\n console.warn(\n 'Next.js Link prefetch is not supported in remote components',\n );\n }\n return (\n <a\n {...props}\n href={props.href as string}\n onClick={(e) => {\n e.preventDefault();\n let preventDefaulted = false;\n e.preventDefault = () => {\n preventDefaulted = true;\n e.defaultPrevented = true;\n };\n if (typeof props.onClick === 'function') {\n props.onClick(e);\n }\n onNavigate?.(e);\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (preventDefaulted) {\n return;\n }\n if (replace) {\n history.replaceState({}, '', props.href as string);\n } else {\n history.pushState({}, '', props.href as string);\n }\n }}\n suppressHydrationWarning\n >\n {children ?? null}\n </a>\n );\n },\n useLinkStatus() {\n return { pending: false };\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/form':\n self.__remote_component_host_shared_modules__?.['next/form'] ??\n shared?.['next/form'] ??\n (() =>\n Promise.resolve({\n default: () => {\n // TODO: implement <Form> component for non-Next.js host applications\n throw new Error('Next.js <Form> component not implemented');\n },\n __esModule: true,\n })),\n 'next/dist/client/image-component':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n Image: imageImpl(bundle),\n __esModule: true,\n })),\n 'next/image':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n default: imageImpl(bundle),\n getImageProps: (_imgProps: ImageProps) => {\n throw new Error(\n 'Next.js getImageProps() is not implemented in remote components',\n );\n },\n __esModule: true,\n })),\n 'next/dist/client/script':\n self.__remote_component_host_shared_modules__?.['next/script'] ??\n shared?.['next/script'] ??\n (() =>\n Promise.resolve({\n // TODO: implement <Script> component for non-Next.js host applications\n // do not throw an error for now\n default: () => null,\n __esModule: true,\n })),\n 'next/router':\n self.__remote_component_host_shared_modules__?.['next/router'] ??\n shared?.['next/router'] ??\n (() =>\n // TODO: incomplete implementation\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n __esModule: true,\n })),\n 'next/dist/build/polyfills/process': () =>\n Promise.resolve({\n default: {\n env: {\n NODE_ENV: 'production',\n },\n },\n __esModule: true,\n }),\n } as Record<string, () => Promise<unknown>>;\n\n polyfill['next/navigation'] = polyfill[\n 'next/dist/client/components/navigation'\n ] as () => Promise<unknown>;\n polyfill['next/link'] = polyfill[\n 'next/dist/client/app-dir/link'\n ] as () => Promise<unknown>;\n polyfill['next/form'] = polyfill[\n 'next/dist/client/app-dir/form'\n ] as () => Promise<unknown>;\n polyfill['next/dist/api/image'] = polyfill[\n 'next/dist/client/image-component'\n ] as () => Promise<unknown>;\n polyfill['next/script'] = polyfill[\n 'next/dist/client/script'\n ] as () => Promise<unknown>;\n\n return polyfill;\n}\n"],"mappings":"AAoDM;AAjDN,SAAS,oBAAoB,QAAgB,KAAa;AACxD,QAAM,OAAO;AAIb,MAAI,KAAK,wBAA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ACF;AAAA,QACF;AAAA,QACA,YAAY;AAAA,MACd,CAAC;AAAA;AAAA,IACL,qCAAqC,MACnC,QAAQ,QAAQ;AAAA,MACd,SAAS;AAAA,QACP,KAAK;AAAA,UACH,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,MACA,YAAY;AAAA,IACd,CAAC;AAAA,EACL;AAEA,WAAS,iBAAiB,IAAI,SAC5B,wCACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,qBAAqB,IAAI,SAChC,kCACF;AACA,WAAS,aAAa,IAAI,SACxB,yBACF;AAEA,SAAO;AACT;","names":[]}
@@ -47,49 +47,22 @@ __export(remote_component_exports, {
47
47
  });
48
48
  module.exports = __toCommonJS(remote_component_exports);
49
49
 
50
- // src/shared/client/component-loader.ts
51
- var React = __toESM(require("react"), 1);
52
- var ReactDOM = __toESM(require("react-dom"), 1);
53
- var ReactDOMClient = __toESM(require("react-dom/client"), 1);
54
- var JSXDevRuntime = __toESM(require("react/jsx-dev-runtime"), 1);
55
- var JSXRuntime = __toESM(require("react/jsx-runtime"), 1);
56
-
57
- // src/shared/webpack/shared-modules.ts
58
- function applySharedModules(bundle, resolve) {
59
- const self = globalThis;
60
- if (self.__remote_webpack_require__?.[bundle]) {
61
- const modulePaths = Object.keys(
62
- self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
63
- );
64
- for (const [key, value] of Object.entries(resolve)) {
65
- let ids = modulePaths.filter((p) => p === key);
66
- if (ids.length === 0) {
67
- ids = modulePaths.filter((p) => p.includes(key));
68
- }
69
- for (let id of ids) {
70
- const webpackBundle = self.__remote_webpack_require__[bundle];
71
- if (webpackBundle.m) {
72
- if (self.__remote_webpack_module_map__?.[bundle]?.[id]) {
73
- id = `${self.__remote_webpack_module_map__[bundle][id]}`;
74
- }
75
- webpackBundle.m[id] = (module2) => {
76
- module2.exports = value;
77
- };
78
- }
79
- }
80
- }
81
- }
82
- }
83
-
84
50
  // src/shared/error.ts
85
51
  var RemoteComponentsError = class extends Error {
52
+ code = "REMOTE_COMPONENTS_ERROR";
86
53
  constructor(message, options) {
87
54
  super(message, options);
88
- this.code = "REMOTE_COMPONENTS_ERROR";
89
55
  this.name = "RemoteComponentsError";
90
56
  }
91
57
  };
92
58
 
59
+ // src/shared/client/component-loader.ts
60
+ var React = __toESM(require("react"), 1);
61
+ var JSXDevRuntime = __toESM(require("react/jsx-dev-runtime"), 1);
62
+ var JSXRuntime = __toESM(require("react/jsx-runtime"), 1);
63
+ var ReactDOM = __toESM(require("react-dom"), 1);
64
+ var ReactDOMClient = __toESM(require("react-dom/client"), 1);
65
+
93
66
  // src/shared/webpack/next-client-pages-loader.ts
94
67
  function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
95
68
  const self = globalThis;
@@ -202,6 +175,128 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
202
175
  return { Component: null, App: null };
203
176
  }
204
177
 
178
+ // src/shared/webpack/shared-modules.ts
179
+ function applySharedModules(bundle, resolve) {
180
+ const self = globalThis;
181
+ if (self.__remote_webpack_require__?.[bundle]) {
182
+ const modulePaths = Object.keys(
183
+ self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
184
+ );
185
+ for (const [key, value] of Object.entries(resolve)) {
186
+ let ids = modulePaths.filter((p) => p === key);
187
+ if (ids.length === 0) {
188
+ ids = modulePaths.filter((p) => p.includes(key));
189
+ }
190
+ for (let id of ids) {
191
+ const webpackBundle = self.__remote_webpack_require__[bundle];
192
+ if (webpackBundle.m) {
193
+ if (self.__remote_webpack_module_map__?.[bundle]?.[id]) {
194
+ id = `${self.__remote_webpack_module_map__[bundle][id]}`;
195
+ }
196
+ webpackBundle.m[id] = (module2) => {
197
+ module2.exports = value;
198
+ };
199
+ }
200
+ }
201
+ }
202
+ }
203
+ }
204
+
205
+ // src/shared/client/rsc.ts
206
+ var import_web_streams_polyfill = require("web-streams-polyfill");
207
+ function fixPayload(payload) {
208
+ if (Array.isArray(payload)) {
209
+ if (payload[0] === "$") {
210
+ fixPayload(payload[3]);
211
+ if (payload.length === 4) {
212
+ payload.push(null, null, 1);
213
+ }
214
+ } else {
215
+ for (const item of payload) {
216
+ fixPayload(item);
217
+ }
218
+ }
219
+ } else if (typeof payload === "object" && payload !== null) {
220
+ for (const key in payload) {
221
+ fixPayload(payload[key]);
222
+ }
223
+ }
224
+ }
225
+ function createRSCStream(rscName, data) {
226
+ return new import_web_streams_polyfill.ReadableStream({
227
+ type: "bytes",
228
+ start(controller) {
229
+ const encoder = new TextEncoder();
230
+ const self = globalThis;
231
+ if (data.length > 0) {
232
+ data.forEach((chunk) => {
233
+ const lines = chunk.split("\n");
234
+ for (const line of lines) {
235
+ const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
236
+ if (match?.groups?.rsc) {
237
+ self[rscName] = self[rscName] ?? [];
238
+ self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
239
+ }
240
+ }
241
+ });
242
+ }
243
+ const allChunks = (self[rscName] ?? [`0:[null]
244
+ `]).join("");
245
+ self[rscName] = null;
246
+ allChunks.split("\n").forEach((chunk) => {
247
+ if (chunk.length > 0) {
248
+ const { before, id, prefix, payload } = /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
249
+ chunk
250
+ )?.groups ?? {};
251
+ if (payload) {
252
+ const jsonPayload = JSON.parse(payload);
253
+ fixPayload(jsonPayload);
254
+ const reconstruct = `${before ?? ""}${id}:${prefix ?? ""}${JSON.stringify(jsonPayload)}`;
255
+ controller.enqueue(encoder.encode(`${reconstruct}
256
+ `));
257
+ } else {
258
+ controller.enqueue(encoder.encode(`${chunk}
259
+ `));
260
+ }
261
+ } else {
262
+ controller.enqueue(encoder.encode(`${chunk}
263
+ `));
264
+ }
265
+ });
266
+ controller.close();
267
+ }
268
+ });
269
+ }
270
+
271
+ // src/shared/client/script-loader.ts
272
+ async function loadScripts(scripts) {
273
+ await Promise.all(
274
+ scripts.map((script) => {
275
+ return new Promise((resolve, reject) => {
276
+ const newSrc = new URL(
277
+ // remove the remote component bundle name identifier from the script src
278
+ script.src.replace(/\/_next\/\[.+\](?<whitespace>%20| )/, "/_next/"),
279
+ location.origin
280
+ ).href;
281
+ const newScript = document.createElement("script");
282
+ newScript.onload = () => {
283
+ resolve();
284
+ };
285
+ newScript.onerror = () => {
286
+ reject(
287
+ new RemoteComponentsError(
288
+ `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
289
+ )
290
+ );
291
+ };
292
+ newScript.src = newSrc;
293
+ newScript.async = true;
294
+ document.head.appendChild(newScript);
295
+ });
296
+ })
297
+ );
298
+ }
299
+
205
300
  // src/shared/utils/index.ts
206
301
  function escapeString(str) {
207
302
  return str.replace(/[^a-z0-9]/g, "_");
@@ -380,7 +475,10 @@ async function handleTurbopackChunk(code, bundle, url) {
380
475
  function createModuleRequire(runtime) {
381
476
  return (id) => {
382
477
  const self = globalThis;
383
- const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? { bundle: "default", id };
478
+ const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? {
479
+ bundle: "default",
480
+ id
481
+ };
384
482
  const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
385
483
  try {
386
484
  if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
@@ -716,101 +814,6 @@ function handleTurbopackModule(bundle, moduleId, id) {
716
814
  return moduleExports.exports;
717
815
  }
718
816
 
719
- // src/shared/client/script-loader.ts
720
- async function loadScripts(scripts) {
721
- await Promise.all(
722
- scripts.map((script) => {
723
- return new Promise((resolve, reject) => {
724
- const newSrc = new URL(
725
- // remove the remote component bundle name identifier from the script src
726
- script.src.replace(/\/_next\/\[.+\](?<whitespace>%20| )/, "/_next/"),
727
- location.origin
728
- ).href;
729
- const newScript = document.createElement("script");
730
- newScript.onload = () => {
731
- resolve();
732
- };
733
- newScript.onerror = () => {
734
- reject(
735
- new RemoteComponentsError(
736
- `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
737
- )
738
- );
739
- };
740
- newScript.src = newSrc;
741
- newScript.async = true;
742
- document.head.appendChild(newScript);
743
- });
744
- })
745
- );
746
- }
747
-
748
- // src/shared/client/rsc.ts
749
- var import_web_streams_polyfill = require("web-streams-polyfill");
750
- function fixPayload(payload) {
751
- if (Array.isArray(payload)) {
752
- if (payload[0] === "$") {
753
- fixPayload(payload[3]);
754
- if (payload.length === 4) {
755
- payload.push(null, null, 1);
756
- }
757
- } else {
758
- for (const item of payload) {
759
- fixPayload(item);
760
- }
761
- }
762
- } else if (typeof payload === "object" && payload !== null) {
763
- for (const key in payload) {
764
- fixPayload(payload[key]);
765
- }
766
- }
767
- }
768
- function createRSCStream(rscName, data) {
769
- return new import_web_streams_polyfill.ReadableStream({
770
- type: "bytes",
771
- start(controller) {
772
- const encoder = new TextEncoder();
773
- const self = globalThis;
774
- if (data.length > 0) {
775
- data.forEach((chunk) => {
776
- const lines = chunk.split("\n");
777
- for (const line of lines) {
778
- const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
779
- if (match?.groups?.rsc) {
780
- self[rscName] = self[rscName] ?? [];
781
- self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
782
- }
783
- }
784
- });
785
- }
786
- const allChunks = (self[rscName] ?? [`0:[null]
787
- `]).join("");
788
- self[rscName] = null;
789
- allChunks.split("\n").forEach((chunk) => {
790
- if (chunk.length > 0) {
791
- const { before, id, prefix, payload } = /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
792
- chunk
793
- )?.groups ?? {};
794
- if (payload) {
795
- const jsonPayload = JSON.parse(payload);
796
- fixPayload(jsonPayload);
797
- const reconstruct = `${before ?? ""}${id}:${prefix ?? ""}${JSON.stringify(jsonPayload)}`;
798
- controller.enqueue(encoder.encode(`${reconstruct}
799
- `));
800
- } else {
801
- controller.enqueue(encoder.encode(`${chunk}
802
- `));
803
- }
804
- } else {
805
- controller.enqueue(encoder.encode(`${chunk}
806
- `));
807
- }
808
- });
809
- controller.close();
810
- }
811
- });
812
- }
813
-
814
817
  // src/shared/client/component-loader.ts
815
818
  async function loadRemoteComponent({
816
819
  url,
@@ -883,7 +886,9 @@ async function loadRemoteComponent({
883
886
  component: null,
884
887
  error: new RemoteComponentsError(
885
888
  `Failed to load remote component "${name}".`,
886
- { cause: error instanceof Error ? error : new Error(String(error)) }
889
+ {
890
+ cause: error instanceof Error ? error : new Error(String(error))
891
+ }
887
892
  )
888
893
  };
889
894
  }
@@ -919,6 +924,48 @@ function loadNextPagesComponent(bundle, route, nextData, name, container) {
919
924
  return { component };
920
925
  }
921
926
 
927
+ // src/shared/client/set-attributes-from-props.ts
928
+ var DOMAttributeNames = {
929
+ acceptCharset: "accept-charset",
930
+ className: "class",
931
+ htmlFor: "for",
932
+ httpEquiv: "http-equiv",
933
+ noModule: "noModule"
934
+ };
935
+ var ignoreProps = [
936
+ "onLoad",
937
+ "onReady",
938
+ "dangerouslySetInnerHTML",
939
+ "children",
940
+ "onError",
941
+ "strategy",
942
+ "stylesheets"
943
+ ];
944
+ function isBooleanScriptAttribute(attr) {
945
+ return ["async", "defer", "noModule"].includes(attr);
946
+ }
947
+ function setAttributesFromProps(el, props) {
948
+ for (const [p, value] of Object.entries(props)) {
949
+ if (!Object.hasOwn(props, p))
950
+ continue;
951
+ if (ignoreProps.includes(p))
952
+ continue;
953
+ if (value === void 0) {
954
+ continue;
955
+ }
956
+ const attr = DOMAttributeNames[p] || p.toLowerCase();
957
+ if (el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr)) {
958
+ el[attr] = Boolean(value);
959
+ } else {
960
+ el.setAttribute(attr, String(value));
961
+ }
962
+ if (value === false || el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr) && (!value || value === "false")) {
963
+ el.setAttribute(attr, "");
964
+ el.removeAttribute(attr);
965
+ }
966
+ }
967
+ }
968
+
922
969
  // src/shared/client/static-loader.ts
923
970
  async function loadStaticRemoteComponent(scripts, url) {
924
971
  const self = globalThis;
@@ -1012,48 +1059,6 @@ async function loadStaticRemoteComponent(scripts, url) {
1012
1059
  }
1013
1060
  );
1014
1061
  }
1015
-
1016
- // src/shared/client/set-attributes-from-props.ts
1017
- var DOMAttributeNames = {
1018
- acceptCharset: "accept-charset",
1019
- className: "class",
1020
- htmlFor: "for",
1021
- httpEquiv: "http-equiv",
1022
- noModule: "noModule"
1023
- };
1024
- var ignoreProps = [
1025
- "onLoad",
1026
- "onReady",
1027
- "dangerouslySetInnerHTML",
1028
- "children",
1029
- "onError",
1030
- "strategy",
1031
- "stylesheets"
1032
- ];
1033
- function isBooleanScriptAttribute(attr) {
1034
- return ["async", "defer", "noModule"].includes(attr);
1035
- }
1036
- function setAttributesFromProps(el, props) {
1037
- for (const [p, value] of Object.entries(props)) {
1038
- if (!Object.prototype.hasOwnProperty.call(props, p))
1039
- continue;
1040
- if (ignoreProps.includes(p))
1041
- continue;
1042
- if (value === void 0) {
1043
- continue;
1044
- }
1045
- const attr = DOMAttributeNames[p] || p.toLowerCase();
1046
- if (el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr)) {
1047
- el[attr] = Boolean(value);
1048
- } else {
1049
- el.setAttribute(attr, String(value));
1050
- }
1051
- if (value === false || el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr) && (!value || value === "false")) {
1052
- el.setAttribute(attr, "");
1053
- el.removeAttribute(attr);
1054
- }
1055
- }
1056
- }
1057
1062
  // Annotate the CommonJS export names for ESM import in node:
1058
1063
  0 && (module.exports = {
1059
1064
  DEFAULT_ROUTE,