remote-components 0.0.33 → 0.0.35

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 (77) hide show
  1. package/dist/{component-loader-28ad0083.d.ts → component-loader-8951c052.d.ts} +6 -4
  2. package/dist/html/host.cjs +353 -129
  3. package/dist/html/host.cjs.map +1 -1
  4. package/dist/html/host.js +353 -129
  5. package/dist/html/host.js.map +1 -1
  6. package/dist/html/remote.cjs +199 -0
  7. package/dist/html/remote.cjs.map +1 -0
  8. package/dist/html/remote.d.ts +2 -0
  9. package/dist/html/remote.js +198 -0
  10. package/dist/html/remote.js.map +1 -0
  11. package/dist/internal/next/host/app-router-client.cjs +60 -19
  12. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  13. package/dist/internal/next/host/app-router-client.d.ts +3 -3
  14. package/dist/internal/next/host/app-router-client.js +65 -23
  15. package/dist/internal/next/host/app-router-client.js.map +1 -1
  16. package/dist/internal/next/host/app-router-compat.cjs.map +1 -1
  17. package/dist/internal/next/host/app-router-compat.d.ts +1 -1
  18. package/dist/internal/next/host/app-router-compat.js.map +1 -1
  19. package/dist/internal/next/remote/render-server.cjs +1 -1
  20. package/dist/internal/next/remote/render-server.cjs.map +1 -1
  21. package/dist/internal/next/remote/render-server.js +1 -1
  22. package/dist/internal/next/remote/render-server.js.map +1 -1
  23. package/dist/internal/shared/client/polyfill.cjs.map +1 -1
  24. package/dist/internal/shared/client/polyfill.js.map +1 -1
  25. package/dist/internal/shared/client/remote-component.cjs +237 -133
  26. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  27. package/dist/internal/shared/client/remote-component.d.ts +29 -22
  28. package/dist/internal/shared/client/remote-component.js +235 -133
  29. package/dist/internal/shared/client/remote-component.js.map +1 -1
  30. package/dist/internal/shared/error.cjs +1 -1
  31. package/dist/internal/shared/error.cjs.map +1 -1
  32. package/dist/internal/shared/error.d.ts +1 -1
  33. package/dist/internal/shared/error.js +1 -1
  34. package/dist/internal/shared/error.js.map +1 -1
  35. package/dist/internal/shared/ssr/dom-flight.cjs +24 -8
  36. package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
  37. package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
  38. package/dist/internal/shared/ssr/dom-flight.js +24 -8
  39. package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
  40. package/dist/internal/shared/ssr/fetch-remote-component.cjs +8 -4
  41. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  42. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +2 -1
  43. package/dist/internal/shared/ssr/fetch-remote-component.js +9 -5
  44. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  45. package/dist/next/config.cjs +100 -86
  46. package/dist/next/config.cjs.map +1 -1
  47. package/dist/next/config.js +100 -86
  48. package/dist/next/config.js.map +1 -1
  49. package/dist/next/host/app-router-server.cjs +1 -0
  50. package/dist/next/host/app-router-server.cjs.map +1 -1
  51. package/dist/next/host/app-router-server.js +2 -1
  52. package/dist/next/host/app-router-server.js.map +1 -1
  53. package/dist/next/host/client/index.cjs +1381 -1187
  54. package/dist/next/host/client/index.cjs.map +1 -1
  55. package/dist/next/host/client/index.d.ts +1 -1
  56. package/dist/next/host/client/index.js +682 -490
  57. package/dist/next/host/client/index.js.map +1 -1
  58. package/dist/next/host/pages-router-server.cjs +4 -4
  59. package/dist/next/host/pages-router-server.cjs.map +1 -1
  60. package/dist/next/host/pages-router-server.js +4 -4
  61. package/dist/next/host/pages-router-server.js.map +1 -1
  62. package/dist/next/{middleware.cjs → proxy.cjs} +24 -14
  63. package/dist/next/proxy.cjs.map +1 -0
  64. package/dist/next/proxy.d.ts +29 -0
  65. package/dist/next/{middleware.js → proxy.js} +21 -11
  66. package/dist/next/proxy.js.map +1 -0
  67. package/dist/react/index.cjs +201 -107
  68. package/dist/react/index.cjs.map +1 -1
  69. package/dist/react/index.d.ts +2 -2
  70. package/dist/react/index.js +206 -112
  71. package/dist/react/index.js.map +1 -1
  72. package/dist/{types-7c207455.d.ts → types-4e7dea94.d.ts} +2 -1
  73. package/dist/{types-e4a3fa37.d.ts → types-cbf6c34f.d.ts} +2 -2
  74. package/package.json +22 -9
  75. package/dist/next/middleware.cjs.map +0 -1
  76. package/dist/next/middleware.d.ts +0 -29
  77. package/dist/next/middleware.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/host/app-router-client.tsx"],"sourcesContent":["'use client';\n\nimport {\n useId,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n startTransition,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport * as Image from 'next/image';\nimport {\n loadRemoteComponent,\n DEFAULT_ROUTE,\n RUNTIME_WEBPACK,\n} from '#internal/shared/client/remote-component';\nimport type { RemoteComponentProps } from '#internal/shared/client/remote-component';\nimport { imageImpl, routerImpl } from '#internal/next/host/app-router-compat';\nimport { attrToProp, escapeString } from '#internal/shared/utils';\n\n// patch react/jsx-runtime to support the shadowrootmode attribute on template elements\ndeclare module 'react/jsx-runtime' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace JSX {\n interface IntrinsicElements {\n template: {\n shadowrootmode?: 'open' | 'closed';\n id?: string;\n ref?: React.Ref<HTMLTemplateElement>;\n dangerouslySetInnerHTML?: {\n __html: string;\n };\n children?: React.ReactNode;\n };\n }\n }\n}\n\n// import { shared } from 'remote-components/shared/host';\nasync function tryImportShared() {\n try {\n const { shared } = await import('remote-components/shared/host/app');\n return shared;\n } catch {\n return {};\n }\n}\n\n/**\n * RemoteComponentClient - 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 RemoteComponentClient({\n url,\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 reset,\n children,\n}: RemoteComponentProps) {\n const remoteComponentId = useId();\n const [component, setComponent] = useState<React.ReactNode | Error>(null);\n const metadataRef = useRef<{\n name: string;\n bundle: string;\n route: string;\n url: string;\n loading: boolean;\n }>({\n name,\n bundle,\n route,\n url,\n loading: false,\n });\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 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 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 =\n `__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)}` 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 // eslint-disable-next-line no-console\n console.error(e);\n });\n }\n }\n }, [\n name,\n isolate,\n links,\n url,\n mode,\n self,\n shadowRootKey,\n shouldUseChildren,\n remoteComponentId,\n ]);\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 (!metadataRef.current.loading &&\n !component &&\n (isolate === false || shadowRootRef.current)) ||\n metadataRef.current.url !== url ||\n metadataRef.current.name !== name ||\n metadataRef.current.bundle !== bundle ||\n metadataRef.current.route !== route\n ) {\n metadataRef.current = {\n name,\n bundle,\n route,\n url,\n loading: true,\n };\n const rscName = `__remote_components_rsc_${escapeString(new URL(url).href)}_${escapeString(name)}`;\n const result = await loadRemoteComponent({\n url: new URL(url, location.origin),\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\n return {\n 'next/router': routerImpl,\n ...shared,\n 'next/image': () =>\n Promise.resolve(imageImpl(Image.default, bundle)),\n 'next/dist/client/image-component': () =>\n Promise.resolve({ Image: imageImpl(Image.default, bundle) }),\n };\n })(),\n remoteShared,\n container: shadowRootRef.current,\n });\n metadataRef.current.loading = false;\n if (result.error) {\n setComponent(result.error);\n } else {\n setComponent(result.component);\n }\n }\n } catch (error: unknown) {\n metadataRef.current.loading = false;\n setComponent(error as Error);\n }\n });\n }, [\n url,\n component,\n name,\n bundle,\n route,\n runtime,\n scripts,\n data,\n nextData,\n remoteShared,\n children,\n links,\n isolate,\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 <>\n {(!nextData || nextData.buildId !== 'development') &&\n isolate !== false &&\n reset ? (\n <style data-remote-components-reset=\"\">{`:host { all: initial; }`}</style>\n ) : null}\n {links.map((link) => (\n <link\n key={JSON.stringify(link)}\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n data-wait={link.rel === 'stylesheet' && link.href ? '' : undefined}\n href={link.href ? new URL(link.href as string, url).href : undefined}\n />\n ))}\n {links\n .filter((link) => link.rel === 'stylesheet')\n .map((link) => (\n <link\n key={JSON.stringify(link)}\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n as=\"style\"\n fetchPriority=\"high\"\n href={\n link.href ? new URL(link.href as string, url).href : undefined\n }\n precedence={bundle}\n rel=\"preload\"\n />\n ))}\n </>\n );\n\n let componentToRender = shouldUseChildren ? (\n <>{children}</>\n ) : (\n (component as React.ReactNode)\n );\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.__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)} = 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 ? <template id={`${name}_start`} /> : 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(/[^a-zA-Z0-9]+/g, '_')}${name}_next_data`}\n type=\"application/json\"\n >\n {JSON.stringify(nextData)}\n </script>\n ) : null}\n {isolate === false ? <template id={`${name}_end`} /> : null}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0UI;AAxUJ,mBAOO;AACP,uBAA6B;AAC7B,YAAuB;AACvB,8BAIO;AAEP,+BAAsC;AACtC,mBAAyC;AAqBzC,eAAe,kBAAkB;AAC/B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,mCAAmC;AACnE,WAAO;AAAA,EACT,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAQO,SAAS,sBAAsB;AAAA,EACpC;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;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,wBAAoB,oBAAM;AAChC,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAkC,IAAI;AACxE,QAAM,kBAAc,qBAMjB;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX,CAAC;AAGD,MAAI,qBAAqB,OAAO;AAC9B,UAAM;AAAA,EACR;AAGA,QAAM,qBACH,CAAC,aACC,aACC,CAAC,YACD,OAAQ,UAA0C,SAChD;AAAA;AAAA;AAAA,EAIN,UAAU,YAAY;AAExB,QAAM,OAAO;AAKb,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,IAAI;AAAA,QACxD,MAAK;AAAA,QAEJ,eAAK,UAAU,QAAQ;AAAA;AAAA,IAC1B,IACE;AAAA,IACH,YAAY,QAAQ,4CAAC,cAAS,IAAI,GAAG,YAAY,IAAK;AAAA,KACzD;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/next/host/app-router-client.tsx"],"sourcesContent":["'use client';\n\nimport * as Image from 'next/image';\nimport {\n startTransition,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { imageImpl, routerImpl } from '#internal/next/host/app-router-compat';\nimport type { RemoteComponentProps } from '#internal/shared/client/remote-component';\nimport {\n DEFAULT_ROUTE,\n loadRemoteComponent,\n loadStaticRemoteComponent,\n RUNTIME_WEBPACK,\n} from '#internal/shared/client/remote-component';\nimport type { MountOrUnmountFunction } from '#internal/shared/client/types';\nimport { attrToProp, escapeString } from '#internal/shared/utils';\n\n// patch react/jsx-runtime to support the shadowrootmode attribute on template elements\ndeclare module 'react/jsx-runtime' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace JSX {\n interface IntrinsicElements {\n template: {\n shadowrootmode?: 'open' | 'closed';\n id?: string;\n ref?: React.Ref<HTMLTemplateElement>;\n dangerouslySetInnerHTML?: {\n __html: string;\n };\n children?: React.ReactNode;\n };\n }\n }\n}\n\n// import { shared } from 'remote-components/shared/host';\nasync function tryImportShared() {\n try {\n const { shared } = await import('remote-components/shared/host/app');\n return shared;\n } catch {\n return {};\n }\n}\n\n/**\n * RemoteComponentClient - 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 RemoteComponentClient({\n url,\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 reset,\n type,\n children,\n}: RemoteComponentProps) {\n const remoteComponentId = useId();\n const [component, setComponent] = useState<React.ReactNode | Error>(null);\n const metadataRef = useRef<{\n name: string;\n bundle: string;\n route: string;\n url: string;\n loading: boolean;\n }>({\n name,\n bundle,\n route,\n url,\n loading: false,\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 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 =\n `__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)}` 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 // eslint-disable-next-line no-console\n console.error(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 // eslint-disable-next-line no-console\n console.error(e);\n }\n }),\n ).catch((e) => {\n // eslint-disable-next-line no-console\n console.error(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 (!metadataRef.current.loading &&\n !component &&\n (isolate === false || shadowRootRef.current)) ||\n metadataRef.current.url !== url ||\n metadataRef.current.name !== name ||\n metadataRef.current.bundle !== bundle ||\n metadataRef.current.route !== route\n ) {\n metadataRef.current = {\n name,\n bundle,\n route,\n url,\n loading: true,\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 new URL(url, location.origin),\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 // eslint-disable-next-line no-console\n console.error(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 // eslint-disable-next-line no-console\n console.error(e);\n setComponent(e as Error);\n });\n return;\n }\n\n const rscName = `__remote_components_rsc_${escapeString(new URL(url).href)}_${escapeString(name)}`;\n const result = await loadRemoteComponent({\n url: new URL(url, location.origin),\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\n return {\n 'next/router': routerImpl,\n ...shared,\n 'next/image': () =>\n Promise.resolve(imageImpl(Image.default, bundle)),\n 'next/dist/client/image-component': () =>\n Promise.resolve({ Image: imageImpl(Image.default, bundle) }),\n };\n })(),\n remoteShared,\n container: shadowRootRef.current,\n });\n metadataRef.current.loading = false;\n if (result.error) {\n setComponent(result.error);\n } else {\n setComponent(result.component);\n }\n }\n } catch (error: unknown) {\n metadataRef.current.loading = false;\n setComponent(error as Error);\n }\n });\n }, [\n url,\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 ]);\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 <>\n {(!nextData || nextData.buildId !== 'development') &&\n isolate !== false &&\n reset ? (\n <style data-remote-components-reset=\"\">{`:host { all: initial; }`}</style>\n ) : null}\n {links.map((link) => (\n <link\n key={JSON.stringify(link)}\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n data-wait={link.rel === 'stylesheet' && link.href ? '' : undefined}\n href={link.href ? new URL(link.href as string, url).href : undefined}\n />\n ))}\n {links\n .filter((link) => link.rel === 'stylesheet')\n .map((link) => (\n <link\n key={JSON.stringify(link)}\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n as=\"style\"\n fetchPriority=\"high\"\n href={\n link.href ? new URL(link.href as string, url).href : undefined\n }\n precedence={bundle}\n rel=\"preload\"\n />\n ))}\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.__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)} = 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(/[^a-zA-Z0-9]+/g, '_')}${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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuYI;AArYJ,YAAuB;AACvB,mBAOO;AACP,uBAA6B;AAC7B,+BAAsC;AAEtC,8BAKO;AAEP,mBAAyC;AAqBzC,eAAe,kBAAkB;AAC/B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,mCAAmC;AACnE,WAAO;AAAA,EACT,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAQO,SAAS,sBAAsB;AAAA,EACpC;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;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,wBAAoB,oBAAM;AAChC,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAkC,IAAI;AACxE,QAAM,kBAAc,qBAMjB;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX,CAAC;AACD,QAAM,eAAW,qBAAmC,IAAI;AACxD,QAAM,aAAS,qBAAmC,IAAI;AACtD,QAAM,oCAAgC,qBAG5B,IAAI;AAGd,MAAI,qBAAqB,OAAO;AAC9B,UAAM;AAAA,EACR;AAGA,QAAM,qBACH,CAAC,aACC,aACC,CAAC,YACD,SAAS,sBACT,OAAQ,UAA0C,SAChD;AAAA;AAAA;AAAA,EAIN,UAAU,YAAY;AAExB,QAAM,OAAO;AAKb,QAAM,gBACJ,sCAAkC,2BAAa,IAAI,IAAI,GAAG,EAAE,IAAI,SAAK,2BAAa,IAAI;AACxF,QAAM,yBAAqB;AAAA,IACzB,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+1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { R as RemoteComponentProps } from '../../../types-7c207455.js';
2
+ import { R as RemoteComponentProps } from '../../../types-4e7dea94.js';
3
3
  import 'react';
4
- import '../../../types-e4a3fa37.js';
4
+ import '../../../types-cbf6c34f.js';
5
5
 
6
6
  declare module 'react/jsx-runtime' {
7
7
  namespace JSX {
@@ -24,6 +24,6 @@ declare module 'react/jsx-runtime' {
24
24
  * This component handles the loading and rendering of remote microfrontends.
25
25
  * It supports both RSC (React Server Components) and Next.js Pages Router based components.
26
26
  */
27
- declare function RemoteComponentClient({ url, name, bundle, route, runtime, data, nextData, scripts, links, remoteShared, isolate, mode, reset, children, }: RemoteComponentProps): react_jsx_runtime.JSX.Element;
27
+ declare function RemoteComponentClient({ url, name, bundle, route, runtime, data, nextData, scripts, links, remoteShared, isolate, mode, reset, type, children, }: RemoteComponentProps): react_jsx_runtime.JSX.Element;
28
28
 
29
29
  export { RemoteComponentClient };
@@ -1,21 +1,22 @@
1
1
  "use client";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import * as Image from "next/image";
3
4
  import {
4
- useId,
5
+ startTransition,
5
6
  useEffect,
7
+ useId,
6
8
  useLayoutEffect,
7
9
  useRef,
8
- useState,
9
- startTransition
10
+ useState
10
11
  } from "react";
11
12
  import { createPortal } from "react-dom";
12
- import * as Image from "next/image";
13
+ import { imageImpl, routerImpl } from "#internal/next/host/app-router-compat";
13
14
  import {
14
- loadRemoteComponent,
15
15
  DEFAULT_ROUTE,
16
+ loadRemoteComponent,
17
+ loadStaticRemoteComponent,
16
18
  RUNTIME_WEBPACK
17
19
  } from "#internal/shared/client/remote-component";
18
- import { imageImpl, routerImpl } from "#internal/next/host/app-router-compat";
19
20
  import { attrToProp, escapeString } from "#internal/shared/utils";
20
21
  async function tryImportShared() {
21
22
  try {
@@ -39,6 +40,7 @@ function RemoteComponentClient({
39
40
  isolate,
40
41
  mode = "open",
41
42
  reset,
43
+ type,
42
44
  children
43
45
  }) {
44
46
  const remoteComponentId = useId();
@@ -50,10 +52,13 @@ function RemoteComponentClient({
50
52
  url,
51
53
  loading: false
52
54
  });
55
+ const startRef = useRef(null);
56
+ const endRef = useRef(null);
57
+ const prevRemoteComponentUnmountRef = useRef(null);
53
58
  if (component instanceof Error) {
54
59
  throw component;
55
60
  }
56
- const shouldUseChildren = (!component || component && !nextData && typeof component.then !== "function") && // if the remote Next.js Pages Router application is in development mode
61
+ const shouldUseChildren = (!component || component && !nextData && type !== "remote-component" && typeof component.then !== "function") && // if the remote Next.js Pages Router application is in development mode
57
62
  // we don't use the provided static HTML
58
63
  // to mitigate layout shift when loading CSS using JavaScript on the client
59
64
  nextData?.buildId !== "development";
@@ -128,17 +133,24 @@ function RemoteComponentClient({
128
133
  });
129
134
  }
130
135
  }
131
- }, [
132
- name,
133
- isolate,
134
- links,
135
- url,
136
- mode,
137
- self,
138
- shadowRootKey,
139
- shouldUseChildren,
140
- remoteComponentId
141
- ]);
136
+ }, [isolate, mode, self, shadowRootKey, shouldUseChildren]);
137
+ useEffect(() => {
138
+ if (prevRemoteComponentUnmountRef.current && component !== children) {
139
+ const { unmount, root } = prevRemoteComponentUnmountRef.current;
140
+ prevRemoteComponentUnmountRef.current = null;
141
+ Promise.all(
142
+ Array.from(unmount).map(async (unmountFn) => {
143
+ try {
144
+ await unmountFn(root);
145
+ } catch (e) {
146
+ console.error(e);
147
+ }
148
+ })
149
+ ).catch((e) => {
150
+ console.error(e);
151
+ });
152
+ }
153
+ }, [component, children]);
142
154
  useEffect(() => {
143
155
  startTransition(async () => {
144
156
  try {
@@ -150,6 +162,36 @@ function RemoteComponentClient({
150
162
  url,
151
163
  loading: true
152
164
  };
165
+ if (type === "remote-component") {
166
+ setComponent(children);
167
+ loadStaticRemoteComponent(
168
+ scripts,
169
+ new URL(url, location.origin)
170
+ ).then(({ mount, unmount }) => {
171
+ if (mount.size > 0) {
172
+ let root = shadowRootRef.current;
173
+ try {
174
+ if (!root && startRef.current && endRef.current) {
175
+ root = document.querySelectorAll(
176
+ `#${startRef.current.id} ~ *:not(#${endRef.current.id}):has(~ #${endRef.current.id})`
177
+ );
178
+ }
179
+ } catch (e) {
180
+ console.error(e);
181
+ }
182
+ if (unmount.size > 0) {
183
+ prevRemoteComponentUnmountRef.current = { unmount, root };
184
+ }
185
+ return Promise.all(
186
+ Array.from(mount).map((mountFn) => mountFn(root))
187
+ );
188
+ }
189
+ }).catch((e) => {
190
+ console.error(e);
191
+ setComponent(e);
192
+ });
193
+ return;
194
+ }
153
195
  const rscName = `__remote_components_rsc_${escapeString(new URL(url).href)}_${escapeString(name)}`;
154
196
  const result = await loadRemoteComponent({
155
197
  url: new URL(url, location.origin),
@@ -200,8 +242,8 @@ function RemoteComponentClient({
200
242
  nextData,
201
243
  remoteShared,
202
244
  children,
203
- links,
204
- isolate
245
+ isolate,
246
+ type
205
247
  ]);
206
248
  if (nextData?.buildId === "development" && shadowRootRef.current && isolate !== false && reset && !shadowRootRef.current.querySelector("[data-remote-components-reset]")) {
207
249
  const style = document.createElement("style");
@@ -256,7 +298,7 @@ function RemoteComponentClient({
256
298
  JSON.stringify(link)
257
299
  ))
258
300
  ] });
259
- let componentToRender = shouldUseChildren ? /* @__PURE__ */ jsx(Fragment, { children }) : component;
301
+ let componentToRender = shouldUseChildren ? children : component;
260
302
  if (isolate !== false) {
261
303
  componentToRender = /* @__PURE__ */ jsxs(
262
304
  "div",
@@ -301,7 +343,7 @@ function RemoteComponentClient({
301
343
  );
302
344
  }
303
345
  return /* @__PURE__ */ jsxs(Fragment, { children: [
304
- isolate === false ? /* @__PURE__ */ jsx("template", { id: `${name}_start` }) : null,
346
+ isolate === false ? /* @__PURE__ */ jsx("template", { id: `${name}_start`, ref: startRef }) : null,
305
347
  /* @__PURE__ */ jsx("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
306
348
  name,
307
349
  bundle,
@@ -318,7 +360,7 @@ function RemoteComponentClient({
318
360
  children: JSON.stringify(nextData)
319
361
  }
320
362
  ) : null,
321
- isolate === false ? /* @__PURE__ */ jsx("template", { id: `${name}_end` }) : null
363
+ isolate === false ? /* @__PURE__ */ jsx("template", { id: `${name}_end`, ref: endRef }) : null
322
364
  ] });
323
365
  }
324
366
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/host/app-router-client.tsx"],"sourcesContent":["'use client';\n\nimport {\n useId,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n startTransition,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport * as Image from 'next/image';\nimport {\n loadRemoteComponent,\n DEFAULT_ROUTE,\n RUNTIME_WEBPACK,\n} from '#internal/shared/client/remote-component';\nimport type { RemoteComponentProps } from '#internal/shared/client/remote-component';\nimport { imageImpl, routerImpl } from '#internal/next/host/app-router-compat';\nimport { attrToProp, escapeString } from '#internal/shared/utils';\n\n// patch react/jsx-runtime to support the shadowrootmode attribute on template elements\ndeclare module 'react/jsx-runtime' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace JSX {\n interface IntrinsicElements {\n template: {\n shadowrootmode?: 'open' | 'closed';\n id?: string;\n ref?: React.Ref<HTMLTemplateElement>;\n dangerouslySetInnerHTML?: {\n __html: string;\n };\n children?: React.ReactNode;\n };\n }\n }\n}\n\n// import { shared } from 'remote-components/shared/host';\nasync function tryImportShared() {\n try {\n const { shared } = await import('remote-components/shared/host/app');\n return shared;\n } catch {\n return {};\n }\n}\n\n/**\n * RemoteComponentClient - 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 RemoteComponentClient({\n url,\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 reset,\n children,\n}: RemoteComponentProps) {\n const remoteComponentId = useId();\n const [component, setComponent] = useState<React.ReactNode | Error>(null);\n const metadataRef = useRef<{\n name: string;\n bundle: string;\n route: string;\n url: string;\n loading: boolean;\n }>({\n name,\n bundle,\n route,\n url,\n loading: false,\n });\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 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 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 =\n `__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)}` 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 // eslint-disable-next-line no-console\n console.error(e);\n });\n }\n }\n }, [\n name,\n isolate,\n links,\n url,\n mode,\n self,\n shadowRootKey,\n shouldUseChildren,\n remoteComponentId,\n ]);\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 (!metadataRef.current.loading &&\n !component &&\n (isolate === false || shadowRootRef.current)) ||\n metadataRef.current.url !== url ||\n metadataRef.current.name !== name ||\n metadataRef.current.bundle !== bundle ||\n metadataRef.current.route !== route\n ) {\n metadataRef.current = {\n name,\n bundle,\n route,\n url,\n loading: true,\n };\n const rscName = `__remote_components_rsc_${escapeString(new URL(url).href)}_${escapeString(name)}`;\n const result = await loadRemoteComponent({\n url: new URL(url, location.origin),\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\n return {\n 'next/router': routerImpl,\n ...shared,\n 'next/image': () =>\n Promise.resolve(imageImpl(Image.default, bundle)),\n 'next/dist/client/image-component': () =>\n Promise.resolve({ Image: imageImpl(Image.default, bundle) }),\n };\n })(),\n remoteShared,\n container: shadowRootRef.current,\n });\n metadataRef.current.loading = false;\n if (result.error) {\n setComponent(result.error);\n } else {\n setComponent(result.component);\n }\n }\n } catch (error: unknown) {\n metadataRef.current.loading = false;\n setComponent(error as Error);\n }\n });\n }, [\n url,\n component,\n name,\n bundle,\n route,\n runtime,\n scripts,\n data,\n nextData,\n remoteShared,\n children,\n links,\n isolate,\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 <>\n {(!nextData || nextData.buildId !== 'development') &&\n isolate !== false &&\n reset ? (\n <style data-remote-components-reset=\"\">{`:host { all: initial; }`}</style>\n ) : null}\n {links.map((link) => (\n <link\n key={JSON.stringify(link)}\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n data-wait={link.rel === 'stylesheet' && link.href ? '' : undefined}\n href={link.href ? new URL(link.href as string, url).href : undefined}\n />\n ))}\n {links\n .filter((link) => link.rel === 'stylesheet')\n .map((link) => (\n <link\n key={JSON.stringify(link)}\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n as=\"style\"\n fetchPriority=\"high\"\n href={\n link.href ? new URL(link.href as string, url).href : undefined\n }\n precedence={bundle}\n rel=\"preload\"\n />\n ))}\n </>\n );\n\n let componentToRender = shouldUseChildren ? (\n <>{children}</>\n ) : (\n (component as React.ReactNode)\n );\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.__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)} = 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 ? <template id={`${name}_start`} /> : 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(/[^a-zA-Z0-9]+/g, '_')}${name}_next_data`}\n type=\"application/json\"\n >\n {JSON.stringify(nextData)}\n </script>\n ) : null}\n {isolate === false ? <template id={`${name}_end`} /> : null}\n </>\n );\n}\n"],"mappings":";AA0UI,mBAII,KAJJ;AAxUJ;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,YAAY,WAAW;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,WAAW,kBAAkB;AACtC,SAAS,YAAY,oBAAoB;AAqBzC,eAAe,kBAAkB;AAC/B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,mCAAmC;AACnE,WAAO;AAAA,EACT,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAQO,SAAS,sBAAsB;AAAA,EACpC;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;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,oBAAoB,MAAM;AAChC,QAAM,CAAC,WAAW,YAAY,IAAI,SAAkC,IAAI;AACxE,QAAM,cAAc,OAMjB;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX,CAAC;AAGD,MAAI,qBAAqB,OAAO;AAC9B,UAAM;AAAA,EACR;AAGA,QAAM,qBACH,CAAC,aACC,aACC,CAAC,YACD,OAAQ,UAA0C,SAChD;AAAA;AAAA;AAAA,EAIN,UA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AAQ,kBAAkB,GAAG,IAAI;AAAA,QACxD,MAAK;AAAA,QAEJ,eAAK,UAAU,QAAQ;AAAA;AAAA,IAC1B,IACE;AAAA,IACH,YAAY,QAAQ,oBAAC,cAAS,IAAI,GAAG,YAAY,IAAK;AAAA,KACzD;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/next/host/app-router-client.tsx"],"sourcesContent":["'use client';\n\nimport * as Image from 'next/image';\nimport {\n startTransition,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { imageImpl, routerImpl } from '#internal/next/host/app-router-compat';\nimport type { RemoteComponentProps } from '#internal/shared/client/remote-component';\nimport {\n DEFAULT_ROUTE,\n loadRemoteComponent,\n loadStaticRemoteComponent,\n RUNTIME_WEBPACK,\n} from '#internal/shared/client/remote-component';\nimport type { MountOrUnmountFunction } from '#internal/shared/client/types';\nimport { attrToProp, escapeString } from '#internal/shared/utils';\n\n// patch react/jsx-runtime to support the shadowrootmode attribute on template elements\ndeclare module 'react/jsx-runtime' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace JSX {\n interface IntrinsicElements {\n template: {\n shadowrootmode?: 'open' | 'closed';\n id?: string;\n ref?: React.Ref<HTMLTemplateElement>;\n dangerouslySetInnerHTML?: {\n __html: string;\n };\n children?: React.ReactNode;\n };\n }\n }\n}\n\n// import { shared } from 'remote-components/shared/host';\nasync function tryImportShared() {\n try {\n const { shared } = await import('remote-components/shared/host/app');\n return shared;\n } catch {\n return {};\n }\n}\n\n/**\n * RemoteComponentClient - 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 RemoteComponentClient({\n url,\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 reset,\n type,\n children,\n}: RemoteComponentProps) {\n const remoteComponentId = useId();\n const [component, setComponent] = useState<React.ReactNode | Error>(null);\n const metadataRef = useRef<{\n name: string;\n bundle: string;\n route: string;\n url: string;\n loading: boolean;\n }>({\n name,\n bundle,\n route,\n url,\n loading: false,\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 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 =\n `__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)}` 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 // eslint-disable-next-line no-console\n console.error(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 // eslint-disable-next-line no-console\n console.error(e);\n }\n }),\n ).catch((e) => {\n // eslint-disable-next-line no-console\n console.error(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 (!metadataRef.current.loading &&\n !component &&\n (isolate === false || shadowRootRef.current)) ||\n metadataRef.current.url !== url ||\n metadataRef.current.name !== name ||\n metadataRef.current.bundle !== bundle ||\n metadataRef.current.route !== route\n ) {\n metadataRef.current = {\n name,\n bundle,\n route,\n url,\n loading: true,\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 new URL(url, location.origin),\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 // eslint-disable-next-line no-console\n console.error(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 // eslint-disable-next-line no-console\n console.error(e);\n setComponent(e as Error);\n });\n return;\n }\n\n const rscName = `__remote_components_rsc_${escapeString(new URL(url).href)}_${escapeString(name)}`;\n const result = await loadRemoteComponent({\n url: new URL(url, location.origin),\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\n return {\n 'next/router': routerImpl,\n ...shared,\n 'next/image': () =>\n Promise.resolve(imageImpl(Image.default, bundle)),\n 'next/dist/client/image-component': () =>\n Promise.resolve({ Image: imageImpl(Image.default, bundle) }),\n };\n })(),\n remoteShared,\n container: shadowRootRef.current,\n });\n metadataRef.current.loading = false;\n if (result.error) {\n setComponent(result.error);\n } else {\n setComponent(result.component);\n }\n }\n } catch (error: unknown) {\n metadataRef.current.loading = false;\n setComponent(error as Error);\n }\n });\n }, [\n url,\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 ]);\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 <>\n {(!nextData || nextData.buildId !== 'development') &&\n isolate !== false &&\n reset ? (\n <style data-remote-components-reset=\"\">{`:host { all: initial; }`}</style>\n ) : null}\n {links.map((link) => (\n <link\n key={JSON.stringify(link)}\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n data-wait={link.rel === 'stylesheet' && link.href ? '' : undefined}\n href={link.href ? new URL(link.href as string, url).href : undefined}\n />\n ))}\n {links\n .filter((link) => link.rel === 'stylesheet')\n .map((link) => (\n <link\n key={JSON.stringify(link)}\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n as=\"style\"\n fetchPriority=\"high\"\n href={\n link.href ? new URL(link.href as string, url).href : undefined\n }\n precedence={bundle}\n rel=\"preload\"\n />\n ))}\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.__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)} = 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(/[^a-zA-Z0-9]+/g, '_')}${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":";AAuYI,mBAII,KAJJ;AArYJ,YAAY,WAAW;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,SAAS,WAAW,kBAAkB;AAEtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,YAAY,oBAAoB;AAqBzC,eAAe,kBAAkB;AAC/B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,mCAAmC;AACnE,WAAO;AAAA,EACT,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAQO,SAAS,sBAAsB;AAAA,EACpC;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;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,oBAAoB,MAAM;AAChC,QAAM,CAAC,WAAW,YAAY,IAAI,SAAkC,IAAI;AACxE,QAAM,cAAc,OAMjB;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX,CAAC;AACD,QAAM,WAAW,OAAmC,IAAI;AACxD,QAAM,SAAS,OAAmC,IAAI;AACtD,QAAM,gCAAgC,OAG5B,IAAI;AAGd,MAAI,qBAAqB,OAAO;AAC9B,UAAM;AAAA,EACR;AAGA,QAAM,qBACH,CAAC,aACC,aACC,CAAC,YACD,SAAS,sBACT,OAAQ,UAA0C,SAChD;AAAA;AAAA;AAAA,EAIN,UAAU,YAAY;AAExB,QAAM,OAAO;AAKb,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QAAQ,oBAAC,cAAS,IAAI,GAAG,YAAY,KAAK,QAAQ,IAAK;AAAA,KACtE;AAEJ;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/host/app-router-compat.tsx"],"sourcesContent":["import type { default as ImageComponentType, ImageProps } from 'next/image';\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport type { NavigateOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime';\nimport { applyBundleUrlToImagePropsSrc } from '#internal/shared/client/polyfill';\n\nexport function imageImpl(\n ImageComponent: typeof ImageComponentType,\n bundle: string,\n) {\n const component = function RemoteImage(props: ImageProps) {\n return (\n <ImageComponent\n {...props}\n src={applyBundleUrlToImagePropsSrc(bundle, props.src)}\n />\n );\n };\n component.default = component;\n return component;\n}\n\nexport const routerImpl = async () => {\n const { useRouter } = await import('next/navigation');\n return Promise.resolve({\n useRouter: () => {\n const router = useRouter();\n const pathname = usePathname();\n const searchParams = useSearchParams();\n const query = Object.fromEntries(searchParams.entries());\n return {\n pathname,\n query,\n asPath: searchParams.toString()\n ? `${pathname}?${searchParams.toString()}`\n : pathname,\n push: (href: string, _: string, options?: NavigateOptions) => {\n router.push(href, options);\n return Promise.resolve(true);\n },\n replace: (href: string, _: string, options?: NavigateOptions) => {\n router.replace(href, options);\n return Promise.resolve(true);\n },\n refresh: () => Promise.resolve(router.refresh()),\n prefetch: async () => {\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.prefetch() in a remote component loaded in the Next.js App Router. prefetch() is a no-op in the App Router.',\n );\n return Promise.resolve();\n },\n back: () => {\n // there's no back() in the App Router\n if (typeof window !== 'undefined') {\n window.history.back();\n }\n },\n reload: () => {\n router.refresh();\n },\n beforePopState: () => {\n // there's no beforePopState() in the App Router\n },\n events: {\n on: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.on() in a remote component loaded in the Next.js App Router. events.on() is a no-op in the App Router.',\n );\n },\n off: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.off() in a remote component loaded in the Next.js App Router. events.off() is a no-op in the App Router.',\n );\n },\n emit: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.emit() in a remote component loaded in the Next.js App Router. events.emit() is a no-op in the App Router.',\n );\n },\n },\n };\n },\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWM;AAVN,wBAA6C;AAE7C,sBAA8C;AAEvC,SAAS,UACd,gBACA,QACA;AACA,QAAM,YAAY,SAAS,YAAY,OAAmB;AACxD,WACE;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACJ,SAAK,+CAA8B,QAAQ,MAAM,GAAG;AAAA;AAAA,IACtD;AAAA,EAEJ;AACA,YAAU,UAAU;AACpB,SAAO;AACT;AAEO,MAAM,aAAa,YAAY;AACpC,QAAM,EAAE,UAAU,IAAI,MAAM,OAAO,iBAAiB;AACpD,SAAO,QAAQ,QAAQ;AAAA,IACrB,WAAW,MAAM;AACf,YAAM,SAAS,UAAU;AACzB,YAAM,eAAW,+BAAY;AAC7B,YAAM,mBAAe,mCAAgB;AACrC,YAAM,QAAQ,OAAO,YAAY,aAAa,QAAQ,CAAC;AACvD,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA,QAAQ,aAAa,SAAS,IAC1B,GAAG,YAAY,aAAa,SAAS,MACrC;AAAA,QACJ,MAAM,CAAC,MAAc,GAAW,YAA8B;AAC5D,iBAAO,KAAK,MAAM,OAAO;AACzB,iBAAO,QAAQ,QAAQ,IAAI;AAAA,QAC7B;AAAA,QACA,SAAS,CAAC,MAAc,GAAW,YAA8B;AAC/D,iBAAO,QAAQ,MAAM,OAAO;AAC5B,iBAAO,QAAQ,QAAQ,IAAI;AAAA,QAC7B;AAAA,QACA,SAAS,MAAM,QAAQ,QAAQ,OAAO,QAAQ,CAAC;AAAA,QAC/C,UAAU,YAAY;AAEpB,kBAAQ;AAAA,YACN;AAAA,UACF;AACA,iBAAO,QAAQ,QAAQ;AAAA,QACzB;AAAA,QACA,MAAM,MAAM;AAEV,cAAI,OAAO,WAAW,aAAa;AACjC,mBAAO,QAAQ,KAAK;AAAA,UACtB;AAAA,QACF;AAAA,QACA,QAAQ,MAAM;AACZ,iBAAO,QAAQ;AAAA,QACjB;AAAA,QACA,gBAAgB,MAAM;AAAA,QAEtB;AAAA,QACA,QAAQ;AAAA,UACN,IAAI,MAAM;AAGR,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,UACA,KAAK,MAAM;AAGT,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,UACA,MAAM,MAAM;AAGV,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/next/host/app-router-compat.tsx"],"sourcesContent":["import type { NavigateOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime';\nimport type { default as ImageComponentType, ImageProps } from 'next/image';\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport { applyBundleUrlToImagePropsSrc } from '#internal/shared/client/polyfill';\n\nexport function imageImpl(\n ImageComponent: typeof ImageComponentType,\n bundle: string,\n) {\n const component = function RemoteImage(props: ImageProps) {\n return (\n <ImageComponent\n {...props}\n src={applyBundleUrlToImagePropsSrc(bundle, props.src)}\n />\n );\n };\n component.default = component;\n return component;\n}\n\nexport const routerImpl = async () => {\n const { useRouter } = await import('next/navigation');\n return Promise.resolve({\n useRouter: () => {\n const router = useRouter();\n const pathname = usePathname();\n const searchParams = useSearchParams();\n const query = Object.fromEntries(searchParams.entries());\n return {\n pathname,\n query,\n asPath: searchParams.toString()\n ? `${pathname}?${searchParams.toString()}`\n : pathname,\n push: (href: string, _: string, options?: NavigateOptions) => {\n router.push(href, options);\n return Promise.resolve(true);\n },\n replace: (href: string, _: string, options?: NavigateOptions) => {\n router.replace(href, options);\n return Promise.resolve(true);\n },\n refresh: () => Promise.resolve(router.refresh()),\n prefetch: async () => {\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.prefetch() in a remote component loaded in the Next.js App Router. prefetch() is a no-op in the App Router.',\n );\n return Promise.resolve();\n },\n back: () => {\n // there's no back() in the App Router\n if (typeof window !== 'undefined') {\n window.history.back();\n }\n },\n reload: () => {\n router.refresh();\n },\n beforePopState: () => {\n // there's no beforePopState() in the App Router\n },\n events: {\n on: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.on() in a remote component loaded in the Next.js App Router. events.on() is a no-op in the App Router.',\n );\n },\n off: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.off() in a remote component loaded in the Next.js App Router. events.off() is a no-op in the App Router.',\n );\n },\n emit: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.emit() in a remote component loaded in the Next.js App Router. events.emit() is a no-op in the App Router.',\n );\n },\n },\n };\n },\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWM;AATN,wBAA6C;AAC7C,sBAA8C;AAEvC,SAAS,UACd,gBACA,QACA;AACA,QAAM,YAAY,SAAS,YAAY,OAAmB;AACxD,WACE;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACJ,SAAK,+CAA8B,QAAQ,MAAM,GAAG;AAAA;AAAA,IACtD;AAAA,EAEJ;AACA,YAAU,UAAU;AACpB,SAAO;AACT;AAEO,MAAM,aAAa,YAAY;AACpC,QAAM,EAAE,UAAU,IAAI,MAAM,OAAO,iBAAiB;AACpD,SAAO,QAAQ,QAAQ;AAAA,IACrB,WAAW,MAAM;AACf,YAAM,SAAS,UAAU;AACzB,YAAM,eAAW,+BAAY;AAC7B,YAAM,mBAAe,mCAAgB;AACrC,YAAM,QAAQ,OAAO,YAAY,aAAa,QAAQ,CAAC;AACvD,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA,QAAQ,aAAa,SAAS,IAC1B,GAAG,YAAY,aAAa,SAAS,MACrC;AAAA,QACJ,MAAM,CAAC,MAAc,GAAW,YAA8B;AAC5D,iBAAO,KAAK,MAAM,OAAO;AACzB,iBAAO,QAAQ,QAAQ,IAAI;AAAA,QAC7B;AAAA,QACA,SAAS,CAAC,MAAc,GAAW,YAA8B;AAC/D,iBAAO,QAAQ,MAAM,OAAO;AAC5B,iBAAO,QAAQ,QAAQ,IAAI;AAAA,QAC7B;AAAA,QACA,SAAS,MAAM,QAAQ,QAAQ,OAAO,QAAQ,CAAC;AAAA,QAC/C,UAAU,YAAY;AAEpB,kBAAQ;AAAA,YACN;AAAA,UACF;AACA,iBAAO,QAAQ,QAAQ;AAAA,QACzB;AAAA,QACA,MAAM,MAAM;AAEV,cAAI,OAAO,WAAW,aAAa;AACjC,mBAAO,QAAQ,KAAK;AAAA,UACtB;AAAA,QACF;AAAA,QACA,QAAQ,MAAM;AACZ,iBAAO,QAAQ;AAAA,QACjB;AAAA,QACA,gBAAgB,MAAM;AAAA,QAEtB;AAAA,QACA,QAAQ;AAAA,UACN,IAAI,MAAM;AAGR,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,UACA,KAAK,MAAM;AAGT,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,UACA,MAAM,MAAM;AAGV,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import ImageComponentType, { ImageProps } from 'next/image';
3
2
  import { NavigateOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime';
3
+ import ImageComponentType, { ImageProps } from 'next/image';
4
4
 
5
5
  declare function imageImpl(ImageComponent: typeof ImageComponentType, bundle: string): {
6
6
  (props: ImageProps): react_jsx_runtime.JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/host/app-router-compat.tsx"],"sourcesContent":["import type { default as ImageComponentType, ImageProps } from 'next/image';\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport type { NavigateOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime';\nimport { applyBundleUrlToImagePropsSrc } from '#internal/shared/client/polyfill';\n\nexport function imageImpl(\n ImageComponent: typeof ImageComponentType,\n bundle: string,\n) {\n const component = function RemoteImage(props: ImageProps) {\n return (\n <ImageComponent\n {...props}\n src={applyBundleUrlToImagePropsSrc(bundle, props.src)}\n />\n );\n };\n component.default = component;\n return component;\n}\n\nexport const routerImpl = async () => {\n const { useRouter } = await import('next/navigation');\n return Promise.resolve({\n useRouter: () => {\n const router = useRouter();\n const pathname = usePathname();\n const searchParams = useSearchParams();\n const query = Object.fromEntries(searchParams.entries());\n return {\n pathname,\n query,\n asPath: searchParams.toString()\n ? `${pathname}?${searchParams.toString()}`\n : pathname,\n push: (href: string, _: string, options?: NavigateOptions) => {\n router.push(href, options);\n return Promise.resolve(true);\n },\n replace: (href: string, _: string, options?: NavigateOptions) => {\n router.replace(href, options);\n return Promise.resolve(true);\n },\n refresh: () => Promise.resolve(router.refresh()),\n prefetch: async () => {\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.prefetch() in a remote component loaded in the Next.js App Router. prefetch() is a no-op in the App Router.',\n );\n return Promise.resolve();\n },\n back: () => {\n // there's no back() in the App Router\n if (typeof window !== 'undefined') {\n window.history.back();\n }\n },\n reload: () => {\n router.refresh();\n },\n beforePopState: () => {\n // there's no beforePopState() in the App Router\n },\n events: {\n on: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.on() in a remote component loaded in the Next.js App Router. events.on() is a no-op in the App Router.',\n );\n },\n off: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.off() in a remote component loaded in the Next.js App Router. events.off() is a no-op in the App Router.',\n );\n },\n emit: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.emit() in a remote component loaded in the Next.js App Router. events.emit() is a no-op in the App Router.',\n );\n },\n },\n };\n },\n });\n};\n"],"mappings":"AAWM;AAVN,SAAS,aAAa,uBAAuB;AAE7C,SAAS,qCAAqC;AAEvC,SAAS,UACd,gBACA,QACA;AACA,QAAM,YAAY,SAAS,YAAY,OAAmB;AACxD,WACE;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACJ,KAAK,8BAA8B,QAAQ,MAAM,GAAG;AAAA;AAAA,IACtD;AAAA,EAEJ;AACA,YAAU,UAAU;AACpB,SAAO;AACT;AAEO,MAAM,aAAa,YAAY;AACpC,QAAM,EAAE,UAAU,IAAI,MAAM,OAAO,iBAAiB;AACpD,SAAO,QAAQ,QAAQ;AAAA,IACrB,WAAW,MAAM;AACf,YAAM,SAAS,UAAU;AACzB,YAAM,WAAW,YAAY;AAC7B,YAAM,eAAe,gBAAgB;AACrC,YAAM,QAAQ,OAAO,YAAY,aAAa,QAAQ,CAAC;AACvD,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA,QAAQ,aAAa,SAAS,IAC1B,GAAG,YAAY,aAAa,SAAS,MACrC;AAAA,QACJ,MAAM,CAAC,MAAc,GAAW,YAA8B;AAC5D,iBAAO,KAAK,MAAM,OAAO;AACzB,iBAAO,QAAQ,QAAQ,IAAI;AAAA,QAC7B;AAAA,QACA,SAAS,CAAC,MAAc,GAAW,YAA8B;AAC/D,iBAAO,QAAQ,MAAM,OAAO;AAC5B,iBAAO,QAAQ,QAAQ,IAAI;AAAA,QAC7B;AAAA,QACA,SAAS,MAAM,QAAQ,QAAQ,OAAO,QAAQ,CAAC;AAAA,QAC/C,UAAU,YAAY;AAEpB,kBAAQ;AAAA,YACN;AAAA,UACF;AACA,iBAAO,QAAQ,QAAQ;AAAA,QACzB;AAAA,QACA,MAAM,MAAM;AAEV,cAAI,OAAO,WAAW,aAAa;AACjC,mBAAO,QAAQ,KAAK;AAAA,UACtB;AAAA,QACF;AAAA,QACA,QAAQ,MAAM;AACZ,iBAAO,QAAQ;AAAA,QACjB;AAAA,QACA,gBAAgB,MAAM;AAAA,QAEtB;AAAA,QACA,QAAQ;AAAA,UACN,IAAI,MAAM;AAGR,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,UACA,KAAK,MAAM;AAGT,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,UACA,MAAM,MAAM;AAGV,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/next/host/app-router-compat.tsx"],"sourcesContent":["import type { NavigateOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime';\nimport type { default as ImageComponentType, ImageProps } from 'next/image';\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport { applyBundleUrlToImagePropsSrc } from '#internal/shared/client/polyfill';\n\nexport function imageImpl(\n ImageComponent: typeof ImageComponentType,\n bundle: string,\n) {\n const component = function RemoteImage(props: ImageProps) {\n return (\n <ImageComponent\n {...props}\n src={applyBundleUrlToImagePropsSrc(bundle, props.src)}\n />\n );\n };\n component.default = component;\n return component;\n}\n\nexport const routerImpl = async () => {\n const { useRouter } = await import('next/navigation');\n return Promise.resolve({\n useRouter: () => {\n const router = useRouter();\n const pathname = usePathname();\n const searchParams = useSearchParams();\n const query = Object.fromEntries(searchParams.entries());\n return {\n pathname,\n query,\n asPath: searchParams.toString()\n ? `${pathname}?${searchParams.toString()}`\n : pathname,\n push: (href: string, _: string, options?: NavigateOptions) => {\n router.push(href, options);\n return Promise.resolve(true);\n },\n replace: (href: string, _: string, options?: NavigateOptions) => {\n router.replace(href, options);\n return Promise.resolve(true);\n },\n refresh: () => Promise.resolve(router.refresh()),\n prefetch: async () => {\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.prefetch() in a remote component loaded in the Next.js App Router. prefetch() is a no-op in the App Router.',\n );\n return Promise.resolve();\n },\n back: () => {\n // there's no back() in the App Router\n if (typeof window !== 'undefined') {\n window.history.back();\n }\n },\n reload: () => {\n router.refresh();\n },\n beforePopState: () => {\n // there's no beforePopState() in the App Router\n },\n events: {\n on: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.on() in a remote component loaded in the Next.js App Router. events.on() is a no-op in the App Router.',\n );\n },\n off: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.off() in a remote component loaded in the Next.js App Router. events.off() is a no-op in the App Router.',\n );\n },\n emit: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.emit() in a remote component loaded in the Next.js App Router. events.emit() is a no-op in the App Router.',\n );\n },\n },\n };\n },\n });\n};\n"],"mappings":"AAWM;AATN,SAAS,aAAa,uBAAuB;AAC7C,SAAS,qCAAqC;AAEvC,SAAS,UACd,gBACA,QACA;AACA,QAAM,YAAY,SAAS,YAAY,OAAmB;AACxD,WACE;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACJ,KAAK,8BAA8B,QAAQ,MAAM,GAAG;AAAA;AAAA,IACtD;AAAA,EAEJ;AACA,YAAU,UAAU;AACpB,SAAO;AACT;AAEO,MAAM,aAAa,YAAY;AACpC,QAAM,EAAE,UAAU,IAAI,MAAM,OAAO,iBAAiB;AACpD,SAAO,QAAQ,QAAQ;AAAA,IACrB,WAAW,MAAM;AACf,YAAM,SAAS,UAAU;AACzB,YAAM,WAAW,YAAY;AAC7B,YAAM,eAAe,gBAAgB;AACrC,YAAM,QAAQ,OAAO,YAAY,aAAa,QAAQ,CAAC;AACvD,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA,QAAQ,aAAa,SAAS,IAC1B,GAAG,YAAY,aAAa,SAAS,MACrC;AAAA,QACJ,MAAM,CAAC,MAAc,GAAW,YAA8B;AAC5D,iBAAO,KAAK,MAAM,OAAO;AACzB,iBAAO,QAAQ,QAAQ,IAAI;AAAA,QAC7B;AAAA,QACA,SAAS,CAAC,MAAc,GAAW,YAA8B;AAC/D,iBAAO,QAAQ,MAAM,OAAO;AAC5B,iBAAO,QAAQ,QAAQ,IAAI;AAAA,QAC7B;AAAA,QACA,SAAS,MAAM,QAAQ,QAAQ,OAAO,QAAQ,CAAC;AAAA,QAC/C,UAAU,YAAY;AAEpB,kBAAQ;AAAA,YACN;AAAA,UACF;AACA,iBAAO,QAAQ,QAAQ;AAAA,QACzB;AAAA,QACA,MAAM,MAAM;AAEV,cAAI,OAAO,WAAW,aAAa;AACjC,mBAAO,QAAQ,KAAK;AAAA,UACtB;AAAA,QACF;AAAA,QACA,QAAQ,MAAM;AACZ,iBAAO,QAAQ;AAAA,QACjB;AAAA,QACA,gBAAgB,MAAM;AAAA,QAEtB;AAAA,QACA,QAAQ;AAAA,UACN,IAAI,MAAM;AAGR,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,UACA,KAAK,MAAM;AAGT,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,UACA,MAAM,MAAM;AAGV,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -32,8 +32,8 @@ __export(render_server_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(render_server_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
- var import_react = require("react");
36
35
  var import_work_async_storage = require("next/dist/server/app-render/work-async-storage.external");
36
+ var import_react = require("react");
37
37
  var import_render_client = require("#internal/next/remote/render-client");
38
38
  var import_error = require("#internal/shared/error");
39
39
  const SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/remote/render-server.tsx"],"sourcesContent":["import { Suspense } from 'react';\nimport { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport { RemoteComponentSharedRemote } from '#internal/next/remote/render-client';\nimport { RemoteComponentsError } from '#internal/shared/error';\nimport type { Manifest } from './types';\n\n// internal Next.js symbol to access the manifest which is stored in the global scope\nconst SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nasync function tryImport<T>(importer: () => Promise<T>) {\n try {\n return (await importer()) as T;\n } catch {\n return {} as T;\n }\n}\n\n// inject the RSC flight data into the HTML response using <script>\n// the RSC flight data is used to hydrate the remote component on the host\n// this approach is similar to an island architecture on the host\n// the remote component is static HTML until it is hydrated using this RSC flight data\nfunction RemoteComponentData({ name, data }: { name: string; data: string[] }) {\n return (\n <script id={`${name}_rsc`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''}self[\"${name}\"].push(${JSON.stringify(\n chunk,\n )});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\nexport interface RemoteComponentProps {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * RemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<RemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { RemoteComponent } from 'remote-components/next';\n *\n * export default function MyPage() {\n * return (\n * <RemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </RemoteComponent>\n * );\n * }\n * ```\n */\nexport async function RemoteComponent({\n name = '__vercel_remote_component',\n children,\n}: RemoteComponentProps): Promise<React.ReactElement> {\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? {\n page: '/',\n route: '/',\n };\n\n // get reference to the manifests from the global scope\n const manifests = (\n globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n }\n )[SERVER_ACTION_MANIFESTS_SINGLETON];\n const manifest = manifests.clientReferenceManifestsPerPage?.[route];\n\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n };\n\n // manually handle the internal Next.js manifest\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\n let clientModules = manifest?.clientModules ?? {};\n const ssrModuleMapping = { ...manifest?.ssrModuleMapping };\n\n // if the remote component is used in a hosting application, we need to mutate the module map to include the zone\n clientModules = Object.fromEntries(\n Object.entries(clientModules).map(([key, value]) => {\n // append a prefix to each entry in the module map to include the zone of the remote component\n const remoteId = `[${PROJECT_ID}] ${value.id}`;\n ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];\n // override the original id with the new remote id\n return [\n key,\n {\n ...value,\n id: remoteId,\n // prepend the current zone to the chunks to handle remote component chunk loading in Webpack\n // this is required to avoid loading the wrong chunk in the host application\n chunks: value.chunks.map((chunk) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [\n { renderToReadableStream: nextRenderToReadableStream },\n { renderToReadableStream: legacyRenderToReadableStream },\n ] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n const renderToReadableStream =\n nextRenderToReadableStream ?? legacyRenderToReadableStream;\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\n\n const data = [];\n const decoder = new TextDecoder();\n\n // convert the stream to an array for safe passing to the client\n for await (const chunk of stream as unknown as AsyncIterable<Uint8Array>) {\n data.push(decoder.decode(chunk));\n }\n\n const runtime = process.env.TURBOPACK ? 'turbopack' : 'webpack';\n const remoteComponentName = `${name}_${route.replace(/[/[\\].]/g, '_')}`;\n\n return (\n // wrap the remote component content into a div to know which part of the HTML belongs to the remote component\n <div\n data-bundle={PROJECT_ID}\n data-route={route}\n data-runtime={runtime}\n data-type=\"nextjs\"\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;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BAAqB;AAAA,UACvD,OAAO,UAAU,cAChB,4EACE;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,2BACE,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,gBAEvD,yBACE,iBAAiB,QAAS,MAAM,SAAS,KAAM;AAAA;AAAA,YAEnD;AAAA,YACA,4CAAC,yBAAS,UAAU,MAAO,UAAS;AAAA,aACtC,IAEA;AAAA,UAGF,4CAAC,uBAAoB,MAAY,MAAM,qBAAqB;AAAA;AAAA;AAAA,IAC9D;AAAA;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/next/remote/render-server.tsx"],"sourcesContent":["import { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport { Suspense } from 'react';\nimport { RemoteComponentSharedRemote } from '#internal/next/remote/render-client';\nimport { RemoteComponentsError } from '#internal/shared/error';\nimport type { Manifest } from './types';\n\n// internal Next.js symbol to access the manifest which is stored in the global scope\nconst SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nasync function tryImport<T>(importer: () => Promise<T>) {\n try {\n return (await importer()) as T;\n } catch {\n return {} as T;\n }\n}\n\n// inject the RSC flight data into the HTML response using <script>\n// the RSC flight data is used to hydrate the remote component on the host\n// this approach is similar to an island architecture on the host\n// the remote component is static HTML until it is hydrated using this RSC flight data\nfunction RemoteComponentData({ name, data }: { name: string; data: string[] }) {\n return (\n <script id={`${name}_rsc`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''}self[\"${name}\"].push(${JSON.stringify(\n chunk,\n )});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\nexport interface RemoteComponentProps {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * RemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<RemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { RemoteComponent } from 'remote-components/next';\n *\n * export default function MyPage() {\n * return (\n * <RemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </RemoteComponent>\n * );\n * }\n * ```\n */\nexport async function RemoteComponent({\n name = '__vercel_remote_component',\n children,\n}: RemoteComponentProps): Promise<React.ReactElement> {\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? {\n page: '/',\n route: '/',\n };\n\n // get reference to the manifests from the global scope\n const manifests = (\n globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n }\n )[SERVER_ACTION_MANIFESTS_SINGLETON];\n const manifest = manifests.clientReferenceManifestsPerPage?.[route];\n\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n };\n\n // manually handle the internal Next.js manifest\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\n let clientModules = manifest?.clientModules ?? {};\n const ssrModuleMapping = { ...manifest?.ssrModuleMapping };\n\n // if the remote component is used in a hosting application, we need to mutate the module map to include the zone\n clientModules = Object.fromEntries(\n Object.entries(clientModules).map(([key, value]) => {\n // append a prefix to each entry in the module map to include the zone of the remote component\n const remoteId = `[${PROJECT_ID}] ${value.id}`;\n ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];\n // override the original id with the new remote id\n return [\n key,\n {\n ...value,\n id: remoteId,\n // prepend the current zone to the chunks to handle remote component chunk loading in Webpack\n // this is required to avoid loading the wrong chunk in the host application\n chunks: value.chunks.map((chunk) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [\n { renderToReadableStream: nextRenderToReadableStream },\n { renderToReadableStream: legacyRenderToReadableStream },\n ] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n const renderToReadableStream =\n nextRenderToReadableStream ?? legacyRenderToReadableStream;\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\n\n const data = [];\n const decoder = new TextDecoder();\n\n // convert the stream to an array for safe passing to the client\n for await (const chunk of stream as unknown as AsyncIterable<Uint8Array>) {\n data.push(decoder.decode(chunk));\n }\n\n const runtime = process.env.TURBOPACK ? 'turbopack' : 'webpack';\n const remoteComponentName = `${name}_${route.replace(/[/[\\].]/g, '_')}`;\n\n return (\n // wrap the remote component content into a div to know which part of the HTML belongs to the remote component\n <div\n data-bundle={PROJECT_ID}\n data-route={route}\n data-runtime={runtime}\n data-type=\"nextjs\"\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BI;AA9BJ,gCAAiC;AACjC,mBAAyB;AACzB,2BAA4C;AAC5C,mBAAsC;AAItC,MAAM,oCAAoC,OAAO;AAAA,EAC/C;AACF;AAEA,MAAM,aACJ,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI;AAEd,eAAe,UAAa,UAA4B;AACtD,MAAI;AACF,WAAQ,MAAM,SAAS;AAAA,EACzB,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAMA,SAAS,oBAAoB,EAAE,MAAM,KAAK,GAAqC;AAC7E,SACE,4CAAC,YAAO,IAAI,GAAG,YACZ,eACE;AAAA,IACC,CAAC,OAAO;AAAA;AAAA,MAEN,GAAG,MAAM,IAAI,SAAS,gBAAgB,gBAAgB,WAAW,eAAe,KAAK;AAAA,QACnF;AAAA,MACF;AAAA;AAAA,EACJ,EACC,KAAK,IAAI,GACd;AAEJ;AAkCA,eAAsB,gBAAgB;AAAA,EACpC,OAAO;AAAA,EACP;AACF,GAAsD;AAEpD,QAAM,EAAE,MAAM,MAAM,IAAI,2CAAiB,SAAS,KAAK;AAAA,IACrD,MAAM;AAAA,IACN,OAAO;AAAA,EACT;AAGA,QAAM,YACJ,WAKA,iCAAiC;AACnC,QAAM,WAAW,UAAU,kCAAkC,KAAK;AAElE,QAAM,OAAO;AAQb,OAAK,iBAAiB,KAAK,kBAAkB,CAAC;AAC9C,OAAK,eAAe,IAAI,IAAI,KAAK,eAAe,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AAA,EACjC;AAEA,QAAM,UAAU,QAAQ,IAAI,YAAY,cAAc;AACtD,QAAM,sBAAsB,GAAG,QAAQ,MAAM,QAAQ,YAAY,GAAG;AAEpE;AAAA;AAAA,IAEE;AAAA,MAAC;AAAA;AAAA,QACC,eAAa;AAAA,QACb,cAAY;AAAA,QACZ,gBAAc;AAAA,QACd,aAAU;AAAA,QACV,IAAI,GAAG;AAAA,QAEP;AAAA,sDAAC,oDAA4B,MAAM,qBAAqB;AAAA,UACvD,OAAO,UAAU,cAChB,4EACE;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,2BACE,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,gBAEvD,yBACE,iBAAiB,QAAS,MAAM,SAAS,KAAM;AAAA;AAAA,YAEnD;AAAA,YACA,4CAAC,yBAAS,UAAU,MAAO,UAAS;AAAA,aACtC,IAEA;AAAA,UAGF,4CAAC,uBAAoB,MAAY,MAAM,qBAAqB;AAAA;AAAA;AAAA,IAC9D;AAAA;AAEJ;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { Suspense } from "react";
3
2
  import { workAsyncStorage } from "next/dist/server/app-render/work-async-storage.external";
3
+ import { Suspense } from "react";
4
4
  import { RemoteComponentSharedRemote } from "#internal/next/remote/render-client";
5
5
  import { RemoteComponentsError } from "#internal/shared/error";
6
6
  const SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/remote/render-server.tsx"],"sourcesContent":["import { Suspense } from 'react';\nimport { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport { RemoteComponentSharedRemote } from '#internal/next/remote/render-client';\nimport { RemoteComponentsError } from '#internal/shared/error';\nimport type { Manifest } from './types';\n\n// internal Next.js symbol to access the manifest which is stored in the global scope\nconst SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nasync function tryImport<T>(importer: () => Promise<T>) {\n try {\n return (await importer()) as T;\n } catch {\n return {} as T;\n }\n}\n\n// inject the RSC flight data into the HTML response using <script>\n// the RSC flight data is used to hydrate the remote component on the host\n// this approach is similar to an island architecture on the host\n// the remote component is static HTML until it is hydrated using this RSC flight data\nfunction RemoteComponentData({ name, data }: { name: string; data: string[] }) {\n return (\n <script id={`${name}_rsc`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''}self[\"${name}\"].push(${JSON.stringify(\n chunk,\n )});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\nexport interface RemoteComponentProps {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * RemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<RemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { RemoteComponent } from 'remote-components/next';\n *\n * export default function MyPage() {\n * return (\n * <RemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </RemoteComponent>\n * );\n * }\n * ```\n */\nexport async function RemoteComponent({\n name = '__vercel_remote_component',\n children,\n}: RemoteComponentProps): Promise<React.ReactElement> {\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? {\n page: '/',\n route: '/',\n };\n\n // get reference to the manifests from the global scope\n const manifests = (\n globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n }\n )[SERVER_ACTION_MANIFESTS_SINGLETON];\n const manifest = manifests.clientReferenceManifestsPerPage?.[route];\n\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n };\n\n // manually handle the internal Next.js manifest\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\n let clientModules = manifest?.clientModules ?? {};\n const ssrModuleMapping = { ...manifest?.ssrModuleMapping };\n\n // if the remote component is used in a hosting application, we need to mutate the module map to include the zone\n clientModules = Object.fromEntries(\n Object.entries(clientModules).map(([key, value]) => {\n // append a prefix to each entry in the module map to include the zone of the remote component\n const remoteId = `[${PROJECT_ID}] ${value.id}`;\n ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];\n // override the original id with the new remote id\n return [\n key,\n {\n ...value,\n id: remoteId,\n // prepend the current zone to the chunks to handle remote component chunk loading in Webpack\n // this is required to avoid loading the wrong chunk in the host application\n chunks: value.chunks.map((chunk) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [\n { renderToReadableStream: nextRenderToReadableStream },\n { renderToReadableStream: legacyRenderToReadableStream },\n ] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n const renderToReadableStream =\n nextRenderToReadableStream ?? legacyRenderToReadableStream;\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\n\n const data = [];\n const decoder = new TextDecoder();\n\n // convert the stream to an array for safe passing to the client\n for await (const chunk of stream as unknown as AsyncIterable<Uint8Array>) {\n data.push(decoder.decode(chunk));\n }\n\n const runtime = process.env.TURBOPACK ? 'turbopack' : 'webpack';\n const remoteComponentName = `${name}_${route.replace(/[/[\\].]/g, '_')}`;\n\n return (\n // wrap the remote component content into a div to know which part of the HTML belongs to the remote component\n <div\n data-bundle={PROJECT_ID}\n data-route={route}\n data-runtime={runtime}\n data-type=\"nextjs\"\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":"AA8BI,SAmKI,UAnKJ,KAmKI,YAnKJ;AA9BJ,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AACjC,SAAS,mCAAmC;AAC5C,SAAS,6BAA6B;AAItC,MAAM,oCAAoC,OAAO;AAAA,EAC/C;AACF;AAEA,MAAM,aACJ,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI;AAEd,eAAe,UAAa,UAA4B;AACtD,MAAI;AACF,WAAQ,MAAM,SAAS;AAAA,EACzB,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAMA,SAAS,oBAAoB,EAAE,MAAM,KAAK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src/next/remote/render-server.tsx"],"sourcesContent":["import { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport { Suspense } from 'react';\nimport { RemoteComponentSharedRemote } from '#internal/next/remote/render-client';\nimport { RemoteComponentsError } from '#internal/shared/error';\nimport type { Manifest } from './types';\n\n// internal Next.js symbol to access the manifest which is stored in the global scope\nconst SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nasync function tryImport<T>(importer: () => Promise<T>) {\n try {\n return (await importer()) as T;\n } catch {\n return {} as T;\n }\n}\n\n// inject the RSC flight data into the HTML response using <script>\n// the RSC flight data is used to hydrate the remote component on the host\n// this approach is similar to an island architecture on the host\n// the remote component is static HTML until it is hydrated using this RSC flight data\nfunction RemoteComponentData({ name, data }: { name: string; data: string[] }) {\n return (\n <script id={`${name}_rsc`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''}self[\"${name}\"].push(${JSON.stringify(\n chunk,\n )});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\nexport interface RemoteComponentProps {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * RemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<RemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { RemoteComponent } from 'remote-components/next';\n *\n * export default function MyPage() {\n * return (\n * <RemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </RemoteComponent>\n * );\n * }\n * ```\n */\nexport async function RemoteComponent({\n name = '__vercel_remote_component',\n children,\n}: RemoteComponentProps): Promise<React.ReactElement> {\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? {\n page: '/',\n route: '/',\n };\n\n // get reference to the manifests from the global scope\n const manifests = (\n globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n }\n )[SERVER_ACTION_MANIFESTS_SINGLETON];\n const manifest = manifests.clientReferenceManifestsPerPage?.[route];\n\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n };\n\n // manually handle the internal Next.js manifest\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\n let clientModules = manifest?.clientModules ?? {};\n const ssrModuleMapping = { ...manifest?.ssrModuleMapping };\n\n // if the remote component is used in a hosting application, we need to mutate the module map to include the zone\n clientModules = Object.fromEntries(\n Object.entries(clientModules).map(([key, value]) => {\n // append a prefix to each entry in the module map to include the zone of the remote component\n const remoteId = `[${PROJECT_ID}] ${value.id}`;\n ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];\n // override the original id with the new remote id\n return [\n key,\n {\n ...value,\n id: remoteId,\n // prepend the current zone to the chunks to handle remote component chunk loading in Webpack\n // this is required to avoid loading the wrong chunk in the host application\n chunks: value.chunks.map((chunk) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [\n { renderToReadableStream: nextRenderToReadableStream },\n { renderToReadableStream: legacyRenderToReadableStream },\n ] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n const renderToReadableStream =\n nextRenderToReadableStream ?? legacyRenderToReadableStream;\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\n\n const data = [];\n const decoder = new TextDecoder();\n\n // convert the stream to an array for safe passing to the client\n for await (const chunk of stream as unknown as AsyncIterable<Uint8Array>) {\n data.push(decoder.decode(chunk));\n }\n\n const runtime = process.env.TURBOPACK ? 'turbopack' : 'webpack';\n const remoteComponentName = `${name}_${route.replace(/[/[\\].]/g, '_')}`;\n\n return (\n // wrap the remote component content into a div to know which part of the HTML belongs to the remote component\n <div\n data-bundle={PROJECT_ID}\n data-route={route}\n data-runtime={runtime}\n data-type=\"nextjs\"\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":"AA8BI,SAmKI,UAnKJ,KAmKI,YAnKJ;AA9BJ,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;AACzB,SAAS,mCAAmC;AAC5C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