remote-components 0.3.2 → 0.3.4

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 (213) hide show
  1. package/dist/config/nextjs.cjs +122 -62
  2. package/dist/config/nextjs.cjs.map +1 -1
  3. package/dist/config/nextjs.js +116 -56
  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/defaults/app.cjs +2 -5
  10. package/dist/host/defaults/app.cjs.map +1 -1
  11. package/dist/host/defaults/app.d.ts +1 -3
  12. package/dist/host/defaults/app.js +1 -4
  13. package/dist/host/defaults/app.js.map +1 -1
  14. package/dist/host/defaults/pages.cjs +2 -5
  15. package/dist/host/defaults/pages.cjs.map +1 -1
  16. package/dist/host/defaults/pages.d.ts +1 -3
  17. package/dist/host/defaults/pages.js +1 -4
  18. package/dist/host/defaults/pages.js.map +1 -1
  19. package/dist/host/defaults/shared.cjs +32 -0
  20. package/dist/host/defaults/shared.cjs.map +1 -0
  21. package/dist/host/defaults/shared.d.ts +3 -0
  22. package/dist/host/defaults/shared.js +8 -0
  23. package/dist/host/defaults/shared.js.map +1 -0
  24. package/dist/host/html.cjs +533 -351
  25. package/dist/host/html.cjs.map +1 -1
  26. package/dist/host/html.js +533 -351
  27. package/dist/host/html.js.map +1 -1
  28. package/dist/host/nextjs/app/client-only.cjs +494 -285
  29. package/dist/host/nextjs/app/client-only.cjs.map +1 -1
  30. package/dist/host/nextjs/app/client-only.js +468 -259
  31. package/dist/host/nextjs/app/client-only.js.map +1 -1
  32. package/dist/host/react.cjs +412 -241
  33. package/dist/host/react.cjs.map +1 -1
  34. package/dist/host/react.js +412 -241
  35. package/dist/host/react.js.map +1 -1
  36. package/dist/internal/config/webpack/apply-shared-modules.cjs +6 -4
  37. package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -1
  38. package/dist/internal/config/webpack/apply-shared-modules.js +6 -4
  39. package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -1
  40. package/dist/internal/config/webpack/next-client-pages-loader.cjs +6 -7
  41. package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
  42. package/dist/internal/config/webpack/next-client-pages-loader.js +6 -7
  43. package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
  44. package/dist/internal/host/nextjs/app-client.cjs +6 -22
  45. package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
  46. package/dist/internal/host/nextjs/app-client.js +5 -11
  47. package/dist/internal/host/nextjs/app-client.js.map +1 -1
  48. package/dist/internal/host/nextjs/dom-flight.cjs +19 -39
  49. package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
  50. package/dist/internal/host/nextjs/dom-flight.js +31 -39
  51. package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
  52. package/dist/internal/host/nextjs/image-shared.cjs +39 -3
  53. package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
  54. package/dist/internal/host/nextjs/image-shared.d.ts +5 -10
  55. package/dist/internal/host/nextjs/image-shared.js +29 -3
  56. package/dist/internal/host/nextjs/image-shared.js.map +1 -1
  57. package/dist/internal/host/nextjs/shared-import.cjs +46 -0
  58. package/dist/internal/host/nextjs/shared-import.cjs.map +1 -0
  59. package/dist/internal/host/nextjs/shared-import.d.ts +3 -0
  60. package/dist/internal/host/nextjs/shared-import.js +12 -0
  61. package/dist/internal/host/nextjs/shared-import.js.map +1 -0
  62. package/dist/internal/host/server/fetch-remote-component.cjs +2 -1
  63. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
  64. package/dist/internal/host/server/fetch-remote-component.js +2 -1
  65. package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
  66. package/dist/internal/host/shared/polyfill.cjs +8 -7
  67. package/dist/internal/host/shared/polyfill.cjs.map +1 -1
  68. package/dist/internal/host/shared/polyfill.js +8 -7
  69. package/dist/internal/host/shared/polyfill.js.map +1 -1
  70. package/dist/internal/host/shared/shared-module-resolver.cjs +117 -0
  71. package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -0
  72. package/dist/internal/host/shared/shared-module-resolver.d.ts +64 -0
  73. package/dist/internal/host/shared/shared-module-resolver.js +78 -0
  74. package/dist/internal/host/shared/shared-module-resolver.js.map +1 -0
  75. package/dist/internal/remote/nextjs/next-internals.cjs +53 -0
  76. package/dist/internal/remote/nextjs/next-internals.cjs.map +1 -0
  77. package/dist/internal/remote/nextjs/next-internals.d.ts +42 -0
  78. package/dist/internal/remote/nextjs/next-internals.js +26 -0
  79. package/dist/internal/remote/nextjs/next-internals.js.map +1 -0
  80. package/dist/internal/runtime/html/apply-origin.cjs +11 -32
  81. package/dist/internal/runtime/html/apply-origin.cjs.map +1 -1
  82. package/dist/internal/runtime/html/apply-origin.js +11 -32
  83. package/dist/internal/runtime/html/apply-origin.js.map +1 -1
  84. package/dist/internal/runtime/html/html-spec.cjs +78 -0
  85. package/dist/internal/runtime/html/html-spec.cjs.map +1 -0
  86. package/dist/internal/runtime/html/html-spec.d.ts +23 -0
  87. package/dist/internal/runtime/html/html-spec.js +41 -0
  88. package/dist/internal/runtime/html/html-spec.js.map +1 -0
  89. package/dist/internal/runtime/html/parse-remote-html.cjs +15 -12
  90. package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
  91. package/dist/internal/runtime/html/parse-remote-html.js +29 -12
  92. package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
  93. package/dist/internal/runtime/html/rewrite-srcset.cjs +38 -0
  94. package/dist/internal/runtime/html/rewrite-srcset.cjs.map +1 -0
  95. package/dist/internal/runtime/html/rewrite-srcset.d.ts +12 -0
  96. package/dist/internal/runtime/html/rewrite-srcset.js +14 -0
  97. package/dist/internal/runtime/html/rewrite-srcset.js.map +1 -0
  98. package/dist/internal/runtime/loaders/component-loader.cjs +25 -44
  99. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
  100. package/dist/internal/runtime/loaders/component-loader.d.ts +3 -1
  101. package/dist/internal/runtime/loaders/component-loader.js +28 -44
  102. package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
  103. package/dist/internal/runtime/loaders/script-loader.cjs +7 -0
  104. package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -1
  105. package/dist/internal/runtime/loaders/script-loader.js +7 -0
  106. package/dist/internal/runtime/loaders/script-loader.js.map +1 -1
  107. package/dist/internal/runtime/loaders/static-loader.cjs +15 -21
  108. package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -1
  109. package/dist/internal/runtime/loaders/static-loader.d.ts +3 -1
  110. package/dist/internal/runtime/loaders/static-loader.js +15 -21
  111. package/dist/internal/runtime/loaders/static-loader.js.map +1 -1
  112. package/dist/internal/runtime/namespace.cjs +82 -0
  113. package/dist/internal/runtime/namespace.cjs.map +1 -0
  114. package/dist/internal/runtime/namespace.d.ts +5 -0
  115. package/dist/internal/runtime/namespace.js +58 -0
  116. package/dist/internal/runtime/namespace.js.map +1 -0
  117. package/dist/internal/runtime/rsc-imports.cjs +86 -0
  118. package/dist/internal/runtime/rsc-imports.cjs.map +1 -0
  119. package/dist/internal/runtime/rsc-imports.d.ts +39 -0
  120. package/dist/internal/runtime/rsc-imports.js +50 -0
  121. package/dist/internal/runtime/rsc-imports.js.map +1 -0
  122. package/dist/internal/{host/shared/resolved-data.cjs → runtime/rsc-runtime.cjs} +3 -3
  123. package/dist/internal/runtime/rsc-runtime.cjs.map +1 -0
  124. package/dist/internal/runtime/rsc-runtime.d.ts +37 -0
  125. package/dist/internal/runtime/rsc-runtime.js +1 -0
  126. package/dist/internal/runtime/rsc.cjs +23 -12
  127. package/dist/internal/runtime/rsc.cjs.map +1 -1
  128. package/dist/internal/runtime/rsc.d.ts +19 -2
  129. package/dist/internal/runtime/rsc.js +20 -11
  130. package/dist/internal/runtime/rsc.js.map +1 -1
  131. package/dist/internal/runtime/turbopack/chunk-loader.cjs +53 -35
  132. package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
  133. package/dist/internal/runtime/turbopack/chunk-loader.d.ts +1 -1
  134. package/dist/internal/runtime/turbopack/chunk-loader.js +53 -35
  135. package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
  136. package/dist/internal/runtime/turbopack/module.cjs +19 -17
  137. package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
  138. package/dist/internal/runtime/turbopack/module.d.ts +23 -1
  139. package/dist/internal/runtime/turbopack/module.js +19 -18
  140. package/dist/internal/runtime/turbopack/module.js.map +1 -1
  141. package/dist/internal/runtime/turbopack/patterns.cjs +26 -10
  142. package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -1
  143. package/dist/internal/runtime/turbopack/patterns.d.ts +44 -49
  144. package/dist/internal/runtime/turbopack/patterns.js +23 -7
  145. package/dist/internal/runtime/turbopack/patterns.js.map +1 -1
  146. package/dist/internal/runtime/turbopack/{webpack-runtime.cjs → remote-scope-setup.cjs} +35 -32
  147. package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -0
  148. package/dist/internal/runtime/turbopack/remote-scope-setup.d.ts +25 -0
  149. package/dist/internal/runtime/turbopack/{webpack-runtime.js → remote-scope-setup.js} +36 -19
  150. package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -0
  151. package/dist/internal/runtime/turbopack/remote-scope.cjs +4 -6
  152. package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
  153. package/dist/internal/runtime/turbopack/remote-scope.d.ts +20 -1
  154. package/dist/internal/runtime/turbopack/remote-scope.js +4 -6
  155. package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
  156. package/dist/internal/runtime/turbopack/shared-modules.cjs +23 -15
  157. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
  158. package/dist/internal/runtime/turbopack/shared-modules.d.ts +13 -1
  159. package/dist/internal/runtime/turbopack/shared-modules.js +25 -18
  160. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
  161. package/dist/internal/runtime/types.cjs.map +1 -1
  162. package/dist/internal/runtime/types.d.ts +5 -41
  163. package/dist/internal/utils/logger.cjs +1 -1
  164. package/dist/internal/utils/logger.cjs.map +1 -1
  165. package/dist/internal/utils/logger.d.ts +2 -2
  166. package/dist/internal/utils/logger.js +1 -1
  167. package/dist/internal/utils/logger.js.map +1 -1
  168. package/dist/internal/utils/project-id-env.cjs +31 -0
  169. package/dist/internal/utils/project-id-env.cjs.map +1 -0
  170. package/dist/internal/utils/project-id-env.d.ts +7 -0
  171. package/dist/internal/utils/project-id-env.js +7 -0
  172. package/dist/internal/utils/project-id-env.js.map +1 -0
  173. package/dist/internal/utils/project-id.cjs +46 -0
  174. package/dist/internal/utils/project-id.cjs.map +1 -0
  175. package/dist/internal/utils/project-id.d.ts +8 -0
  176. package/dist/internal/utils/project-id.js +22 -0
  177. package/dist/internal/utils/project-id.js.map +1 -0
  178. package/dist/remote/defaults/app.cjs +2 -5
  179. package/dist/remote/defaults/app.cjs.map +1 -1
  180. package/dist/remote/defaults/app.d.ts +1 -3
  181. package/dist/remote/defaults/app.js +1 -4
  182. package/dist/remote/defaults/app.js.map +1 -1
  183. package/dist/remote/defaults/pages.cjs +2 -5
  184. package/dist/remote/defaults/pages.cjs.map +1 -1
  185. package/dist/remote/defaults/pages.d.ts +1 -3
  186. package/dist/remote/defaults/pages.js +1 -4
  187. package/dist/remote/defaults/pages.js.map +1 -1
  188. package/dist/remote/defaults/shared.cjs +32 -0
  189. package/dist/remote/defaults/shared.cjs.map +1 -0
  190. package/dist/remote/defaults/shared.d.ts +3 -0
  191. package/dist/remote/defaults/shared.js +8 -0
  192. package/dist/remote/defaults/shared.js.map +1 -0
  193. package/dist/remote/html.cjs +78 -22
  194. package/dist/remote/html.cjs.map +1 -1
  195. package/dist/remote/html.js +78 -22
  196. package/dist/remote/html.js.map +1 -1
  197. package/dist/remote/nextjs/app.cjs +16 -56
  198. package/dist/remote/nextjs/app.cjs.map +1 -1
  199. package/dist/remote/nextjs/app.js +26 -46
  200. package/dist/remote/nextjs/app.js.map +1 -1
  201. package/dist/remote/nextjs/pages.cjs +2 -1
  202. package/dist/remote/nextjs/pages.cjs.map +1 -1
  203. package/dist/remote/nextjs/pages.js +2 -1
  204. package/dist/remote/nextjs/pages.js.map +1 -1
  205. package/dist/types-59251814.d.ts +94 -0
  206. package/package.json +1 -1
  207. package/dist/internal/host/shared/resolved-data.cjs.map +0 -1
  208. package/dist/internal/host/shared/resolved-data.d.ts +0 -48
  209. package/dist/internal/host/shared/resolved-data.js +0 -1
  210. package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +0 -1
  211. package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +0 -23
  212. package/dist/internal/runtime/turbopack/webpack-runtime.js.map +0 -1
  213. /package/dist/internal/{host/shared/resolved-data.js.map → runtime/rsc-runtime.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/host/nextjs/app-client.tsx"],"sourcesContent":["'use client';\n\nimport {\n startTransition,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { createImageLoaderSharedEntries } from '#internal/host/nextjs/image-shared';\nimport { useResolveClientUrl } from '#internal/host/react/hooks/use-resolve-client-url';\nimport { getClientOrServerUrl } from '#internal/host/server/get-client-or-server-url';\nimport type { ConsumeClientOnlyConfig } from '#internal/host/shared/config';\nimport type { ConsumeServerData } from '#internal/host/shared/server-handoff';\nimport { createHostState } from '#internal/host/shared/state';\nimport { DEFAULT_ROUTE, RUNTIME_WEBPACK } from '#internal/runtime/constants';\nimport { loadRemoteComponent } from '#internal/runtime/loaders/component-loader';\nimport { loadStaticRemoteComponent } from '#internal/runtime/loaders/static-loader';\nimport type { MountOrUnmountFunction } from '#internal/runtime/types';\nimport { escapeString } from '#internal/utils';\nimport { logError } from '#internal/utils/logger';\nimport { routerImpl } from './app-compat';\nimport { RemoteComponentLinks } from './remote-component-links';\n\n/**\n * Extends the RSC-serializable data with {@link ConsumeClientConfig} fields\n * (like `resolveClientUrl`) that can't cross the server→client boundary\n * but are accepted when this component is used directly as a client import.\n */\ninterface ConsumeRemoteComponentClientProps\n extends ConsumeServerData,\n ConsumeClientOnlyConfig {}\n\n// import { shared } from 'remote-components/shared/host';\nasync function tryImportShared() {\n try {\n const { shared } = await import('#remote-components/host/defaults/app');\n return shared;\n } catch {\n return {};\n }\n}\n\n/**\n * ConsumeRemoteComponentClient - Main component for rendering remote components\n *\n * This component handles the loading and rendering of remote microfrontends.\n * It supports both RSC (React Server Components) and Next.js Pages Router based components.\n */\nexport function ConsumeRemoteComponentClient({\n src,\n serverUrl,\n name,\n bundle,\n route = DEFAULT_ROUTE,\n runtime = RUNTIME_WEBPACK,\n data,\n nextData,\n scripts = [],\n links = [],\n remoteShared = {},\n isolate,\n mode = 'open',\n resolveClientUrl: resolveClientUrlProp,\n reset,\n type,\n children,\n}: ConsumeRemoteComponentClientProps) {\n const remoteComponentId = useId();\n const [component, setComponent] = useState<React.ReactNode | Error>(null);\n const url = getClientOrServerUrl(src, serverUrl);\n const resolveClientUrl = useResolveClientUrl(resolveClientUrlProp, url.href);\n // TODO: prev* fields and abortController are not populated — the App Router\n // client doesn't support onChange or abort yet. Populate these when adding\n // onChange lifecycle support to match the HTML and React hosts.\n const hostStateRef = useRef(createHostState());\n const metadataRef = useRef<{\n name: string;\n bundle: string;\n route: string;\n url: string;\n }>({\n name,\n bundle,\n route,\n url: url.href,\n });\n const startRef = useRef<HTMLTemplateElement | null>(null);\n const endRef = useRef<HTMLTemplateElement | null>(null);\n const prevRemoteComponentUnmountRef = useRef<{\n unmount: Set<MountOrUnmountFunction>;\n root: ShadowRoot | DocumentFragment | null;\n } | null>(null);\n\n // Handle errors by re-throwing them\n if (component instanceof Error) {\n throw component;\n }\n\n // determine whether to use children or loaded component\n const shouldUseChildren =\n (!component ||\n (component &&\n !nextData &&\n type !== 'remote-component' &&\n typeof (component as unknown as Promise<unknown>).then !==\n 'function')) &&\n // if the remote Next.js Pages Router application is in development mode\n // we don't use the provided static HTML\n // to mitigate layout shift when loading CSS using JavaScript on the client\n nextData?.buildId !== 'development';\n\n // The pathname is used so this URL is the same across server and client requests for relative src's\n const keySuffix = `${escapeString(bundle)}_${escapeString(\n url.pathname,\n )}_${escapeString(name)}`;\n\n const self = globalThis as Record<\n `__remote_components_shadowroot_${string}`,\n ShadowRoot | null\n > &\n Record<`__remote_components_container_${string}`, HTMLDivElement | null>;\n const shadowRootKey = `__remote_components_shadowroot_${keySuffix}` as const;\n const shadowContainerRef = useRef<HTMLDivElement | null>(\n typeof document === 'undefined'\n ? null\n : document.querySelector(\n `[data-remote-component-id=\"shadowroot_${remoteComponentId}\"]`,\n ),\n );\n const shadowRootRef = useRef<ShadowRoot | null>(\n self[shadowRootKey] ?? shadowContainerRef.current?.shadowRoot ?? null,\n );\n const ssrShadowRootContentRef = useRef<NodeListOf<ChildNode> | null>(\n shadowRootRef.current?.querySelectorAll('*') ?? null,\n );\n const ssrLinksStylesRef = useRef<(HTMLLinkElement | HTMLStyleElement)[]>([]);\n\n if (self[shadowRootKey] && shadowRootRef.current) {\n self[shadowRootKey] = null;\n }\n\n useLayoutEffect(() => {\n if (\n !shadowContainerRef.current ||\n shadowContainerRef.current !== shadowRootRef.current?.host\n ) {\n shadowRootRef.current = null;\n }\n\n if (\n isolate !== false &&\n typeof document !== 'undefined' &&\n !shadowRootRef.current\n ) {\n let shadowRootElement: ShadowRoot | null = null;\n const element = shadowContainerRef.current;\n\n shadowRootElement = self[shadowRootKey] ?? element?.shadowRoot ?? null;\n self[shadowRootKey] = null;\n\n if (!shadowRootElement && element) {\n // create a shadow root if it doesn't exist\n // this is a fallback for browsers that don't support declarative shadow DOM\n try {\n shadowRootElement = element.attachShadow({ mode });\n } catch {\n // do nothing if attachShadow fails because of existing shadow root\n }\n }\n\n if (shadowRootElement) {\n shadowRootRef.current = shadowRootElement;\n }\n }\n\n if (\n shadowRootRef.current &&\n ssrShadowRootContentRef.current &&\n !shouldUseChildren\n ) {\n // remove all nodes from the shadow root except links\n ssrShadowRootContentRef.current.forEach((node) => {\n if (node.nodeName !== 'LINK' && node.nodeName !== 'STYLE') {\n node.parentNode?.removeChild(node);\n } else {\n ssrLinksStylesRef.current.push(\n node as HTMLLinkElement | HTMLStyleElement,\n );\n }\n });\n ssrShadowRootContentRef.current = null;\n }\n\n if (ssrLinksStylesRef.current.length > 0 && shadowRootRef.current) {\n const waitForLoad =\n shadowRootRef.current.querySelectorAll('link[data-wait]');\n if (waitForLoad.length > 0) {\n Promise.all(\n Array.from(waitForLoad).map(\n (link) =>\n new Promise<void>((resolve) => {\n link.addEventListener('load', () => resolve());\n link.addEventListener('error', () => resolve());\n }),\n ),\n )\n .then(() => {\n waitForLoad.forEach((el) => {\n el.removeAttribute('data-wait');\n });\n\n // remove SSR injected styles and links\n ssrLinksStylesRef.current.forEach((el) => {\n el.parentNode?.removeChild(el);\n });\n ssrLinksStylesRef.current = [];\n })\n .catch((e) => {\n logError('NextAppRouter', 'Error in cleanup.', e);\n });\n }\n }\n }, [isolate, mode, self, shadowRootKey, shouldUseChildren]);\n\n useEffect(() => {\n // run unmount functions when the component changes or unmounts\n if (prevRemoteComponentUnmountRef.current && component !== children) {\n const { unmount, root } = prevRemoteComponentUnmountRef.current;\n prevRemoteComponentUnmountRef.current = null;\n Promise.all(\n Array.from(unmount).map(async (unmountFn) => {\n try {\n await unmountFn(root);\n } catch (e) {\n logError('NextAppRouter', 'Error in unmount.', e);\n }\n }),\n ).catch((e) => {\n logError('NextAppRouter', 'Error in unmount cleanup.', e);\n });\n }\n }, [component, children]);\n\n useEffect(() => {\n startTransition(async () => {\n try {\n // if we have a component, we don't need to load it again\n if (\n (hostStateRef.current.stage !== 'loading' &&\n !component &&\n (isolate === false || shadowRootRef.current)) ||\n metadataRef.current.url !== url.href ||\n metadataRef.current.name !== name ||\n metadataRef.current.bundle !== bundle ||\n metadataRef.current.route !== route\n ) {\n hostStateRef.current.stage = 'loading';\n metadataRef.current = {\n name,\n bundle,\n route,\n url: url.href,\n };\n\n // use the children as the component when type is remote-component\n if (type === 'remote-component') {\n setComponent(children);\n // load static scripts and execute mount functions\n // run this async but don't await it as we render children immediately\n loadStaticRemoteComponent(\n scripts as HTMLScriptElement[],\n url,\n resolveClientUrl,\n )\n .then(({ mount, unmount }) => {\n if (mount.size > 0) {\n let root: ShadowRoot | DocumentFragment | null =\n shadowRootRef.current;\n try {\n if (!root && startRef.current && endRef.current) {\n root = document.querySelectorAll(\n `#${startRef.current.id} ~ *:not(#${endRef.current.id}):has(~ #${endRef.current.id})`,\n ) as unknown as DocumentFragment;\n }\n } catch (e) {\n logError('NextAppRouter', 'Error finding root element.', e);\n }\n if (unmount.size > 0) {\n prevRemoteComponentUnmountRef.current = { unmount, root };\n }\n return Promise.all(\n Array.from(mount).map((mountFn) => mountFn(root)),\n );\n }\n })\n .catch((e) => {\n logError(\n 'NextAppRouter',\n 'Error loading static remote component.',\n e,\n );\n setComponent(e as Error);\n });\n return;\n }\n\n const rscName = `__remote_components_rsc_${keySuffix}`;\n const result = await loadRemoteComponent({\n url,\n name,\n bundle,\n route,\n runtime,\n rscName,\n data,\n nextData,\n scripts,\n shared: (async () => {\n const shared = await tryImportShared();\n\n if ('__remote_components_missing_shared__' in shared) {\n await shared.__remote_components_missing_shared__();\n }\n return {\n 'next/router': routerImpl,\n ...shared,\n ...createImageLoaderSharedEntries({ bound: resolveClientUrl }),\n };\n })(),\n remoteShared,\n container: shadowRootRef.current,\n resolveClientUrl,\n });\n if (result.error) {\n hostStateRef.current.stage = 'error';\n setComponent(result.error);\n } else {\n hostStateRef.current.stage = 'loaded';\n setComponent(result.component);\n }\n }\n } catch (error: unknown) {\n hostStateRef.current.stage = 'error';\n setComponent(error as Error);\n }\n });\n }, [\n component,\n name,\n bundle,\n route,\n runtime,\n scripts,\n data,\n nextData,\n remoteShared,\n children,\n isolate,\n type,\n keySuffix,\n url,\n resolveClientUrl,\n ]);\n\n if (\n nextData?.buildId === 'development' &&\n shadowRootRef.current &&\n isolate !== false &&\n reset &&\n !shadowRootRef.current.querySelector('[data-remote-components-reset]')\n ) {\n // inject reset styles into the shadow root\n const style = document.createElement('style');\n style.setAttribute('data-remote-components-reset', '');\n style.textContent = `:host { all: initial; }`;\n shadowRootRef.current.insertBefore(style, shadowRootRef.current.firstChild);\n } else if (\n shadowRootRef.current &&\n isolate !== false &&\n !reset &&\n shadowRootRef.current.querySelector('[data-remote-components-reset]')\n ) {\n // ensure reset styles are the first child in the shadow root\n const style = shadowRootRef.current.querySelector(\n '[data-remote-components-reset]',\n );\n if (style && shadowRootRef.current.firstChild !== style) {\n shadowRootRef.current.removeChild(style);\n }\n }\n\n const linksToRender = (\n <RemoteComponentLinks\n links={links}\n url={url}\n serverUrl={serverUrl}\n bundle={bundle}\n isolate={isolate}\n reset={reset}\n isDevelopment={nextData?.buildId === 'development'}\n />\n );\n\n let componentToRender = shouldUseChildren\n ? children\n : (component as React.ReactNode);\n\n if (isolate !== false) {\n componentToRender = (\n <div\n data-remote-component-id={`shadowroot_${remoteComponentId}`}\n data-remote-component-isolation-root=\"\"\n id={`shadowroot_${name}`}\n ref={shadowContainerRef}\n >\n {typeof document === 'undefined' ? (\n // eslint-disable-next-line react/no-unknown-property\n <template shadowrootmode={mode}>\n {mode === 'closed' ? (\n <div\n dangerouslySetInnerHTML={{\n __html: `<img\n alt=\"\" decoding=\"async\" style=\"display:none\"\n src=\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==\"\n onload=\"(function(el){\n const root = el.getRootNode();\n globalThis.${shadowRootKey} = root;\n el.parentElement.remove();\n })(this)\"\n />`,\n }}\n />\n ) : null}\n {linksToRender}\n {shouldUseChildren ? children : null}\n </template>\n ) : null}\n {typeof document !== 'undefined' &&\n shadowRootRef.current &&\n !shouldUseChildren\n ? createPortal(\n <>\n {linksToRender}\n {componentToRender}\n </>,\n shadowRootRef.current,\n )\n : null}\n </div>\n );\n }\n\n return (\n <>\n {isolate === false ? (\n <template id={`${name}_start`} ref={startRef} />\n ) : null}\n <script data-remote-component type=\"application/json\">\n {JSON.stringify({\n name,\n bundle,\n route,\n runtime,\n })}\n </script>\n {isolate === false ? linksToRender : null}\n {componentToRender}\n {nextData ? (\n <script\n id={`${bundle}_${route.replace(\n /[^a-zA-Z0-9]+/g,\n '_',\n )}${name}_next_data`}\n type=\"application/json\"\n >\n {JSON.stringify(nextData)}\n </script>\n ) : null}\n {isolate === false ? <template id={`${name}_end`} ref={endRef} /> : null}\n </>\n );\n}\n"],"mappings":";AA2YI,SAiDU,UAjDV,KAyBM,YAzBN;AAzYJ;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,SAAS,sCAAsC;AAC/C,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AAGrC,SAAS,uBAAuB;AAChC,SAAS,eAAe,uBAAuB;AAC/C,SAAS,2BAA2B;AACpC,SAAS,iCAAiC;AAE1C,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,4BAA4B;AAYrC,eAAe,kBAAkB;AAC/B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,sCAAsC;AACtE,WAAO;AAAA,EACT,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAQO,SAAS,6BAA6B;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,UAAU,CAAC;AAAA,EACX,QAAQ,CAAC;AAAA,EACT,eAAe,CAAC;AAAA,EAChB;AAAA,EACA,OAAO;AAAA,EACP,kBAAkB;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AACF,GAAsC;AACpC,QAAM,oBAAoB,MAAM;AAChC,QAAM,C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,IACE;AAAA,cACH;AAAA,cACA,oBAAoB,WAAW;AAAA,eAClC;AAAA,cACE;AAAA,UACH,OAAO,aAAa,eACrB,cAAc,WACd,CAAC,oBACG;AAAA,YACE,iCACG;AAAA;AAAA,cACA;AAAA,eACH;AAAA,YACA,cAAc;AAAA,UAChB,IACA;AAAA;AAAA;AAAA,IACN;AAAA,EAEJ;AAEA,SACE,iCACG;AAAA,gBAAY,QACX,oBAAC,cAAS,IAAI,GAAG,cAAc,KAAK,UAAU,IAC5C;AAAA,IACJ,oBAAC,YAAO,yBAAqB,MAAC,MAAK,oBAChC,eAAK,UAAU;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC,GACH;AAAA,IACC,YAAY,QAAQ,gBAAgB;AAAA,IACpC;AAAA,IACA,WACC;AAAA,MAAC;AAAA;AAAA,QACC,IAAI,GAAG,UAAU,MAAM;AAAA,UACrB;AAAA,UACA;AAAA,QACF,IAAI;AAAA,QACJ,MAAK;AAAA,QAEJ,eAAK,UAAU,QAAQ;AAAA;AAAA,IAC1B,IACE;AAAA,IACH,YAAY,QAAQ,oBAAC,cAAS,IAAI,GAAG,YAAY,KAAK,QAAQ,IAAK;AAAA,KACtE;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/host/nextjs/app-client.tsx"],"sourcesContent":["'use client';\n\nimport {\n startTransition,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { createImageLoaderSharedEntries } from '#internal/host/nextjs/image-shared';\nimport { tryImportShared } from '#internal/host/nextjs/shared-import';\nimport { useResolveClientUrl } from '#internal/host/react/hooks/use-resolve-client-url';\nimport { getClientOrServerUrl } from '#internal/host/server/get-client-or-server-url';\nimport type { ConsumeClientOnlyConfig } from '#internal/host/shared/config';\nimport type { ConsumeServerData } from '#internal/host/shared/server-handoff';\nimport { createHostState } from '#internal/host/shared/state';\nimport { DEFAULT_ROUTE, RUNTIME_WEBPACK } from '#internal/runtime/constants';\nimport { loadRemoteComponent } from '#internal/runtime/loaders/component-loader';\nimport { loadStaticRemoteComponent } from '#internal/runtime/loaders/static-loader';\nimport type { MountOrUnmountFunction } from '#internal/runtime/types';\nimport { escapeString } from '#internal/utils';\nimport { logError } from '#internal/utils/logger';\nimport { routerImpl } from './app-compat';\nimport { RemoteComponentLinks } from './remote-component-links';\n\n/**\n * Extends the RSC-serializable data with {@link ConsumeClientConfig} fields\n * (like `resolveClientUrl`) that can't cross the server→client boundary\n * but are accepted when this component is used directly as a client import.\n */\ninterface ConsumeRemoteComponentClientProps\n extends ConsumeServerData,\n ConsumeClientOnlyConfig {}\n\n/**\n * ConsumeRemoteComponentClient - Main component for rendering remote components\n *\n * This component handles the loading and rendering of remote microfrontends.\n * It supports both RSC (React Server Components) and Next.js Pages Router based components.\n */\nexport function ConsumeRemoteComponentClient({\n src,\n serverUrl,\n name,\n bundle,\n route = DEFAULT_ROUTE,\n runtime = RUNTIME_WEBPACK,\n data,\n nextData,\n scripts = [],\n links = [],\n remoteShared = {},\n isolate,\n mode = 'open',\n resolveClientUrl: resolveClientUrlProp,\n reset,\n type,\n children,\n}: ConsumeRemoteComponentClientProps) {\n const remoteComponentId = useId();\n const [component, setComponent] = useState<React.ReactNode | Error>(null);\n const url = getClientOrServerUrl(src, serverUrl);\n const resolveClientUrl = useResolveClientUrl(resolveClientUrlProp, url.href);\n // TODO: prev* fields and abortController are not populated — the App Router\n // client doesn't support onChange or abort yet. Populate these when adding\n // onChange lifecycle support to match the HTML and React hosts.\n const hostStateRef = useRef(createHostState());\n const metadataRef = useRef<{\n name: string;\n bundle: string;\n route: string;\n url: string;\n }>({\n name,\n bundle,\n route,\n url: url.href,\n });\n const startRef = useRef<HTMLTemplateElement | null>(null);\n const endRef = useRef<HTMLTemplateElement | null>(null);\n const prevRemoteComponentUnmountRef = useRef<{\n unmount: Set<MountOrUnmountFunction>;\n root: ShadowRoot | DocumentFragment | null;\n } | null>(null);\n\n // Handle errors by re-throwing them\n if (component instanceof Error) {\n throw component;\n }\n\n // determine whether to use children or loaded component\n const shouldUseChildren =\n (!component ||\n (component &&\n !nextData &&\n type !== 'remote-component' &&\n typeof (component as unknown as Promise<unknown>).then !==\n 'function')) &&\n // if the remote Next.js Pages Router application is in development mode\n // we don't use the provided static HTML\n // to mitigate layout shift when loading CSS using JavaScript on the client\n nextData?.buildId !== 'development';\n\n // The pathname is used so this URL is the same across server and client requests for relative src's\n const keySuffix = `${escapeString(bundle)}_${escapeString(\n url.pathname,\n )}_${escapeString(name)}`;\n\n const self = globalThis as Record<\n `__remote_components_shadowroot_${string}`,\n ShadowRoot | null\n > &\n Record<`__remote_components_container_${string}`, HTMLDivElement | null>;\n const shadowRootKey = `__remote_components_shadowroot_${keySuffix}` as const;\n const shadowContainerRef = useRef<HTMLDivElement | null>(\n typeof document === 'undefined'\n ? null\n : document.querySelector(\n `[data-remote-component-id=\"shadowroot_${remoteComponentId}\"]`,\n ),\n );\n const shadowRootRef = useRef<ShadowRoot | null>(\n self[shadowRootKey] ?? shadowContainerRef.current?.shadowRoot ?? null,\n );\n const ssrShadowRootContentRef = useRef<NodeListOf<ChildNode> | null>(null);\n const ssrLinksStylesRef = useRef<(HTMLLinkElement | HTMLStyleElement)[]>([]);\n\n if (self[shadowRootKey] && shadowRootRef.current) {\n self[shadowRootKey] = null;\n }\n\n useLayoutEffect(() => {\n if (\n !shadowContainerRef.current ||\n shadowContainerRef.current !== shadowRootRef.current?.host\n ) {\n shadowRootRef.current = null;\n }\n\n if (\n isolate !== false &&\n typeof document !== 'undefined' &&\n !shadowRootRef.current\n ) {\n let shadowRootElement: ShadowRoot | null = null;\n const element = shadowContainerRef.current;\n\n shadowRootElement = self[shadowRootKey] ?? element?.shadowRoot ?? null;\n self[shadowRootKey] = null;\n\n if (!shadowRootElement && element) {\n // create a shadow root if it doesn't exist\n // this is a fallback for browsers that don't support declarative shadow DOM\n try {\n shadowRootElement = element.attachShadow({ mode });\n } catch {\n // do nothing if attachShadow fails because of existing shadow root\n }\n }\n\n if (shadowRootElement) {\n shadowRootRef.current = shadowRootElement;\n }\n }\n\n // Capture SSR content once the shadow root is available. This runs\n // while shouldUseChildren is still true (before the portal adds its\n // own content), so the query captures only server-rendered nodes.\n if (\n !ssrShadowRootContentRef.current &&\n shadowRootRef.current &&\n shouldUseChildren\n ) {\n ssrShadowRootContentRef.current =\n shadowRootRef.current.querySelectorAll('*');\n }\n\n if (\n shadowRootRef.current &&\n ssrShadowRootContentRef.current &&\n !shouldUseChildren\n ) {\n // remove all nodes from the shadow root except links\n ssrShadowRootContentRef.current.forEach((node) => {\n if (node.nodeName !== 'LINK' && node.nodeName !== 'STYLE') {\n node.parentNode?.removeChild(node);\n } else {\n ssrLinksStylesRef.current.push(\n node as HTMLLinkElement | HTMLStyleElement,\n );\n }\n });\n ssrShadowRootContentRef.current = null;\n }\n\n if (ssrLinksStylesRef.current.length > 0 && shadowRootRef.current) {\n const waitForLoad =\n shadowRootRef.current.querySelectorAll('link[data-wait]');\n if (waitForLoad.length > 0) {\n Promise.all(\n Array.from(waitForLoad).map(\n (link) =>\n new Promise<void>((resolve) => {\n link.addEventListener('load', () => resolve());\n link.addEventListener('error', () => resolve());\n }),\n ),\n )\n .then(() => {\n waitForLoad.forEach((el) => {\n el.removeAttribute('data-wait');\n });\n\n // remove SSR injected styles and links\n ssrLinksStylesRef.current.forEach((el) => {\n el.parentNode?.removeChild(el);\n });\n ssrLinksStylesRef.current = [];\n })\n .catch((e) => {\n logError('NextAppRouter', 'Error in cleanup.', e);\n });\n }\n }\n }, [isolate, mode, self, shadowRootKey, shouldUseChildren]);\n\n useEffect(() => {\n // run unmount functions when the component changes or unmounts\n if (prevRemoteComponentUnmountRef.current && component !== children) {\n const { unmount, root } = prevRemoteComponentUnmountRef.current;\n prevRemoteComponentUnmountRef.current = null;\n Promise.all(\n Array.from(unmount).map(async (unmountFn) => {\n try {\n await unmountFn(root);\n } catch (e) {\n logError('NextAppRouter', 'Error in unmount.', e);\n }\n }),\n ).catch((e) => {\n logError('NextAppRouter', 'Error in unmount cleanup.', e);\n });\n }\n }, [component, children]);\n\n useEffect(() => {\n startTransition(async () => {\n try {\n // if we have a component, we don't need to load it again\n if (\n (hostStateRef.current.stage !== 'loading' &&\n !component &&\n (isolate === false || shadowRootRef.current)) ||\n metadataRef.current.url !== url.href ||\n metadataRef.current.name !== name ||\n metadataRef.current.bundle !== bundle ||\n metadataRef.current.route !== route\n ) {\n hostStateRef.current.stage = 'loading';\n metadataRef.current = {\n name,\n bundle,\n route,\n url: url.href,\n };\n\n // use the children as the component when type is remote-component\n if (type === 'remote-component') {\n setComponent(children);\n // load static scripts and execute mount functions\n // run this async but don't await it as we render children immediately\n loadStaticRemoteComponent(\n scripts as HTMLScriptElement[],\n url,\n resolveClientUrl,\n )\n .then(({ mount, unmount }) => {\n if (mount.size > 0) {\n let root: ShadowRoot | DocumentFragment | null =\n shadowRootRef.current;\n try {\n if (!root && startRef.current && endRef.current) {\n root = document.querySelectorAll(\n `#${startRef.current.id} ~ *:not(#${endRef.current.id}):has(~ #${endRef.current.id})`,\n ) as unknown as DocumentFragment;\n }\n } catch (e) {\n logError('NextAppRouter', 'Error finding root element.', e);\n }\n if (unmount.size > 0) {\n prevRemoteComponentUnmountRef.current = { unmount, root };\n }\n return Promise.all(\n Array.from(mount).map((mountFn) => mountFn(root)),\n );\n }\n })\n .catch((e) => {\n logError(\n 'NextAppRouter',\n 'Error loading static remote component.',\n e,\n );\n setComponent(e as Error);\n });\n return;\n }\n\n const rscName = `__remote_components_rsc_${keySuffix}`;\n const result = await loadRemoteComponent({\n url,\n name,\n bundle,\n route,\n runtime,\n rscName,\n data,\n nextData,\n scripts,\n shared: (async () => {\n const shared = await tryImportShared();\n\n if ('__remote_components_missing_shared__' in shared) {\n await shared.__remote_components_missing_shared__();\n }\n return {\n 'next/router': routerImpl,\n ...shared,\n ...createImageLoaderSharedEntries({ bound: resolveClientUrl }),\n };\n })(),\n remoteShared,\n container: shadowRootRef.current,\n resolveClientUrl,\n });\n if (result.error) {\n hostStateRef.current.stage = 'error';\n setComponent(result.error);\n } else {\n hostStateRef.current.stage = 'loaded';\n setComponent(result.component);\n }\n }\n } catch (error: unknown) {\n hostStateRef.current.stage = 'error';\n setComponent(error as Error);\n }\n });\n }, [\n component,\n name,\n bundle,\n route,\n runtime,\n scripts,\n data,\n nextData,\n remoteShared,\n children,\n isolate,\n type,\n keySuffix,\n url,\n resolveClientUrl,\n ]);\n\n if (\n nextData?.buildId === 'development' &&\n shadowRootRef.current &&\n isolate !== false &&\n reset &&\n !shadowRootRef.current.querySelector('[data-remote-components-reset]')\n ) {\n // inject reset styles into the shadow root\n const style = document.createElement('style');\n style.setAttribute('data-remote-components-reset', '');\n style.textContent = `:host { all: initial; }`;\n shadowRootRef.current.insertBefore(style, shadowRootRef.current.firstChild);\n } else if (\n shadowRootRef.current &&\n isolate !== false &&\n !reset &&\n shadowRootRef.current.querySelector('[data-remote-components-reset]')\n ) {\n // ensure reset styles are the first child in the shadow root\n const style = shadowRootRef.current.querySelector(\n '[data-remote-components-reset]',\n );\n if (style && shadowRootRef.current.firstChild !== style) {\n shadowRootRef.current.removeChild(style);\n }\n }\n\n const linksToRender = (\n <RemoteComponentLinks\n links={links}\n url={url}\n serverUrl={serverUrl}\n bundle={bundle}\n isolate={isolate}\n reset={reset}\n isDevelopment={nextData?.buildId === 'development'}\n />\n );\n\n let componentToRender = shouldUseChildren\n ? children\n : (component as React.ReactNode);\n\n if (isolate !== false) {\n componentToRender = (\n <div\n data-remote-component-id={`shadowroot_${remoteComponentId}`}\n data-remote-component-isolation-root=\"\"\n id={`shadowroot_${name}`}\n ref={shadowContainerRef}\n >\n {typeof document === 'undefined' ? (\n // eslint-disable-next-line react/no-unknown-property\n <template shadowrootmode={mode}>\n {mode === 'closed' ? (\n <div\n dangerouslySetInnerHTML={{\n __html: `<img\n alt=\"\" decoding=\"async\" style=\"display:none\"\n src=\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==\"\n onload=\"(function(el){\n const root = el.getRootNode();\n globalThis.${shadowRootKey} = root;\n el.parentElement.remove();\n })(this)\"\n />`,\n }}\n />\n ) : null}\n {linksToRender}\n {shouldUseChildren ? children : null}\n </template>\n ) : null}\n {typeof document !== 'undefined' &&\n shadowRootRef.current &&\n !shouldUseChildren\n ? createPortal(\n <>\n {linksToRender}\n {componentToRender}\n </>,\n shadowRootRef.current,\n )\n : null}\n </div>\n );\n }\n\n return (\n <>\n {isolate === false ? (\n <template id={`${name}_start`} ref={startRef} />\n ) : null}\n <script data-remote-component type=\"application/json\">\n {JSON.stringify({\n name,\n bundle,\n route,\n runtime,\n })}\n </script>\n {isolate === false ? linksToRender : null}\n {componentToRender}\n {nextData ? (\n <script\n id={`${bundle}_${route.replace(\n /[^a-zA-Z0-9]+/g,\n '_',\n )}${name}_next_data`}\n type=\"application/json\"\n >\n {JSON.stringify(nextData)}\n </script>\n ) : null}\n {isolate === false ? <template id={`${name}_end`} ref={endRef} /> : null}\n </>\n );\n}\n"],"mappings":";AA4YI,SAiDU,UAjDV,KAyBM,YAzBN;AA1YJ;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,SAAS,sCAAsC;AAC/C,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AAGrC,SAAS,uBAAuB;AAChC,SAAS,eAAe,uBAAuB;AAC/C,SAAS,2BAA2B;AACpC,SAAS,iCAAiC;AAE1C,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,4BAA4B;AAiB9B,SAAS,6BAA6B;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,UAAU,CAAC;AAAA,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AA,QAEJ;AAAA,iBAAO,aAAa;AAAA;AAAA,YAEnB,qBAAC,cAAS,gBAAgB,MACvB;AAAA,uBAAS,WACR;AAAA,gBAAC;AAAA;AAAA,kBACC,yBAAyB;AAAA,oBACvB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA,qBAKL;AAAA;AAAA;AAAA;AAAA,kBAIL;AAAA;AAAA,cACF,IACE;AAAA,cACH;AAAA,cACA,oBAAoB,WAAW;AAAA,eAClC;AAAA,cACE;AAAA,UACH,OAAO,aAAa,eACrB,cAAc,WACd,CAAC,oBACG;AAAA,YACE,iCACG;AAAA;AAAA,cACA;AAAA,eACH;AAAA,YACA,cAAc;AAAA,UAChB,IACA;AAAA;AAAA;AAAA,IACN;AAAA,EAEJ;AAEA,SACE,iCACG;AAAA,gBAAY,QACX,oBAAC,cAAS,IAAI,GAAG,cAAc,KAAK,UAAU,IAC5C;AAAA,IACJ,oBAAC,YAAO,yBAAqB,MAAC,MAAK,oBAChC,eAAK,UAAU;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC,GACH;AAAA,IACC,YAAY,QAAQ,gBAAgB;AAAA,IACpC;AAAA,IACA,WACC;AAAA,MAAC;AAAA;AAAA,QACC,IAAI,GAAG,UAAU,MAAM;AAAA,UACrB;AAAA,UACA;AAAA,QACF,IAAI;AAAA,QACJ,MAAK;AAAA,QAEJ,eAAK,UAAU,QAAQ;AAAA;AAAA,IAC1B,IACE;AAAA,IACH,YAAY,QAAQ,oBAAC,cAAS,IAAI,GAAG,YAAY,KAAK,QAAQ,IAAK;AAAA,KACtE;AAEJ;","names":[]}
@@ -34,19 +34,11 @@ module.exports = __toCommonJS(dom_flight_exports);
34
34
  var import_parse5 = require("parse5");
35
35
  var import_react_property = require("react-property");
36
36
  var import_style_to_js = __toESM(require("style-to-js"), 1);
37
+ var import_html_spec = require("#internal/runtime/html/html-spec");
38
+ var import_rewrite_srcset = require("#internal/runtime/html/rewrite-srcset");
37
39
  import_react_property.possibleStandardNames.fetchpriority = "fetchPriority";
38
40
  import_react_property.possibleStandardNames["data-precedence"] = "precedence";
39
- const applyOriginToNodes = [
40
- "img",
41
- "source",
42
- "video",
43
- "audio",
44
- "track",
45
- "iframe",
46
- "embed",
47
- "script",
48
- "link"
49
- ];
41
+ const applyOriginToNodes = import_html_spec.ORIGIN_REWRITE_TAGS;
50
42
  function visit(node, context = {
51
43
  url: new URL("http://localhost"),
52
44
  active: false
@@ -85,26 +77,14 @@ function visit(node, context = {
85
77
  }
86
78
  const srcSet = node.attrsObj?.srcset;
87
79
  if (srcSet) {
88
- const srcSetValue = srcSet.split(",").map((entry) => {
89
- const [url, descriptor] = entry.trim().split(/\s+/);
90
- if (!url)
91
- return entry;
92
- const absoluteUrl = new URL(url, origin).href;
93
- return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
94
- }).join(", ");
80
+ const srcSetValue = (0, import_rewrite_srcset.rewriteSrcset)(srcSet, origin);
95
81
  if (node.attrsObjToArray && "srcset" in node.attrsObjToArray) {
96
82
  node.attrsObjToArray.srcset.value = srcSetValue;
97
83
  }
98
84
  }
99
85
  const imageSrcSet = node.attrsObj?.imagesrcset;
100
86
  if (imageSrcSet) {
101
- const srcSetValue = imageSrcSet.split(",").map((entry) => {
102
- const [url, descriptor] = entry.trim().split(/\s+/);
103
- if (!url)
104
- return entry;
105
- const absoluteUrl = new URL(url, origin).href;
106
- return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
107
- }).join(", ");
87
+ const srcSetValue = (0, import_rewrite_srcset.rewriteSrcset)(imageSrcSet, origin);
108
88
  if (node.attrsObjToArray && "imagesrcset" in node.attrsObjToArray) {
109
89
  node.attrsObjToArray.imagesrcset.value = srcSetValue;
110
90
  }
@@ -112,12 +92,12 @@ function visit(node, context = {
112
92
  }
113
93
  if (node.nodeName === "script" || node.nodeName === "link") {
114
94
  const nodeId = node.attrsObj?.id;
115
- if (nodeId?.endsWith("_shared")) {
95
+ if (nodeId?.endsWith(import_html_spec.ID_SUFFIX_SHARED)) {
116
96
  context.onShared?.(
117
97
  JSON.parse(node.childNodes[0].value)
118
98
  );
119
99
  return null;
120
- } else if (nodeId?.endsWith("_rsc") && "childNodes" in node) {
100
+ } else if (nodeId?.endsWith(import_html_spec.ID_SUFFIX_RSC) && "childNodes" in node) {
121
101
  if (!context.visitedRSCNodes) {
122
102
  context.visitedRSCNodes = /* @__PURE__ */ new Set();
123
103
  }
@@ -125,7 +105,7 @@ function visit(node, context = {
125
105
  context.visitedRSCNodes.add(node);
126
106
  context.onRSC?.(node.childNodes[0].value);
127
107
  }
128
- } else if (nodeId === "__NEXT_DATA__" && "childNodes" in node) {
108
+ } else if (nodeId === import_html_spec.NEXT_DATA_ID && "childNodes" in node) {
129
109
  context.onHTML?.(
130
110
  `<script id="__REMOTE_NEXT_DATA__" type="application/json">${node.childNodes[0].value}</script>`
131
111
  );
@@ -142,7 +122,7 @@ function visit(node, context = {
142
122
  }
143
123
  context.onNextData?.(nextDataValue);
144
124
  } else if (node.childNodes.length === 0) {
145
- if (node.nodeName === "script" && node.attrsObj && !("src" in node.attrsObj) && !("data-src" in node.attrsObj)) {
125
+ if (node.nodeName === "script" && node.attrsObj && !("src" in node.attrsObj) && !(import_html_spec.DATA_SRC in node.attrsObj)) {
146
126
  return [
147
127
  "$",
148
128
  node.nodeName,
@@ -159,7 +139,7 @@ function visit(node, context = {
159
139
  if (node.nodeName === "script") {
160
140
  context.onScript?.(
161
141
  node.attrs.reduce((props, attr) => {
162
- if (attr.name === "data-src") {
142
+ if (attr.name === import_html_spec.DATA_SRC) {
163
143
  props.src = attr.value;
164
144
  } else {
165
145
  props[attr.name] = attr.value || true;
@@ -171,12 +151,12 @@ function visit(node, context = {
171
151
  if (src) {
172
152
  node.attrs = node.attrs.filter((attr) => attr.name !== "src");
173
153
  node.attrs.push({
174
- name: "data-src",
154
+ name: import_html_spec.DATA_SRC,
175
155
  value: src
176
156
  });
177
157
  if (node.attrsObj) {
178
158
  delete node.attrsObj.src;
179
- node.attrsObj["data-src"] = src;
159
+ node.attrsObj[import_html_spec.DATA_SRC] = src;
180
160
  }
181
161
  }
182
162
  context.onHTML?.((0, import_parse5.serializeOuter)(node));
@@ -211,7 +191,7 @@ function visit(node, context = {
211
191
  if (!context.visitedNonActiveNodes) {
212
192
  context.visitedNonActiveNodes = /* @__PURE__ */ new Set();
213
193
  }
214
- if ("childNodes" in node && !(node.nodeName === "remote-component" && !node.attrsObj?.src && (context.name ? node.attrsObj?.name !== context.name : false))) {
194
+ if ("childNodes" in node && !(node.nodeName === import_html_spec.TAG_REMOTE_COMPONENT && !node.attrsObj?.src && (context.name ? node.attrsObj?.name !== context.name : false))) {
215
195
  if (!context.visitedNonActiveNodes.has(node)) {
216
196
  context.visitedNonActiveNodes.add(node);
217
197
  node.childNodes.forEach((childNode) => {
@@ -240,13 +220,13 @@ function visit(node, context = {
240
220
  return null;
241
221
  default: {
242
222
  const nodeId = node.attrsObj?.id;
243
- if (node.nodeName === "remote-component" && !node.attrsObj?.src && (!context.name || node.attrsObj?.name === context.name) || node.nodeName === "div" && (nodeId === "__next" || (context.name ? nodeId?.startsWith(context.name) : node.attrsObj && "data-bundle" in node.attrsObj && node.attrsObj["data-bundle"] && "data-route" in node.attrsObj && nodeId?.endsWith("_ssr")))) {
223
+ if (node.nodeName === import_html_spec.TAG_REMOTE_COMPONENT && !node.attrsObj?.src && (!context.name || node.attrsObj?.name === context.name) || node.nodeName === "div" && (nodeId === "__next" || (context.name ? nodeId?.startsWith(context.name) : node.attrsObj && import_html_spec.DATA_BUNDLE in node.attrsObj && node.attrsObj[import_html_spec.DATA_BUNDLE] && import_html_spec.DATA_ROUTE in node.attrsObj && nodeId?.endsWith(import_html_spec.ID_SUFFIX_SSR)))) {
244
224
  context.onMetadata?.({
245
- bundle: node.attrsObj?.["data-bundle"],
246
- route: node.attrsObj?.["data-route"],
247
- runtime: node.attrsObj?.["data-runtime"] ?? (node.nodeName === "remote-component" ? "script" : void 0),
248
- id: nodeId?.endsWith("_ssr") ? nodeId : void 0,
249
- type: node.nodeName === "remote-component" ? "remote-component" : node.attrsObj?.["data-type"]
225
+ bundle: node.attrsObj?.[import_html_spec.DATA_BUNDLE],
226
+ route: node.attrsObj?.[import_html_spec.DATA_ROUTE],
227
+ runtime: node.attrsObj?.[import_html_spec.DATA_RUNTIME] ?? (node.nodeName === import_html_spec.TAG_REMOTE_COMPONENT ? "script" : void 0),
228
+ id: nodeId?.endsWith(import_html_spec.ID_SUFFIX_SSR) ? nodeId : void 0,
229
+ type: node.nodeName === import_html_spec.TAG_REMOTE_COMPONENT ? import_html_spec.TAG_REMOTE_COMPONENT : node.attrsObj?.[import_html_spec.DATA_TYPE]
250
230
  });
251
231
  context.onHTML?.((0, import_parse5.serializeOuter)(node));
252
232
  return node.childNodes.reduce((acc, childNode) => {
@@ -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;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+B;AAO/B,4BAAyD;AACzD,yBAAsB;AAItB,4CAAsB,gBAAgB;AACtC,4CAAsB,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;AA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;AACjB,YAAI,KAAK,SAAS,SAAS;AACzB,gBAAM,YAAQ,mBAAAA,SAAU,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,gBAAI,yCAAkB,KAAK,IAAI,GAAG;AAChC,gBAAM,KAAK,IAAI,IAAI,KAAK;AACxB,iBAAO;AAAA,QACT;AACA,cAAM,4CAAsB,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":["styleToJs"]}
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;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+B;AAO/B,4BAAyD;AACzD,yBAAsB;AACtB,uBAYO;AACP,4BAA8B;AAI9B,4CAAsB,gBAAgB;AACtC,4CAAsB,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,KAAK,aAAa,aAAa;AAC3D,SAAK,kBAAkB,CAAC;AACxB,SAAK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aAAa,WAAW,KAAK,SAAS,SAAS;AACtD,gBAAM,eAAe,KAAK;AAC1B,iBAAO;AAAA,QACT;AACA,gBAAI,yCAAkB,KAAK,IAAI,GAAG;AAChC,gBAAM,KAAK,IAAI,IAAI,KAAK;AACxB,iBAAO;AAAA,QACT;AACA,cAAM,4CAAsB,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":["styleToJs"]}
@@ -1,19 +1,23 @@
1
1
  import { serializeOuter } from "parse5";
2
2
  import { isCustomAttribute, possibleStandardNames } from "react-property";
3
3
  import styleToJs from "style-to-js";
4
+ import {
5
+ DATA_BUNDLE,
6
+ DATA_ROUTE,
7
+ DATA_RUNTIME,
8
+ DATA_SRC,
9
+ DATA_TYPE,
10
+ ID_SUFFIX_RSC,
11
+ ID_SUFFIX_SHARED,
12
+ ID_SUFFIX_SSR,
13
+ NEXT_DATA_ID,
14
+ ORIGIN_REWRITE_TAGS,
15
+ TAG_REMOTE_COMPONENT
16
+ } from "#internal/runtime/html/html-spec";
17
+ import { rewriteSrcset } from "#internal/runtime/html/rewrite-srcset";
4
18
  possibleStandardNames.fetchpriority = "fetchPriority";
5
19
  possibleStandardNames["data-precedence"] = "precedence";
6
- const applyOriginToNodes = [
7
- "img",
8
- "source",
9
- "video",
10
- "audio",
11
- "track",
12
- "iframe",
13
- "embed",
14
- "script",
15
- "link"
16
- ];
20
+ const applyOriginToNodes = ORIGIN_REWRITE_TAGS;
17
21
  function visit(node, context = {
18
22
  url: new URL("http://localhost"),
19
23
  active: false
@@ -52,26 +56,14 @@ function visit(node, context = {
52
56
  }
53
57
  const srcSet = node.attrsObj?.srcset;
54
58
  if (srcSet) {
55
- const srcSetValue = srcSet.split(",").map((entry) => {
56
- const [url, descriptor] = entry.trim().split(/\s+/);
57
- if (!url)
58
- return entry;
59
- const absoluteUrl = new URL(url, origin).href;
60
- return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
61
- }).join(", ");
59
+ const srcSetValue = rewriteSrcset(srcSet, origin);
62
60
  if (node.attrsObjToArray && "srcset" in node.attrsObjToArray) {
63
61
  node.attrsObjToArray.srcset.value = srcSetValue;
64
62
  }
65
63
  }
66
64
  const imageSrcSet = node.attrsObj?.imagesrcset;
67
65
  if (imageSrcSet) {
68
- const srcSetValue = imageSrcSet.split(",").map((entry) => {
69
- const [url, descriptor] = entry.trim().split(/\s+/);
70
- if (!url)
71
- return entry;
72
- const absoluteUrl = new URL(url, origin).href;
73
- return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
74
- }).join(", ");
66
+ const srcSetValue = rewriteSrcset(imageSrcSet, origin);
75
67
  if (node.attrsObjToArray && "imagesrcset" in node.attrsObjToArray) {
76
68
  node.attrsObjToArray.imagesrcset.value = srcSetValue;
77
69
  }
@@ -79,12 +71,12 @@ function visit(node, context = {
79
71
  }
80
72
  if (node.nodeName === "script" || node.nodeName === "link") {
81
73
  const nodeId = node.attrsObj?.id;
82
- if (nodeId?.endsWith("_shared")) {
74
+ if (nodeId?.endsWith(ID_SUFFIX_SHARED)) {
83
75
  context.onShared?.(
84
76
  JSON.parse(node.childNodes[0].value)
85
77
  );
86
78
  return null;
87
- } else if (nodeId?.endsWith("_rsc") && "childNodes" in node) {
79
+ } else if (nodeId?.endsWith(ID_SUFFIX_RSC) && "childNodes" in node) {
88
80
  if (!context.visitedRSCNodes) {
89
81
  context.visitedRSCNodes = /* @__PURE__ */ new Set();
90
82
  }
@@ -92,7 +84,7 @@ function visit(node, context = {
92
84
  context.visitedRSCNodes.add(node);
93
85
  context.onRSC?.(node.childNodes[0].value);
94
86
  }
95
- } else if (nodeId === "__NEXT_DATA__" && "childNodes" in node) {
87
+ } else if (nodeId === NEXT_DATA_ID && "childNodes" in node) {
96
88
  context.onHTML?.(
97
89
  `<script id="__REMOTE_NEXT_DATA__" type="application/json">${node.childNodes[0].value}</script>`
98
90
  );
@@ -109,7 +101,7 @@ function visit(node, context = {
109
101
  }
110
102
  context.onNextData?.(nextDataValue);
111
103
  } else if (node.childNodes.length === 0) {
112
- if (node.nodeName === "script" && node.attrsObj && !("src" in node.attrsObj) && !("data-src" in node.attrsObj)) {
104
+ if (node.nodeName === "script" && node.attrsObj && !("src" in node.attrsObj) && !(DATA_SRC in node.attrsObj)) {
113
105
  return [
114
106
  "$",
115
107
  node.nodeName,
@@ -126,7 +118,7 @@ function visit(node, context = {
126
118
  if (node.nodeName === "script") {
127
119
  context.onScript?.(
128
120
  node.attrs.reduce((props, attr) => {
129
- if (attr.name === "data-src") {
121
+ if (attr.name === DATA_SRC) {
130
122
  props.src = attr.value;
131
123
  } else {
132
124
  props[attr.name] = attr.value || true;
@@ -138,12 +130,12 @@ function visit(node, context = {
138
130
  if (src) {
139
131
  node.attrs = node.attrs.filter((attr) => attr.name !== "src");
140
132
  node.attrs.push({
141
- name: "data-src",
133
+ name: DATA_SRC,
142
134
  value: src
143
135
  });
144
136
  if (node.attrsObj) {
145
137
  delete node.attrsObj.src;
146
- node.attrsObj["data-src"] = src;
138
+ node.attrsObj[DATA_SRC] = src;
147
139
  }
148
140
  }
149
141
  context.onHTML?.(serializeOuter(node));
@@ -178,7 +170,7 @@ function visit(node, context = {
178
170
  if (!context.visitedNonActiveNodes) {
179
171
  context.visitedNonActiveNodes = /* @__PURE__ */ new Set();
180
172
  }
181
- if ("childNodes" in node && !(node.nodeName === "remote-component" && !node.attrsObj?.src && (context.name ? node.attrsObj?.name !== context.name : false))) {
173
+ if ("childNodes" in node && !(node.nodeName === TAG_REMOTE_COMPONENT && !node.attrsObj?.src && (context.name ? node.attrsObj?.name !== context.name : false))) {
182
174
  if (!context.visitedNonActiveNodes.has(node)) {
183
175
  context.visitedNonActiveNodes.add(node);
184
176
  node.childNodes.forEach((childNode) => {
@@ -207,13 +199,13 @@ function visit(node, context = {
207
199
  return null;
208
200
  default: {
209
201
  const nodeId = node.attrsObj?.id;
210
- if (node.nodeName === "remote-component" && !node.attrsObj?.src && (!context.name || node.attrsObj?.name === context.name) || node.nodeName === "div" && (nodeId === "__next" || (context.name ? nodeId?.startsWith(context.name) : node.attrsObj && "data-bundle" in node.attrsObj && node.attrsObj["data-bundle"] && "data-route" in node.attrsObj && nodeId?.endsWith("_ssr")))) {
202
+ if (node.nodeName === TAG_REMOTE_COMPONENT && !node.attrsObj?.src && (!context.name || node.attrsObj?.name === context.name) || node.nodeName === "div" && (nodeId === "__next" || (context.name ? nodeId?.startsWith(context.name) : node.attrsObj && DATA_BUNDLE in node.attrsObj && node.attrsObj[DATA_BUNDLE] && DATA_ROUTE in node.attrsObj && nodeId?.endsWith(ID_SUFFIX_SSR)))) {
211
203
  context.onMetadata?.({
212
- bundle: node.attrsObj?.["data-bundle"],
213
- route: node.attrsObj?.["data-route"],
214
- runtime: node.attrsObj?.["data-runtime"] ?? (node.nodeName === "remote-component" ? "script" : void 0),
215
- id: nodeId?.endsWith("_ssr") ? nodeId : void 0,
216
- type: node.nodeName === "remote-component" ? "remote-component" : node.attrsObj?.["data-type"]
204
+ bundle: node.attrsObj?.[DATA_BUNDLE],
205
+ route: node.attrsObj?.[DATA_ROUTE],
206
+ runtime: node.attrsObj?.[DATA_RUNTIME] ?? (node.nodeName === TAG_REMOTE_COMPONENT ? "script" : void 0),
207
+ id: nodeId?.endsWith(ID_SUFFIX_SSR) ? nodeId : void 0,
208
+ type: node.nodeName === TAG_REMOTE_COMPONENT ? TAG_REMOTE_COMPONENT : node.attrsObj?.[DATA_TYPE]
217
209
  });
218
210
  context.onHTML?.(serializeOuter(node));
219
211
  return node.childNodes.reduce((acc, childNode) => {
@@ -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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C;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,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,SAAS,uBAAuB;AAAA,IACvC;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