remote-components 0.3.3 → 0.3.5

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 (176) hide show
  1. package/dist/config/nextjs.cjs +86 -37
  2. package/dist/config/nextjs.cjs.map +1 -1
  3. package/dist/config/nextjs.js +86 -37
  4. package/dist/config/nextjs.js.map +1 -1
  5. package/dist/config/webpack.cjs +5 -1
  6. package/dist/config/webpack.cjs.map +1 -1
  7. package/dist/config/webpack.js +5 -1
  8. package/dist/config/webpack.js.map +1 -1
  9. package/dist/host/html.cjs +861 -617
  10. package/dist/host/html.cjs.map +1 -1
  11. package/dist/host/html.js +861 -617
  12. package/dist/host/html.js.map +1 -1
  13. package/dist/host/nextjs/app/client-only.cjs +700 -383
  14. package/dist/host/nextjs/app/client-only.cjs.map +1 -1
  15. package/dist/host/nextjs/app/client-only.js +674 -357
  16. package/dist/host/nextjs/app/client-only.js.map +1 -1
  17. package/dist/host/nextjs/app.cjs +34 -2
  18. package/dist/host/nextjs/app.cjs.map +1 -1
  19. package/dist/host/nextjs/app.js +35 -3
  20. package/dist/host/nextjs/app.js.map +1 -1
  21. package/dist/host/react.cjs +641 -352
  22. package/dist/host/react.cjs.map +1 -1
  23. package/dist/host/react.js +641 -352
  24. package/dist/host/react.js.map +1 -1
  25. package/dist/internal/config/webpack/apply-shared-modules.cjs +6 -4
  26. package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -1
  27. package/dist/internal/config/webpack/apply-shared-modules.js +6 -4
  28. package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -1
  29. package/dist/internal/config/webpack/next-client-pages-loader.cjs +6 -7
  30. package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
  31. package/dist/internal/config/webpack/next-client-pages-loader.js +6 -7
  32. package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
  33. package/dist/internal/host/nextjs/app-client.cjs +42 -27
  34. package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
  35. package/dist/internal/host/nextjs/app-client.js +42 -27
  36. package/dist/internal/host/nextjs/app-client.js.map +1 -1
  37. package/dist/internal/host/nextjs/dom-flight.cjs +19 -39
  38. package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
  39. package/dist/internal/host/nextjs/dom-flight.js +31 -39
  40. package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
  41. package/dist/internal/host/nextjs/image-shared.cjs +39 -3
  42. package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
  43. package/dist/internal/host/nextjs/image-shared.d.ts +5 -10
  44. package/dist/internal/host/nextjs/image-shared.js +29 -3
  45. package/dist/internal/host/nextjs/image-shared.js.map +1 -1
  46. package/dist/internal/host/nextjs/remote-component-links.cjs +24 -13
  47. package/dist/internal/host/nextjs/remote-component-links.cjs.map +1 -1
  48. package/dist/internal/host/nextjs/remote-component-links.d.ts +3 -0
  49. package/dist/internal/host/nextjs/remote-component-links.js +24 -13
  50. package/dist/internal/host/nextjs/remote-component-links.js.map +1 -1
  51. package/dist/internal/host/server/fetch-remote-component.cjs +2 -1
  52. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
  53. package/dist/internal/host/server/fetch-remote-component.js +2 -1
  54. package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
  55. package/dist/internal/host/shared/lifecycle.cjs +69 -0
  56. package/dist/internal/host/shared/lifecycle.cjs.map +1 -0
  57. package/dist/internal/host/shared/lifecycle.d.ts +34 -0
  58. package/dist/internal/host/shared/lifecycle.js +44 -0
  59. package/dist/internal/host/shared/lifecycle.js.map +1 -0
  60. package/dist/internal/host/shared/pipeline.cjs +222 -0
  61. package/dist/internal/host/shared/pipeline.cjs.map +1 -0
  62. package/dist/internal/host/shared/pipeline.d.ts +153 -0
  63. package/dist/internal/host/shared/pipeline.js +200 -0
  64. package/dist/internal/host/shared/pipeline.js.map +1 -0
  65. package/dist/internal/host/shared/polyfill.cjs +8 -7
  66. package/dist/internal/host/shared/polyfill.cjs.map +1 -1
  67. package/dist/internal/host/shared/polyfill.js +8 -7
  68. package/dist/internal/host/shared/polyfill.js.map +1 -1
  69. package/dist/internal/host/shared/shared-module-resolver.cjs +117 -0
  70. package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -0
  71. package/dist/internal/host/shared/shared-module-resolver.d.ts +64 -0
  72. package/dist/internal/host/shared/shared-module-resolver.js +78 -0
  73. package/dist/internal/host/shared/shared-module-resolver.js.map +1 -0
  74. package/dist/internal/remote/nextjs/next-internals.cjs +53 -0
  75. package/dist/internal/remote/nextjs/next-internals.cjs.map +1 -0
  76. package/dist/internal/remote/nextjs/next-internals.d.ts +42 -0
  77. package/dist/internal/remote/nextjs/next-internals.js +26 -0
  78. package/dist/internal/remote/nextjs/next-internals.js.map +1 -0
  79. package/dist/internal/runtime/html/apply-origin.cjs +11 -32
  80. package/dist/internal/runtime/html/apply-origin.cjs.map +1 -1
  81. package/dist/internal/runtime/html/apply-origin.js +11 -32
  82. package/dist/internal/runtime/html/apply-origin.js.map +1 -1
  83. package/dist/internal/runtime/html/html-spec.cjs +78 -0
  84. package/dist/internal/runtime/html/html-spec.cjs.map +1 -0
  85. package/dist/internal/runtime/html/html-spec.d.ts +23 -0
  86. package/dist/internal/runtime/html/html-spec.js +41 -0
  87. package/dist/internal/runtime/html/html-spec.js.map +1 -0
  88. package/dist/internal/runtime/html/parse-remote-html.cjs +15 -12
  89. package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
  90. package/dist/internal/runtime/html/parse-remote-html.js +29 -12
  91. package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
  92. package/dist/internal/runtime/html/rewrite-srcset.cjs +38 -0
  93. package/dist/internal/runtime/html/rewrite-srcset.cjs.map +1 -0
  94. package/dist/internal/runtime/html/rewrite-srcset.d.ts +12 -0
  95. package/dist/internal/runtime/html/rewrite-srcset.js +14 -0
  96. package/dist/internal/runtime/html/rewrite-srcset.js.map +1 -0
  97. package/dist/internal/runtime/loaders/component-loader.cjs +25 -44
  98. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
  99. package/dist/internal/runtime/loaders/component-loader.d.ts +3 -1
  100. package/dist/internal/runtime/loaders/component-loader.js +28 -44
  101. package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
  102. package/dist/internal/runtime/loaders/static-loader.cjs +15 -21
  103. package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -1
  104. package/dist/internal/runtime/loaders/static-loader.d.ts +3 -1
  105. package/dist/internal/runtime/loaders/static-loader.js +15 -21
  106. package/dist/internal/runtime/loaders/static-loader.js.map +1 -1
  107. package/dist/internal/runtime/namespace.cjs +82 -0
  108. package/dist/internal/runtime/namespace.cjs.map +1 -0
  109. package/dist/internal/runtime/namespace.d.ts +5 -0
  110. package/dist/internal/runtime/namespace.js +58 -0
  111. package/dist/internal/runtime/namespace.js.map +1 -0
  112. package/dist/internal/runtime/rsc-imports.cjs +86 -0
  113. package/dist/internal/runtime/rsc-imports.cjs.map +1 -0
  114. package/dist/internal/runtime/rsc-imports.d.ts +39 -0
  115. package/dist/internal/runtime/rsc-imports.js +50 -0
  116. package/dist/internal/runtime/rsc-imports.js.map +1 -0
  117. package/dist/internal/runtime/rsc-runtime.cjs +17 -0
  118. package/dist/internal/runtime/rsc-runtime.cjs.map +1 -0
  119. package/dist/internal/runtime/rsc-runtime.d.ts +37 -0
  120. package/dist/internal/runtime/rsc-runtime.js +1 -0
  121. package/dist/internal/runtime/rsc-runtime.js.map +1 -0
  122. package/dist/internal/runtime/rsc.cjs +23 -12
  123. package/dist/internal/runtime/rsc.cjs.map +1 -1
  124. package/dist/internal/runtime/rsc.d.ts +19 -2
  125. package/dist/internal/runtime/rsc.js +20 -11
  126. package/dist/internal/runtime/rsc.js.map +1 -1
  127. package/dist/internal/runtime/turbopack/chunk-loader.cjs +53 -35
  128. package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
  129. package/dist/internal/runtime/turbopack/chunk-loader.d.ts +1 -1
  130. package/dist/internal/runtime/turbopack/chunk-loader.js +53 -35
  131. package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
  132. package/dist/internal/runtime/turbopack/module.cjs +17 -4
  133. package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
  134. package/dist/internal/runtime/turbopack/module.d.ts +23 -1
  135. package/dist/internal/runtime/turbopack/module.js +16 -4
  136. package/dist/internal/runtime/turbopack/module.js.map +1 -1
  137. package/dist/internal/runtime/turbopack/patterns.cjs +26 -10
  138. package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -1
  139. package/dist/internal/runtime/turbopack/patterns.d.ts +44 -49
  140. package/dist/internal/runtime/turbopack/patterns.js +23 -7
  141. package/dist/internal/runtime/turbopack/patterns.js.map +1 -1
  142. package/dist/internal/runtime/turbopack/{webpack-runtime.cjs → remote-scope-setup.cjs} +35 -32
  143. package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -0
  144. package/dist/internal/runtime/turbopack/remote-scope-setup.d.ts +25 -0
  145. package/dist/internal/runtime/turbopack/{webpack-runtime.js → remote-scope-setup.js} +36 -19
  146. package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -0
  147. package/dist/internal/runtime/turbopack/remote-scope.cjs +4 -6
  148. package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
  149. package/dist/internal/runtime/turbopack/remote-scope.d.ts +20 -1
  150. package/dist/internal/runtime/turbopack/remote-scope.js +4 -6
  151. package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
  152. package/dist/internal/runtime/turbopack/shared-modules.cjs +21 -15
  153. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
  154. package/dist/internal/runtime/turbopack/shared-modules.d.ts +9 -2
  155. package/dist/internal/runtime/turbopack/shared-modules.js +24 -18
  156. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
  157. package/dist/internal/runtime/types.cjs.map +1 -1
  158. package/dist/internal/runtime/types.d.ts +5 -41
  159. package/dist/internal/utils/logger.cjs +1 -1
  160. package/dist/internal/utils/logger.cjs.map +1 -1
  161. package/dist/internal/utils/logger.d.ts +2 -2
  162. package/dist/internal/utils/logger.js +1 -1
  163. package/dist/internal/utils/logger.js.map +1 -1
  164. package/dist/remote/html.cjs +78 -22
  165. package/dist/remote/html.cjs.map +1 -1
  166. package/dist/remote/html.js +78 -22
  167. package/dist/remote/html.js.map +1 -1
  168. package/dist/remote/nextjs/app.cjs +14 -55
  169. package/dist/remote/nextjs/app.cjs.map +1 -1
  170. package/dist/remote/nextjs/app.js +24 -45
  171. package/dist/remote/nextjs/app.js.map +1 -1
  172. package/dist/types-59251814.d.ts +94 -0
  173. package/package.json +2 -2
  174. package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +0 -1
  175. package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +0 -23
  176. package/dist/internal/runtime/turbopack/webpack-runtime.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/host/nextjs/dom-flight.ts"],"sourcesContent":["import { serializeOuter } from 'parse5';\nimport type {\n ChildNode,\n Element,\n Node,\n TextNode,\n} from 'parse5/dist/tree-adapters/default';\nimport { isCustomAttribute, possibleStandardNames } from 'react-property';\nimport styleToJs from 'style-to-js';\nimport type { RawMetadataAttrs } from '#internal/runtime/metadata';\n\n// add fetch-priority to the possible standard names\npossibleStandardNames.fetchpriority = 'fetchPriority';\npossibleStandardNames['data-precedence'] = 'precedence';\n\nexport interface Context {\n name?: string;\n url: URL;\n origin?: string;\n defer?: boolean;\n active?: boolean;\n visitedRSCNodes?: Set<Node>;\n visitedNonActiveNodes?: Set<Node>;\n onMetadata?: (attrs: RawMetadataAttrs) => void;\n onScript?: (attrs: Record<string, string | boolean>) => void;\n onLink?: (attrs: Record<string, string | boolean>) => void;\n onRSC?: (rsc: string) => void;\n onNextData?: (data: {\n props: {\n pageProps: Record<string, unknown>;\n __REMOTE_COMPONENT__?: {\n bundle: string;\n runtime: string;\n };\n };\n page?: string;\n }) => void;\n onHTML?: (html: string) => void;\n onShared?: (shared: Record<string, string>) => void;\n onError?: (message: string, stack?: string) => void;\n}\n\nexport type RSC =\n | ['$', string, null, Record<string, unknown>, null, null, number]\n | (\n | ['$', string, null, Record<string, unknown>, null, null, number]\n | string\n | null\n )[]\n | string\n | null;\n\nconst applyOriginToNodes = [\n 'img',\n 'source',\n 'video',\n 'audio',\n 'track',\n 'iframe',\n 'embed',\n 'script',\n 'link',\n];\n\nexport function visit(\n node: (Node | ChildNode) & {\n attrsObj?: Record<string, string>;\n attrsObjToArray?: Record<string, { name: string; value: string }>;\n },\n context: Context = {\n url: new URL('http://localhost'),\n active: false,\n },\n): RSC | RSC[] | string | null {\n if ('attrs' in node && typeof node.attrsObj === 'undefined') {\n node.attrsObjToArray = {};\n node.attrsObj = node.attrs.reduce<Record<string, string>>((acc, attr) => {\n acc[attr.name] = attr.value;\n if (node.attrsObjToArray) {\n node.attrsObjToArray[attr.name] = attr;\n }\n return acc;\n }, {});\n }\n\n if (\n node.nodeName === 'template' &&\n node.attrsObj?.['data-next-error-message']\n ) {\n context.onError?.(\n node.attrsObj['data-next-error-message'],\n node.attrsObj['data-next-error-stack'],\n );\n }\n\n // apply origin to src and srcset attributes\n if (\n applyOriginToNodes.includes(node.nodeName.toLowerCase()) &&\n 'attrs' in node\n ) {\n const origin = context.origin ?? context.url.origin;\n const src = node.attrsObj?.src;\n if (src) {\n const url = new URL(src, origin);\n if (node.attrsObjToArray && 'src' in node.attrsObjToArray) {\n node.attrsObjToArray.src.value = url.href;\n }\n }\n const href = node.attrsObj?.href;\n if (href) {\n const url = new URL(href, origin);\n if (node.attrsObjToArray && 'href' in node.attrsObjToArray) {\n node.attrsObjToArray.href.value = url.href;\n }\n }\n\n const srcSet = node.attrsObj?.srcset;\n if (srcSet) {\n const srcSetValue = srcSet\n .split(',')\n .map((entry) => {\n const [url, descriptor] = entry.trim().split(/\\s+/);\n if (!url) return entry;\n\n const absoluteUrl = new URL(url, origin).href;\n return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;\n })\n .join(', ');\n if (node.attrsObjToArray && 'srcset' in node.attrsObjToArray) {\n node.attrsObjToArray.srcset.value = srcSetValue;\n }\n }\n const imageSrcSet = node.attrsObj?.imagesrcset;\n if (imageSrcSet) {\n const srcSetValue = imageSrcSet\n .split(',')\n .map((entry) => {\n const [url, descriptor] = entry.trim().split(/\\s+/);\n if (!url) return entry;\n\n const absoluteUrl = new URL(url, origin).href;\n return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;\n })\n .join(', ');\n if (node.attrsObjToArray && 'imagesrcset' in node.attrsObjToArray) {\n node.attrsObjToArray.imagesrcset.value = srcSetValue;\n }\n }\n }\n\n if (node.nodeName === 'script' || node.nodeName === 'link') {\n const nodeId = node.attrsObj?.id;\n if (nodeId?.endsWith('_shared')) {\n context.onShared?.(\n JSON.parse((node.childNodes[0] as TextNode).value) as Record<\n string,\n string\n >,\n );\n return null;\n } else if (nodeId?.endsWith('_rsc') && 'childNodes' in node) {\n if (!context.visitedRSCNodes) {\n context.visitedRSCNodes = new Set();\n }\n if (\n !context.visitedRSCNodes.has(node) &&\n (context.name ? nodeId.startsWith(context.name) : true)\n ) {\n context.visitedRSCNodes.add(node);\n context.onRSC?.((node.childNodes[0] as TextNode).value);\n }\n } else if (nodeId === '__NEXT_DATA__' && 'childNodes' in node) {\n context.onHTML?.(\n `<script id=\"__REMOTE_NEXT_DATA__\" type=\"application/json\">${(node.childNodes[0] as TextNode).value}</script>`,\n );\n const nextDataValue = JSON.parse(\n (node.childNodes[0] as TextNode).value,\n ) as {\n props: {\n pageProps: Record<string, unknown>;\n __REMOTE_COMPONENT__?: { bundle: string; runtime: string };\n };\n page?: string;\n };\n if (nextDataValue.props.__REMOTE_COMPONENT__) {\n context.onMetadata?.({\n bundle: nextDataValue.props.__REMOTE_COMPONENT__.bundle,\n runtime: nextDataValue.props.__REMOTE_COMPONENT__.runtime,\n id: '__next',\n route: nextDataValue.page,\n });\n }\n context.onNextData?.(nextDataValue);\n } else if (node.childNodes.length === 0) {\n if (\n node.nodeName === 'script' &&\n node.attrsObj &&\n !('src' in node.attrsObj) &&\n !('data-src' in node.attrsObj)\n ) {\n return [\n '$',\n node.nodeName,\n null,\n node.attrs.reduce<Record<string, string>>((props, attr) => {\n props[possibleStandardNames[attr.name] ?? attr.name] = attr.value;\n return props;\n }, {}),\n null,\n null,\n 1,\n ] as RSC;\n }\n if (node.nodeName === 'script') {\n context.onScript?.(\n node.attrs.reduce<Record<string, string | boolean>>((props, attr) => {\n if (attr.name === 'data-src') {\n props.src = attr.value;\n } else {\n props[attr.name] = attr.value || true;\n }\n return props;\n }, {}),\n );\n const src = node.attrsObj?.src;\n if (src) {\n node.attrs = node.attrs.filter((attr) => attr.name !== 'src');\n node.attrs.push({\n name: 'data-src',\n value: src,\n });\n if (node.attrsObj) {\n delete node.attrsObj.src;\n node.attrsObj['data-src'] = src;\n }\n }\n context.onHTML?.(serializeOuter(node));\n } else {\n context.onLink?.(\n node.attrs.reduce<Record<string, string | boolean>>((props, attr) => {\n if (attr.name === 'href') {\n attr.value = new URL(attr.value, context.url.origin).href;\n }\n props[possibleStandardNames[attr.name] ?? attr.name] =\n attr.value || true;\n return props;\n }, {}),\n );\n context.onHTML?.(serializeOuter(node));\n }\n return null;\n } else if (\n context.active &&\n node.nodeName === 'script' &&\n 'childNodes' in node &&\n node.childNodes.length > 0\n ) {\n // inline script\n context.onScript?.({\n ...node.attrs.reduce<Record<string, string | boolean>>(\n (props, attr) => {\n props[attr.name] = attr.value || true;\n return props;\n },\n {},\n ),\n textContent: (node.childNodes[0] as TextNode).value,\n });\n return null;\n }\n }\n\n if (!context.active) {\n if (!context.visitedNonActiveNodes) {\n context.visitedNonActiveNodes = new Set();\n }\n\n if (\n 'childNodes' in node &&\n !(\n node.nodeName === 'remote-component' &&\n !node.attrsObj?.src &&\n (context.name ? node.attrsObj?.name !== context.name : false)\n )\n ) {\n if (!context.visitedNonActiveNodes.has(node)) {\n context.visitedNonActiveNodes.add(node);\n (node as Element).childNodes.forEach((childNode) => {\n visit(childNode, context);\n });\n }\n } else return null;\n }\n\n switch (node.nodeName) {\n case '#document-fragment':\n return node.childNodes.reduce<RSC[]>((acc, childNode) => {\n const result = visit(childNode, context);\n if (result !== null) {\n acc.push(result as unknown as RSC);\n }\n return acc;\n }, []);\n case '#text':\n return (node as TextNode).value;\n case '#comment':\n case 'head':\n case 'meta':\n case 'title':\n case 'noscript':\n return null;\n default: {\n const nodeId = node.attrsObj?.id;\n\n if (\n (node.nodeName === 'remote-component' &&\n !node.attrsObj?.src &&\n (!context.name || node.attrsObj?.name === context.name)) ||\n (node.nodeName === 'div' &&\n (nodeId === '__next' ||\n (context.name\n ? nodeId?.startsWith(context.name)\n : node.attrsObj &&\n 'data-bundle' in node.attrsObj &&\n node.attrsObj['data-bundle'] &&\n 'data-route' in node.attrsObj &&\n nodeId?.endsWith('_ssr'))))\n ) {\n context.onMetadata?.({\n bundle: node.attrsObj?.['data-bundle'],\n route: node.attrsObj?.['data-route'],\n runtime:\n node.attrsObj?.['data-runtime'] ??\n (node.nodeName === 'remote-component' ? 'script' : undefined),\n id: nodeId?.endsWith('_ssr') ? nodeId : undefined,\n type:\n node.nodeName === 'remote-component'\n ? 'remote-component'\n : node.attrsObj?.['data-type'],\n });\n context.onHTML?.(serializeOuter(node));\n return node.childNodes.reduce<RSC[]>((acc, childNode) => {\n const result = visit(childNode, {\n ...context,\n active: true,\n });\n if (result !== null) {\n acc.push(result as unknown as RSC);\n }\n return acc;\n }, []);\n }\n const childNodes = (node as Element).childNodes.reduce<unknown[]>(\n (acc, childNode) => {\n const result = visit(childNode, context);\n if (result !== null) {\n acc.push(result as unknown);\n }\n return acc;\n },\n [],\n );\n const children = childNodes.length > 1 ? childNodes : childNodes[0];\n const nodeProps = (node as Element).attrs.reduce<\n Record<string, string | ReturnType<typeof styleToJs>> & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n children?: any;\n }\n >((props, attr) => {\n if (attr.name === 'style') {\n props.style = styleToJs(attr.value, {\n reactCompat: true,\n });\n return props;\n }\n if (node.nodeName === 'input' && attr.name === 'value') {\n props.defaultValue = attr.value;\n return props;\n }\n if (isCustomAttribute(attr.name)) {\n props[attr.name] = attr.value;\n return props;\n }\n props[possibleStandardNames[attr.name] ?? attr.name] = attr.value;\n return props;\n }, {});\n if (typeof children !== 'undefined') {\n if (\n node.nodeName === 'script' &&\n typeof children === 'string' &&\n children.startsWith('$')\n ) {\n nodeProps.children = `$${children}`;\n } else {\n nodeProps.children = children;\n }\n }\n if (!context.active) {\n if (childNodes.length > 0) {\n return childNodes as RSC;\n }\n return null;\n }\n return ['$', node.nodeName, null, nodeProps, null, null, 1] as RSC;\n }\n }\n}\n"],"mappings":"AAAA,SAAS,sBAAsB;AAO/B,SAAS,mBAAmB,6BAA6B;AACzD,OAAO,eAAe;AAItB,sBAAsB,gBAAgB;AACtC,sBAAsB,iBAAiB,IAAI;AAuC3C,MAAM,qBAAqB;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,MACd,MAIA,UAAmB;AAAA,EACjB,KAAK,IAAI,IAAI,kBAAkB;AAAA,EAC/B,QAAQ;AACV,GAC6B;AAC7B,MAAI,WAAW,QAAQ,OAAO,KAAK,aAAa,aAAa;AAC3D,SAAK,kBAAkB,CAAC;AACxB,SAAK,WAAW,KAAK,MAAM,OAA+B,CAAC,KAAK,SAAS;AACvE,UAAI,KAAK,IAAI,IAAI,KAAK;AACtB,UAAI,KAAK,iBAAiB;AACxB,aAAK,gBAAgB,KAAK,IAAI,IAAI;AAAA,MACpC;AACA,aAAO;AAAA,IACT,GAAG,CAAC,CAAC;AAAA,EACP;AAEA,MACE,KAAK,aAAa,cAClB,KAAK,WAAW,yBAAyB,GACzC;AACA,YAAQ;AAAA,MACN,KAAK,SAAS,yBAAyB;AAAA,MACvC,KAAK,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SAAS,SAAS;AACzB,gBAAM,QAAQ,UAAU,KAAK,OAAO;AAAA,YAClC,aAAa;AAAA,UACf,CAAC;AACD,iBAAO;AAAA,QACT;AACA,YAAI,KAAK,aAAa,WAAW,KAAK,SAAS,SAAS;AACtD,gBAAM,eAAe,KAAK;AAC1B,iBAAO;AAAA,QACT;AACA,YAAI,kBAAkB,KAAK,IAAI,GAAG;AAChC,gBAAM,KAAK,IAAI,IAAI,KAAK;AACxB,iBAAO;AAAA,QACT;AACA,cAAM,sBAAsB,KAAK,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK;AAC5D,eAAO;AAAA,MACT,GAAG,CAAC,CAAC;AACL,UAAI,OAAO,aAAa,aAAa;AACnC,YACE,KAAK,aAAa,YAClB,OAAO,aAAa,YACpB,SAAS,WAAW,GAAG,GACvB;AACA,oBAAU,WAAW,IAAI;AAAA,QAC3B,OAAO;AACL,oBAAU,WAAW;AAAA,QACvB;AAAA,MACF;AACA,UAAI,CAAC,QAAQ,QAAQ;AACnB,YAAI,WAAW,SAAS,GAAG;AACzB,iBAAO;AAAA,QACT;AACA,eAAO;AAAA,MACT;AACA,aAAO,CAAC,KAAK,KAAK,UAAU,MAAM,WAAW,MAAM,MAAM,CAAC;AAAA,IAC5D;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/host/nextjs/dom-flight.ts"],"sourcesContent":["import { serializeOuter } from 'parse5';\nimport type {\n ChildNode,\n Element,\n Node,\n TextNode,\n} from 'parse5/dist/tree-adapters/default';\nimport { isCustomAttribute, possibleStandardNames } from 'react-property';\nimport styleToJs from 'style-to-js';\nimport {\n DATA_BUNDLE,\n DATA_ROUTE,\n DATA_RUNTIME,\n DATA_SRC,\n DATA_TYPE,\n ID_SUFFIX_RSC,\n ID_SUFFIX_SHARED,\n ID_SUFFIX_SSR,\n NEXT_DATA_ID,\n ORIGIN_REWRITE_TAGS,\n TAG_REMOTE_COMPONENT,\n} from '#internal/runtime/html/html-spec';\nimport { rewriteSrcset } from '#internal/runtime/html/rewrite-srcset';\nimport type { RawMetadataAttrs } from '#internal/runtime/metadata';\n\n// add fetch-priority to the possible standard names\npossibleStandardNames.fetchpriority = 'fetchPriority';\npossibleStandardNames['data-precedence'] = 'precedence';\n\nexport interface Context {\n name?: string;\n url: URL;\n origin?: string;\n defer?: boolean;\n active?: boolean;\n visitedRSCNodes?: Set<Node>;\n visitedNonActiveNodes?: Set<Node>;\n onMetadata?: (attrs: RawMetadataAttrs) => void;\n onScript?: (attrs: Record<string, string | boolean>) => void;\n onLink?: (attrs: Record<string, string | boolean>) => void;\n onRSC?: (rsc: string) => void;\n onNextData?: (data: {\n props: {\n pageProps: Record<string, unknown>;\n __REMOTE_COMPONENT__?: {\n bundle: string;\n runtime: string;\n };\n };\n page?: string;\n }) => void;\n onHTML?: (html: string) => void;\n onShared?: (shared: Record<string, string>) => void;\n onError?: (message: string, stack?: string) => void;\n}\n\nexport type RSC =\n | ['$', string, null, Record<string, unknown>, null, null, number]\n | (\n | ['$', string, null, Record<string, unknown>, null, null, number]\n | string\n | null\n )[]\n | string\n | null;\n\nconst applyOriginToNodes: readonly string[] = ORIGIN_REWRITE_TAGS;\n\nexport function visit(\n node: (Node | ChildNode) & {\n attrsObj?: Record<string, string>;\n attrsObjToArray?: Record<string, { name: string; value: string }>;\n },\n context: Context = {\n url: new URL('http://localhost'),\n active: false,\n },\n): RSC | RSC[] | string | null {\n if ('attrs' in node && typeof node.attrsObj === 'undefined') {\n node.attrsObjToArray = {};\n node.attrsObj = node.attrs.reduce<Record<string, string>>((acc, attr) => {\n acc[attr.name] = attr.value;\n if (node.attrsObjToArray) {\n node.attrsObjToArray[attr.name] = attr;\n }\n return acc;\n }, {});\n }\n\n if (\n node.nodeName === 'template' &&\n node.attrsObj?.['data-next-error-message']\n ) {\n context.onError?.(\n node.attrsObj['data-next-error-message'],\n node.attrsObj['data-next-error-stack'],\n );\n }\n\n // apply origin to src and srcset attributes\n if (\n applyOriginToNodes.includes(node.nodeName.toLowerCase()) &&\n 'attrs' in node\n ) {\n const origin = context.origin ?? context.url.origin;\n const src = node.attrsObj?.src;\n if (src) {\n const url = new URL(src, origin);\n if (node.attrsObjToArray && 'src' in node.attrsObjToArray) {\n node.attrsObjToArray.src.value = url.href;\n }\n }\n const href = node.attrsObj?.href;\n if (href) {\n const url = new URL(href, origin);\n if (node.attrsObjToArray && 'href' in node.attrsObjToArray) {\n node.attrsObjToArray.href.value = url.href;\n }\n }\n\n const srcSet = node.attrsObj?.srcset;\n if (srcSet) {\n const srcSetValue = rewriteSrcset(srcSet, origin);\n if (node.attrsObjToArray && 'srcset' in node.attrsObjToArray) {\n node.attrsObjToArray.srcset.value = srcSetValue;\n }\n }\n const imageSrcSet = node.attrsObj?.imagesrcset;\n if (imageSrcSet) {\n const srcSetValue = rewriteSrcset(imageSrcSet, origin);\n if (node.attrsObjToArray && 'imagesrcset' in node.attrsObjToArray) {\n node.attrsObjToArray.imagesrcset.value = srcSetValue;\n }\n }\n }\n\n if (node.nodeName === 'script' || node.nodeName === 'link') {\n const nodeId = node.attrsObj?.id;\n if (nodeId?.endsWith(ID_SUFFIX_SHARED)) {\n context.onShared?.(\n JSON.parse((node.childNodes[0] as TextNode).value) as Record<\n string,\n string\n >,\n );\n return null;\n } else if (nodeId?.endsWith(ID_SUFFIX_RSC) && 'childNodes' in node) {\n if (!context.visitedRSCNodes) {\n context.visitedRSCNodes = new Set();\n }\n if (\n !context.visitedRSCNodes.has(node) &&\n (context.name ? nodeId.startsWith(context.name) : true)\n ) {\n context.visitedRSCNodes.add(node);\n context.onRSC?.((node.childNodes[0] as TextNode).value);\n }\n } else if (nodeId === NEXT_DATA_ID && 'childNodes' in node) {\n context.onHTML?.(\n `<script id=\"__REMOTE_NEXT_DATA__\" type=\"application/json\">${(node.childNodes[0] as TextNode).value}</script>`,\n );\n const nextDataValue = JSON.parse(\n (node.childNodes[0] as TextNode).value,\n ) as {\n props: {\n pageProps: Record<string, unknown>;\n __REMOTE_COMPONENT__?: { bundle: string; runtime: string };\n };\n page?: string;\n };\n if (nextDataValue.props.__REMOTE_COMPONENT__) {\n context.onMetadata?.({\n bundle: nextDataValue.props.__REMOTE_COMPONENT__.bundle,\n runtime: nextDataValue.props.__REMOTE_COMPONENT__.runtime,\n id: '__next',\n route: nextDataValue.page,\n });\n }\n context.onNextData?.(nextDataValue);\n } else if (node.childNodes.length === 0) {\n if (\n node.nodeName === 'script' &&\n node.attrsObj &&\n !('src' in node.attrsObj) &&\n !(DATA_SRC in node.attrsObj)\n ) {\n return [\n '$',\n node.nodeName,\n null,\n node.attrs.reduce<Record<string, string>>((props, attr) => {\n props[possibleStandardNames[attr.name] ?? attr.name] = attr.value;\n return props;\n }, {}),\n null,\n null,\n 1,\n ] as RSC;\n }\n if (node.nodeName === 'script') {\n context.onScript?.(\n node.attrs.reduce<Record<string, string | boolean>>((props, attr) => {\n if (attr.name === DATA_SRC) {\n props.src = attr.value;\n } else {\n props[attr.name] = attr.value || true;\n }\n return props;\n }, {}),\n );\n const src = node.attrsObj?.src;\n if (src) {\n node.attrs = node.attrs.filter((attr) => attr.name !== 'src');\n node.attrs.push({\n name: DATA_SRC,\n value: src,\n });\n if (node.attrsObj) {\n delete node.attrsObj.src;\n node.attrsObj[DATA_SRC] = src;\n }\n }\n context.onHTML?.(serializeOuter(node));\n } else {\n context.onLink?.(\n node.attrs.reduce<Record<string, string | boolean>>((props, attr) => {\n if (attr.name === 'href') {\n attr.value = new URL(attr.value, context.url.origin).href;\n }\n props[possibleStandardNames[attr.name] ?? attr.name] =\n attr.value || true;\n return props;\n }, {}),\n );\n context.onHTML?.(serializeOuter(node));\n }\n return null;\n } else if (\n context.active &&\n node.nodeName === 'script' &&\n 'childNodes' in node &&\n node.childNodes.length > 0\n ) {\n // inline script\n context.onScript?.({\n ...node.attrs.reduce<Record<string, string | boolean>>(\n (props, attr) => {\n props[attr.name] = attr.value || true;\n return props;\n },\n {},\n ),\n textContent: (node.childNodes[0] as TextNode).value,\n });\n return null;\n }\n }\n\n if (!context.active) {\n if (!context.visitedNonActiveNodes) {\n context.visitedNonActiveNodes = new Set();\n }\n\n if (\n 'childNodes' in node &&\n !(\n node.nodeName === TAG_REMOTE_COMPONENT &&\n !node.attrsObj?.src &&\n (context.name ? node.attrsObj?.name !== context.name : false)\n )\n ) {\n if (!context.visitedNonActiveNodes.has(node)) {\n context.visitedNonActiveNodes.add(node);\n (node as Element).childNodes.forEach((childNode) => {\n visit(childNode, context);\n });\n }\n } else return null;\n }\n\n switch (node.nodeName) {\n case '#document-fragment':\n return node.childNodes.reduce<RSC[]>((acc, childNode) => {\n const result = visit(childNode, context);\n if (result !== null) {\n acc.push(result as unknown as RSC);\n }\n return acc;\n }, []);\n case '#text':\n return (node as TextNode).value;\n case '#comment':\n case 'head':\n case 'meta':\n case 'title':\n case 'noscript':\n return null;\n default: {\n const nodeId = node.attrsObj?.id;\n\n if (\n (node.nodeName === TAG_REMOTE_COMPONENT &&\n !node.attrsObj?.src &&\n (!context.name || node.attrsObj?.name === context.name)) ||\n (node.nodeName === 'div' &&\n (nodeId === '__next' ||\n (context.name\n ? nodeId?.startsWith(context.name)\n : node.attrsObj &&\n DATA_BUNDLE in node.attrsObj &&\n node.attrsObj[DATA_BUNDLE] &&\n DATA_ROUTE in node.attrsObj &&\n nodeId?.endsWith(ID_SUFFIX_SSR))))\n ) {\n context.onMetadata?.({\n bundle: node.attrsObj?.[DATA_BUNDLE],\n route: node.attrsObj?.[DATA_ROUTE],\n runtime:\n node.attrsObj?.[DATA_RUNTIME] ??\n (node.nodeName === TAG_REMOTE_COMPONENT ? 'script' : undefined),\n id: nodeId?.endsWith(ID_SUFFIX_SSR) ? nodeId : undefined,\n type:\n node.nodeName === TAG_REMOTE_COMPONENT\n ? TAG_REMOTE_COMPONENT\n : node.attrsObj?.[DATA_TYPE],\n });\n context.onHTML?.(serializeOuter(node));\n return node.childNodes.reduce<RSC[]>((acc, childNode) => {\n const result = visit(childNode, {\n ...context,\n active: true,\n });\n if (result !== null) {\n acc.push(result as unknown as RSC);\n }\n return acc;\n }, []);\n }\n const childNodes = (node as Element).childNodes.reduce<unknown[]>(\n (acc, childNode) => {\n const result = visit(childNode, context);\n if (result !== null) {\n acc.push(result as unknown);\n }\n return acc;\n },\n [],\n );\n const children = childNodes.length > 1 ? childNodes : childNodes[0];\n const nodeProps = (node as Element).attrs.reduce<\n Record<string, string | ReturnType<typeof styleToJs>> & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n children?: any;\n }\n >((props, attr) => {\n if (attr.name === 'style') {\n props.style = styleToJs(attr.value, {\n reactCompat: true,\n });\n return props;\n }\n if (node.nodeName === 'input' && attr.name === 'value') {\n props.defaultValue = attr.value;\n return props;\n }\n if (isCustomAttribute(attr.name)) {\n props[attr.name] = attr.value;\n return props;\n }\n props[possibleStandardNames[attr.name] ?? attr.name] = attr.value;\n return props;\n }, {});\n if (typeof children !== 'undefined') {\n if (\n node.nodeName === 'script' &&\n typeof children === 'string' &&\n children.startsWith('$')\n ) {\n nodeProps.children = `$${children}`;\n } else {\n nodeProps.children = children;\n }\n }\n if (!context.active) {\n if (childNodes.length > 0) {\n return childNodes as RSC;\n }\n return null;\n }\n return ['$', node.nodeName, null, nodeProps, null, null, 1] as RSC;\n }\n }\n}\n"],"mappings":"AAAA,SAAS,sBAAsB;AAO/B,SAAS,mBAAmB,6BAA6B;AACzD,OAAO,eAAe;AACtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAI9B,sBAAsB,gBAAgB;AACtC,sBAAsB,iBAAiB,IAAI;AAuC3C,MAAM,qBAAwC;AAEvC,SAAS,MACd,MAIA,UAAmB;AAAA,EACjB,KAAK,IAAI,IAAI,kBAAkB;AAAA,EAC/B,QAAQ;AACV,GAC6B;AAC7B,MAAI,WAAW,QAAQ,OAAO,KA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QACT;AACA,YAAI,KAAK,aAAa,WAAW,KAAK,SAAS,SAAS;AACtD,gBAAM,eAAe,KAAK;AAC1B,iBAAO;AAAA,QACT;AACA,YAAI,kBAAkB,KAAK,IAAI,GAAG;AAChC,gBAAM,KAAK,IAAI,IAAI,KAAK;AACxB,iBAAO;AAAA,QACT;AACA,cAAM,sBAAsB,KAAK,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK;AAC5D,eAAO;AAAA,MACT,GAAG,CAAC,CAAC;AACL,UAAI,OAAO,aAAa,aAAa;AACnC,YACE,KAAK,aAAa,YAClB,OAAO,aAAa,YACpB,SAAS,WAAW,GAAG,GACvB;AACA,oBAAU,WAAW,IAAI;AAAA,QAC3B,OAAO;AACL,oBAAU,WAAW;AAAA,QACvB;AAAA,MACF;AACA,UAAI,CAAC,QAAQ,QAAQ;AACnB,YAAI,WAAW,SAAS,GAAG;AACzB,iBAAO;AAAA,QACT;AACA,eAAO;AAAA,MACT;AACA,aAAO,CAAC,KAAK,KAAK,UAAU,MAAM,WAAW,MAAM,MAAM,CAAC;AAAA,IAC5D;AAAA,EACF;AACF;","names":[]}
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,12 +17,21 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var image_shared_exports = {};
20
30
  __export(image_shared_exports, {
21
31
  createImageLoaderSharedEntries: () => createImageLoaderSharedEntries
22
32
  });
23
33
  module.exports = __toCommonJS(image_shared_exports);
34
+ var import_react = require("react");
24
35
  var import_remote_image_loader = require("#internal/host/shared/remote-image-loader");
25
36
  var import_remote_scope = require("#internal/runtime/turbopack/remote-scope");
26
37
  var import_default_resolve_client_url = require("#internal/runtime/url/default-resolve-client-url");
@@ -34,16 +45,41 @@ function createImageLoaderSharedEntries({
34
45
  bound,
35
46
  unbound
36
47
  } = {}) {
37
- const entry = (bundle) => {
48
+ const loaderEntry = (bundle) => {
38
49
  const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);
39
50
  return Promise.resolve({
40
51
  default: (0, import_remote_image_loader.createRemoteImageLoader)(bundle, resolveClientUrl),
41
52
  __esModule: true
42
53
  });
43
54
  };
55
+ const imageEntry = async (bundle) => {
56
+ const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);
57
+ const rawLoader = (0, import_remote_image_loader.createRemoteImageLoader)(bundle, resolveClientUrl);
58
+ const remoteLoader = Object.assign(
59
+ (p) => rawLoader({ ...p, config: { path: "/_next/image" } }),
60
+ { __next_img_default: true }
61
+ );
62
+ const mod = await import("next/image");
63
+ const OriginalImage = mod.default;
64
+ const RemoteImage = (0, import_react.forwardRef)(
65
+ (props, ref) => (0, import_react.createElement)(OriginalImage, {
66
+ ...props,
67
+ loader: props.loader ?? remoteLoader,
68
+ ref
69
+ })
70
+ );
71
+ RemoteImage.displayName = "RemoteImage";
72
+ return { ...mod, default: RemoteImage, __esModule: true };
73
+ };
44
74
  return {
45
- "next/dist/shared/lib/image-loader": entry,
46
- "next/dist/esm/shared/lib/image-loader": entry
75
+ "next/dist/shared/lib/image-loader": loaderEntry,
76
+ "next/dist/esm/shared/lib/image-loader": loaderEntry,
77
+ // Can be removed once 0.2.x support is dropped.
78
+ "next/image": imageEntry,
79
+ // Can be removed once 0.2.x support is dropped.
80
+ "next/dist/client/image-component": imageEntry,
81
+ // Can be removed once 0.2.x support is dropped.
82
+ "next/dist/api/image": imageEntry
47
83
  };
48
84
  }
49
85
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/host/nextjs/image-shared.ts"],"sourcesContent":["import { createRemoteImageLoader } from '#internal/host/shared/remote-image-loader';\nimport { getScope } from '#internal/runtime/turbopack/remote-scope';\nimport { bindResolveClientUrl } from '#internal/runtime/url/default-resolve-client-url';\nimport type {\n InternalResolveClientUrl,\n ResolveClientUrl,\n} from '#internal/runtime/url/resolve-client-url';\n\ntype SharedImageModule = (bundle: string) => Promise<unknown>;\n\nfunction resolveForBundle(\n unbound: ResolveClientUrl | undefined,\n bundle: string,\n): InternalResolveClientUrl | undefined {\n if (!unbound) return undefined;\n const remoteSrc = getScope(bundle)?.url.href ?? '';\n return bindResolveClientUrl(unbound, remoteSrc);\n}\n\n/**\n * Creates shared module entries for `next/dist/shared/lib/image-loader` (and\n * its ESM alias). These ensure that any code path in the remote's bundle that\n * directly imports the image loader — rather than going through the shared\n * `next/image` entry — still routes image optimization requests to the remote\n * and through the host's proxy when deployment protection is active.\n *\n * Pass `bound` when the resolver already has `remoteSrc` applied (App Router —\n * `useResolveClientUrl` returns the bound form). Pass `unbound` when only the\n * raw 2-arg `ResolveClientUrl` is available (Pages Router, client-only\n * provider) — binding is deferred until the bundle URL is known at resolution\n * time.\n */\nexport function createImageLoaderSharedEntries({\n bound,\n unbound,\n}: {\n bound?: InternalResolveClientUrl;\n unbound?: ResolveClientUrl;\n} = {}): Record<string, SharedImageModule> {\n const entry: SharedImageModule = (bundle: string) => {\n const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);\n return Promise.resolve({\n default: createRemoteImageLoader(bundle, resolveClientUrl),\n __esModule: true,\n });\n };\n return {\n 'next/dist/shared/lib/image-loader': entry,\n 'next/dist/esm/shared/lib/image-loader': entry,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAAwC;AACxC,0BAAyB;AACzB,wCAAqC;AAQrC,SAAS,iBACP,SACA,QACsC;AACtC,MAAI,CAAC;AAAS,WAAO;AACrB,QAAM,gBAAY,8BAAS,MAAM,GAAG,IAAI,QAAQ;AAChD,aAAO,wDAAqB,SAAS,SAAS;AAChD;AAeO,SAAS,+BAA+B;AAAA,EAC7C;AAAA,EACA;AACF,IAGI,CAAC,GAAsC;AACzC,QAAM,QAA2B,CAAC,WAAmB;AACnD,UAAM,mBAAmB,SAAS,iBAAiB,SAAS,MAAM;AAClE,WAAO,QAAQ,QAAQ;AAAA,MACrB,aAAS,oDAAwB,QAAQ,gBAAgB;AAAA,MACzD,YAAY;AAAA,IACd,CAAC;AAAA,EACH;AACA,SAAO;AAAA,IACL,qCAAqC;AAAA,IACrC,yCAAyC;AAAA,EAC3C;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/host/nextjs/image-shared.ts"],"sourcesContent":["import { createElement, forwardRef } from 'react';\nimport { createRemoteImageLoader } from '#internal/host/shared/remote-image-loader';\nimport { getScope } from '#internal/runtime/turbopack/remote-scope';\nimport { bindResolveClientUrl } from '#internal/runtime/url/default-resolve-client-url';\nimport type {\n InternalResolveClientUrl,\n ResolveClientUrl,\n} from '#internal/runtime/url/resolve-client-url';\n\ntype SharedImageModule = (bundle: string) => Promise<unknown>;\n\nfunction resolveForBundle(\n unbound: ResolveClientUrl | undefined,\n bundle: string,\n): InternalResolveClientUrl | undefined {\n if (!unbound) return undefined;\n const remoteSrc = getScope(bundle)?.url.href ?? '';\n return bindResolveClientUrl(unbound, remoteSrc);\n}\n\n/**\n * Creates shared module entries for image-related modules that route\n * optimization requests through the remote's `/_next/image` endpoint.\n *\n * Pass `bound` when the resolver already has `remoteSrc` applied (App Router).\n * Pass `unbound` when only the raw 2-arg `ResolveClientUrl` is available\n * (Pages Router, client-only provider).\n */\nexport function createImageLoaderSharedEntries({\n bound,\n unbound,\n}: {\n bound?: InternalResolveClientUrl;\n unbound?: ResolveClientUrl;\n} = {}): Record<string, SharedImageModule> {\n const loaderEntry: SharedImageModule = (bundle: string) => {\n const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);\n return Promise.resolve({\n default: createRemoteImageLoader(bundle, resolveClientUrl),\n __esModule: true,\n });\n };\n\n // Cross-version compat: remotes <=0.2.x request `next/image` as a shared module.\n // Wraps the host's Image component with the remote image loader injected\n // via the `loader` prop. Can be removed once 0.2.x support is dropped.\n const imageEntry: SharedImageModule = async (bundle: string) => {\n const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);\n const rawLoader = createRemoteImageLoader(bundle, resolveClientUrl);\n // Wrap to match Next.js `ImageLoader` signature (no `config` param).\n // The raw loader expects `{ config, src, width, quality }` but the public\n // `loader` prop is called with `{ src, width, quality }` only.\n const remoteLoader = Object.assign(\n (p: { src: string; width: number; quality?: number }) =>\n rawLoader({ ...p, config: { path: '/_next/image' } }),\n { __next_img_default: true as const },\n );\n const mod = await import('next/image');\n const OriginalImage = mod.default;\n type ImageProps = Parameters<typeof OriginalImage>[0];\n const RemoteImage = forwardRef<HTMLImageElement, ImageProps>((props, ref) =>\n createElement(OriginalImage, {\n ...props,\n loader: props.loader ?? remoteLoader,\n ref,\n }),\n );\n RemoteImage.displayName = 'RemoteImage';\n return { ...mod, default: RemoteImage, __esModule: true };\n };\n\n return {\n 'next/dist/shared/lib/image-loader': loaderEntry,\n 'next/dist/esm/shared/lib/image-loader': loaderEntry,\n // Can be removed once 0.2.x support is dropped.\n 'next/image': imageEntry,\n // Can be removed once 0.2.x support is dropped.\n 'next/dist/client/image-component': imageEntry,\n // Can be removed once 0.2.x support is dropped.\n 'next/dist/api/image': imageEntry,\n };\n}\n"],"mappings":";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AEpC,uBAAuB;AAAA,EACzB;AACF;","names":[]}
@@ -2,17 +2,12 @@ import { InternalResolveClientUrl, ResolveClientUrl } from '../../runtime/url/re
2
2
 
3
3
  type SharedImageModule = (bundle: string) => Promise<unknown>;
4
4
  /**
5
- * Creates shared module entries for `next/dist/shared/lib/image-loader` (and
6
- * its ESM alias). These ensure that any code path in the remote's bundle that
7
- * directly imports the image loader — rather than going through the shared
8
- * `next/image` entry — still routes image optimization requests to the remote
9
- * and through the host's proxy when deployment protection is active.
5
+ * Creates shared module entries for image-related modules that route
6
+ * optimization requests through the remote's `/_next/image` endpoint.
10
7
  *
11
- * Pass `bound` when the resolver already has `remoteSrc` applied (App Router
12
- * `useResolveClientUrl` returns the bound form). Pass `unbound` when only the
13
- * raw 2-arg `ResolveClientUrl` is available (Pages Router, client-only
14
- * provider) — binding is deferred until the bundle URL is known at resolution
15
- * time.
8
+ * Pass `bound` when the resolver already has `remoteSrc` applied (App Router).
9
+ * Pass `unbound` when only the raw 2-arg `ResolveClientUrl` is available
10
+ * (Pages Router, client-only provider).
16
11
  */
17
12
  declare function createImageLoaderSharedEntries({ bound, unbound, }?: {
18
13
  bound?: InternalResolveClientUrl;
@@ -1,3 +1,4 @@
1
+ import { createElement, forwardRef } from "react";
1
2
  import { createRemoteImageLoader } from "#internal/host/shared/remote-image-loader";
2
3
  import { getScope } from "#internal/runtime/turbopack/remote-scope";
3
4
  import { bindResolveClientUrl } from "#internal/runtime/url/default-resolve-client-url";
@@ -11,16 +12,41 @@ function createImageLoaderSharedEntries({
11
12
  bound,
12
13
  unbound
13
14
  } = {}) {
14
- const entry = (bundle) => {
15
+ const loaderEntry = (bundle) => {
15
16
  const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);
16
17
  return Promise.resolve({
17
18
  default: createRemoteImageLoader(bundle, resolveClientUrl),
18
19
  __esModule: true
19
20
  });
20
21
  };
22
+ const imageEntry = async (bundle) => {
23
+ const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);
24
+ const rawLoader = createRemoteImageLoader(bundle, resolveClientUrl);
25
+ const remoteLoader = Object.assign(
26
+ (p) => rawLoader({ ...p, config: { path: "/_next/image" } }),
27
+ { __next_img_default: true }
28
+ );
29
+ const mod = await import("next/image");
30
+ const OriginalImage = mod.default;
31
+ const RemoteImage = forwardRef(
32
+ (props, ref) => createElement(OriginalImage, {
33
+ ...props,
34
+ loader: props.loader ?? remoteLoader,
35
+ ref
36
+ })
37
+ );
38
+ RemoteImage.displayName = "RemoteImage";
39
+ return { ...mod, default: RemoteImage, __esModule: true };
40
+ };
21
41
  return {
22
- "next/dist/shared/lib/image-loader": entry,
23
- "next/dist/esm/shared/lib/image-loader": entry
42
+ "next/dist/shared/lib/image-loader": loaderEntry,
43
+ "next/dist/esm/shared/lib/image-loader": loaderEntry,
44
+ // Can be removed once 0.2.x support is dropped.
45
+ "next/image": imageEntry,
46
+ // Can be removed once 0.2.x support is dropped.
47
+ "next/dist/client/image-component": imageEntry,
48
+ // Can be removed once 0.2.x support is dropped.
49
+ "next/dist/api/image": imageEntry
24
50
  };
25
51
  }
26
52
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/host/nextjs/image-shared.ts"],"sourcesContent":["import { createRemoteImageLoader } from '#internal/host/shared/remote-image-loader';\nimport { getScope } from '#internal/runtime/turbopack/remote-scope';\nimport { bindResolveClientUrl } from '#internal/runtime/url/default-resolve-client-url';\nimport type {\n InternalResolveClientUrl,\n ResolveClientUrl,\n} from '#internal/runtime/url/resolve-client-url';\n\ntype SharedImageModule = (bundle: string) => Promise<unknown>;\n\nfunction resolveForBundle(\n unbound: ResolveClientUrl | undefined,\n bundle: string,\n): InternalResolveClientUrl | undefined {\n if (!unbound) return undefined;\n const remoteSrc = getScope(bundle)?.url.href ?? '';\n return bindResolveClientUrl(unbound, remoteSrc);\n}\n\n/**\n * Creates shared module entries for `next/dist/shared/lib/image-loader` (and\n * its ESM alias). These ensure that any code path in the remote's bundle that\n * directly imports the image loader — rather than going through the shared\n * `next/image` entry — still routes image optimization requests to the remote\n * and through the host's proxy when deployment protection is active.\n *\n * Pass `bound` when the resolver already has `remoteSrc` applied (App Router —\n * `useResolveClientUrl` returns the bound form). Pass `unbound` when only the\n * raw 2-arg `ResolveClientUrl` is available (Pages Router, client-only\n * provider) — binding is deferred until the bundle URL is known at resolution\n * time.\n */\nexport function createImageLoaderSharedEntries({\n bound,\n unbound,\n}: {\n bound?: InternalResolveClientUrl;\n unbound?: ResolveClientUrl;\n} = {}): Record<string, SharedImageModule> {\n const entry: SharedImageModule = (bundle: string) => {\n const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);\n return Promise.resolve({\n default: createRemoteImageLoader(bundle, resolveClientUrl),\n __esModule: true,\n });\n };\n return {\n 'next/dist/shared/lib/image-loader': entry,\n 'next/dist/esm/shared/lib/image-loader': entry,\n };\n}\n"],"mappings":"AAAA,SAAS,+BAA+B;AACxC,SAAS,gBAAgB;AACzB,SAAS,4BAA4B;AAQrC,SAAS,iBACP,SACA,QACsC;AACtC,MAAI,CAAC;AAAS,WAAO;AACrB,QAAM,YAAY,SAAS,MAAM,GAAG,IAAI,QAAQ;AAChD,SAAO,qBAAqB,SAAS,SAAS;AAChD;AAeO,SAAS,+BAA+B;AAAA,EAC7C;AAAA,EACA;AACF,IAGI,CAAC,GAAsC;AACzC,QAAM,QAA2B,CAAC,WAAmB;AACnD,UAAM,mBAAmB,SAAS,iBAAiB,SAAS,MAAM;AAClE,WAAO,QAAQ,QAAQ;AAAA,MACrB,SAAS,wBAAwB,QAAQ,gBAAgB;AAAA,MACzD,YAAY;AAAA,IACd,CAAC;AAAA,EACH;AACA,SAAO;AAAA,IACL,qCAAqC;AAAA,IACrC,yCAAyC;AAAA,EAC3C;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/host/nextjs/image-shared.ts"],"sourcesContent":["import { createElement, forwardRef } from 'react';\nimport { createRemoteImageLoader } from '#internal/host/shared/remote-image-loader';\nimport { getScope } from '#internal/runtime/turbopack/remote-scope';\nimport { bindResolveClientUrl } from '#internal/runtime/url/default-resolve-client-url';\nimport type {\n InternalResolveClientUrl,\n ResolveClientUrl,\n} from '#internal/runtime/url/resolve-client-url';\n\ntype SharedImageModule = (bundle: string) => Promise<unknown>;\n\nfunction resolveForBundle(\n unbound: ResolveClientUrl | undefined,\n bundle: string,\n): InternalResolveClientUrl | undefined {\n if (!unbound) return undefined;\n const remoteSrc = getScope(bundle)?.url.href ?? '';\n return bindResolveClientUrl(unbound, remoteSrc);\n}\n\n/**\n * Creates shared module entries for image-related modules that route\n * optimization requests through the remote's `/_next/image` endpoint.\n *\n * Pass `bound` when the resolver already has `remoteSrc` applied (App Router).\n * Pass `unbound` when only the raw 2-arg `ResolveClientUrl` is available\n * (Pages Router, client-only provider).\n */\nexport function createImageLoaderSharedEntries({\n bound,\n unbound,\n}: {\n bound?: InternalResolveClientUrl;\n unbound?: ResolveClientUrl;\n} = {}): Record<string, SharedImageModule> {\n const loaderEntry: SharedImageModule = (bundle: string) => {\n const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);\n return Promise.resolve({\n default: createRemoteImageLoader(bundle, resolveClientUrl),\n __esModule: true,\n });\n };\n\n // Cross-version compat: remotes <=0.2.x request `next/image` as a shared module.\n // Wraps the host's Image component with the remote image loader injected\n // via the `loader` prop. Can be removed once 0.2.x support is dropped.\n const imageEntry: SharedImageModule = async (bundle: string) => {\n const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);\n const rawLoader = createRemoteImageLoader(bundle, resolveClientUrl);\n // Wrap to match Next.js `ImageLoader` signature (no `config` param).\n // The raw loader expects `{ config, src, width, quality }` but the public\n // `loader` prop is called with `{ src, width, quality }` only.\n const remoteLoader = Object.assign(\n (p: { src: string; width: number; quality?: number }) =>\n rawLoader({ ...p, config: { path: '/_next/image' } }),\n { __next_img_default: true as const },\n );\n const mod = await import('next/image');\n const OriginalImage = mod.default;\n type ImageProps = Parameters<typeof OriginalImage>[0];\n const RemoteImage = forwardRef<HTMLImageElement, ImageProps>((props, ref) =>\n createElement(OriginalImage, {\n ...props,\n loader: props.loader ?? remoteLoader,\n ref,\n }),\n );\n RemoteImage.displayName = 'RemoteImage';\n return { ...mod, default: RemoteImage, __esModule: true };\n };\n\n return {\n 'next/dist/shared/lib/image-loader': loaderEntry,\n 'next/dist/esm/shared/lib/image-loader': loaderEntry,\n // Can be removed once 0.2.x support is dropped.\n 'next/image': imageEntry,\n // Can be removed once 0.2.x support is dropped.\n 'next/dist/client/image-component': imageEntry,\n // Can be removed once 0.2.x support is dropped.\n 'next/dist/api/image': imageEntry,\n };\n}\n"],"mappings":"AAAA,SAAS,eAAe,kBAAkB;AAC1C,SAAS,+BAA+B;AACxC,SAAS,gBAAgB;AACzB,SAAS,4BAA4B;AAQrC,SAAS,iBACP,SACA,QACsC;AACtC,MAAI,CAAC;AAAS,WAAO;AACrB,QAAM,YAAY,SAAS,MAAM,GAAG,IAAI,QAAQ;AAChD,SAAO,qBAAqB,SAAS,SAAS;AAChD;AAUO,SAAS,+BAA+B;AAAA,EAC7C;AAAA,EACA;AACF,IAGI,CAAC,GAAsC;AACzC,QAAM,cAAiC,CAAC,WAAmB;AACzD,UAAM,mBAAmB,SAAS,iBAAiB,SAAS,MAAM;AAClE,WAAO,QAAQ,QAAQ;AAAA,MACrB,SAAS,wBAAwB,QAAQ,gBAAgB;AAAA,MACzD,YAAY;AAAA,IACd,CAAC;AAAA,EACH;AAKA,QAAM,aAAgC,OAAO,WAAmB;AAC9D,UAAM,mBAAmB,SAAS,iBAAiB,SAAS,MAAM;AAClE,UAAM,YAAY,wBAAwB,QAAQ,gBAAgB;AAIlE,UAAM,eAAe,OAAO;AAAA,MAC1B,CAAC,MACC,UAAU,EAAE,GAAG,GAAG,QAAQ,EAAE,MAAM,eAAe,EAAE,CAAC;AAAA,MACtD,EAAE,oBAAoB,KAAc;AAAA,IACtC;AACA,UAAM,MAAM,MAAM,OAAO,YAAY;AACrC,UAAM,gBAAgB,IAAI;AAE1B,UAAM,cAAc;AAAA,MAAyC,CAAC,OAAO,QACnE,cAAc,eAAe;AAAA,QAC3B,GAAG;AAAA,QACH,QAAQ,MAAM,UAAU;AAAA,QACxB;AAAA,MACF,CAAC;AAAA,IACH;AACA,gBAAY,cAAc;AAC1B,WAAO,EAAE,GAAG,KAAK,SAAS,aAAa,YAAY,KAAK;AAAA,EAC1D;AAEA,SAAO;AAAA,IACL,qCAAqC;AAAA,IACrC,yCAAyC;AAAA;AAAA,IAEzC,cAAc;AAAA;AAAA,IAEd,oCAAoC;AAAA;AAAA,IAEpC,uBAAuB;AAAA,EACzB;AACF;","names":[]}
@@ -22,6 +22,7 @@ __export(remote_component_links_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(remote_component_links_exports);
24
24
  var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_react_dom = require("react-dom");
25
26
  var import_get_client_src = require("#internal/host/server/get-client-src");
26
27
  var import_utils = require("#internal/utils");
27
28
  function RemoteComponentLinks({
@@ -51,19 +52,29 @@ function RemoteComponentLinks({
51
52
  JSON.stringify(link)
52
53
  );
53
54
  }),
54
- useShadowDom ? links.filter((link) => link.rel === "stylesheet").map((link) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
55
- RenderLink,
56
- {
57
- link,
58
- serverUrl,
59
- url,
60
- as: "style",
61
- fetchPriority: "high",
62
- precedence: bundle,
63
- rel: "preload"
64
- },
65
- `preload-${JSON.stringify(link)}`
66
- )) : null
55
+ useShadowDom ? links.filter((link) => link.rel === "stylesheet").map((link) => {
56
+ const href = (0, import_get_client_src.getClientSrc)(link.href, serverUrl);
57
+ if (typeof import_react_dom.preload === "function") {
58
+ (0, import_react_dom.preload)(href, {
59
+ as: "style",
60
+ fetchPriority: "high"
61
+ });
62
+ return null;
63
+ }
64
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
65
+ RenderLink,
66
+ {
67
+ link,
68
+ serverUrl,
69
+ url,
70
+ as: "style",
71
+ fetchPriority: "high",
72
+ precedence: bundle,
73
+ rel: "preload"
74
+ },
75
+ `preload-${JSON.stringify(link)}`
76
+ );
77
+ }) : null
67
78
  ] });
68
79
  }
69
80
  function RenderLink({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/host/nextjs/remote-component-links.tsx"],"sourcesContent":["import { getClientSrc } from '#internal/host/server/get-client-src';\nimport { attrToProp } from '#internal/utils';\n\ninterface RemoteComponentLinksProps {\n links: Record<string, string | boolean | undefined>[];\n url: URL;\n serverUrl: string;\n bundle: string;\n isolate: boolean | undefined;\n reset: boolean | undefined;\n isDevelopment: boolean;\n}\n\n/**\n * Renders stylesheet and other link elements for remote components.\n *\n * For shadow DOM (isolate !== false):\n * - Renders links inline (they go into the shadow root)\n * - Adds preload hints to <head> for early fetching\n *\n * For non-shadow DOM (isolate === false):\n * - Uses React's `precedence` prop to hoist stylesheets to <head>\n * - This blocks rendering until CSS loads, preventing layout shift\n */\nexport function RemoteComponentLinks({\n links,\n url,\n serverUrl,\n bundle,\n isolate,\n reset,\n isDevelopment,\n}: RemoteComponentLinksProps) {\n const useShadowDom = isolate !== false;\n const showResetStyles = !isDevelopment && useShadowDom && reset;\n\n return (\n <>\n {showResetStyles ? (\n <style data-remote-components-reset=\"\">{`:host { all: initial; }`}</style>\n ) : null}\n {links.map((link) => {\n const isStylesheet = link.rel === 'stylesheet' && link.href;\n return (\n <RenderLink\n key={JSON.stringify(link)}\n link={link}\n url={url}\n serverUrl={serverUrl}\n data-wait={isStylesheet ? '' : undefined}\n // For non-shadow DOM, use precedence to hoist stylesheets to <head>\n precedence={!useShadowDom && isStylesheet ? bundle : undefined}\n />\n );\n })}\n {useShadowDom\n ? links\n .filter((link) => link.rel === 'stylesheet')\n .map((link) => (\n <RenderLink\n key={`preload-${JSON.stringify(link)}`}\n link={link}\n serverUrl={serverUrl}\n url={url}\n as=\"style\"\n fetchPriority=\"high\"\n precedence={bundle}\n rel=\"preload\"\n />\n ))\n : null}\n </>\n );\n}\n\nfunction RenderLink({\n link,\n url,\n serverUrl,\n ...rest\n}: {\n link: Record<string, string | boolean | undefined>;\n url: URL;\n serverUrl: string;\n} & React.LinkHTMLAttributes<HTMLLinkElement>) {\n return (\n <link\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n href={getClientSrc(link.href, serverUrl)}\n {...rest}\n />\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqCI;AArCJ,4BAA6B;AAC7B,mBAA2B;AAuBpB,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA8B;AAC5B,QAAM,eAAe,YAAY;AACjC,QAAM,kBAAkB,CAAC,iBAAiB,gBAAgB;AAE1D,SACE,4EACG;AAAA,sBACC,4CAAC,WAAM,gCAA6B,IAAI,qCAA0B,IAChE;AAAA,IACH,MAAM,IAAI,CAAC,SAAS;AACnB,YAAM,eAAe,KAAK,QAAQ,gBAAgB,KAAK;AACvD,aACE;AAAA,QAAC;AAAA;AAAA,UAEC;AAAA,UACA;AAAA,UACA;AAAA,UACA,aAAW,eAAe,KAAK;AAAA,UAE/B,YAAY,CAAC,gBAAgB,eAAe,SAAS;AAAA;AAAA,QANhD,KAAK,UAAU,IAAI;AAAA,MAO1B;AAAA,IAEJ,CAAC;AAAA,IACA,eACG,MACG,OAAO,CAAC,SAAS,KAAK,QAAQ,YAAY,EAC1C,IAAI,CAAC,SACJ;AAAA,MAAC;AAAA;AAAA,QAEC;AAAA,QACA;AAAA,QACA;AAAA,QACA,IAAG;AAAA,QACH,eAAc;AAAA,QACd,YAAY;AAAA,QACZ,KAAI;AAAA;AAAA,MAPC,WAAW,KAAK,UAAU,IAAI;AAAA,IAQrC,CACD,IACH;AAAA,KACN;AAEJ;AAEA,SAAS,WAAW;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAI+C;AAC7C,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG,OAAO,QAAQ,IAAI,EAAE;AAAA,QACvB,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AACrB,cACE,QAAQ,UACR,QAAQ,gBACR,OAAO,UAAU,UACjB;AACA,gBAAI,wBAAW,GAAG,KAAK,GAAG,IAAI;AAAA,UAChC;AACA,iBAAO;AAAA,QACT;AAAA,QACA,CAAC;AAAA,MACH;AAAA,MACA,UAAM,oCAAa,KAAK,MAAM,SAAS;AAAA,MACtC,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/host/nextjs/remote-component-links.tsx"],"sourcesContent":["import { preload as reactDomPreload } from 'react-dom';\nimport { getClientSrc } from '#internal/host/server/get-client-src';\nimport { attrToProp } from '#internal/utils';\n\ninterface RemoteComponentLinksProps {\n links: Record<string, string | boolean | undefined>[];\n url: URL;\n serverUrl: string;\n bundle: string;\n isolate: boolean | undefined;\n reset: boolean | undefined;\n isDevelopment: boolean;\n}\n\n/**\n * Renders stylesheet and other link elements for remote components.\n *\n * For shadow DOM (isolate !== false):\n * - Renders links inline (they go into the shadow root)\n * - Adds preload hints to <head> for early fetching\n *\n * For non-shadow DOM (isolate === false):\n * - Uses React's `precedence` prop to hoist stylesheets to <head>\n * - This blocks rendering until CSS loads, preventing layout shift\n *\n * Uses the React DOM `preload()` API when available for stylesheet preloads,\n * falling back to `<link rel=\"preload\">` elements.\n */\nexport function RemoteComponentLinks({\n links,\n url,\n serverUrl,\n bundle,\n isolate,\n reset,\n isDevelopment,\n}: RemoteComponentLinksProps) {\n const useShadowDom = isolate !== false;\n const showResetStyles = !isDevelopment && useShadowDom && reset;\n\n return (\n <>\n {showResetStyles ? (\n <style data-remote-components-reset=\"\">{`:host { all: initial; }`}</style>\n ) : null}\n {links.map((link) => {\n const isStylesheet = link.rel === 'stylesheet' && link.href;\n return (\n <RenderLink\n key={JSON.stringify(link)}\n link={link}\n url={url}\n serverUrl={serverUrl}\n data-wait={isStylesheet ? '' : undefined}\n // For non-shadow DOM, use precedence to hoist stylesheets to <head>\n precedence={!useShadowDom && isStylesheet ? bundle : undefined}\n />\n );\n })}\n {useShadowDom\n ? links\n .filter((link) => link.rel === 'stylesheet')\n .map((link) => {\n const href = getClientSrc(link.href, serverUrl);\n if (typeof reactDomPreload === 'function') {\n reactDomPreload(href, {\n as: 'style',\n fetchPriority: 'high',\n });\n return null;\n }\n return (\n <RenderLink\n key={`preload-${JSON.stringify(link)}`}\n link={link}\n serverUrl={serverUrl}\n url={url}\n as=\"style\"\n fetchPriority=\"high\"\n precedence={bundle}\n rel=\"preload\"\n />\n );\n })\n : null}\n </>\n );\n}\n\nfunction RenderLink({\n link,\n url,\n serverUrl,\n ...rest\n}: {\n link: Record<string, string | boolean | undefined>;\n url: URL;\n serverUrl: string;\n} & React.LinkHTMLAttributes<HTMLLinkElement>) {\n return (\n <link\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n href={getClientSrc(link.href, serverUrl)}\n {...rest}\n />\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCI;AAzCJ,uBAA2C;AAC3C,4BAA6B;AAC7B,mBAA2B;AA0BpB,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA8B;AAC5B,QAAM,eAAe,YAAY;AACjC,QAAM,kBAAkB,CAAC,iBAAiB,gBAAgB;AAE1D,SACE,4EACG;AAAA,sBACC,4CAAC,WAAM,gCAA6B,IAAI,qCAA0B,IAChE;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["reactDomPreload"]}
@@ -19,6 +19,9 @@ interface RemoteComponentLinksProps {
19
19
  * For non-shadow DOM (isolate === false):
20
20
  * - Uses React's `precedence` prop to hoist stylesheets to <head>
21
21
  * - This blocks rendering until CSS loads, preventing layout shift
22
+ *
23
+ * Uses the React DOM `preload()` API when available for stylesheet preloads,
24
+ * falling back to `<link rel="preload">` elements.
22
25
  */
23
26
  declare function RemoteComponentLinks({ links, url, serverUrl, bundle, isolate, reset, isDevelopment, }: RemoteComponentLinksProps): react_jsx_runtime.JSX.Element;
24
27
 
@@ -1,4 +1,5 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { preload as reactDomPreload } from "react-dom";
2
3
  import { getClientSrc } from "#internal/host/server/get-client-src";
3
4
  import { attrToProp } from "#internal/utils";
4
5
  function RemoteComponentLinks({
@@ -28,19 +29,29 @@ function RemoteComponentLinks({
28
29
  JSON.stringify(link)
29
30
  );
30
31
  }),
31
- useShadowDom ? links.filter((link) => link.rel === "stylesheet").map((link) => /* @__PURE__ */ jsx(
32
- RenderLink,
33
- {
34
- link,
35
- serverUrl,
36
- url,
37
- as: "style",
38
- fetchPriority: "high",
39
- precedence: bundle,
40
- rel: "preload"
41
- },
42
- `preload-${JSON.stringify(link)}`
43
- )) : null
32
+ useShadowDom ? links.filter((link) => link.rel === "stylesheet").map((link) => {
33
+ const href = getClientSrc(link.href, serverUrl);
34
+ if (typeof reactDomPreload === "function") {
35
+ reactDomPreload(href, {
36
+ as: "style",
37
+ fetchPriority: "high"
38
+ });
39
+ return null;
40
+ }
41
+ return /* @__PURE__ */ jsx(
42
+ RenderLink,
43
+ {
44
+ link,
45
+ serverUrl,
46
+ url,
47
+ as: "style",
48
+ fetchPriority: "high",
49
+ precedence: bundle,
50
+ rel: "preload"
51
+ },
52
+ `preload-${JSON.stringify(link)}`
53
+ );
54
+ }) : null
44
55
  ] });
45
56
  }
46
57
  function RenderLink({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/host/nextjs/remote-component-links.tsx"],"sourcesContent":["import { getClientSrc } from '#internal/host/server/get-client-src';\nimport { attrToProp } from '#internal/utils';\n\ninterface RemoteComponentLinksProps {\n links: Record<string, string | boolean | undefined>[];\n url: URL;\n serverUrl: string;\n bundle: string;\n isolate: boolean | undefined;\n reset: boolean | undefined;\n isDevelopment: boolean;\n}\n\n/**\n * Renders stylesheet and other link elements for remote components.\n *\n * For shadow DOM (isolate !== false):\n * - Renders links inline (they go into the shadow root)\n * - Adds preload hints to <head> for early fetching\n *\n * For non-shadow DOM (isolate === false):\n * - Uses React's `precedence` prop to hoist stylesheets to <head>\n * - This blocks rendering until CSS loads, preventing layout shift\n */\nexport function RemoteComponentLinks({\n links,\n url,\n serverUrl,\n bundle,\n isolate,\n reset,\n isDevelopment,\n}: RemoteComponentLinksProps) {\n const useShadowDom = isolate !== false;\n const showResetStyles = !isDevelopment && useShadowDom && reset;\n\n return (\n <>\n {showResetStyles ? (\n <style data-remote-components-reset=\"\">{`:host { all: initial; }`}</style>\n ) : null}\n {links.map((link) => {\n const isStylesheet = link.rel === 'stylesheet' && link.href;\n return (\n <RenderLink\n key={JSON.stringify(link)}\n link={link}\n url={url}\n serverUrl={serverUrl}\n data-wait={isStylesheet ? '' : undefined}\n // For non-shadow DOM, use precedence to hoist stylesheets to <head>\n precedence={!useShadowDom && isStylesheet ? bundle : undefined}\n />\n );\n })}\n {useShadowDom\n ? links\n .filter((link) => link.rel === 'stylesheet')\n .map((link) => (\n <RenderLink\n key={`preload-${JSON.stringify(link)}`}\n link={link}\n serverUrl={serverUrl}\n url={url}\n as=\"style\"\n fetchPriority=\"high\"\n precedence={bundle}\n rel=\"preload\"\n />\n ))\n : null}\n </>\n );\n}\n\nfunction RenderLink({\n link,\n url,\n serverUrl,\n ...rest\n}: {\n link: Record<string, string | boolean | undefined>;\n url: URL;\n serverUrl: string;\n} & React.LinkHTMLAttributes<HTMLLinkElement>) {\n return (\n <link\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n href={getClientSrc(link.href, serverUrl)}\n {...rest}\n />\n );\n}\n"],"mappings":"AAqCI,mBAEI,KAFJ;AArCJ,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAuBpB,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA8B;AAC5B,QAAM,eAAe,YAAY;AACjC,QAAM,kBAAkB,CAAC,iBAAiB,gBAAgB;AAE1D,SACE,iCACG;AAAA,sBACC,oBAAC,WAAM,gCAA6B,IAAI,qCAA0B,IAChE;AAAA,IACH,MAAM,IAAI,CAAC,SAAS;AACnB,YAAM,eAAe,KAAK,QAAQ,gBAAgB,KAAK;AACvD,aACE;AAAA,QAAC;AAAA;AAAA,UAEC;AAAA,UACA;AAAA,UACA;AAAA,UACA,aAAW,eAAe,KAAK;AAAA,UAE/B,YAAY,CAAC,gBAAgB,eAAe,SAAS;AAAA;AAAA,QANhD,KAAK,UAAU,IAAI;AAAA,MAO1B;AAAA,IAEJ,CAAC;AAAA,IACA,eACG,MACG,OAAO,CAAC,SAAS,KAAK,QAAQ,YAAY,EAC1C,IAAI,CAAC,SACJ;AAAA,MAAC;AAAA;AAAA,QAEC;AAAA,QACA;AAAA,QACA;AAAA,QACA,IAAG;AAAA,QACH,eAAc;AAAA,QACd,YAAY;AAAA,QACZ,KAAI;AAAA;AAAA,MAPC,WAAW,KAAK,UAAU,IAAI;AAAA,IAQrC,CACD,IACH;AAAA,KACN;AAEJ;AAEA,SAAS,WAAW;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAI+C;AAC7C,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG,OAAO,QAAQ,IAAI,EAAE;AAAA,QACvB,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AACrB,cACE,QAAQ,UACR,QAAQ,gBACR,OAAO,UAAU,UACjB;AACA,gBAAI,WAAW,GAAG,KAAK,GAAG,IAAI;AAAA,UAChC;AACA,iBAAO;AAAA,QACT;AAAA,QACA,CAAC;AAAA,MACH;AAAA,MACA,MAAM,aAAa,KAAK,MAAM,SAAS;AAAA,MACtC,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/host/nextjs/remote-component-links.tsx"],"sourcesContent":["import { preload as reactDomPreload } from 'react-dom';\nimport { getClientSrc } from '#internal/host/server/get-client-src';\nimport { attrToProp } from '#internal/utils';\n\ninterface RemoteComponentLinksProps {\n links: Record<string, string | boolean | undefined>[];\n url: URL;\n serverUrl: string;\n bundle: string;\n isolate: boolean | undefined;\n reset: boolean | undefined;\n isDevelopment: boolean;\n}\n\n/**\n * Renders stylesheet and other link elements for remote components.\n *\n * For shadow DOM (isolate !== false):\n * - Renders links inline (they go into the shadow root)\n * - Adds preload hints to <head> for early fetching\n *\n * For non-shadow DOM (isolate === false):\n * - Uses React's `precedence` prop to hoist stylesheets to <head>\n * - This blocks rendering until CSS loads, preventing layout shift\n *\n * Uses the React DOM `preload()` API when available for stylesheet preloads,\n * falling back to `<link rel=\"preload\">` elements.\n */\nexport function RemoteComponentLinks({\n links,\n url,\n serverUrl,\n bundle,\n isolate,\n reset,\n isDevelopment,\n}: RemoteComponentLinksProps) {\n const useShadowDom = isolate !== false;\n const showResetStyles = !isDevelopment && useShadowDom && reset;\n\n return (\n <>\n {showResetStyles ? (\n <style data-remote-components-reset=\"\">{`:host { all: initial; }`}</style>\n ) : null}\n {links.map((link) => {\n const isStylesheet = link.rel === 'stylesheet' && link.href;\n return (\n <RenderLink\n key={JSON.stringify(link)}\n link={link}\n url={url}\n serverUrl={serverUrl}\n data-wait={isStylesheet ? '' : undefined}\n // For non-shadow DOM, use precedence to hoist stylesheets to <head>\n precedence={!useShadowDom && isStylesheet ? bundle : undefined}\n />\n );\n })}\n {useShadowDom\n ? links\n .filter((link) => link.rel === 'stylesheet')\n .map((link) => {\n const href = getClientSrc(link.href, serverUrl);\n if (typeof reactDomPreload === 'function') {\n reactDomPreload(href, {\n as: 'style',\n fetchPriority: 'high',\n });\n return null;\n }\n return (\n <RenderLink\n key={`preload-${JSON.stringify(link)}`}\n link={link}\n serverUrl={serverUrl}\n url={url}\n as=\"style\"\n fetchPriority=\"high\"\n precedence={bundle}\n rel=\"preload\"\n />\n );\n })\n : null}\n </>\n );\n}\n\nfunction RenderLink({\n link,\n url,\n serverUrl,\n ...rest\n}: {\n link: Record<string, string | boolean | undefined>;\n url: URL;\n serverUrl: string;\n} & React.LinkHTMLAttributes<HTMLLinkElement>) {\n return (\n <link\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n href={getClientSrc(link.href, serverUrl)}\n {...rest}\n />\n );\n}\n"],"mappings":"AAyCI,mBAEI,KAFJ;AAzCJ,SAAS,WAAW,uBAAuB;AAC3C,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AA0BpB,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA8B;AAC5B,QAAM,eAAe,YAAY;AACjC,QAAM,kBAAkB,CAAC,iBAAiB,gBAAgB;AAE1D,SACE,iCACG;AAAA,sBACC,oBAAC,WAAM,gCAA6B,IAAI,qCAA0B,IAChE;AAAA,IACH,MAAM,IAAI,CAAC,SAAS;AACnB,YAAM,eAAe,KAAK,QAAQ,gBAAgB,KAAK;AACvD,aACE;AAAA,QAAC;AAAA;AAAA,UAEC;AAAA,UACA;AAAA,UACA;AAAA,UACA,aAAW,eAAe,KAAK;AAAA,UAE/B,YAAY,CAAC,gBAAgB,eAAe,SAAS;AAAA;AAAA,QANhD,KAAK,UAAU,IAAI;AAAA,MAO1B;AAAA,IAEJ,CAAC;AAAA,IACA,eACG,MACG,OAAO,CAAC,SAAS,KAAK,QAAQ,YAAY,EAC1C,IAAI,CAAC,SAAS;AACb,YAAM,OAAO,aAAa,KAAK,MAAM,SAAS;AAC9C,UAAI,OAAO,oBAAoB,YAAY;AACzC,wBAAgB,MAAM;AAAA,UACpB,IAAI;AAAA,UACJ,eAAe;AAAA,QACjB,CAAC;AACD,eAAO;AAAA,MACT;AACA,aACE;AAAA,QAAC;AAAA;AAAA,UAEC;AAAA,UACA;AAAA,UACA;AAAA,UACA,IAAG;AAAA,UACH,eAAc;AAAA,UACd,YAAY;AAAA,UACZ,KAAI;AAAA;AAAA,QAPC,WAAW,KAAK,UAAU,IAAI;AAAA,MAQrC;AAAA,IAEJ,CAAC,IACH;AAAA,KACN;AAEJ;AAEA,SAAS,WAAW;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAI+C;AAC7C,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG,OAAO,QAAQ,IAAI,EAAE;AAAA,QACvB,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AACrB,cACE,QAAQ,UACR,QAAQ,gBACR,OAAO,UAAU,UACjB;AACA,gBAAI,WAAW,GAAG,KAAK,GAAG,IAAI;AAAA,UAChC;AACA,iBAAO;AAAA,QACT;AAAA,QACA,CAAC;AAAA,MACH;AAAA,MACA,MAAM,aAAa,KAAK,MAAM,SAAS;AAAA,MACtC,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
@@ -38,12 +38,13 @@ var import_fetch_with_hooks = require("#internal/host/server/fetch-with-hooks");
38
38
  var import_get_client_src = require("#internal/host/server/get-client-src");
39
39
  var import_get_ssr_relative_path_base_url = require("#internal/host/server/get-ssr-relative-path-base-url");
40
40
  var import_metadata = require("#internal/runtime/metadata");
41
+ var import_rsc_imports = require("#internal/runtime/rsc-imports");
41
42
  var import_utils = require("#internal/utils");
42
43
  var import_error = require("#internal/utils/error");
43
44
  async function buildRscComponent(rsc, serverUrl) {
44
45
  const componentRSC = `0:${JSON.stringify(rsc)}
45
46
  `;
46
- const { createFromReadableStream } = await import("next/dist/compiled/react-server-dom-webpack/client.edge");
47
+ const { createFromReadableStream } = await (0, import_rsc_imports.importRSCClientEdge)();
47
48
  return createFromReadableStream(
48
49
  new ReadableStream({
49
50
  type: "bytes",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/host/server/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { type RSC, visit } from '#internal/host/nextjs/dom-flight';\nimport {\n getSkeletonHtml,\n getSkeletonMessage,\n} from '#internal/host/nextjs/skeleton';\nimport { fetchWithHooks } from '#internal/host/server/fetch-with-hooks';\nimport { getClientSrc } from '#internal/host/server/get-client-src';\nimport { getSSRRelativePathBaseUrl } from '#internal/host/server/get-ssr-relative-path-base-url';\nimport type {\n LinkDescriptor,\n ScriptDescriptor,\n} from '#internal/host/shared/asset-descriptors';\nimport type {\n OnRequestHook,\n OnResponseHook,\n} from '#internal/host/shared/fetch-interceptors';\nimport {\n buildMetadata,\n type RawMetadataAttrs,\n type RemoteComponentMetadata,\n} from '#internal/runtime/metadata';\nimport { computeScopedName } from '#internal/utils';\nimport {\n failedToFetchRemoteComponentError,\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport type { FetchRemoteComponentResponse, NextData } from './types';\n\n/**\n * Converts RSC flight data into a React element tree using the edge streaming\n * runtime. The manifest tells React how to resolve module references back to\n * the remote origin.\n */\nasync function buildRscComponent(\n rsc: RSC | RSC[] | string | null,\n serverUrl: URL,\n): Promise<React.ReactNode> {\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n const { createFromReadableStream } = await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\n );\n return createFromReadableStream(\n new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n controller.enqueue(encoder.encode(componentRSC));\n controller.close();\n },\n }),\n {\n serverConsumerManifest: {\n moduleLoading: {\n prefix: serverUrl.origin,\n crossOrigin: true,\n },\n moduleMap: {},\n },\n },\n );\n}\n\nfunction buildSkeletonResponse(\n serverUrl: URL,\n metadata: RemoteComponentMetadata,\n skeletonComponent: React.ReactNode | undefined,\n): FetchRemoteComponentResponse {\n return {\n name: 'remote-component-skeleton',\n serverUrl,\n metadata: {\n ...metadata,\n type: 'remote-component',\n },\n rsc: getSkeletonMessage(),\n scripts: [],\n links: [],\n hydrationData: [],\n nextData: undefined,\n component: skeletonComponent,\n html: getSkeletonHtml(serverUrl.href),\n remoteShared: {},\n };\n}\n\n/**\n * Rewrites the bundle identifier in RSC flight data from the plain bundle\n * name to the origin-qualified scoped name. When multiple remotes share the\n * same bundle name (e.g. production and preview of the same app), this\n * makes each one unique so the client can look up the correct RemoteScope\n * by name alone.\n *\n * `[bundle] /path` → `[scopedName] /path`\n * `[bundle] 12345` → `[scopedName] 12345`\n *\n * Only applied for cross-origin remotes — same-origin chunks keep the\n * plain bundle name since there's no ambiguity.\n */\nfunction scopeChunkReferences(\n chunk: string,\n bundle: string,\n scopedName: string,\n): string {\n return chunk.replaceAll(`[${bundle}]`, `[${scopedName}]`);\n}\n\n/**\n * Walks the parsed HTML fragment and extracts all remote component data:\n * metadata, scripts, links, hydration data, Next.js data, shared deps, and HTML.\n */\nfunction visitFragment(\n fragment: DefaultTreeAdapterMap['documentFragment'],\n serverUrl: URL,\n remoteName: string | undefined,\n) {\n const scriptSrcSet = new Set<string>();\n const scriptTextSet = new Set<string>();\n const scripts: ScriptDescriptor[] = [];\n\n const linkKeySet = new Set<string>();\n const links: LinkDescriptor[] = [];\n\n const hydrationData: string[] = [];\n const htmlChunks = new Set<string>();\n\n let metadata: RemoteComponentMetadata | undefined;\n let nextData: NextData | undefined;\n let remoteShared: Record<string, string> = {};\n let hasRSC = false;\n let hasShared = false;\n let error: RemoteComponentsError | undefined;\n\n // For cross-origin remotes, rewrite bundle identifiers in RSC chunks to\n // the scoped name so the client dispatchers resolve the correct scope.\n // Chunks are collected raw during visit() and rewritten afterwards because\n // RSC script tags appear before the metadata element in the HTML.\n const isCrossOrigin = serverUrl.origin !== getSSRRelativePathBaseUrl();\n\n const rawRscChunks: string[] = [];\n\n const rsc = visit(fragment, {\n url: serverUrl,\n name: remoteName,\n onMetadata(attrs: RawMetadataAttrs) {\n const incoming = buildMetadata(attrs, serverUrl);\n // Skip multiple component detection for Pages Router (__next) since\n // it only supports one remote component per page\n if (\n !remoteName &&\n metadata &&\n metadata.id !== incoming.id &&\n incoming.id !== '__next' &&\n metadata.id !== '__next' &&\n !nextData\n ) {\n throw multipleRemoteComponentsError(serverUrl.href);\n }\n metadata = incoming;\n },\n onScript(attrs) {\n const clientSrc = getClientSrc(attrs.src, serverUrl.href);\n const textContent =\n typeof attrs.textContent === 'string' ? attrs.textContent : undefined;\n\n if (textContent) {\n if (!scriptTextSet.has(textContent)) {\n scriptTextSet.add(textContent);\n scripts.push({ src: '', textContent });\n }\n } else if (!scriptSrcSet.has(clientSrc)) {\n scriptSrcSet.add(clientSrc);\n scripts.push({ src: clientSrc });\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: getClientSrc(attrs.href, serverUrl.href),\n };\n const linkKey = `${relativeAttrs.href}::${attrs.rel}`;\n if (!linkKeySet.has(linkKey)) {\n linkKeySet.add(linkKey);\n links.push(relativeAttrs);\n }\n },\n onRSC(chunk) {\n rawRscChunks.push(chunk);\n hasRSC = true;\n },\n onNextData(data) {\n nextData = data;\n },\n onHTML(chunk) {\n if (!htmlChunks.has(chunk)) {\n htmlChunks.add(chunk);\n }\n },\n onShared(_shared) {\n remoteShared = _shared;\n hasShared = true;\n },\n onError(message, stack) {\n error = new RemoteComponentsError(message);\n if (stack) {\n error.stack = stack;\n }\n },\n });\n\n // Rewrite bundle identifiers in RSC chunk references to use the scoped name\n // so the client dispatchers can resolve the correct scope with a direct lookup.\n // This must happen after visit() because RSC script tags appear before the\n // metadata element in the HTML.\n if (isCrossOrigin && metadata?.bundle) {\n const scopedName = computeScopedName(metadata.bundle, {\n remoteHost: serverUrl.host,\n isCrossOrigin: true,\n });\n for (const chunk of rawRscChunks) {\n hydrationData.push(\n scopeChunkReferences(chunk, metadata.bundle, scopedName),\n );\n }\n } else {\n hydrationData.push(...rawRscChunks);\n }\n\n if (error) {\n throw error;\n }\n\n if (metadata) {\n if (!hasRSC && !nextData && metadata.type === 'nextjs') {\n throw new RemoteComponentsError(\n `The Remote Component at \"${serverUrl.href}\" seems to be a Next.js component but it does not contain any RSC flight data or Next.js props data. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n if (\n metadata.type === 'nextjs' &&\n !hasShared &&\n !nextData?.props.__REMOTE_COMPONENT__?.shared\n ) {\n throw new RemoteComponentsError(\n `No shared dependencies found for Remote Component at \"${serverUrl.href}\". Make sure the remote URL is correct and contains a Remote Component with shared dependencies.`,\n );\n }\n }\n\n const resolvedShared =\n nextData?.props.__REMOTE_COMPONENT__?.shared ?? remoteShared;\n\n return {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared: resolvedShared,\n html: Array.from(htmlChunks).join(''),\n };\n}\n\nexport async function fetchRemoteComponent(\n src: string | URL,\n options: {\n name?: string;\n rsc?: boolean;\n /** Whether this is being called from Next.js App Router. Used to enable skeleton fallback during SSG builds. */\n appRouter?: boolean;\n onRequest?: OnRequestHook;\n onResponse?: OnResponseHook;\n } = {},\n): Promise<FetchRemoteComponentResponse> {\n const ssrRelativePathBaseUrl = getSSRRelativePathBaseUrl();\n const serverUrl = new URL(src, ssrRelativePathBaseUrl);\n\n const tags = [\n '_vc_rc:fetch-remote-component',\n // the max size of a next cache tag is 256 characters\n serverUrl.host.slice(0, 256),\n // use the suffix so this tag is unique if multiple remote\n // components have the same host, but unique pathnames / query params\n (typeof src === 'string' ? src : src.href).slice(-256),\n ];\n if (options.name) {\n tags.push(options.name.slice(-256));\n }\n\n const fetchInit = {\n next: {\n tags,\n },\n };\n\n const res = await fetchWithHooks(serverUrl, fetchInit, {\n onRequest: options.onRequest,\n onResponse: options.onResponse,\n });\n\n // If there is an error in the remote, parse and extract the remote error (except 404 and 401).\n if (!res.ok && !res.body) {\n throw failedToFetchRemoteComponentError(serverUrl.href, res);\n }\n\n if (res.status === 401) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'If you are using Deployment Protection, ensure the automation bypass environment variable secret in the host matches an automation bypass value in the remote. See https://remote-components-docs.vercel.sh/docs/concepts/cors-external-urls#deployment-protection for details.',\n );\n }\n\n if (res.status === 404) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'Check if you can open it in the browser.',\n );\n }\n\n // create a parser for the HTML response\n const parser = Parser.getFragmentParser<DefaultTreeAdapterMap>();\n\n if (!res.body) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `Response body is empty. Check if you can open it in the browser and you see the Remote Component content.`,\n );\n }\n\n const decoder = new TextDecoder();\n // read the response body as a stream and parse it using the parse5 fragment parser\n for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {\n parser.tokenizer.write(decoder.decode(chunk), false);\n }\n const fragment = parser.getFragment();\n\n const remoteName =\n options.name || (serverUrl.hash ? serverUrl.hash.substring(1) : undefined);\n\n const {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared,\n html,\n } = visitFragment(fragment, serverUrl, remoteName);\n\n if (!metadata) {\n // For microfrontend builds during run time, the host and remote build\n // may be happening concurrently. In this case, the request will 404.\n // We want to allow the build to continue with a placeholder remote\n // component. Once the build completes, vercel will automatically revalidate\n // ISR and fetch the built remote component.\n const isSSGBuild = process.env.NEXT_PHASE === 'phase-production-build';\n // If the remote component is part of a microfrontend, the src provided\n // will be relative.\n const isSSRRelativePathBase =\n serverUrl.host === new URL(ssrRelativePathBaseUrl).host;\n // Only want this skeleton behaviour in previews to unblock development.\n // For production, the remote component should already be built.\n const isPreview = process.env.VERCEL_TARGET_ENV === 'preview';\n\n if (isSSGBuild && isSSRRelativePathBase && isPreview && options.appRouter) {\n let skeletonComponent: React.ReactNode | undefined;\n if (options.rsc) {\n const { createElement } = await import('react');\n skeletonComponent = createElement('div', {\n dangerouslySetInnerHTML: {\n __html: getSkeletonHtml(serverUrl.href),\n },\n });\n }\n\n return buildSkeletonResponse(\n serverUrl,\n buildMetadata({}, serverUrl),\n skeletonComponent,\n );\n }\n\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `No Remote Component found. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n const name = remoteName || metadata.name;\n const component = options.rsc\n ? await buildRscComponent(rsc, serverUrl)\n : undefined;\n\n return {\n name,\n serverUrl,\n metadata,\n rsc,\n scripts,\n links,\n hydrationData,\n nextData,\n component,\n html,\n remoteShared,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmD;AACnD,wBAAgC;AAChC,sBAGO;AACP,8BAA+B;AAC/B,4BAA6B;AAC7B,4CAA0C;AAS1C,sBAIO;AACP,mBAAkC;AAClC,mBAIO;AAQP,eAAe,kBACb,KACA,WAC0B;AAC1B,QAAM,eAAe,KAAK,KAAK,UAAU,GAAG;AAAA;AAC5C,QAAM,EAAE,yBAAyB,IAAI,MAAM,OACzC,yDACF;AACA,SAAO;AAAA,IACL,IAAI,eAAe;AAAA,MACjB,MAAM;AAAA,MACN,MAAM,YAAY;AAChB,cAAM,UAAU,IAAI,YAAY;AAChC,mBAAW,QAAQ,QAAQ,OAAO,YAAY,CAAC;AAC/C,mBAAW,MAAM;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,IACD;AAAA,MACE,wBAAwB;AAAA,QACtB,eAAe;AAAA,UACb,QAAQ,UAAU;AAAA,UAClB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UACxC;AAAA,QACF,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,QACL;AAAA,YACA,+BAAc,CAAC,GAAG,SAAS;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AAEA,cAAM;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,OAAO,cAAc,SAAS;AACpC,QAAM,YAAY,QAAQ,MACtB,MAAM,kBAAkB,KAAK,SAAS,IACtC;AAEJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/host/server/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { type RSC, visit } from '#internal/host/nextjs/dom-flight';\nimport {\n getSkeletonHtml,\n getSkeletonMessage,\n} from '#internal/host/nextjs/skeleton';\nimport { fetchWithHooks } from '#internal/host/server/fetch-with-hooks';\nimport { getClientSrc } from '#internal/host/server/get-client-src';\nimport { getSSRRelativePathBaseUrl } from '#internal/host/server/get-ssr-relative-path-base-url';\nimport type {\n LinkDescriptor,\n ScriptDescriptor,\n} from '#internal/host/shared/asset-descriptors';\nimport type {\n OnRequestHook,\n OnResponseHook,\n} from '#internal/host/shared/fetch-interceptors';\nimport {\n buildMetadata,\n type RawMetadataAttrs,\n type RemoteComponentMetadata,\n} from '#internal/runtime/metadata';\nimport { importRSCClientEdge } from '#internal/runtime/rsc-imports';\nimport { computeScopedName } from '#internal/utils';\nimport {\n failedToFetchRemoteComponentError,\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport type { FetchRemoteComponentResponse, NextData } from './types';\n\n/**\n * Converts RSC flight data into a React element tree using the edge streaming\n * runtime. The manifest tells React how to resolve module references back to\n * the remote origin.\n */\nasync function buildRscComponent(\n rsc: RSC | RSC[] | string | null,\n serverUrl: URL,\n): Promise<React.ReactNode> {\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n const { createFromReadableStream } = await importRSCClientEdge();\n return createFromReadableStream(\n new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n controller.enqueue(encoder.encode(componentRSC));\n controller.close();\n },\n }),\n {\n serverConsumerManifest: {\n moduleLoading: {\n prefix: serverUrl.origin,\n crossOrigin: true,\n },\n moduleMap: {},\n },\n },\n );\n}\n\nfunction buildSkeletonResponse(\n serverUrl: URL,\n metadata: RemoteComponentMetadata,\n skeletonComponent: React.ReactNode | undefined,\n): FetchRemoteComponentResponse {\n return {\n name: 'remote-component-skeleton',\n serverUrl,\n metadata: {\n ...metadata,\n type: 'remote-component',\n },\n rsc: getSkeletonMessage(),\n scripts: [],\n links: [],\n hydrationData: [],\n nextData: undefined,\n component: skeletonComponent,\n html: getSkeletonHtml(serverUrl.href),\n remoteShared: {},\n };\n}\n\n/**\n * Rewrites the bundle identifier in RSC flight data from the plain bundle\n * name to the origin-qualified scoped name. When multiple remotes share the\n * same bundle name (e.g. production and preview of the same app), this\n * makes each one unique so the client can look up the correct RemoteScope\n * by name alone.\n *\n * `[bundle] /path` → `[scopedName] /path`\n * `[bundle] 12345` → `[scopedName] 12345`\n *\n * Only applied for cross-origin remotes — same-origin chunks keep the\n * plain bundle name since there's no ambiguity.\n */\nfunction scopeChunkReferences(\n chunk: string,\n bundle: string,\n scopedName: string,\n): string {\n return chunk.replaceAll(`[${bundle}]`, `[${scopedName}]`);\n}\n\n/**\n * Walks the parsed HTML fragment and extracts all remote component data:\n * metadata, scripts, links, hydration data, Next.js data, shared deps, and HTML.\n */\nfunction visitFragment(\n fragment: DefaultTreeAdapterMap['documentFragment'],\n serverUrl: URL,\n remoteName: string | undefined,\n) {\n const scriptSrcSet = new Set<string>();\n const scriptTextSet = new Set<string>();\n const scripts: ScriptDescriptor[] = [];\n\n const linkKeySet = new Set<string>();\n const links: LinkDescriptor[] = [];\n\n const hydrationData: string[] = [];\n const htmlChunks = new Set<string>();\n\n let metadata: RemoteComponentMetadata | undefined;\n let nextData: NextData | undefined;\n let remoteShared: Record<string, string> = {};\n let hasRSC = false;\n let hasShared = false;\n let error: RemoteComponentsError | undefined;\n\n // For cross-origin remotes, rewrite bundle identifiers in RSC chunks to\n // the scoped name so the client dispatchers resolve the correct scope.\n // Chunks are collected raw during visit() and rewritten afterwards because\n // RSC script tags appear before the metadata element in the HTML.\n const isCrossOrigin = serverUrl.origin !== getSSRRelativePathBaseUrl();\n\n const rawRscChunks: string[] = [];\n\n const rsc = visit(fragment, {\n url: serverUrl,\n name: remoteName,\n onMetadata(attrs: RawMetadataAttrs) {\n const incoming = buildMetadata(attrs, serverUrl);\n // Skip multiple component detection for Pages Router (__next) since\n // it only supports one remote component per page\n if (\n !remoteName &&\n metadata &&\n metadata.id !== incoming.id &&\n incoming.id !== '__next' &&\n metadata.id !== '__next' &&\n !nextData\n ) {\n throw multipleRemoteComponentsError(serverUrl.href);\n }\n metadata = incoming;\n },\n onScript(attrs) {\n const clientSrc = getClientSrc(attrs.src, serverUrl.href);\n const textContent =\n typeof attrs.textContent === 'string' ? attrs.textContent : undefined;\n\n if (textContent) {\n if (!scriptTextSet.has(textContent)) {\n scriptTextSet.add(textContent);\n scripts.push({ src: '', textContent });\n }\n } else if (!scriptSrcSet.has(clientSrc)) {\n scriptSrcSet.add(clientSrc);\n scripts.push({ src: clientSrc });\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: getClientSrc(attrs.href, serverUrl.href),\n };\n const linkKey = `${relativeAttrs.href}::${attrs.rel}`;\n if (!linkKeySet.has(linkKey)) {\n linkKeySet.add(linkKey);\n links.push(relativeAttrs);\n }\n },\n onRSC(chunk) {\n rawRscChunks.push(chunk);\n hasRSC = true;\n },\n onNextData(data) {\n nextData = data;\n },\n onHTML(chunk) {\n if (!htmlChunks.has(chunk)) {\n htmlChunks.add(chunk);\n }\n },\n onShared(_shared) {\n remoteShared = _shared;\n hasShared = true;\n },\n onError(message, stack) {\n error = new RemoteComponentsError(message);\n if (stack) {\n error.stack = stack;\n }\n },\n });\n\n // Rewrite bundle identifiers in RSC chunk references to use the scoped name\n // so the client dispatchers can resolve the correct scope with a direct lookup.\n // This must happen after visit() because RSC script tags appear before the\n // metadata element in the HTML.\n if (isCrossOrigin && metadata?.bundle) {\n const scopedName = computeScopedName(metadata.bundle, {\n remoteHost: serverUrl.host,\n isCrossOrigin: true,\n });\n for (const chunk of rawRscChunks) {\n hydrationData.push(\n scopeChunkReferences(chunk, metadata.bundle, scopedName),\n );\n }\n } else {\n hydrationData.push(...rawRscChunks);\n }\n\n if (error) {\n throw error;\n }\n\n if (metadata) {\n if (!hasRSC && !nextData && metadata.type === 'nextjs') {\n throw new RemoteComponentsError(\n `The Remote Component at \"${serverUrl.href}\" seems to be a Next.js component but it does not contain any RSC flight data or Next.js props data. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n if (\n metadata.type === 'nextjs' &&\n !hasShared &&\n !nextData?.props.__REMOTE_COMPONENT__?.shared\n ) {\n throw new RemoteComponentsError(\n `No shared dependencies found for Remote Component at \"${serverUrl.href}\". Make sure the remote URL is correct and contains a Remote Component with shared dependencies.`,\n );\n }\n }\n\n const resolvedShared =\n nextData?.props.__REMOTE_COMPONENT__?.shared ?? remoteShared;\n\n return {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared: resolvedShared,\n html: Array.from(htmlChunks).join(''),\n };\n}\n\nexport async function fetchRemoteComponent(\n src: string | URL,\n options: {\n name?: string;\n rsc?: boolean;\n /** Whether this is being called from Next.js App Router. Used to enable skeleton fallback during SSG builds. */\n appRouter?: boolean;\n onRequest?: OnRequestHook;\n onResponse?: OnResponseHook;\n } = {},\n): Promise<FetchRemoteComponentResponse> {\n const ssrRelativePathBaseUrl = getSSRRelativePathBaseUrl();\n const serverUrl = new URL(src, ssrRelativePathBaseUrl);\n\n const tags = [\n '_vc_rc:fetch-remote-component',\n // the max size of a next cache tag is 256 characters\n serverUrl.host.slice(0, 256),\n // use the suffix so this tag is unique if multiple remote\n // components have the same host, but unique pathnames / query params\n (typeof src === 'string' ? src : src.href).slice(-256),\n ];\n if (options.name) {\n tags.push(options.name.slice(-256));\n }\n\n const fetchInit = {\n next: {\n tags,\n },\n };\n\n const res = await fetchWithHooks(serverUrl, fetchInit, {\n onRequest: options.onRequest,\n onResponse: options.onResponse,\n });\n\n // If there is an error in the remote, parse and extract the remote error (except 404 and 401).\n if (!res.ok && !res.body) {\n throw failedToFetchRemoteComponentError(serverUrl.href, res);\n }\n\n if (res.status === 401) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'If you are using Deployment Protection, ensure the automation bypass environment variable secret in the host matches an automation bypass value in the remote. See https://remote-components-docs.vercel.sh/docs/concepts/cors-external-urls#deployment-protection for details.',\n );\n }\n\n if (res.status === 404) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'Check if you can open it in the browser.',\n );\n }\n\n // create a parser for the HTML response\n const parser = Parser.getFragmentParser<DefaultTreeAdapterMap>();\n\n if (!res.body) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `Response body is empty. Check if you can open it in the browser and you see the Remote Component content.`,\n );\n }\n\n const decoder = new TextDecoder();\n // read the response body as a stream and parse it using the parse5 fragment parser\n for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {\n parser.tokenizer.write(decoder.decode(chunk), false);\n }\n const fragment = parser.getFragment();\n\n const remoteName =\n options.name || (serverUrl.hash ? serverUrl.hash.substring(1) : undefined);\n\n const {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared,\n html,\n } = visitFragment(fragment, serverUrl, remoteName);\n\n if (!metadata) {\n // For microfrontend builds during run time, the host and remote build\n // may be happening concurrently. In this case, the request will 404.\n // We want to allow the build to continue with a placeholder remote\n // component. Once the build completes, vercel will automatically revalidate\n // ISR and fetch the built remote component.\n const isSSGBuild = process.env.NEXT_PHASE === 'phase-production-build';\n // If the remote component is part of a microfrontend, the src provided\n // will be relative.\n const isSSRRelativePathBase =\n serverUrl.host === new URL(ssrRelativePathBaseUrl).host;\n // Only want this skeleton behaviour in previews to unblock development.\n // For production, the remote component should already be built.\n const isPreview = process.env.VERCEL_TARGET_ENV === 'preview';\n\n if (isSSGBuild && isSSRRelativePathBase && isPreview && options.appRouter) {\n let skeletonComponent: React.ReactNode | undefined;\n if (options.rsc) {\n const { createElement } = await import('react');\n skeletonComponent = createElement('div', {\n dangerouslySetInnerHTML: {\n __html: getSkeletonHtml(serverUrl.href),\n },\n });\n }\n\n return buildSkeletonResponse(\n serverUrl,\n buildMetadata({}, serverUrl),\n skeletonComponent,\n );\n }\n\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `No Remote Component found. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n const name = remoteName || metadata.name;\n const component = options.rsc\n ? await buildRscComponent(rsc, serverUrl)\n : undefined;\n\n return {\n name,\n serverUrl,\n metadata,\n rsc,\n scripts,\n links,\n hydrationData,\n nextData,\n component,\n html,\n remoteShared,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmD;AACnD,wBAAgC;AAChC,sBAGO;AACP,8BAA+B;AAC/B,4BAA6B;AAC7B,4CAA0C;AAS1C,sBAIO;AACP,yBAAoC;AACpC,mBAAkC;AAClC,mBAIO;AAQP,eAAe,kBACb,KACA,WAC0B;AAC1B,QAAM,eAAe,KAAK,KAAK,UAAU,GAAG;AAAA;AAC5C,QAAM,EAAE,yBAAyB,IAAI,UAAM,wCAAoB;AAC/D,SAAO;AAAA,IACL,IAAI,eAAe;AAAA,MACjB,MAAM;AAAA,MACN,MAAM,YAAY;AAChB,cAAM,UAAU,IAAI,YAAY;AAChC,mBAAW,QAAQ,QAAQ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AAQ,KAAK;AACf,cAAM,EAAE,cAAc,IAAI,MAAM,OAAO,OAAO;AAC9C,4BAAoB,cAAc,OAAO;AAAA,UACvC,yBAAyB;AAAA,YACvB,YAAQ,iCAAgB,UAAU,IAAI;AAAA,UACxC;AAAA,QACF,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,QACL;AAAA,YACA,+BAAc,CAAC,GAAG,SAAS;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AAEA,cAAM;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,OAAO,cAAc,SAAS;AACpC,QAAM,YAAY,QAAQ,MACtB,MAAM,kBAAkB,KAAK,SAAS,IACtC;AAEJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -10,6 +10,7 @@ import { getSSRRelativePathBaseUrl } from "#internal/host/server/get-ssr-relativ
10
10
  import {
11
11
  buildMetadata
12
12
  } from "#internal/runtime/metadata";
13
+ import { importRSCClientEdge } from "#internal/runtime/rsc-imports";
13
14
  import { computeScopedName } from "#internal/utils";
14
15
  import {
15
16
  failedToFetchRemoteComponentError,
@@ -19,7 +20,7 @@ import {
19
20
  async function buildRscComponent(rsc, serverUrl) {
20
21
  const componentRSC = `0:${JSON.stringify(rsc)}
21
22
  `;
22
- const { createFromReadableStream } = await import("next/dist/compiled/react-server-dom-webpack/client.edge");
23
+ const { createFromReadableStream } = await importRSCClientEdge();
23
24
  return createFromReadableStream(
24
25
  new ReadableStream({
25
26
  type: "bytes",