remote-components 0.0.51 → 0.1.2

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 (135) hide show
  1. package/dist/{component-loader-1838f572.d.ts → component-loader-21865da3.d.ts} +142 -16
  2. package/dist/host-config-58cdccea.d.ts +87 -0
  3. package/dist/html/host.cjs +589 -377
  4. package/dist/html/host.cjs.map +1 -1
  5. package/dist/html/host.d.ts +2 -0
  6. package/dist/html/host.js +588 -377
  7. package/dist/html/host.js.map +1 -1
  8. package/dist/html/remote.cjs +65 -57
  9. package/dist/html/remote.cjs.map +1 -1
  10. package/dist/html/remote.js +65 -57
  11. package/dist/html/remote.js.map +1 -1
  12. package/dist/internal/next/host/app-router-client.cjs +21 -10
  13. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  14. package/dist/internal/next/host/app-router-client.d.ts +36 -14
  15. package/dist/internal/next/host/app-router-client.js +21 -10
  16. package/dist/internal/next/host/app-router-client.js.map +1 -1
  17. package/dist/internal/next/remote/render-server.cjs.map +1 -1
  18. package/dist/internal/next/remote/render-server.d.ts +13 -14
  19. package/dist/internal/next/remote/render-server.js.map +1 -1
  20. package/dist/internal/react/context.cjs +43 -0
  21. package/dist/internal/react/context.cjs.map +1 -0
  22. package/dist/internal/react/context.d.ts +20 -0
  23. package/dist/internal/react/context.js +18 -0
  24. package/dist/internal/react/context.js.map +1 -0
  25. package/dist/internal/react/hooks/use-resolve-client-url.cjs +39 -0
  26. package/dist/internal/react/hooks/use-resolve-client-url.cjs.map +1 -0
  27. package/dist/internal/react/hooks/use-resolve-client-url.d.ts +5 -0
  28. package/dist/internal/react/hooks/use-resolve-client-url.js +15 -0
  29. package/dist/internal/react/hooks/use-resolve-client-url.js.map +1 -0
  30. package/dist/internal/shared/client/apply-origin.cjs +10 -5
  31. package/dist/internal/shared/client/apply-origin.cjs.map +1 -1
  32. package/dist/internal/shared/client/apply-origin.d.ts +3 -1
  33. package/dist/internal/shared/client/apply-origin.js +10 -5
  34. package/dist/internal/shared/client/apply-origin.js.map +1 -1
  35. package/dist/internal/shared/client/default-resolve-client-url.cjs +32 -0
  36. package/dist/internal/shared/client/default-resolve-client-url.cjs.map +1 -0
  37. package/dist/internal/shared/client/default-resolve-client-url.d.ts +5 -0
  38. package/dist/internal/shared/client/default-resolve-client-url.js +10 -0
  39. package/dist/internal/shared/client/default-resolve-client-url.js.map +1 -0
  40. package/dist/internal/shared/client/protected-rc-fallback.cjs +11 -2
  41. package/dist/internal/shared/client/protected-rc-fallback.cjs.map +1 -1
  42. package/dist/internal/shared/client/protected-rc-fallback.d.ts +2 -1
  43. package/dist/internal/shared/client/protected-rc-fallback.js +9 -1
  44. package/dist/internal/shared/client/protected-rc-fallback.js.map +1 -1
  45. package/dist/internal/shared/client/proxy-through-host.cjs +65 -0
  46. package/dist/internal/shared/client/proxy-through-host.cjs.map +1 -0
  47. package/dist/internal/shared/client/proxy-through-host.d.ts +62 -0
  48. package/dist/internal/shared/client/proxy-through-host.js +40 -0
  49. package/dist/internal/shared/client/proxy-through-host.js.map +1 -0
  50. package/dist/internal/shared/client/remote-component.cjs +121 -137
  51. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  52. package/dist/internal/shared/client/remote-component.d.ts +7 -5
  53. package/dist/internal/shared/client/remote-component.js +120 -137
  54. package/dist/internal/shared/client/remote-component.js.map +1 -1
  55. package/dist/internal/shared/constants.cjs +3 -0
  56. package/dist/internal/shared/constants.cjs.map +1 -1
  57. package/dist/internal/shared/constants.d.ts +2 -1
  58. package/dist/internal/shared/constants.js +2 -0
  59. package/dist/internal/shared/constants.js.map +1 -1
  60. package/dist/internal/shared/contract/host-state.cjs +38 -0
  61. package/dist/internal/shared/contract/host-state.cjs.map +1 -0
  62. package/dist/internal/shared/contract/host-state.d.ts +53 -0
  63. package/dist/internal/shared/contract/host-state.js +14 -0
  64. package/dist/internal/shared/contract/host-state.js.map +1 -0
  65. package/dist/internal/shared/contract/resolve-name-from-src.cjs +40 -0
  66. package/dist/internal/shared/contract/resolve-name-from-src.cjs.map +1 -0
  67. package/dist/internal/shared/contract/resolve-name-from-src.d.ts +13 -0
  68. package/dist/internal/shared/contract/resolve-name-from-src.js +16 -0
  69. package/dist/internal/shared/contract/resolve-name-from-src.js.map +1 -0
  70. package/dist/internal/shared/error.cjs +70 -0
  71. package/dist/internal/shared/error.cjs.map +1 -1
  72. package/dist/internal/shared/error.d.ts +3 -1
  73. package/dist/internal/shared/error.js +71 -0
  74. package/dist/internal/shared/error.js.map +1 -1
  75. package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
  76. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  77. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +1 -1
  78. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  79. package/dist/internal/shared/ssr/fetch-with-hooks.cjs +7 -2
  80. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
  81. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +1 -1
  82. package/dist/internal/shared/ssr/fetch-with-hooks.js +7 -2
  83. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
  84. package/dist/internal/shared/utils/logger.cjs +26 -10
  85. package/dist/internal/shared/utils/logger.cjs.map +1 -1
  86. package/dist/internal/shared/utils/logger.d.ts +6 -1
  87. package/dist/internal/shared/utils/logger.js +24 -9
  88. package/dist/internal/shared/utils/logger.js.map +1 -1
  89. package/dist/next/config.cjs +2 -2
  90. package/dist/next/config.cjs.map +1 -1
  91. package/dist/next/config.js +2 -2
  92. package/dist/next/config.js.map +1 -1
  93. package/dist/next/host/app-router-server.cjs.map +1 -1
  94. package/dist/next/host/app-router-server.d.ts +11 -41
  95. package/dist/next/host/app-router-server.js.map +1 -1
  96. package/dist/next/host/client/index.cjs +467 -298
  97. package/dist/next/host/client/index.cjs.map +1 -1
  98. package/dist/next/host/client/index.d.ts +3 -1
  99. package/dist/next/host/client/index.js +445 -277
  100. package/dist/next/host/client/index.js.map +1 -1
  101. package/dist/next/host/pages-router-client.cjs +15 -2
  102. package/dist/next/host/pages-router-client.cjs.map +1 -1
  103. package/dist/next/host/pages-router-client.d.ts +14 -26
  104. package/dist/next/host/pages-router-client.js +15 -2
  105. package/dist/next/host/pages-router-client.js.map +1 -1
  106. package/dist/next/host/pages-router-server.cjs +2 -0
  107. package/dist/next/host/pages-router-server.cjs.map +1 -1
  108. package/dist/next/host/pages-router-server.d.ts +17 -31
  109. package/dist/next/host/pages-router-server.js +2 -0
  110. package/dist/next/host/pages-router-server.js.map +1 -1
  111. package/dist/next/index.cjs.map +1 -1
  112. package/dist/next/index.d.ts +13 -39
  113. package/dist/next/index.js.map +1 -1
  114. package/dist/next/proxy.cjs +33 -6
  115. package/dist/next/proxy.cjs.map +1 -1
  116. package/dist/next/proxy.js +33 -6
  117. package/dist/next/proxy.js.map +1 -1
  118. package/dist/next/remote/server.d.ts +4 -0
  119. package/dist/proxy-through-host-a676a522.d.ts +52 -0
  120. package/dist/react/index.cjs +486 -298
  121. package/dist/react/index.cjs.map +1 -1
  122. package/dist/react/index.d.ts +27 -40
  123. package/dist/react/index.js +463 -277
  124. package/dist/react/index.js.map +1 -1
  125. package/dist/shared/host/proxy.cjs +32 -6
  126. package/dist/shared/host/proxy.cjs.map +1 -1
  127. package/dist/shared/host/proxy.js +36 -7
  128. package/dist/shared/host/proxy.js.map +1 -1
  129. package/dist/{types-cbe44b51.d.ts → types-2b26a246.d.ts} +23 -6
  130. package/package.json +1 -1
  131. package/dist/internal/shared/client/fetch-with-protected-rc-fallback.cjs +0 -65
  132. package/dist/internal/shared/client/fetch-with-protected-rc-fallback.cjs.map +0 -1
  133. package/dist/internal/shared/client/fetch-with-protected-rc-fallback.d.ts +0 -13
  134. package/dist/internal/shared/client/fetch-with-protected-rc-fallback.js +0 -41
  135. package/dist/internal/shared/client/fetch-with-protected-rc-fallback.js.map +0 -1
@@ -1 +1 @@
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);\nconst MANIFESTS_SINGLETON = Symbol.for('next.server.manifests');\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 /** Called right before a new remote component load starts. */\n onBeforeLoad?: (src: string | URL) => void;\n /** Called when the remote component has been successfully loaded and mounted. */\n onLoad?: (src: string | URL) => void;\n /** Called when an error occurs while loading or mounting the remote component. */\n onError?: (error: unknown) => void;\n /** Called when a different remote component is loaded into the same wrapper. */\n onChange?: (info: {\n previousSrc: string | URL | null;\n nextSrc: string | URL | null;\n previousName: string | undefined;\n nextName: string | undefined;\n }) => void;\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 self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n [MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerRoute?: Map<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n __RSC_SERVER_MANIFEST?: Record<string, unknown>;\n };\n const manifests =\n self[MANIFESTS_SINGLETON] ?? self[SERVER_ACTION_MANIFESTS_SINGLETON] ?? {};\n const manifest =\n 'clientReferenceManifestsPerRoute' in manifests\n ? manifests.clientReferenceManifestsPerRoute?.get?.(route)\n : 'clientReferenceManifestsPerPage' in manifests\n ? manifests.clientReferenceManifestsPerPage?.[route]\n : undefined;\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 self.__RSC_SERVER_MANIFEST = self.__RSC_SERVER_MANIFEST || {};\n self.__RSC_SERVER_MANIFEST[page] =\n self.__RSC_SERVER_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":"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","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 type { HostLifecycleCallbacks } from '#internal/shared/contract/host-config';\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);\nconst MANIFESTS_SINGLETON = Symbol.for('next.server.manifests');\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\n/**\n * Props for exposing a Next.js component as a remote component.\n *\n * Extends {@link HostLifecycleCallbacks} so the host can wire up lifecycle\n * events. The `children` prop is the component content to expose (required,\n * unlike host props where children are an optional loading fallback).\n */\nexport interface RemoteComponentProps extends HostLifecycleCallbacks {\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 self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n [MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerRoute?: Map<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n __RSC_SERVER_MANIFEST?: Record<string, unknown>;\n };\n const manifests =\n self[MANIFESTS_SINGLETON] ?? self[SERVER_ACTION_MANIFESTS_SINGLETON] ?? {};\n const manifest =\n 'clientReferenceManifestsPerRoute' in manifests\n ? manifests.clientReferenceManifestsPerRoute?.get?.(route)\n : 'clientReferenceManifestsPerPage' in manifests\n ? manifests.clientReferenceManifestsPerPage?.[route]\n : undefined;\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 self.__RSC_SERVER_MANIFEST = self.__RSC_SERVER_MANIFEST || {};\n self.__RSC_SERVER_MANIFEST[page] =\n self.__RSC_SERVER_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":"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","names":[]}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var context_exports = {};
21
+ __export(context_exports, {
22
+ RemoteComponentsProvider: () => RemoteComponentsProvider,
23
+ useRemoteComponentsContext: () => useRemoteComponentsContext
24
+ });
25
+ module.exports = __toCommonJS(context_exports);
26
+ var import_jsx_runtime = require("react/jsx-runtime");
27
+ var import_react = require("react");
28
+ const RemoteComponentsContext = (0, import_react.createContext)({});
29
+ function RemoteComponentsProvider({
30
+ resolveClientUrl,
31
+ children
32
+ }) {
33
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RemoteComponentsContext, { value: { resolveClientUrl }, children });
34
+ }
35
+ function useRemoteComponentsContext() {
36
+ return (0, import_react.useContext)(RemoteComponentsContext);
37
+ }
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ RemoteComponentsProvider,
41
+ useRemoteComponentsContext
42
+ });
43
+ //# sourceMappingURL=context.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/react/context.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, useContext } from 'react';\nimport type { ResolveClientUrl } from '#internal/shared/client/proxy-through-host';\n\ninterface RemoteComponentsContextValue {\n resolveClientUrl?: ResolveClientUrl;\n}\n\nconst RemoteComponentsContext = createContext<RemoteComponentsContextValue>({});\n\n/**\n * Client-side context provider for passing `resolveClientUrl` to all nested\n * `<RemoteComponent>` instances. Since `resolveClientUrl` is a function, it\n * can't be passed as a prop through Server Components — this provider should\n * wrap the tree in a Client Component boundary so the callback is available\n * on the client where asset fetches happen.\n */\nexport function RemoteComponentsProvider({\n resolveClientUrl,\n children,\n}: {\n resolveClientUrl?: ResolveClientUrl;\n children: React.ReactNode;\n}) {\n return (\n <RemoteComponentsContext value={{ resolveClientUrl }}>\n {children}\n </RemoteComponentsContext>\n );\n}\n\nexport function useRemoteComponentsContext(): RemoteComponentsContextValue {\n return useContext(RemoteComponentsContext);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BI;AAxBJ,mBAA0C;AAO1C,MAAM,8BAA0B,4BAA4C,CAAC,CAAC;AASvE,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AACF,GAGG;AACD,SACE,4CAAC,2BAAwB,OAAO,EAAE,iBAAiB,GAChD,UACH;AAEJ;AAEO,SAAS,6BAA2D;AACzE,aAAO,yBAAW,uBAAuB;AAC3C;","names":[]}
@@ -0,0 +1,20 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ResolveClientUrl } from '../shared/client/proxy-through-host.js';
3
+
4
+ interface RemoteComponentsContextValue {
5
+ resolveClientUrl?: ResolveClientUrl;
6
+ }
7
+ /**
8
+ * Client-side context provider for passing `resolveClientUrl` to all nested
9
+ * `<RemoteComponent>` instances. Since `resolveClientUrl` is a function, it
10
+ * can't be passed as a prop through Server Components — this provider should
11
+ * wrap the tree in a Client Component boundary so the callback is available
12
+ * on the client where asset fetches happen.
13
+ */
14
+ declare function RemoteComponentsProvider({ resolveClientUrl, children, }: {
15
+ resolveClientUrl?: ResolveClientUrl;
16
+ children: React.ReactNode;
17
+ }): react_jsx_runtime.JSX.Element;
18
+ declare function useRemoteComponentsContext(): RemoteComponentsContextValue;
19
+
20
+ export { RemoteComponentsProvider, useRemoteComponentsContext };
@@ -0,0 +1,18 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { createContext, useContext } from "react";
4
+ const RemoteComponentsContext = createContext({});
5
+ function RemoteComponentsProvider({
6
+ resolveClientUrl,
7
+ children
8
+ }) {
9
+ return /* @__PURE__ */ jsx(RemoteComponentsContext, { value: { resolveClientUrl }, children });
10
+ }
11
+ function useRemoteComponentsContext() {
12
+ return useContext(RemoteComponentsContext);
13
+ }
14
+ export {
15
+ RemoteComponentsProvider,
16
+ useRemoteComponentsContext
17
+ };
18
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/react/context.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, useContext } from 'react';\nimport type { ResolveClientUrl } from '#internal/shared/client/proxy-through-host';\n\ninterface RemoteComponentsContextValue {\n resolveClientUrl?: ResolveClientUrl;\n}\n\nconst RemoteComponentsContext = createContext<RemoteComponentsContextValue>({});\n\n/**\n * Client-side context provider for passing `resolveClientUrl` to all nested\n * `<RemoteComponent>` instances. Since `resolveClientUrl` is a function, it\n * can't be passed as a prop through Server Components — this provider should\n * wrap the tree in a Client Component boundary so the callback is available\n * on the client where asset fetches happen.\n */\nexport function RemoteComponentsProvider({\n resolveClientUrl,\n children,\n}: {\n resolveClientUrl?: ResolveClientUrl;\n children: React.ReactNode;\n}) {\n return (\n <RemoteComponentsContext value={{ resolveClientUrl }}>\n {children}\n </RemoteComponentsContext>\n );\n}\n\nexport function useRemoteComponentsContext(): RemoteComponentsContextValue {\n return useContext(RemoteComponentsContext);\n}\n"],"mappings":";AA0BI;AAxBJ,SAAS,eAAe,kBAAkB;AAO1C,MAAM,0BAA0B,cAA4C,CAAC,CAAC;AASvE,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AACF,GAGG;AACD,SACE,oBAAC,2BAAwB,OAAO,EAAE,iBAAiB,GAChD,UACH;AAEJ;AAEO,SAAS,6BAA2D;AACzE,SAAO,WAAW,uBAAuB;AAC3C;","names":[]}
@@ -0,0 +1,39 @@
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 use_resolve_client_url_exports = {};
20
+ __export(use_resolve_client_url_exports, {
21
+ useResolveClientUrl: () => useResolveClientUrl
22
+ });
23
+ module.exports = __toCommonJS(use_resolve_client_url_exports);
24
+ var import_react = require("react");
25
+ var import_context = require("#internal/react/context");
26
+ var import_default_resolve_client_url = require("#internal/shared/client/default-resolve-client-url");
27
+ function useResolveClientUrl(prop, urlHref) {
28
+ const { resolveClientUrl: contextValue } = (0, import_context.useRemoteComponentsContext)();
29
+ const resolveClientUrl = prop ?? contextValue;
30
+ return (0, import_react.useMemo)(
31
+ () => (0, import_default_resolve_client_url.bindResolveClientUrl)(resolveClientUrl, urlHref),
32
+ [resolveClientUrl, urlHref]
33
+ );
34
+ }
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ useResolveClientUrl
38
+ });
39
+ //# sourceMappingURL=use-resolve-client-url.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/react/hooks/use-resolve-client-url.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useRemoteComponentsContext } from '#internal/react/context';\nimport { bindResolveClientUrl } from '#internal/shared/client/default-resolve-client-url';\nimport type { ResolveClientUrl } from '#internal/shared/client/proxy-through-host';\n\nexport function useResolveClientUrl(\n prop: ResolveClientUrl | undefined,\n urlHref: string,\n) {\n const { resolveClientUrl: contextValue } = useRemoteComponentsContext();\n const resolveClientUrl = prop ?? contextValue;\n return useMemo(\n () => bindResolveClientUrl(resolveClientUrl, urlHref),\n [resolveClientUrl, urlHref],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;AACxB,qBAA2C;AAC3C,wCAAqC;AAG9B,SAAS,oBACd,MACA,SACA;AACA,QAAM,EAAE,kBAAkB,aAAa,QAAI,2CAA2B;AACtE,QAAM,mBAAmB,QAAQ;AACjC,aAAO;AAAA,IACL,UAAM,wDAAqB,kBAAkB,OAAO;AAAA,IACpD,CAAC,kBAAkB,OAAO;AAAA,EAC5B;AACF;","names":[]}
@@ -0,0 +1,5 @@
1
+ import { ResolveClientUrl, InternalResolveClientUrl } from '../../shared/client/proxy-through-host.js';
2
+
3
+ declare function useResolveClientUrl(prop: ResolveClientUrl | undefined, urlHref: string): InternalResolveClientUrl | undefined;
4
+
5
+ export { useResolveClientUrl };
@@ -0,0 +1,15 @@
1
+ import { useMemo } from "react";
2
+ import { useRemoteComponentsContext } from "#internal/react/context";
3
+ import { bindResolveClientUrl } from "#internal/shared/client/default-resolve-client-url";
4
+ function useResolveClientUrl(prop, urlHref) {
5
+ const { resolveClientUrl: contextValue } = useRemoteComponentsContext();
6
+ const resolveClientUrl = prop ?? contextValue;
7
+ return useMemo(
8
+ () => bindResolveClientUrl(resolveClientUrl, urlHref),
9
+ [resolveClientUrl, urlHref]
10
+ );
11
+ }
12
+ export {
13
+ useResolveClientUrl
14
+ };
15
+ //# sourceMappingURL=use-resolve-client-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/react/hooks/use-resolve-client-url.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useRemoteComponentsContext } from '#internal/react/context';\nimport { bindResolveClientUrl } from '#internal/shared/client/default-resolve-client-url';\nimport type { ResolveClientUrl } from '#internal/shared/client/proxy-through-host';\n\nexport function useResolveClientUrl(\n prop: ResolveClientUrl | undefined,\n urlHref: string,\n) {\n const { resolveClientUrl: contextValue } = useRemoteComponentsContext();\n const resolveClientUrl = prop ?? contextValue;\n return useMemo(\n () => bindResolveClientUrl(resolveClientUrl, urlHref),\n [resolveClientUrl, urlHref],\n );\n}\n"],"mappings":"AAAA,SAAS,eAAe;AACxB,SAAS,kCAAkC;AAC3C,SAAS,4BAA4B;AAG9B,SAAS,oBACd,MACA,SACA;AACA,QAAM,EAAE,kBAAkB,aAAa,IAAI,2BAA2B;AACtE,QAAM,mBAAmB,QAAQ;AACjC,SAAO;AAAA,IACL,MAAM,qBAAqB,kBAAkB,OAAO;AAAA,IACpD,CAAC,kBAAkB,OAAO;AAAA,EAC5B;AACF;","names":[]}
@@ -32,7 +32,7 @@ const tagNames = [
32
32
  "script",
33
33
  "link"
34
34
  ];
35
- function applyOriginToNodes(doc, url) {
35
+ function applyOriginToNodes(doc, url, resolveClientUrl) {
36
36
  if (url.origin !== location.origin) {
37
37
  const nodes = doc.querySelectorAll(
38
38
  tagNames.map(
@@ -41,12 +41,15 @@ function applyOriginToNodes(doc, url) {
41
41
  );
42
42
  nodes.forEach((node) => {
43
43
  if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
44
- node.src = new URL(node.getAttribute("src") ?? "/", url).href;
44
+ const absoluteSrc = new URL(node.getAttribute("src") ?? "/", url).href;
45
+ const isScript = node.tagName.toLowerCase() === "script";
46
+ node.src = isScript ? absoluteSrc : resolveClientUrl?.(absoluteSrc) ?? absoluteSrc;
45
47
  }
46
48
  if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
49
+ const absoluteHref = new URL(node.getAttribute("href") ?? "/", url).href;
47
50
  node.setAttribute(
48
51
  "href",
49
- new URL(node.getAttribute("href") ?? "/", url).href
52
+ resolveClientUrl?.(absoluteHref) ?? absoluteHref
50
53
  );
51
54
  }
52
55
  if (node.hasAttribute("srcset")) {
@@ -55,7 +58,8 @@ function applyOriginToNodes(doc, url) {
55
58
  if (!urlPart)
56
59
  return entry;
57
60
  const absoluteUrl = new URL(urlPart, url).href;
58
- return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
61
+ const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
62
+ return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
59
63
  }).join(", ");
60
64
  if (srcSet) {
61
65
  node.setAttribute("srcset", srcSet);
@@ -67,7 +71,8 @@ function applyOriginToNodes(doc, url) {
67
71
  if (!urlPart)
68
72
  return entry;
69
73
  const absoluteUrl = new URL(urlPart, url).href;
70
- return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
74
+ const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
75
+ return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
71
76
  }).join(", ");
72
77
  if (srcSet) {
73
78
  node.setAttribute("imagesrcset", srcSet);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/client/apply-origin.ts"],"sourcesContent":["const tagNames = [\n 'img',\n 'source',\n 'video',\n 'audio',\n 'track',\n 'iframe',\n 'embed',\n 'script',\n 'link',\n];\n\nexport function applyOriginToNodes(doc: Document | HTMLElement, url: URL) {\n if (url.origin !== location.origin) {\n const nodes = doc.querySelectorAll<HTMLImageElement>(\n tagNames\n .map(\n (type) =>\n `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`,\n )\n .join(','),\n );\n nodes.forEach((node) => {\n if (\n node.hasAttribute('src') &&\n /^[./]+\\/?/.test(node.getAttribute('src') ?? '')\n ) {\n node.src = new URL(node.getAttribute('src') ?? '/', url).href;\n }\n if (\n node.hasAttribute('href') &&\n /^[./]+\\/?/.test(node.getAttribute('href') ?? '')\n ) {\n node.setAttribute(\n 'href',\n new URL(node.getAttribute('href') ?? '/', url).href,\n );\n }\n if (node.hasAttribute('srcset')) {\n const srcSet = node\n .getAttribute('srcset')\n ?.split(',')\n .map((entry) => {\n const [urlPart, descriptor] = entry.trim().split(/\\s+/);\n if (!urlPart) return entry;\n\n const absoluteUrl = new URL(urlPart, url).href;\n return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;\n })\n .join(', ');\n if (srcSet) {\n node.setAttribute('srcset', srcSet);\n }\n }\n if (node.hasAttribute('imagesrcset')) {\n const srcSet = node\n .getAttribute('imagesrcset')\n ?.split(',')\n .map((entry) => {\n const [urlPart, descriptor] = entry.trim().split(/\\s+/);\n if (!urlPart) return entry;\n\n const absoluteUrl = new URL(urlPart, url).href;\n return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;\n })\n .join(', ');\n if (srcSet) {\n node.setAttribute('imagesrcset', srcSet);\n }\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,WAAW;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,mBAAmB,KAA6B,KAAU;AACxE,MAAI,IAAI,WAAW,SAAS,QAAQ;AAClC,UAAM,QAAQ,IAAI;AAAA,MAChB,SACG;AAAA,QACC,CAAC,SACC,GAAG,aAAa,gBAAgB,cAAc;AAAA,MAClD,EACC,KAAK,GAAG;AAAA,IACb;AACA,UAAM,QAAQ,CAAC,SAAS;AACtB,UACE,KAAK,aAAa,KAAK,KACvB,YAAY,KAAK,KAAK,aAAa,KAAK,KAAK,EAAE,GAC/C;AACA,aAAK,MAAM,IAAI,IAAI,KAAK,aAAa,KAAK,KAAK,KAAK,GAAG,EAAE;AAAA,MAC3D;AACA,UACE,KAAK,aAAa,MAAM,KACxB,YAAY,KAAK,KAAK,aAAa,MAAM,KAAK,EAAE,GAChD;AACA,aAAK;AAAA,UACH;AAAA,UACA,IAAI,IAAI,KAAK,aAAa,MAAM,KAAK,KAAK,GAAG,EAAE;AAAA,QACjD;AAAA,MACF;AACA,UAAI,KAAK,aAAa,QAAQ,GAAG;AAC/B,cAAM,SAAS,KACZ,aAAa,QAAQ,GACpB,MAAM,GAAG,EACV,IAAI,CAAC,UAAU;AACd,gBAAM,CAAC,SAAS,UAAU,IAAI,MAAM,KAAK,EAAE,MAAM,KAAK;AACtD,cAAI,CAAC;AAAS,mBAAO;AAErB,gBAAM,cAAc,IAAI,IAAI,SAAS,GAAG,EAAE;AAC1C,iBAAO,aAAa,GAAG,eAAe,eAAe;AAAA,QACvD,CAAC,EACA,KAAK,IAAI;AACZ,YAAI,QAAQ;AACV,eAAK,aAAa,UAAU,MAAM;AAAA,QACpC;AAAA,MACF;AACA,UAAI,KAAK,aAAa,aAAa,GAAG;AACpC,cAAM,SAAS,KACZ,aAAa,aAAa,GACzB,MAAM,GAAG,EACV,IAAI,CAAC,UAAU;AACd,gBAAM,CAAC,SAAS,UAAU,IAAI,MAAM,KAAK,EAAE,MAAM,KAAK;AACtD,cAAI,CAAC;AAAS,mBAAO;AAErB,gBAAM,cAAc,IAAI,IAAI,SAAS,GAAG,EAAE;AAC1C,iBAAO,aAAa,GAAG,eAAe,eAAe;AAAA,QACvD,CAAC,EACA,KAAK,IAAI;AACZ,YAAI,QAAQ;AACV,eAAK,aAAa,eAAe,MAAM;AAAA,QACzC;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/shared/client/apply-origin.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/shared/ssr/types';\n\nconst tagNames = [\n 'img',\n 'source',\n 'video',\n 'audio',\n 'track',\n 'iframe',\n 'embed',\n 'script',\n 'link',\n];\n\nexport function applyOriginToNodes(\n doc: Document | HTMLElement,\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n if (url.origin !== location.origin) {\n const nodes = doc.querySelectorAll<HTMLImageElement>(\n tagNames\n .map(\n (type) =>\n `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`,\n )\n .join(','),\n );\n nodes.forEach((node) => {\n if (\n node.hasAttribute('src') &&\n /^[./]+\\/?/.test(node.getAttribute('src') ?? '')\n ) {\n const absoluteSrc = new URL(node.getAttribute('src') ?? '/', url).href;\n // Script elements are handled by the loaders (script-loader, static-loader)\n // which apply the callback themselves. Only apply it here for non-script elements.\n const isScript = node.tagName.toLowerCase() === 'script';\n node.src = isScript\n ? absoluteSrc\n : (resolveClientUrl?.(absoluteSrc) ?? absoluteSrc);\n }\n if (\n node.hasAttribute('href') &&\n /^[./]+\\/?/.test(node.getAttribute('href') ?? '')\n ) {\n const absoluteHref = new URL(node.getAttribute('href') ?? '/', url)\n .href;\n node.setAttribute(\n 'href',\n resolveClientUrl?.(absoluteHref) ?? absoluteHref,\n );\n }\n if (node.hasAttribute('srcset')) {\n const srcSet = node\n .getAttribute('srcset')\n ?.split(',')\n .map((entry) => {\n const [urlPart, descriptor] = entry.trim().split(/\\s+/);\n if (!urlPart) return entry;\n\n const absoluteUrl = new URL(urlPart, url).href;\n const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;\n return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;\n })\n .join(', ');\n if (srcSet) {\n node.setAttribute('srcset', srcSet);\n }\n }\n if (node.hasAttribute('imagesrcset')) {\n const srcSet = node\n .getAttribute('imagesrcset')\n ?.split(',')\n .map((entry) => {\n const [urlPart, descriptor] = entry.trim().split(/\\s+/);\n if (!urlPart) return entry;\n\n const absoluteUrl = new URL(urlPart, url).href;\n const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;\n return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;\n })\n .join(', ');\n if (srcSet) {\n node.setAttribute('imagesrcset', srcSet);\n }\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,MAAM,WAAW;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,mBACd,KACA,KACA,kBACA;AACA,MAAI,IAAI,WAAW,SAAS,QAAQ;AAClC,UAAM,QAAQ,IAAI;AAAA,MAChB,SACG;AAAA,QACC,CAAC,SACC,GAAG,aAAa,gBAAgB,cAAc;AAAA,MAClD,EACC,KAAK,GAAG;AAAA,IACb;AACA,UAAM,QAAQ,CAAC,SAAS;AACtB,UACE,KAAK,aAAa,KAAK,KACvB,YAAY,KAAK,KAAK,aAAa,KAAK,KAAK,EAAE,GAC/C;AACA,cAAM,cAAc,IAAI,IAAI,KAAK,aAAa,KAAK,KAAK,KAAK,GAAG,EAAE;AAGlE,cAAM,WAAW,KAAK,QAAQ,YAAY,MAAM;AAChD,aAAK,MAAM,WACP,cACC,mBAAmB,WAAW,KAAK;AAAA,MAC1C;AACA,UACE,KAAK,aAAa,MAAM,KACxB,YAAY,KAAK,KAAK,aAAa,MAAM,KAAK,EAAE,GAChD;AACA,cAAM,eAAe,IAAI,IAAI,KAAK,aAAa,MAAM,KAAK,KAAK,GAAG,EAC/D;AACH,aAAK;AAAA,UACH;AAAA,UACA,mBAAmB,YAAY,KAAK;AAAA,QACtC;AAAA,MACF;AACA,UAAI,KAAK,aAAa,QAAQ,GAAG;AAC/B,cAAM,SAAS,KACZ,aAAa,QAAQ,GACpB,MAAM,GAAG,EACV,IAAI,CAAC,UAAU;AACd,gBAAM,CAAC,SAAS,UAAU,IAAI,MAAM,KAAK,EAAE,MAAM,KAAK;AACtD,cAAI,CAAC;AAAS,mBAAO;AAErB,gBAAM,cAAc,IAAI,IAAI,SAAS,GAAG,EAAE;AAC1C,gBAAM,cAAc,mBAAmB,WAAW,KAAK;AACvD,iBAAO,aAAa,GAAG,eAAe,eAAe;AAAA,QACvD,CAAC,EACA,KAAK,IAAI;AACZ,YAAI,QAAQ;AACV,eAAK,aAAa,UAAU,MAAM;AAAA,QACpC;AAAA,MACF;AACA,UAAI,KAAK,aAAa,aAAa,GAAG;AACpC,cAAM,SAAS,KACZ,aAAa,aAAa,GACzB,MAAM,GAAG,EACV,IAAI,CAAC,UAAU;AACd,gBAAM,CAAC,SAAS,UAAU,IAAI,MAAM,KAAK,EAAE,MAAM,KAAK;AACtD,cAAI,CAAC;AAAS,mBAAO;AAErB,gBAAM,cAAc,IAAI,IAAI,SAAS,GAAG,EAAE;AAC1C,gBAAM,cAAc,mBAAmB,WAAW,KAAK;AACvD,iBAAO,aAAa,GAAG,eAAe,eAAe;AAAA,QACvD,CAAC,EACA,KAAK,IAAI;AACZ,YAAI,QAAQ;AACV,eAAK,aAAa,eAAe,MAAM;AAAA,QACzC;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1,3 +1,5 @@
1
- declare function applyOriginToNodes(doc: Document | HTMLElement, url: URL): void;
1
+ import { InternalResolveClientUrl } from './proxy-through-host.js';
2
+
3
+ declare function applyOriginToNodes(doc: Document | HTMLElement, url: URL, resolveClientUrl?: InternalResolveClientUrl): void;
2
4
 
3
5
  export { applyOriginToNodes };
@@ -9,7 +9,7 @@ const tagNames = [
9
9
  "script",
10
10
  "link"
11
11
  ];
12
- function applyOriginToNodes(doc, url) {
12
+ function applyOriginToNodes(doc, url, resolveClientUrl) {
13
13
  if (url.origin !== location.origin) {
14
14
  const nodes = doc.querySelectorAll(
15
15
  tagNames.map(
@@ -18,12 +18,15 @@ function applyOriginToNodes(doc, url) {
18
18
  );
19
19
  nodes.forEach((node) => {
20
20
  if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
21
- node.src = new URL(node.getAttribute("src") ?? "/", url).href;
21
+ const absoluteSrc = new URL(node.getAttribute("src") ?? "/", url).href;
22
+ const isScript = node.tagName.toLowerCase() === "script";
23
+ node.src = isScript ? absoluteSrc : resolveClientUrl?.(absoluteSrc) ?? absoluteSrc;
22
24
  }
23
25
  if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
26
+ const absoluteHref = new URL(node.getAttribute("href") ?? "/", url).href;
24
27
  node.setAttribute(
25
28
  "href",
26
- new URL(node.getAttribute("href") ?? "/", url).href
29
+ resolveClientUrl?.(absoluteHref) ?? absoluteHref
27
30
  );
28
31
  }
29
32
  if (node.hasAttribute("srcset")) {
@@ -32,7 +35,8 @@ function applyOriginToNodes(doc, url) {
32
35
  if (!urlPart)
33
36
  return entry;
34
37
  const absoluteUrl = new URL(urlPart, url).href;
35
- return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
38
+ const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
39
+ return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
36
40
  }).join(", ");
37
41
  if (srcSet) {
38
42
  node.setAttribute("srcset", srcSet);
@@ -44,7 +48,8 @@ function applyOriginToNodes(doc, url) {
44
48
  if (!urlPart)
45
49
  return entry;
46
50
  const absoluteUrl = new URL(urlPart, url).href;
47
- return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
51
+ const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
52
+ return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
48
53
  }).join(", ");
49
54
  if (srcSet) {
50
55
  node.setAttribute("imagesrcset", srcSet);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/client/apply-origin.ts"],"sourcesContent":["const tagNames = [\n 'img',\n 'source',\n 'video',\n 'audio',\n 'track',\n 'iframe',\n 'embed',\n 'script',\n 'link',\n];\n\nexport function applyOriginToNodes(doc: Document | HTMLElement, url: URL) {\n if (url.origin !== location.origin) {\n const nodes = doc.querySelectorAll<HTMLImageElement>(\n tagNames\n .map(\n (type) =>\n `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`,\n )\n .join(','),\n );\n nodes.forEach((node) => {\n if (\n node.hasAttribute('src') &&\n /^[./]+\\/?/.test(node.getAttribute('src') ?? '')\n ) {\n node.src = new URL(node.getAttribute('src') ?? '/', url).href;\n }\n if (\n node.hasAttribute('href') &&\n /^[./]+\\/?/.test(node.getAttribute('href') ?? '')\n ) {\n node.setAttribute(\n 'href',\n new URL(node.getAttribute('href') ?? '/', url).href,\n );\n }\n if (node.hasAttribute('srcset')) {\n const srcSet = node\n .getAttribute('srcset')\n ?.split(',')\n .map((entry) => {\n const [urlPart, descriptor] = entry.trim().split(/\\s+/);\n if (!urlPart) return entry;\n\n const absoluteUrl = new URL(urlPart, url).href;\n return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;\n })\n .join(', ');\n if (srcSet) {\n node.setAttribute('srcset', srcSet);\n }\n }\n if (node.hasAttribute('imagesrcset')) {\n const srcSet = node\n .getAttribute('imagesrcset')\n ?.split(',')\n .map((entry) => {\n const [urlPart, descriptor] = entry.trim().split(/\\s+/);\n if (!urlPart) return entry;\n\n const absoluteUrl = new URL(urlPart, url).href;\n return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;\n })\n .join(', ');\n if (srcSet) {\n node.setAttribute('imagesrcset', srcSet);\n }\n }\n });\n }\n}\n"],"mappings":"AAAA,MAAM,WAAW;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,mBAAmB,KAA6B,KAAU;AACxE,MAAI,IAAI,WAAW,SAAS,QAAQ;AAClC,UAAM,QAAQ,IAAI;AAAA,MAChB,SACG;AAAA,QACC,CAAC,SACC,GAAG,aAAa,gBAAgB,cAAc;AAAA,MAClD,EACC,KAAK,GAAG;AAAA,IACb;AACA,UAAM,QAAQ,CAAC,SAAS;AACtB,UACE,KAAK,aAAa,KAAK,KACvB,YAAY,KAAK,KAAK,aAAa,KAAK,KAAK,EAAE,GAC/C;AACA,aAAK,MAAM,IAAI,IAAI,KAAK,aAAa,KAAK,KAAK,KAAK,GAAG,EAAE;AAAA,MAC3D;AACA,UACE,KAAK,aAAa,MAAM,KACxB,YAAY,KAAK,KAAK,aAAa,MAAM,KAAK,EAAE,GAChD;AACA,aAAK;AAAA,UACH;AAAA,UACA,IAAI,IAAI,KAAK,aAAa,MAAM,KAAK,KAAK,GAAG,EAAE;AAAA,QACjD;AAAA,MACF;AACA,UAAI,KAAK,aAAa,QAAQ,GAAG;AAC/B,cAAM,SAAS,KACZ,aAAa,QAAQ,GACpB,MAAM,GAAG,EACV,IAAI,CAAC,UAAU;AACd,gBAAM,CAAC,SAAS,UAAU,IAAI,MAAM,KAAK,EAAE,MAAM,KAAK;AACtD,cAAI,CAAC;AAAS,mBAAO;AAErB,gBAAM,cAAc,IAAI,IAAI,SAAS,GAAG,EAAE;AAC1C,iBAAO,aAAa,GAAG,eAAe,eAAe;AAAA,QACvD,CAAC,EACA,KAAK,IAAI;AACZ,YAAI,QAAQ;AACV,eAAK,aAAa,UAAU,MAAM;AAAA,QACpC;AAAA,MACF;AACA,UAAI,KAAK,aAAa,aAAa,GAAG;AACpC,cAAM,SAAS,KACZ,aAAa,aAAa,GACzB,MAAM,GAAG,EACV,IAAI,CAAC,UAAU;AACd,gBAAM,CAAC,SAAS,UAAU,IAAI,MAAM,KAAK,EAAE,MAAM,KAAK;AACtD,cAAI,CAAC;AAAS,mBAAO;AAErB,gBAAM,cAAc,IAAI,IAAI,SAAS,GAAG,EAAE;AAC1C,iBAAO,aAAa,GAAG,eAAe,eAAe;AAAA,QACvD,CAAC,EACA,KAAK,IAAI;AACZ,YAAI,QAAQ;AACV,eAAK,aAAa,eAAe,MAAM;AAAA,QACzC;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/shared/client/apply-origin.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/shared/ssr/types';\n\nconst tagNames = [\n 'img',\n 'source',\n 'video',\n 'audio',\n 'track',\n 'iframe',\n 'embed',\n 'script',\n 'link',\n];\n\nexport function applyOriginToNodes(\n doc: Document | HTMLElement,\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n if (url.origin !== location.origin) {\n const nodes = doc.querySelectorAll<HTMLImageElement>(\n tagNames\n .map(\n (type) =>\n `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`,\n )\n .join(','),\n );\n nodes.forEach((node) => {\n if (\n node.hasAttribute('src') &&\n /^[./]+\\/?/.test(node.getAttribute('src') ?? '')\n ) {\n const absoluteSrc = new URL(node.getAttribute('src') ?? '/', url).href;\n // Script elements are handled by the loaders (script-loader, static-loader)\n // which apply the callback themselves. Only apply it here for non-script elements.\n const isScript = node.tagName.toLowerCase() === 'script';\n node.src = isScript\n ? absoluteSrc\n : (resolveClientUrl?.(absoluteSrc) ?? absoluteSrc);\n }\n if (\n node.hasAttribute('href') &&\n /^[./]+\\/?/.test(node.getAttribute('href') ?? '')\n ) {\n const absoluteHref = new URL(node.getAttribute('href') ?? '/', url)\n .href;\n node.setAttribute(\n 'href',\n resolveClientUrl?.(absoluteHref) ?? absoluteHref,\n );\n }\n if (node.hasAttribute('srcset')) {\n const srcSet = node\n .getAttribute('srcset')\n ?.split(',')\n .map((entry) => {\n const [urlPart, descriptor] = entry.trim().split(/\\s+/);\n if (!urlPart) return entry;\n\n const absoluteUrl = new URL(urlPart, url).href;\n const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;\n return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;\n })\n .join(', ');\n if (srcSet) {\n node.setAttribute('srcset', srcSet);\n }\n }\n if (node.hasAttribute('imagesrcset')) {\n const srcSet = node\n .getAttribute('imagesrcset')\n ?.split(',')\n .map((entry) => {\n const [urlPart, descriptor] = entry.trim().split(/\\s+/);\n if (!urlPart) return entry;\n\n const absoluteUrl = new URL(urlPart, url).href;\n const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;\n return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;\n })\n .join(', ');\n if (srcSet) {\n node.setAttribute('imagesrcset', srcSet);\n }\n }\n });\n }\n}\n"],"mappings":"AAEA,MAAM,WAAW;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,mBACd,KACA,KACA,kBACA;AACA,MAAI,IAAI,WAAW,SAAS,QAAQ;AAClC,UAAM,QAAQ,IAAI;AAAA,MAChB,SACG;AAAA,QACC,CAAC,SACC,GAAG,aAAa,gBAAgB,cAAc;AAAA,MAClD,EACC,KAAK,GAAG;AAAA,IACb;AACA,UAAM,QAAQ,CAAC,SAAS;AACtB,UACE,KAAK,aAAa,KAAK,KACvB,YAAY,KAAK,KAAK,aAAa,KAAK,KAAK,EAAE,GAC/C;AACA,cAAM,cAAc,IAAI,IAAI,KAAK,aAAa,KAAK,KAAK,KAAK,GAAG,EAAE;AAGlE,cAAM,WAAW,KAAK,QAAQ,YAAY,MAAM;AAChD,aAAK,MAAM,WACP,cACC,mBAAmB,WAAW,KAAK;AAAA,MAC1C;AACA,UACE,KAAK,aAAa,MAAM,KACxB,YAAY,KAAK,KAAK,aAAa,MAAM,KAAK,EAAE,GAChD;AACA,cAAM,eAAe,IAAI,IAAI,KAAK,aAAa,MAAM,KAAK,KAAK,GAAG,EAC/D;AACH,aAAK;AAAA,UACH;AAAA,UACA,mBAAmB,YAAY,KAAK;AAAA,QACtC;AAAA,MACF;AACA,UAAI,KAAK,aAAa,QAAQ,GAAG;AAC/B,cAAM,SAAS,KACZ,aAAa,QAAQ,GACpB,MAAM,GAAG,EACV,IAAI,CAAC,UAAU;AACd,gBAAM,CAAC,SAAS,UAAU,IAAI,MAAM,KAAK,EAAE,MAAM,KAAK;AACtD,cAAI,CAAC;AAAS,mBAAO;AAErB,gBAAM,cAAc,IAAI,IAAI,SAAS,GAAG,EAAE;AAC1C,gBAAM,cAAc,mBAAmB,WAAW,KAAK;AACvD,iBAAO,aAAa,GAAG,eAAe,eAAe;AAAA,QACvD,CAAC,EACA,KAAK,IAAI;AACZ,YAAI,QAAQ;AACV,eAAK,aAAa,UAAU,MAAM;AAAA,QACpC;AAAA,MACF;AACA,UAAI,KAAK,aAAa,aAAa,GAAG;AACpC,cAAM,SAAS,KACZ,aAAa,aAAa,GACzB,MAAM,GAAG,EACV,IAAI,CAAC,UAAU;AACd,gBAAM,CAAC,SAAS,UAAU,IAAI,MAAM,KAAK,EAAE,MAAM,KAAK;AACtD,cAAI,CAAC;AAAS,mBAAO;AAErB,gBAAM,cAAc,IAAI,IAAI,SAAS,GAAG,EAAE;AAC1C,gBAAM,cAAc,mBAAmB,WAAW,KAAK;AACvD,iBAAO,aAAa,GAAG,eAAe,eAAe;AAAA,QACvD,CAAC,EACA,KAAK,IAAI;AACZ,YAAI,QAAQ;AACV,eAAK,aAAa,eAAe,MAAM;AAAA,QACzC;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -0,0 +1,32 @@
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 default_resolve_client_url_exports = {};
20
+ __export(default_resolve_client_url_exports, {
21
+ bindResolveClientUrl: () => bindResolveClientUrl
22
+ });
23
+ module.exports = __toCommonJS(default_resolve_client_url_exports);
24
+ var import_proxy_through_host = require("./proxy-through-host");
25
+ function bindResolveClientUrl(prop, remoteSrc) {
26
+ return prop ? (0, import_proxy_through_host.withRemoteSrc)(prop, remoteSrc) : void 0;
27
+ }
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ bindResolveClientUrl
31
+ });
32
+ //# sourceMappingURL=default-resolve-client-url.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/shared/client/default-resolve-client-url.ts"],"sourcesContent":["import {\n type InternalResolveClientUrl,\n type ResolveClientUrl,\n withRemoteSrc,\n} from './proxy-through-host';\n\nexport function bindResolveClientUrl(\n prop: ResolveClientUrl | undefined,\n remoteSrc: string,\n): InternalResolveClientUrl | undefined {\n return prop ? withRemoteSrc(prop, remoteSrc) : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAIO;AAEA,SAAS,qBACd,MACA,WACsC;AACtC,SAAO,WAAO,yCAAc,MAAM,SAAS,IAAI;AACjD;","names":[]}
@@ -0,0 +1,5 @@
1
+ import { ResolveClientUrl, InternalResolveClientUrl } from './proxy-through-host.js';
2
+
3
+ declare function bindResolveClientUrl(prop: ResolveClientUrl | undefined, remoteSrc: string): InternalResolveClientUrl | undefined;
4
+
5
+ export { bindResolveClientUrl };
@@ -0,0 +1,10 @@
1
+ import {
2
+ withRemoteSrc
3
+ } from "./proxy-through-host";
4
+ function bindResolveClientUrl(prop, remoteSrc) {
5
+ return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
6
+ }
7
+ export {
8
+ bindResolveClientUrl
9
+ };
10
+ //# sourceMappingURL=default-resolve-client-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/shared/client/default-resolve-client-url.ts"],"sourcesContent":["import {\n type InternalResolveClientUrl,\n type ResolveClientUrl,\n withRemoteSrc,\n} from './proxy-through-host';\n\nexport function bindResolveClientUrl(\n prop: ResolveClientUrl | undefined,\n remoteSrc: string,\n): InternalResolveClientUrl | undefined {\n return prop ? withRemoteSrc(prop, remoteSrc) : undefined;\n}\n"],"mappings":"AAAA;AAAA,EAGE;AAAA,OACK;AAEA,SAAS,qBACd,MACA,WACsC;AACtC,SAAO,OAAO,cAAc,MAAM,SAAS,IAAI;AACjD;","names":[]}
@@ -18,15 +18,24 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var protected_rc_fallback_exports = {};
20
20
  __export(protected_rc_fallback_exports, {
21
- generateProtectedRcFallbackSrc: () => generateProtectedRcFallbackSrc
21
+ generateProtectedRcFallbackSrc: () => generateProtectedRcFallbackSrc,
22
+ isProxiedUrl: () => isProxiedUrl
22
23
  });
23
24
  module.exports = __toCommonJS(protected_rc_fallback_exports);
24
25
  var import_constants = require("#internal/shared/constants");
25
26
  function generateProtectedRcFallbackSrc(url) {
26
27
  return `${import_constants.RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
27
28
  }
29
+ function isProxiedUrl(url) {
30
+ try {
31
+ return new URL(url, location.href).pathname === import_constants.RC_PROTECTED_REMOTE_FETCH_PATHNAME;
32
+ } catch {
33
+ return false;
34
+ }
35
+ }
28
36
  // Annotate the CommonJS export names for ESM import in node:
29
37
  0 && (module.exports = {
30
- generateProtectedRcFallbackSrc
38
+ generateProtectedRcFallbackSrc,
39
+ isProxiedUrl
31
40
  });
32
41
  //# sourceMappingURL=protected-rc-fallback.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/client/protected-rc-fallback.ts"],"sourcesContent":["import { RC_PROTECTED_REMOTE_FETCH_PATHNAME } from '#internal/shared/constants';\n\n/**\n * Generates a fallback URL that proxies the request through the host's protected remote fetch endpoint\n */\nexport function generateProtectedRcFallbackSrc(url: string): string {\n return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmD;AAK5C,SAAS,+BAA+B,KAAqB;AAClE,SAAO,GAAG,2DAA0C,mBAAmB,GAAG;AAC5E;","names":[]}
1
+ {"version":3,"sources":["../../../../src/shared/client/protected-rc-fallback.ts"],"sourcesContent":["import { RC_PROTECTED_REMOTE_FETCH_PATHNAME } from '#internal/shared/constants';\n\n/**\n * Generates a fallback URL that proxies the request through the host's protected remote fetch endpoint\n */\nexport function generateProtectedRcFallbackSrc(url: string): string {\n return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;\n}\n\nexport function isProxiedUrl(url: string): boolean {\n try {\n return (\n new URL(url, location.href).pathname ===\n RC_PROTECTED_REMOTE_FETCH_PATHNAME\n );\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmD;AAK5C,SAAS,+BAA+B,KAAqB;AAClE,SAAO,GAAG,2DAA0C,mBAAmB,GAAG;AAC5E;AAEO,SAAS,aAAa,KAAsB;AACjD,MAAI;AACF,WACE,IAAI,IAAI,KAAK,SAAS,IAAI,EAAE,aAC5B;AAAA,EAEJ,QAAE;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -2,5 +2,6 @@
2
2
  * Generates a fallback URL that proxies the request through the host's protected remote fetch endpoint
3
3
  */
4
4
  declare function generateProtectedRcFallbackSrc(url: string): string;
5
+ declare function isProxiedUrl(url: string): boolean;
5
6
 
6
- export { generateProtectedRcFallbackSrc };
7
+ export { generateProtectedRcFallbackSrc, isProxiedUrl };
@@ -2,7 +2,15 @@ import { RC_PROTECTED_REMOTE_FETCH_PATHNAME } from "#internal/shared/constants";
2
2
  function generateProtectedRcFallbackSrc(url) {
3
3
  return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
4
4
  }
5
+ function isProxiedUrl(url) {
6
+ try {
7
+ return new URL(url, location.href).pathname === RC_PROTECTED_REMOTE_FETCH_PATHNAME;
8
+ } catch {
9
+ return false;
10
+ }
11
+ }
5
12
  export {
6
- generateProtectedRcFallbackSrc
13
+ generateProtectedRcFallbackSrc,
14
+ isProxiedUrl
7
15
  };
8
16
  //# sourceMappingURL=protected-rc-fallback.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/client/protected-rc-fallback.ts"],"sourcesContent":["import { RC_PROTECTED_REMOTE_FETCH_PATHNAME } from '#internal/shared/constants';\n\n/**\n * Generates a fallback URL that proxies the request through the host's protected remote fetch endpoint\n */\nexport function generateProtectedRcFallbackSrc(url: string): string {\n return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;\n}\n"],"mappings":"AAAA,SAAS,0CAA0C;AAK5C,SAAS,+BAA+B,KAAqB;AAClE,SAAO,GAAG,0CAA0C,mBAAmB,GAAG;AAC5E;","names":[]}
1
+ {"version":3,"sources":["../../../../src/shared/client/protected-rc-fallback.ts"],"sourcesContent":["import { RC_PROTECTED_REMOTE_FETCH_PATHNAME } from '#internal/shared/constants';\n\n/**\n * Generates a fallback URL that proxies the request through the host's protected remote fetch endpoint\n */\nexport function generateProtectedRcFallbackSrc(url: string): string {\n return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;\n}\n\nexport function isProxiedUrl(url: string): boolean {\n try {\n return (\n new URL(url, location.href).pathname ===\n RC_PROTECTED_REMOTE_FETCH_PATHNAME\n );\n } catch {\n return false;\n }\n}\n"],"mappings":"AAAA,SAAS,0CAA0C;AAK5C,SAAS,+BAA+B,KAAqB;AAClE,SAAO,GAAG,0CAA0C,mBAAmB,GAAG;AAC5E;AAEO,SAAS,aAAa,KAAsB;AACjD,MAAI;AACF,WACE,IAAI,IAAI,KAAK,SAAS,IAAI,EAAE,aAC5B;AAAA,EAEJ,QAAE;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,65 @@
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 proxy_through_host_exports = {};
20
+ __export(proxy_through_host_exports, {
21
+ proxyClientRequestsThroughHost: () => proxyClientRequestsThroughHost,
22
+ withRemoteSrc: () => withRemoteSrc
23
+ });
24
+ module.exports = __toCommonJS(proxy_through_host_exports);
25
+ var import_protected_rc_fallback = require("./protected-rc-fallback");
26
+ function withRemoteSrc(resolveClientUrl, remoteSrc) {
27
+ const remoteOrigin = parseOrigin(remoteSrc);
28
+ return (url) => {
29
+ const urlOrigin = parseOrigin(url);
30
+ if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
31
+ return void 0;
32
+ }
33
+ return resolveClientUrl(remoteSrc, url);
34
+ };
35
+ }
36
+ function parseOrigin(url) {
37
+ try {
38
+ return new URL(url).origin;
39
+ } catch {
40
+ return void 0;
41
+ }
42
+ }
43
+ const proxyClientRequestsThroughHost = (remoteSrc, url) => {
44
+ if (typeof location === "undefined") {
45
+ return void 0;
46
+ }
47
+ const remoteOrigin = new URL(remoteSrc, location.href).origin;
48
+ if (remoteOrigin === location.origin) {
49
+ return void 0;
50
+ }
51
+ try {
52
+ const parsed = new URL(url, location.href);
53
+ if (parsed.origin === remoteOrigin) {
54
+ return (0, import_protected_rc_fallback.generateProtectedRcFallbackSrc)(url);
55
+ }
56
+ } catch {
57
+ }
58
+ return void 0;
59
+ };
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ proxyClientRequestsThroughHost,
63
+ withRemoteSrc
64
+ });
65
+ //# sourceMappingURL=proxy-through-host.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/shared/client/proxy-through-host.ts"],"sourcesContent":["import { generateProtectedRcFallbackSrc } from './protected-rc-fallback';\n\n/**\n * Intercepts client-side URL resolution for remote component resources.\n * Called before each asset (script, stylesheet, chunk, module, image) is fetched.\n *\n * Return a new URL string to redirect the fetch (e.g., through a proxy),\n * or undefined to use the original URL.\n *\n * @param remoteSrc - The `src` of the remote component being loaded\n * @param url - The asset URL about to be fetched\n *\n * @example\n * // Proxy all assets from the remote's origin through the host\n * const resolveClientUrl = (remoteSrc, url) => {\n * const remoteOrigin = new URL(remoteSrc).origin;\n * const parsed = new URL(url);\n * if (parsed.origin !== location.origin && parsed.origin === remoteOrigin) {\n * return `/rc-fetch-protected-remote?url=${encodeURIComponent(url)}`;\n * }\n * };\n */\nexport type ResolveClientUrl = (\n remoteSrc: string,\n url: string,\n) => string | undefined;\n\n/**\n * Internal bound resolver — `ResolveClientUrl` with `remoteSrc` already applied.\n * Used by internal loaders that don't need to know the remote src.\n */\nexport type InternalResolveClientUrl = (url: string) => string | undefined;\n\n/**\n * Binds a `ResolveClientUrl` to a specific `remoteSrc`, producing an\n * `InternalResolveClientUrl` that only needs the asset URL.\n *\n * Only invokes the callback for URLs whose origin matches the remote\n * component's origin. Third-party scripts (e.g. `vercel.live` toolbar)\n * are left untouched. To proxy additional domains in the future, a\n * field or flag can be added to the host configuration.\n */\nexport function withRemoteSrc(\n resolveClientUrl: ResolveClientUrl,\n remoteSrc: string,\n): InternalResolveClientUrl {\n const remoteOrigin = parseOrigin(remoteSrc);\n return (url) => {\n const urlOrigin = parseOrigin(url);\n if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {\n return undefined;\n }\n return resolveClientUrl(remoteSrc, url);\n };\n}\n\nfunction parseOrigin(url: string): string | undefined {\n try {\n return new URL(url).origin;\n } catch {\n return undefined;\n }\n}\n\n/**\n * A `ResolveClientUrl` that proxies cross-origin asset URLs\n * through the host's protected remote fetch endpoint (`/rc-fetch-protected-remote`).\n * Same-origin URLs are left unchanged.\n *\n * On Vercel preview deployments, deployment protection blocks direct cross-origin\n * asset fetches. This function proxies those requests through the host so they\n * inherit the host's authentication cookies.\n *\n * Requires `withRemoteComponentsHost` middleware on the host to handle the\n * proxied requests. Configure `allowedProxyUrls` to restrict which URLs can\n * be proxied.\n *\n * @example\n * ```tsx\n * import { RemoteComponent, proxyClientRequestsThroughHost } from 'remote-components/react';\n *\n * <RemoteComponent\n * src=\"https://remote-app.com/components/header\"\n * resolveClientUrl={proxyClientRequestsThroughHost}\n * />\n * ```\n */\nexport const proxyClientRequestsThroughHost: ResolveClientUrl = (\n remoteSrc,\n url,\n) => {\n if (typeof location === 'undefined') {\n return undefined;\n }\n const remoteOrigin = new URL(remoteSrc, location.href).origin;\n if (remoteOrigin === location.origin) {\n return undefined;\n }\n try {\n const parsed = new URL(url, location.href);\n if (parsed.origin === remoteOrigin) {\n return generateProtectedRcFallbackSrc(url);\n }\n } catch {\n // If URL parsing fails, return undefined to use the original\n }\n return undefined;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mCAA+C;AA0CxC,SAAS,cACd,kBACA,WAC0B;AAC1B,QAAM,eAAe,YAAY,SAAS;AAC1C,SAAO,CAAC,QAAQ;AACd,UAAM,YAAY,YAAY,GAAG;AACjC,QAAI,gBAAgB,aAAa,cAAc,cAAc;AAC3D,aAAO;AAAA,IACT;AACA,WAAO,iBAAiB,WAAW,GAAG;AAAA,EACxC;AACF;AAEA,SAAS,YAAY,KAAiC;AACpD,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAE;AACA,WAAO;AAAA,EACT;AACF;AAyBO,MAAM,iCAAmD,CAC9D,WACA,QACG;AACH,MAAI,OAAO,aAAa,aAAa;AACnC,WAAO;AAAA,EACT;AACA,QAAM,eAAe,IAAI,IAAI,WAAW,SAAS,IAAI,EAAE;AACvD,MAAI,iBAAiB,SAAS,QAAQ;AACpC,WAAO;AAAA,EACT;AACA,MAAI;AACF,UAAM,SAAS,IAAI,IAAI,KAAK,SAAS,IAAI;AACzC,QAAI,OAAO,WAAW,cAAc;AAClC,iBAAO,6DAA+B,GAAG;AAAA,IAC3C;AAAA,EACF,QAAE;AAAA,EAEF;AACA,SAAO;AACT;","names":[]}