remote-components 0.3.6 → 0.4.0

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 (126) hide show
  1. package/dist/{chunk-6IUP26UK.cjs → chunk-42TVDI3G.cjs} +5 -4
  2. package/dist/chunk-42TVDI3G.cjs.map +1 -0
  3. package/dist/chunk-5KTAEO52.cjs +28 -0
  4. package/dist/chunk-5KTAEO52.cjs.map +1 -0
  5. package/dist/{chunk-42N2ZLE2.js → chunk-5WL3FP4V.js} +6 -6
  6. package/dist/{chunk-ZPMTZ3KJ.js → chunk-AKOMV2UF.js} +4 -3
  7. package/dist/chunk-AKOMV2UF.js.map +1 -0
  8. package/dist/{chunk-ER73O65F.cjs → chunk-AYC2AWUG.cjs} +23 -23
  9. package/dist/{chunk-KEPHL25S.js → chunk-D5GNZB6O.js} +2 -1
  10. package/dist/chunk-D5GNZB6O.js.map +1 -0
  11. package/dist/{chunk-F44NODUS.cjs → chunk-EYALF655.cjs} +26 -26
  12. package/dist/{chunk-XCFYWSLD.cjs → chunk-JJTCFQHE.cjs} +31 -19
  13. package/dist/chunk-JJTCFQHE.cjs.map +1 -0
  14. package/dist/{chunk-OO4AMJWO.js → chunk-LQ7VQ74E.js} +2 -2
  15. package/dist/{chunk-2VQGCACH.js → chunk-MKO52FRO.js} +30 -18
  16. package/dist/chunk-MKO52FRO.js.map +1 -0
  17. package/dist/{chunk-KYJWRZ2B.js → chunk-N3KPUFOB.js} +3 -3
  18. package/dist/chunk-N3SQTOSE.cjs +25 -0
  19. package/dist/chunk-N3SQTOSE.cjs.map +1 -0
  20. package/dist/{chunk-W5ESPGHH.js → chunk-NN5V3FVD.js} +27 -15
  21. package/dist/chunk-NN5V3FVD.js.map +1 -0
  22. package/dist/chunk-RHGEBXPL.js +25 -0
  23. package/dist/chunk-RHGEBXPL.js.map +1 -0
  24. package/dist/{chunk-R4QFK5TN.cjs → chunk-RLI4YTBJ.cjs} +20 -4
  25. package/dist/chunk-RLI4YTBJ.cjs.map +1 -0
  26. package/dist/{chunk-HNZVEIKN.js → chunk-SAGYPGIQ.js} +18 -2
  27. package/dist/chunk-SAGYPGIQ.js.map +1 -0
  28. package/dist/chunk-STIJO4AG.js +28 -0
  29. package/dist/chunk-STIJO4AG.js.map +1 -0
  30. package/dist/{chunk-CREXMFMF.cjs → chunk-TZT7DLO5.cjs} +4 -4
  31. package/dist/{chunk-KKBEMQU7.cjs → chunk-Y4GMYUJT.cjs} +41 -29
  32. package/dist/chunk-Y4GMYUJT.cjs.map +1 -0
  33. package/dist/{chunk-7MVFHOIP.cjs → chunk-Z2SLBFQL.cjs} +2 -1
  34. package/dist/chunk-Z2SLBFQL.cjs.map +1 -0
  35. package/dist/config/nextjs.cjs +7 -12
  36. package/dist/config/nextjs.cjs.map +1 -1
  37. package/dist/config/nextjs.js +4 -9
  38. package/dist/config/nextjs.js.map +1 -1
  39. package/dist/host/html.cjs +29 -28
  40. package/dist/host/html.cjs.map +1 -1
  41. package/dist/host/html.js +12 -11
  42. package/dist/host/html.js.map +1 -1
  43. package/dist/host/navigation.cjs +8 -0
  44. package/dist/host/navigation.d.ts +30 -0
  45. package/dist/host/navigation.js +8 -0
  46. package/dist/host/nextjs/app/client-only.cjs +16 -14
  47. package/dist/host/nextjs/app/client-only.cjs.map +1 -1
  48. package/dist/host/nextjs/app/client-only.d.ts +2 -1
  49. package/dist/host/nextjs/app/client-only.js +11 -9
  50. package/dist/host/nextjs/app/client-only.js.map +1 -1
  51. package/dist/host/react.cjs +14 -10
  52. package/dist/host/react.d.ts +2 -1
  53. package/dist/host/react.js +15 -11
  54. package/dist/{index-4c65355c.d.ts → index-d2ce8a3f.d.ts} +22 -2
  55. package/dist/internal/config/webpack/next-client-pages-loader.cjs +27 -15
  56. package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
  57. package/dist/internal/config/webpack/next-client-pages-loader.d.ts +3 -5
  58. package/dist/internal/config/webpack/next-client-pages-loader.js +27 -15
  59. package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
  60. package/dist/internal/host/nextjs/app-client.d.ts +1 -1
  61. package/dist/internal/host/react/context.d.ts +2 -2
  62. package/dist/internal/host/shared/navigate-event.cjs +51 -0
  63. package/dist/internal/host/shared/navigate-event.cjs.map +1 -0
  64. package/dist/internal/host/shared/navigate-event.d.ts +21 -0
  65. package/dist/internal/host/shared/navigate-event.js +26 -0
  66. package/dist/internal/host/shared/navigate-event.js.map +1 -0
  67. package/dist/internal/host/shared/pipeline.d.ts +2 -2
  68. package/dist/internal/host/shared/polyfill.cjs +14 -0
  69. package/dist/internal/host/shared/polyfill.cjs.map +1 -1
  70. package/dist/internal/host/shared/polyfill.js +16 -0
  71. package/dist/internal/host/shared/polyfill.js.map +1 -1
  72. package/dist/internal/runtime/loaders/component-loader.d.ts +2 -2
  73. package/dist/internal/runtime/loaders/script-loader.cjs +2 -1
  74. package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -1
  75. package/dist/internal/runtime/loaders/script-loader.js +2 -1
  76. package/dist/internal/runtime/loaders/script-loader.js.map +1 -1
  77. package/dist/internal/runtime/loaders/static-loader.d.ts +2 -1
  78. package/dist/internal/runtime/namespace.cjs +1 -0
  79. package/dist/internal/runtime/namespace.cjs.map +1 -1
  80. package/dist/internal/runtime/namespace.d.ts +2 -1
  81. package/dist/internal/runtime/namespace.js +1 -0
  82. package/dist/internal/runtime/namespace.js.map +1 -1
  83. package/dist/internal/runtime/types.d.ts +2 -1
  84. package/dist/navigate-event-baee0b63.d.ts +14 -0
  85. package/dist/remote/html.cjs +1 -1
  86. package/dist/remote/html.js +1 -1
  87. package/dist/{script-6W5JRBZK.cjs → script-D5AD7HLV.cjs} +4 -4
  88. package/dist/{script-IFEBOLIA.js → script-VPOI7ARP.js} +3 -3
  89. package/dist/{server-handoff-ce13bebc.d.ts → server-handoff-8c89b856.d.ts} +2 -2
  90. package/dist/{static-loader-X4TSF5KW.js → static-loader-OHSAUD62.js} +3 -3
  91. package/dist/static-loader-OHSAUD62.js.map +1 -0
  92. package/dist/static-loader-UDIXK5MV.cjs +11 -0
  93. package/dist/static-loader-UDIXK5MV.cjs.map +1 -0
  94. package/dist/{turbopack-NPGO3MWS.js → turbopack-DK6L7P3J.js} +6 -5
  95. package/dist/{turbopack-NPGO3MWS.js.map → turbopack-DK6L7P3J.js.map} +1 -1
  96. package/dist/{turbopack-WRMKPNN4.cjs → turbopack-PSD4THQE.cjs} +13 -12
  97. package/dist/turbopack-PSD4THQE.cjs.map +1 -0
  98. package/dist/{types-59251814.d.ts → types-8b0edd78.d.ts} +7 -0
  99. package/dist/{webpack-DUBHPYD6.js → webpack-KSDNIXMS.js} +6 -5
  100. package/dist/{webpack-DUBHPYD6.js.map → webpack-KSDNIXMS.js.map} +1 -1
  101. package/dist/{webpack-KSCMCL7M.cjs → webpack-SIFRCBIN.cjs} +13 -12
  102. package/dist/webpack-SIFRCBIN.cjs.map +1 -0
  103. package/package.json +9 -1
  104. package/dist/chunk-2VQGCACH.js.map +0 -1
  105. package/dist/chunk-6IUP26UK.cjs.map +0 -1
  106. package/dist/chunk-7MVFHOIP.cjs.map +0 -1
  107. package/dist/chunk-HNZVEIKN.js.map +0 -1
  108. package/dist/chunk-KEPHL25S.js.map +0 -1
  109. package/dist/chunk-KKBEMQU7.cjs.map +0 -1
  110. package/dist/chunk-R4QFK5TN.cjs.map +0 -1
  111. package/dist/chunk-W5ESPGHH.js.map +0 -1
  112. package/dist/chunk-XCFYWSLD.cjs.map +0 -1
  113. package/dist/chunk-ZPMTZ3KJ.js.map +0 -1
  114. package/dist/static-loader-ZYD5BO4D.cjs +0 -11
  115. package/dist/turbopack-WRMKPNN4.cjs.map +0 -1
  116. package/dist/webpack-KSCMCL7M.cjs.map +0 -1
  117. /package/dist/{chunk-42N2ZLE2.js.map → chunk-5WL3FP4V.js.map} +0 -0
  118. /package/dist/{chunk-ER73O65F.cjs.map → chunk-AYC2AWUG.cjs.map} +0 -0
  119. /package/dist/{chunk-F44NODUS.cjs.map → chunk-EYALF655.cjs.map} +0 -0
  120. /package/dist/{chunk-OO4AMJWO.js.map → chunk-LQ7VQ74E.js.map} +0 -0
  121. /package/dist/{chunk-KYJWRZ2B.js.map → chunk-N3KPUFOB.js.map} +0 -0
  122. /package/dist/{chunk-CREXMFMF.cjs.map → chunk-TZT7DLO5.cjs.map} +0 -0
  123. /package/dist/{static-loader-ZYD5BO4D.cjs.map → host/navigation.cjs.map} +0 -0
  124. /package/dist/{static-loader-X4TSF5KW.js.map → host/navigation.js.map} +0 -0
  125. /package/dist/{script-6W5JRBZK.cjs.map → script-D5AD7HLV.cjs.map} +0 -0
  126. /package/dist/{script-IFEBOLIA.js.map → script-VPOI7ARP.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/config/webpack/apply-shared-modules.ts","../src/config/webpack/next-client-pages-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;AASA,IAAM,wBACJ;AAEK,SAAS,mBACd,QACA,SACA;AACA;AAAA,IACE;AAAA,IACA,0CAA0C;AAAA,EAC5C;AACA;AAAA,IACE;AAAA,IACA,8BAA8B,OAAO,KAAK,OAAO;AAAA,EACnD;AAGA,QAAM,OAAO;AAab,QAAM,QAAQ,SAAS,MAAM;AAI7B,QAAM,gBACJ,OAAO,kBAAkB,KAAK,6BAA6B,MAAM;AAEnE,MAAI,eAAe;AACjB,UAAM,cAAc,OAAO;AAAA,MACzB,KAAK,gCAAgC,MAAM,KAAK,cAAc,KAAK,CAAC;AAAA,IACtE;AACA;AAAA,MACE;AAAA,MACA,sCAAsC,YAAY;AAAA,IACpD;AAGA,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AAClD,YAAM,WAAW,YAAY,OAAO,CAAC,MAAM,MAAM,GAAG;AACpD,YAAM,MACJ,SAAS,SAAS,IACd,WACA,YAAY,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC;AAE/C,UAAI,IAAI,WAAW,GAAG;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GAAG;AAEpB,QAAI,CAAC,SAAS,MAAM,GAAG;AAErB,YAAM,QAAQ;AACd,aAAO,KAAK,KAAK,6BAA6B,MAAM,GAAG,KAAK,CAAC,CAAC,EAC3D,OAAO,CAAC,OAAO,MAAM,KAAK,EAAE,CAAC,EAC7B,QAAQ,CAAC,OAAO;AACf,aAAK,6BAA6B,MAAM,IAAI,EAAE;AAAA,MAChD,CAAC;AAEH,aAAO,KAAK,KAAK,gCAAgC,MAAM,KAAK,CAAC,CAAC,EAC3D,OAAO,CAAC,SAAS,MAAM,KAAK,IAAI,CAAC,EACjC,QAAQ,CAAC,SAAS;AACjB,cAAM,KAAK,KAAK,gCAAgC,MAAM,IAAI,IAAI;AAC9D,YAAI,IAAI;AACN,eAAK,6BAA6B,MAAM,IAAI,EAAE;AAAA,QAChD;AAAA,MACF,CAAC;AAEH,YAAM,WAAW,CAAC;AAClB,UAAI,OAAO,QAAQ;AACnB,aAAO,QAAQ,SAAS,YAAY;AAClC,iBAAS,KAAK,IAAI;AAClB,aAAK,OAAO;AACZ,eAAO,QAAQ;AAAA,MACjB;AACA,eAAS,MAAM,IAAI;AAAA,IACrB;AAEA,mBAAe;AAGf,WAAO,KAAK;AACZ,SAAK,WAAW;AAGhB,QAAI,iBAAiB;AACnB,sBAAgB,YAAY,YAAY,eAAe;AAAA,IACzD;AAEA,YAAQ,OAAO;AACf,eAAW,OAAO;AAElB,UAAM,SAAS,EAAE,WAAW,IAAI;AAChC,OAAG,mBAAmB,QAAQ,IAAI;AAClC,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,WAAW,MAAM,KAAK,KAAK;AACtC","sourcesContent":["// Webpack shared module patching\n// used in multiple remote component host types\n// multiple host types includes: HTML custom element for remote components and Next.js host application\n// we are using this shared function to patch a Webpack module map\n// to use shared modules between the host application and the remote component\n\nimport { getScope } from '#internal/runtime/turbopack/remote-scope';\nimport { logDebug, logWarn } from '#internal/utils/logger';\n\nconst DEDUPLICATION_SKIPPED =\n 'shared module deduplication skipped. The remote may load its own copy of shared dependencies.';\n\nexport function applySharedModules(\n bundle: string,\n resolve: Record<string, unknown>,\n) {\n logDebug(\n 'SharedModules',\n `applySharedModules called for bundle: \"${bundle}\"`,\n );\n logDebug(\n 'SharedModules',\n `Shared modules to resolve: ${Object.keys(resolve)}`,\n );\n\n // make a typed reference to the global scope\n const self = globalThis as typeof globalThis & {\n // webpack remote module loading function scoped for each bundle\n __remote_webpack_require__?: Record<\n string,\n ((remoteId: string) => unknown) & {\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n }\n >;\n // webpack module map for each bundle used in production builds\n __remote_webpack_module_map__?: Record<string, Record<string, number>>;\n } & Record<string, string[]>;\n\n // Prefer scope-based access when available.\n const scope = getScope(bundle);\n // @legacy(v0.3.4) — fall back to global __remote_webpack_require__ for hosts that\n // haven't run setupWebpackRuntime yet (e.g. HTML host's inline path).\n // Remove once all host types go through the shared pipeline (Phase 5).\n const webpackBundle =\n scope?.webpackRequire ?? self.__remote_webpack_require__?.[bundle];\n\n if (webpackBundle) {\n const modulePaths = Object.keys(\n self.__remote_webpack_module_map__?.[bundle] ?? webpackBundle.m ?? {},\n );\n logDebug(\n 'SharedModules',\n `Available module paths for bundle \"${bundle}\": ${modulePaths}`,\n );\n\n // patch all modules in the bundle to use the shared modules\n for (const [key, value] of Object.entries(resolve)) {\n const exactIds = modulePaths.filter((p) => p === key);\n const ids =\n exactIds.length > 0\n ? exactIds\n : modulePaths.filter((p) => p.includes(key));\n\n if (ids.length === 0) {\n logDebug(\n 'SharedModules',\n `No matching module path found for shared module \"${key}\"`,\n );\n }\n\n for (const id of ids) {\n if (webpackBundle.m) {\n // if we have a module map, we need to use the mapped id\n // this is required for production builds where the module ids are module id numbers\n const resolvedId = self.__remote_webpack_module_map__?.[bundle]?.[id]\n ? `${self.__remote_webpack_module_map__[bundle][id]}`\n : id;\n if (resolvedId !== id) {\n logDebug(\n 'SharedModules',\n `Mapped module id: \"${id}\" -> \"${resolvedId}\"`,\n );\n }\n // create a mock module which exports the shared module\n webpackBundle.m[resolvedId] = (module) => {\n module.exports = value;\n };\n } else {\n logWarn(\n 'SharedModules',\n `webpackBundle.m is not available for bundle \"${bundle}\" — ${DEDUPLICATION_SKIPPED}`,\n );\n }\n }\n }\n } else {\n logWarn(\n 'SharedModules',\n `No webpack require found for bundle \"${bundle}\" — ${DEDUPLICATION_SKIPPED}`,\n );\n logDebug(\n 'SharedModules',\n `Available bundles: ${Object.keys(self.__remote_webpack_require__ ?? {})}`,\n );\n }\n}\n","import { getNamespace } from '#internal/runtime/namespace';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\n// module loader for Next.js Pages Router\nexport function nextClientPagesLoader(\n bundle: string,\n route: string,\n styleContainer: HTMLHeadElement | ShadowRoot | null = document.head,\n) {\n // make a typed reference to the global scope\n const self = globalThis as typeof globalThis & {\n // webpack remote module loading function scoped for each bundle\n __remote_webpack_require__?: Record<\n string,\n ((remoteId: string | number) => unknown) & {\n c?: Record<\n string | number,\n { id: string; parents: string[]; children: string[] }\n >;\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n type?: 'turbopack' | 'webpack';\n }\n >;\n // webpack module map for each bundle used in production builds\n __remote_webpack_module_map__?: Record<string, Record<string, number>>;\n // Next.js client pages loader reference storage\n __NEXT_P?: [\n (\n | [\n string,\n () => { default?: React.ComponentType<Record<string, unknown>> },\n ]\n | undefined\n ),\n (\n | [\n string,\n () => {\n default?: React.ComponentType<\n {\n Component: React.ComponentType<Record<string, unknown>>;\n } & Record<string, unknown>\n >;\n },\n ]\n | undefined\n ),\n (\n | [\n string,\n () => {\n default?: React.ComponentType<\n {\n Component: React.ComponentType<Record<string, unknown>>;\n } & Record<string, unknown>\n >;\n },\n ]\n | undefined\n ),\n ];\n };\n\n const ns = getNamespace();\n ns.pageComponentCache ??= {};\n const cacheKey = `${bundle}:${route}`;\n\n // Applies the cached CSS for `bundle` into the caller's styleContainer.\n // Mirrors the final CSS-attach step of the fresh-load path so that cache\n // hits and additional host instances (each with their own shadow root)\n // still receive the styles.\n const applyBundleCss = () => {\n const elements = ns.cssCache[bundle] ?? [];\n if (styleContainer) {\n for (const el of elements) {\n styleContainer.appendChild(el.cloneNode(true));\n }\n } else {\n for (const el of elements) {\n document.head.appendChild(el);\n }\n }\n };\n\n // On repeat loads (e.g. after history.back()) the next-client-pages-loader\n // chunk is already cached by webpack and its factory won't re-run, so\n // __NEXT_P wouldn't be populated. Reuse the Component/App extracted on the\n // first load, but still run the CSS attach below because the caller may be\n // a different host instance with its own styleContainer.\n const cachedEntry = ns.pageComponentCache[cacheKey];\n if (cachedEntry) {\n applyBundleCss();\n return cachedEntry;\n }\n\n // temporarily remove the original Next.js CSS loader\n const nextCssOriginal = document.querySelector(\n `[id=\"__next_css__DO_NOT_USE__\"]:not([data-bundle=\"${bundle}\"][data-route=\"${route}\"])`,\n );\n if (nextCssOriginal) {\n nextCssOriginal.parentNode?.removeChild(nextCssOriginal);\n }\n\n // create a new Next.js CSS loader element\n const nextCss = document.createElement('noscript');\n nextCss.id = '__next_css__DO_NOT_USE__';\n nextCss.setAttribute('data-bundle', bundle);\n nextCss.setAttribute('data-route', route);\n const nextCssEnd = document.createElement('noscript');\n nextCssEnd.id = '__next_css__DO_NOT_USE_END__';\n nextCssEnd.setAttribute('data-bundle', bundle);\n nextCssEnd.setAttribute('data-route', route);\n document.head.appendChild(nextCssEnd);\n document.head.appendChild(nextCss);\n\n // find the page component loader chunk\n const componentLoaderChunk =\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=${encodeURIComponent(route)}!`),\n ) ??\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n self.__remote_webpack_module_map__?.[bundle]?.[\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=${encodeURIComponent(route)}!`),\n ) ??\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n ''\n ] ??\n -1;\n\n // find the app loader chunk\n const appLoaderChunk =\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=%2F_app`),\n ) ??\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n self.__remote_webpack_module_map__?.[bundle]?.[\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=%2F_app`),\n ) ??\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n ''\n ] ??\n -1;\n\n // if we didn't find the component loader or app loader, throw an error\n if (!(componentLoaderChunk && appLoaderChunk)) {\n throw new RemoteComponentsError(\n `Next.js client pages loader not found in bundle \"${bundle}\".`,\n );\n }\n\n // temporarily store the original __NEXT_P reference\n // this is required to avoid conflicts with the Next.js client pages loader\n // which uses the same global variable to store the page components\n const __NEXT_P_ORIGINAL = self.__NEXT_P;\n const selfOriginal = self;\n delete selfOriginal.__NEXT_P;\n\n // load the component and app loader chunks\n self.__remote_webpack_require__?.[bundle]?.(\n self.__remote_webpack_require__[bundle].type !== 'turbopack'\n ? componentLoaderChunk\n : `[${bundle}] ${componentLoaderChunk}`,\n );\n if (\n typeof appLoaderChunk === 'string' ||\n (typeof appLoaderChunk === 'number' && appLoaderChunk !== -1)\n ) {\n self.__remote_webpack_require__?.[bundle]?.(\n self.__remote_webpack_require__[bundle].type !== 'turbopack'\n ? appLoaderChunk\n : `[${bundle}] ${appLoaderChunk}`,\n );\n }\n\n // if we have the __NEXT_P global variable, we can extract the component and app\n if (self.__NEXT_P) {\n const [, componentLoader] = self.__NEXT_P[0] ?? [\n undefined,\n () => ({ default: null }),\n ];\n const [, appLoader] = self.__NEXT_P[2] ?? [\n undefined,\n () => ({\n default: null,\n }),\n ];\n const { default: Component = null } = componentLoader();\n const { default: App = null } = appLoader();\n\n const cssCache = ns.cssCache;\n\n if (!cssCache[bundle]) {\n // load the CSS files from the remote bundle\n const cssRE = /\\.s?css$/;\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {})\n .filter((id) => cssRE.test(id))\n .forEach((id) => {\n self.__remote_webpack_require__?.[bundle]?.(id);\n });\n\n Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {})\n .filter((path) => cssRE.test(path))\n .forEach((path) => {\n const id = self.__remote_webpack_module_map__?.[bundle]?.[path];\n if (id) {\n self.__remote_webpack_require__?.[bundle]?.(id);\n }\n });\n\n const elements = [];\n let node = nextCss.previousSibling;\n while (node && node !== nextCssEnd) {\n elements.push(node);\n node.remove();\n node = nextCss.previousSibling;\n }\n cssCache[bundle] = elements;\n }\n\n applyBundleCss();\n\n // restore the original __NEXT_P reference\n delete self.__NEXT_P;\n self.__NEXT_P = __NEXT_P_ORIGINAL;\n\n // restore the original Next.js CSS loader\n if (nextCssOriginal) {\n nextCssOriginal.parentNode?.appendChild(nextCssOriginal);\n }\n\n nextCss.remove();\n nextCssEnd.remove();\n\n const result = { Component, App };\n ns.pageComponentCache[cacheKey] = result;\n return result;\n }\n\n return { Component: null, App: null };\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getNamespace
3
- } from "./chunk-KEPHL25S.js";
3
+ } from "./chunk-D5GNZB6O.js";
4
4
  import {
5
5
  logError,
6
6
  warnCrossOriginFetchError
@@ -152,4 +152,4 @@ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
152
152
  export {
153
153
  loadStaticRemoteComponent
154
154
  };
155
- //# sourceMappingURL=chunk-OO4AMJWO.js.map
155
+ //# sourceMappingURL=chunk-LQ7VQ74E.js.map
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  getScope
3
- } from "./chunk-HNZVEIKN.js";
3
+ } from "./chunk-SAGYPGIQ.js";
4
4
  import {
5
5
  getNamespace
6
- } from "./chunk-KEPHL25S.js";
6
+ } from "./chunk-D5GNZB6O.js";
7
7
  import {
8
8
  RemoteComponentsError,
9
9
  logDebug,
@@ -76,6 +76,26 @@ function applySharedModules(bundle, resolve) {
76
76
  // src/config/webpack/next-client-pages-loader.ts
77
77
  function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
78
78
  const self = globalThis;
79
+ const ns = getNamespace();
80
+ ns.pageComponentCache ??= {};
81
+ const cacheKey = `${bundle}:${route}`;
82
+ const applyBundleCss = () => {
83
+ const elements = ns.cssCache[bundle] ?? [];
84
+ if (styleContainer) {
85
+ for (const el of elements) {
86
+ styleContainer.appendChild(el.cloneNode(true));
87
+ }
88
+ } else {
89
+ for (const el of elements) {
90
+ document.head.appendChild(el);
91
+ }
92
+ }
93
+ };
94
+ const cachedEntry = ns.pageComponentCache[cacheKey];
95
+ if (cachedEntry) {
96
+ applyBundleCss();
97
+ return cachedEntry;
98
+ }
79
99
  const nextCssOriginal = document.querySelector(
80
100
  `[id="__next_css__DO_NOT_USE__"]:not([data-bundle="${bundle}"][data-route="${route}"])`
81
101
  );
@@ -137,9 +157,9 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
137
157
  default: null
138
158
  })
139
159
  ];
140
- const { default: Component } = componentLoader();
141
- const { default: App } = appLoader();
142
- const cssCache = getNamespace().cssCache;
160
+ const { default: Component = null } = componentLoader();
161
+ const { default: App = null } = appLoader();
162
+ const cssCache = ns.cssCache;
143
163
  if (!cssCache[bundle]) {
144
164
  const cssRE = /\.s?css$/;
145
165
  Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).filter((id) => cssRE.test(id)).forEach((id) => {
@@ -160,17 +180,7 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
160
180
  }
161
181
  cssCache[bundle] = elements;
162
182
  }
163
- if (styleContainer) {
164
- const elements = cssCache[bundle];
165
- elements.forEach((el) => {
166
- styleContainer.appendChild(el.cloneNode(true));
167
- });
168
- } else {
169
- const elements = cssCache[bundle];
170
- elements.forEach((el) => {
171
- document.head.appendChild(el);
172
- });
173
- }
183
+ applyBundleCss();
174
184
  delete self.__NEXT_P;
175
185
  self.__NEXT_P = __NEXT_P_ORIGINAL;
176
186
  if (nextCssOriginal) {
@@ -178,7 +188,9 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
178
188
  }
179
189
  nextCss.remove();
180
190
  nextCssEnd.remove();
181
- return { Component, App };
191
+ const result = { Component, App };
192
+ ns.pageComponentCache[cacheKey] = result;
193
+ return result;
182
194
  }
183
195
  return { Component: null, App: null };
184
196
  }
@@ -187,4 +199,4 @@ export {
187
199
  applySharedModules,
188
200
  nextClientPagesLoader
189
201
  };
190
- //# sourceMappingURL=chunk-2VQGCACH.js.map
202
+ //# sourceMappingURL=chunk-MKO52FRO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/config/webpack/apply-shared-modules.ts","../src/config/webpack/next-client-pages-loader.ts"],"sourcesContent":["// Webpack shared module patching\n// used in multiple remote component host types\n// multiple host types includes: HTML custom element for remote components and Next.js host application\n// we are using this shared function to patch a Webpack module map\n// to use shared modules between the host application and the remote component\n\nimport { getScope } from '#internal/runtime/turbopack/remote-scope';\nimport { logDebug, logWarn } from '#internal/utils/logger';\n\nconst DEDUPLICATION_SKIPPED =\n 'shared module deduplication skipped. The remote may load its own copy of shared dependencies.';\n\nexport function applySharedModules(\n bundle: string,\n resolve: Record<string, unknown>,\n) {\n logDebug(\n 'SharedModules',\n `applySharedModules called for bundle: \"${bundle}\"`,\n );\n logDebug(\n 'SharedModules',\n `Shared modules to resolve: ${Object.keys(resolve)}`,\n );\n\n // make a typed reference to the global scope\n const self = globalThis as typeof globalThis & {\n // webpack remote module loading function scoped for each bundle\n __remote_webpack_require__?: Record<\n string,\n ((remoteId: string) => unknown) & {\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n }\n >;\n // webpack module map for each bundle used in production builds\n __remote_webpack_module_map__?: Record<string, Record<string, number>>;\n } & Record<string, string[]>;\n\n // Prefer scope-based access when available.\n const scope = getScope(bundle);\n // @legacy(v0.3.4) — fall back to global __remote_webpack_require__ for hosts that\n // haven't run setupWebpackRuntime yet (e.g. HTML host's inline path).\n // Remove once all host types go through the shared pipeline (Phase 5).\n const webpackBundle =\n scope?.webpackRequire ?? self.__remote_webpack_require__?.[bundle];\n\n if (webpackBundle) {\n const modulePaths = Object.keys(\n self.__remote_webpack_module_map__?.[bundle] ?? webpackBundle.m ?? {},\n );\n logDebug(\n 'SharedModules',\n `Available module paths for bundle \"${bundle}\": ${modulePaths}`,\n );\n\n // patch all modules in the bundle to use the shared modules\n for (const [key, value] of Object.entries(resolve)) {\n const exactIds = modulePaths.filter((p) => p === key);\n const ids =\n exactIds.length > 0\n ? exactIds\n : modulePaths.filter((p) => p.includes(key));\n\n if (ids.length === 0) {\n logDebug(\n 'SharedModules',\n `No matching module path found for shared module \"${key}\"`,\n );\n }\n\n for (const id of ids) {\n if (webpackBundle.m) {\n // if we have a module map, we need to use the mapped id\n // this is required for production builds where the module ids are module id numbers\n const resolvedId = self.__remote_webpack_module_map__?.[bundle]?.[id]\n ? `${self.__remote_webpack_module_map__[bundle][id]}`\n : id;\n if (resolvedId !== id) {\n logDebug(\n 'SharedModules',\n `Mapped module id: \"${id}\" -> \"${resolvedId}\"`,\n );\n }\n // create a mock module which exports the shared module\n webpackBundle.m[resolvedId] = (module) => {\n module.exports = value;\n };\n } else {\n logWarn(\n 'SharedModules',\n `webpackBundle.m is not available for bundle \"${bundle}\" — ${DEDUPLICATION_SKIPPED}`,\n );\n }\n }\n }\n } else {\n logWarn(\n 'SharedModules',\n `No webpack require found for bundle \"${bundle}\" — ${DEDUPLICATION_SKIPPED}`,\n );\n logDebug(\n 'SharedModules',\n `Available bundles: ${Object.keys(self.__remote_webpack_require__ ?? {})}`,\n );\n }\n}\n","import { getNamespace } from '#internal/runtime/namespace';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\n// module loader for Next.js Pages Router\nexport function nextClientPagesLoader(\n bundle: string,\n route: string,\n styleContainer: HTMLHeadElement | ShadowRoot | null = document.head,\n) {\n // make a typed reference to the global scope\n const self = globalThis as typeof globalThis & {\n // webpack remote module loading function scoped for each bundle\n __remote_webpack_require__?: Record<\n string,\n ((remoteId: string | number) => unknown) & {\n c?: Record<\n string | number,\n { id: string; parents: string[]; children: string[] }\n >;\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n type?: 'turbopack' | 'webpack';\n }\n >;\n // webpack module map for each bundle used in production builds\n __remote_webpack_module_map__?: Record<string, Record<string, number>>;\n // Next.js client pages loader reference storage\n __NEXT_P?: [\n (\n | [\n string,\n () => { default?: React.ComponentType<Record<string, unknown>> },\n ]\n | undefined\n ),\n (\n | [\n string,\n () => {\n default?: React.ComponentType<\n {\n Component: React.ComponentType<Record<string, unknown>>;\n } & Record<string, unknown>\n >;\n },\n ]\n | undefined\n ),\n (\n | [\n string,\n () => {\n default?: React.ComponentType<\n {\n Component: React.ComponentType<Record<string, unknown>>;\n } & Record<string, unknown>\n >;\n },\n ]\n | undefined\n ),\n ];\n };\n\n const ns = getNamespace();\n ns.pageComponentCache ??= {};\n const cacheKey = `${bundle}:${route}`;\n\n // Applies the cached CSS for `bundle` into the caller's styleContainer.\n // Mirrors the final CSS-attach step of the fresh-load path so that cache\n // hits and additional host instances (each with their own shadow root)\n // still receive the styles.\n const applyBundleCss = () => {\n const elements = ns.cssCache[bundle] ?? [];\n if (styleContainer) {\n for (const el of elements) {\n styleContainer.appendChild(el.cloneNode(true));\n }\n } else {\n for (const el of elements) {\n document.head.appendChild(el);\n }\n }\n };\n\n // On repeat loads (e.g. after history.back()) the next-client-pages-loader\n // chunk is already cached by webpack and its factory won't re-run, so\n // __NEXT_P wouldn't be populated. Reuse the Component/App extracted on the\n // first load, but still run the CSS attach below because the caller may be\n // a different host instance with its own styleContainer.\n const cachedEntry = ns.pageComponentCache[cacheKey];\n if (cachedEntry) {\n applyBundleCss();\n return cachedEntry;\n }\n\n // temporarily remove the original Next.js CSS loader\n const nextCssOriginal = document.querySelector(\n `[id=\"__next_css__DO_NOT_USE__\"]:not([data-bundle=\"${bundle}\"][data-route=\"${route}\"])`,\n );\n if (nextCssOriginal) {\n nextCssOriginal.parentNode?.removeChild(nextCssOriginal);\n }\n\n // create a new Next.js CSS loader element\n const nextCss = document.createElement('noscript');\n nextCss.id = '__next_css__DO_NOT_USE__';\n nextCss.setAttribute('data-bundle', bundle);\n nextCss.setAttribute('data-route', route);\n const nextCssEnd = document.createElement('noscript');\n nextCssEnd.id = '__next_css__DO_NOT_USE_END__';\n nextCssEnd.setAttribute('data-bundle', bundle);\n nextCssEnd.setAttribute('data-route', route);\n document.head.appendChild(nextCssEnd);\n document.head.appendChild(nextCss);\n\n // find the page component loader chunk\n const componentLoaderChunk =\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=${encodeURIComponent(route)}!`),\n ) ??\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n self.__remote_webpack_module_map__?.[bundle]?.[\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=${encodeURIComponent(route)}!`),\n ) ??\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n ''\n ] ??\n -1;\n\n // find the app loader chunk\n const appLoaderChunk =\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=%2F_app`),\n ) ??\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n self.__remote_webpack_module_map__?.[bundle]?.[\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) =>\n key.includes('/webpack/loaders/next-client-pages-loader.js') &&\n key.includes(`page=%2F_app`),\n ) ??\n Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(\n (key) => key.includes('/next/dist/client/page-loader.js'),\n ) ??\n ''\n ] ??\n -1;\n\n // if we didn't find the component loader or app loader, throw an error\n if (!(componentLoaderChunk && appLoaderChunk)) {\n throw new RemoteComponentsError(\n `Next.js client pages loader not found in bundle \"${bundle}\".`,\n );\n }\n\n // temporarily store the original __NEXT_P reference\n // this is required to avoid conflicts with the Next.js client pages loader\n // which uses the same global variable to store the page components\n const __NEXT_P_ORIGINAL = self.__NEXT_P;\n const selfOriginal = self;\n delete selfOriginal.__NEXT_P;\n\n // load the component and app loader chunks\n self.__remote_webpack_require__?.[bundle]?.(\n self.__remote_webpack_require__[bundle].type !== 'turbopack'\n ? componentLoaderChunk\n : `[${bundle}] ${componentLoaderChunk}`,\n );\n if (\n typeof appLoaderChunk === 'string' ||\n (typeof appLoaderChunk === 'number' && appLoaderChunk !== -1)\n ) {\n self.__remote_webpack_require__?.[bundle]?.(\n self.__remote_webpack_require__[bundle].type !== 'turbopack'\n ? appLoaderChunk\n : `[${bundle}] ${appLoaderChunk}`,\n );\n }\n\n // if we have the __NEXT_P global variable, we can extract the component and app\n if (self.__NEXT_P) {\n const [, componentLoader] = self.__NEXT_P[0] ?? [\n undefined,\n () => ({ default: null }),\n ];\n const [, appLoader] = self.__NEXT_P[2] ?? [\n undefined,\n () => ({\n default: null,\n }),\n ];\n const { default: Component = null } = componentLoader();\n const { default: App = null } = appLoader();\n\n const cssCache = ns.cssCache;\n\n if (!cssCache[bundle]) {\n // load the CSS files from the remote bundle\n const cssRE = /\\.s?css$/;\n Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {})\n .filter((id) => cssRE.test(id))\n .forEach((id) => {\n self.__remote_webpack_require__?.[bundle]?.(id);\n });\n\n Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {})\n .filter((path) => cssRE.test(path))\n .forEach((path) => {\n const id = self.__remote_webpack_module_map__?.[bundle]?.[path];\n if (id) {\n self.__remote_webpack_require__?.[bundle]?.(id);\n }\n });\n\n const elements = [];\n let node = nextCss.previousSibling;\n while (node && node !== nextCssEnd) {\n elements.push(node);\n node.remove();\n node = nextCss.previousSibling;\n }\n cssCache[bundle] = elements;\n }\n\n applyBundleCss();\n\n // restore the original __NEXT_P reference\n delete self.__NEXT_P;\n self.__NEXT_P = __NEXT_P_ORIGINAL;\n\n // restore the original Next.js CSS loader\n if (nextCssOriginal) {\n nextCssOriginal.parentNode?.appendChild(nextCssOriginal);\n }\n\n nextCss.remove();\n nextCssEnd.remove();\n\n const result = { Component, App };\n ns.pageComponentCache[cacheKey] = result;\n return result;\n }\n\n return { Component: null, App: null };\n}\n"],"mappings":";;;;;;;;;;;;;AASA,IAAM,wBACJ;AAEK,SAAS,mBACd,QACA,SACA;AACA;AAAA,IACE;AAAA,IACA,0CAA0C;AAAA,EAC5C;AACA;AAAA,IACE;AAAA,IACA,8BAA8B,OAAO,KAAK,OAAO;AAAA,EACnD;AAGA,QAAM,OAAO;AAab,QAAM,QAAQ,SAAS,MAAM;AAI7B,QAAM,gBACJ,OAAO,kBAAkB,KAAK,6BAA6B,MAAM;AAEnE,MAAI,eAAe;AACjB,UAAM,cAAc,OAAO;AAAA,MACzB,KAAK,gCAAgC,MAAM,KAAK,cAAc,KAAK,CAAC;AAAA,IACtE;AACA;AAAA,MACE;AAAA,MACA,sCAAsC,YAAY;AAAA,IACpD;AAGA,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AAClD,YAAM,WAAW,YAAY,OAAO,CAAC,MA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KN.js";
11
+ } from "./chunk-SAGYPGIQ.js";
12
12
  import {
13
13
  getNamespace
14
- } from "./chunk-KEPHL25S.js";
14
+ } from "./chunk-D5GNZB6O.js";
15
15
  import {
16
16
  RemoteComponentsError,
17
17
  failedProxiedAssetError,
@@ -706,4 +706,4 @@ export {
706
706
  initializeSharedModules,
707
707
  setupRemoteScope
708
708
  };
709
- //# sourceMappingURL=chunk-KYJWRZ2B.js.map
709
+ //# sourceMappingURL=chunk-N3KPUFOB.js.map
@@ -0,0 +1,25 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunk5KTAEO52cjs = require('./chunk-5KTAEO52.cjs');
5
+
6
+ // src/host/navigation/index.ts
7
+ function onRemoteNavigate(callback) {
8
+ if (typeof window === "undefined") {
9
+ return () => {
10
+ };
11
+ }
12
+ const handler = (event) => {
13
+ const detail = event.detail;
14
+ callback(_chunk5KTAEO52cjs.parseRemoteNavigateDetail.call(void 0, detail));
15
+ };
16
+ window.addEventListener(_chunk5KTAEO52cjs.REMOTE_NAVIGATE_EVENT, handler);
17
+ return () => {
18
+ window.removeEventListener(_chunk5KTAEO52cjs.REMOTE_NAVIGATE_EVENT, handler);
19
+ };
20
+ }
21
+
22
+
23
+
24
+ exports.onRemoteNavigate = onRemoteNavigate;
25
+ //# sourceMappingURL=chunk-N3SQTOSE.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/host/navigation/index.ts"],"names":[],"mappings":";;;;;;AAkCO,SAAS,iBACd,UACY;AACZ,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AACA,QAAM,UAAU,CAAC,UAAiB;AAChC,UAAM,SAAU,MAA4C;AAC5D,aAAS,0BAA0B,MAAM,CAAC;AAAA,EAC5C;AACA,SAAO,iBAAiB,uBAAuB,OAAO;AACtD,SAAO,MAAM;AACX,WAAO,oBAAoB,uBAAuB,OAAO;AAAA,EAC3D;AACF","sourcesContent":["import {\n parseRemoteNavigateDetail,\n REMOTE_NAVIGATE_EVENT,\n type RemoteNavigateDetail,\n type RemoteNavigateEvent,\n} from '#internal/host/shared/navigate-event';\n\nexport type { RemoteNavigateEvent } from '#internal/host/shared/navigate-event';\n\n/**\n * Subscribe to navigation requests from remote components. One subscription\n * handles every `<ConsumeRemoteComponent>` on the page. SSR-safe: no-op when\n * `window` is undefined.\n *\n * In React, prefer `useRemoteNavigate` from `remote-components/host/react` —\n * it avoids re-registering the listener on every render.\n *\n * @example React Router\n * ```ts\n * useEffect(\n * () =>\n * onRemoteNavigate((e) =>\n * navigate(e.pathname + e.search, { replace: e.type === 'replace' }),\n * ),\n * [navigate],\n * );\n * ```\n *\n * @example Plain HTML\n * ```ts\n * // Always replace — the polyfill already pushed/replaced the browser history entry.\n * onRemoteNavigate((e) => window.location.replace(e.url));\n * ```\n */\nexport function onRemoteNavigate(\n callback: (event: RemoteNavigateEvent) => void,\n): () => void {\n if (typeof window === 'undefined') {\n return () => {};\n }\n const handler = (event: Event) => {\n const detail = (event as CustomEvent<RemoteNavigateDetail>).detail;\n callback(parseRemoteNavigateDetail(detail));\n };\n window.addEventListener(REMOTE_NAVIGATE_EVENT, handler);\n return () => {\n window.removeEventListener(REMOTE_NAVIGATE_EVENT, handler);\n };\n}\n"]}
@@ -7,10 +7,13 @@ import {
7
7
  makeReactEmitter,
8
8
  preparePipeline,
9
9
  resolveNameFromSrc
10
- } from "./chunk-42N2ZLE2.js";
10
+ } from "./chunk-5WL3FP4V.js";
11
11
  import {
12
12
  loadStaticRemoteComponent
13
- } from "./chunk-OO4AMJWO.js";
13
+ } from "./chunk-LQ7VQ74E.js";
14
+ import {
15
+ onRemoteNavigate
16
+ } from "./chunk-RHGEBXPL.js";
14
17
  import {
15
18
  DEFAULT_COMPONENT_NAME,
16
19
  DEFAULT_ROUTE,
@@ -18,10 +21,10 @@ import {
18
21
  RUNTIME_WEBPACK,
19
22
  attrToProp,
20
23
  escapeString
21
- } from "./chunk-HNZVEIKN.js";
24
+ } from "./chunk-SAGYPGIQ.js";
22
25
  import {
23
26
  getNamespace
24
- } from "./chunk-KEPHL25S.js";
27
+ } from "./chunk-D5GNZB6O.js";
25
28
  import {
26
29
  RemoteComponentsError,
27
30
  errorFromFailedFetch,
@@ -31,11 +34,11 @@ import {
31
34
  // src/host/react/index.tsx
32
35
  import {
33
36
  startTransition,
34
- useEffect,
37
+ useEffect as useEffect2,
35
38
  useId,
36
39
  useLayoutEffect as useLayoutEffect2,
37
40
  useMemo as useMemo2,
38
- useRef as useRef2,
41
+ useRef as useRef3,
39
42
  useState as useState2
40
43
  } from "react";
41
44
  import { createPortal } from "react-dom";
@@ -159,6 +162,14 @@ function getRemoteComponentHtml(html) {
159
162
  return "";
160
163
  }
161
164
 
165
+ // src/host/react/hooks/use-remote-navigate.ts
166
+ import { useEffect, useRef as useRef2 } from "react";
167
+ function useRemoteNavigate(callback) {
168
+ const callbackRef = useRef2(callback);
169
+ callbackRef.current = callback;
170
+ useEffect(() => onRemoteNavigate((event) => callbackRef.current(event)), []);
171
+ }
172
+
162
173
  // src/host/react/index.tsx
163
174
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
164
175
  import { createElement } from "react";
@@ -206,13 +217,13 @@ function ConsumeRemoteComponent({
206
217
  mode,
207
218
  keySuffix
208
219
  });
209
- const htmlRef = useRef2(
220
+ const htmlRef = useRef3(
210
221
  typeof document !== "undefined" ? document.querySelector(
211
222
  `[data-remote-component-id="shadowroot_${keySuffix}"]`
212
223
  )?.shadowRoot?.innerHTML ?? document.getElementById(`__REMOTE_COMPONENT${name}`)?.innerHTML ?? document.querySelector(`div[data-bundle][data-route][id^="${name}"]`)?.innerHTML ?? document.querySelector("div[data-bundle][data-route]")?.innerHTML : null
213
224
  );
214
- const endTemplateRef = useRef2(null);
215
- const childrenRef = useRef2(
225
+ const endTemplateRef = useRef3(null);
226
+ const childrenRef = useRef3(
216
227
  typeof document !== "undefined" ? (() => {
217
228
  let el = document.querySelector(`template[id="${name}_start"]`);
218
229
  const elements = [];
@@ -225,10 +236,10 @@ function ConsumeRemoteComponent({
225
236
  return elements;
226
237
  })() : []
227
238
  );
228
- const hostStateRef = useRef2(createHostState());
229
- const componentHydrationHtml = useRef2(null);
230
- const prevRemoteComponentContainerRef = useRef2(null);
231
- const unmountRef = useRef2(null);
239
+ const hostStateRef = useRef3(createHostState());
240
+ const componentHydrationHtml = useRef3(null);
241
+ const prevRemoteComponentContainerRef = useRef3(null);
242
+ const unmountRef = useRef3(null);
232
243
  useLayoutEffect2(() => {
233
244
  return () => {
234
245
  delete getNamespace().shadowRoots[keySuffix];
@@ -265,7 +276,7 @@ function ConsumeRemoteComponent({
265
276
  }
266
277
  }
267
278
  }, [shadowRoot, remoteComponent, name]);
268
- useEffect(() => {
279
+ useEffect2(() => {
269
280
  if (src && src !== hostStateRef.current.prevSrc) {
270
281
  const previousSrc = hostStateRef.current.prevSrc;
271
282
  const previousName = hostStateRef.current.prevName;
@@ -665,6 +676,7 @@ function ConsumeRemoteComponent({
665
676
  }
666
677
 
667
678
  export {
679
+ useRemoteNavigate,
668
680
  ConsumeRemoteComponent
669
681
  };
670
- //# sourceMappingURL=chunk-W5ESPGHH.js.map
682
+ //# sourceMappingURL=chunk-NN5V3FVD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/host/react/index.tsx","../src/runtime/html/set-attributes-from-props.ts","../src/host/react/hooks/use-resolve-client-url.ts","../src/host/react/hooks/use-shadow-root.ts","../src/host/react/utils/extract-remote-html.ts","../src/host/react/hooks/use-remote-navigate.ts"],"sourcesContent":["import {\n startTransition,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { useRemoteComponentsContext } from '#internal/host/react/context';\nimport { fetchWithHooks } from '#internal/host/server/fetch-with-hooks';\nimport { getClientOrServerUrl } from '#internal/host/server/get-client-or-server-url';\nimport type { ConsumeRemoteComponentConfig } from '#internal/host/shared/config';\nimport { makeReactEmitter } from '#internal/host/shared/lifecycle';\nimport { loadPrepared, preparePipeline } from '#internal/host/shared/pipeline';\nimport type { ConsumeServerData } from '#internal/host/shared/server-handoff';\nimport { createHostState } from '#internal/host/shared/state';\nimport { resolveNameFromSrc } from '#internal/host/utils/resolve-name-from-src';\nimport {\n DEFAULT_COMPONENT_NAME,\n DEFAULT_ROUTE,\n RUNTIME_SCRIPT,\n RUNTIME_WEBPACK,\n} from '#internal/runtime/constants';\nimport { setAttributesFromProps } from '#internal/runtime/html/set-attributes-from-props';\nimport { loadStaticRemoteComponent } from '#internal/runtime/loaders/static-loader';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { attrToProp, escapeString } from '#internal/utils';\nimport { isAbortError } from '#internal/utils/abort';\nimport {\n errorFromFailedFetch,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport type { MountOrUnmountFunction } from '#remote-components/runtime/types';\nimport { useResolveClientUrl } from './hooks/use-resolve-client-url';\nimport { useShadowRoot } from './hooks/use-shadow-root';\nimport {\n DUMMY_FALLBACK,\n getRemoteComponentHtml,\n} from './utils/extract-remote-html';\n\n/**\n * Props for the React remote component host.\n *\n * Extends {@link ConsumeRemoteComponentConfig} with `children` for loading\n * fallback content.\n *\n * To react to navigations originating from embedded remote components, set up\n * a single top-level subscription with `onRemoteNavigate` from\n * `remote-components/host/navigation` and route the event to your host's\n * router.\n */\nexport interface ConsumeRemoteComponentProps\n extends ConsumeRemoteComponentConfig {\n /** Loading fallback content displayed while the remote component is being fetched. */\n children?: React.ReactNode;\n}\n\n/**\n * ConsumeRemoteComponent is a React component that fetches and renders a remote component.\n * It supports SSR and can isolate the remote component in a shadow DOM.\n *\n * @param props - The properties for the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<ConsumeRemoteComponent>` in your React application to consume a remote component from a remote application:\n *\n * ```tsx\n * import { ConsumeRemoteComponent } from 'remote-components/host/react';\n *\n * export default function App() {\n * return (\n * <>\n * <h1>Welcome to My App</h1>\n * <p>This page consumes a remote component from another application.</p>\n * <ConsumeRemoteComponent src=\"/nextjs-app-remote/components/header\" />\n * </>\n * );\n * }\n * ```\n *\n * To share modules, you can provide a shared module map with references to the shared modules:\n *\n * ```tsx\n * <ConsumeRemoteComponent\n * src=\"/nextjs-app-remote/components/header\"\n * shared={{\n * '@/components/provider': () => import('@/components/host-provider')\n * }}\n * />\n * ```\n */\nexport function ConsumeRemoteComponent({\n src,\n isolate,\n mode = 'open',\n reset,\n credentials: credentialsProp,\n name: nameProp = DEFAULT_COMPONENT_NAME,\n shared: sharedProp,\n children,\n onBeforeLoad,\n onLoad,\n onError,\n onChange,\n onRequest,\n onResponse,\n resolveClientUrl: resolveClientUrlProp,\n}: ConsumeRemoteComponentProps) {\n const instanceId = useId();\n\n const { credentials: contextCredentials, shared: contextShared } =\n useRemoteComponentsContext();\n const credentials = credentialsProp ?? contextCredentials ?? 'same-origin';\n const shared = sharedProp ?? contextShared ?? {};\n const emitter = useMemo(\n () => makeReactEmitter({ onBeforeLoad, onLoad, onError, onChange }),\n [onBeforeLoad, onLoad, onError, onChange],\n );\n\n const name = useMemo(\n () => resolveNameFromSrc(src, nameProp),\n [src, nameProp],\n );\n\n const [data, setData] = useState<Omit<ConsumeServerData, 'children'> | null>(\n null,\n );\n\n const url = useMemo(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);\n\n const resolveClientUrl = useResolveClientUrl(resolveClientUrlProp, url.href);\n\n // for relative src paths, use just the pathname as the unique id.\n // for static urls, use the full url as the unique id as the path may not be unique.\n // this id needs to be the same for server and client side rendering.\n // note that if this needs to be more unique, can pass through the bundle as an id prop and ammend it to this id.\n const id =\n url.origin ===\n (typeof location !== 'undefined' ? location.origin : DUMMY_FALLBACK)\n ? url.pathname\n : url.href;\n\n //instanceId prevents multiple components with the same src from sharing a shadow root\n const keySuffix = `${escapeString(id)}_${escapeString(\n data?.name ?? name,\n )}_${escapeString(instanceId)}`;\n\n const [remoteComponent, setRemoteComponent] = useState<\n React.ReactNode | Error\n >(null);\n\n const { shadowRoot, shadowRootContainerRef } = useShadowRoot({\n isolate,\n mode,\n keySuffix,\n });\n\n const htmlRef = useRef<string | null>(\n typeof document !== 'undefined'\n ? (document.querySelector(\n `[data-remote-component-id=\"shadowroot_${keySuffix}\"]`,\n )?.shadowRoot?.innerHTML ??\n document.getElementById(`__REMOTE_COMPONENT${name}`)?.innerHTML ??\n document.querySelector(`div[data-bundle][data-route][id^=\"${name}\"]`)\n ?.innerHTML ??\n document.querySelector('div[data-bundle][data-route]')?.innerHTML)\n : null,\n );\n const endTemplateRef = useRef<HTMLTemplateElement | null>(null);\n // collect initial content that needs to be removed after remote component renders\n const childrenRef = useRef(\n typeof document !== 'undefined'\n ? (() => {\n let el = document.querySelector(`template[id=\"${name}_start\"]`);\n const elements = [];\n while (el && el.id !== `${name}_end`) {\n if (\n el.id !== `${name}_start` &&\n !el.getAttribute('data-remote-component')\n ) {\n elements.push(el);\n }\n el = el.nextElementSibling as HTMLTemplateElement | null;\n }\n return elements;\n })()\n : [],\n );\n const hostStateRef = useRef(createHostState());\n const componentHydrationHtml = useRef<string | null>(null);\n const prevRemoteComponentContainerRef = useRef<HTMLDivElement | null>(null);\n const unmountRef = useRef<Set<MountOrUnmountFunction> | null>(null);\n\n // Clean up the shadow root cache on unmount to prevent memory leaks\n useLayoutEffect(() => {\n return () => {\n delete getNamespace().shadowRoots[keySuffix];\n };\n }, [keySuffix]);\n\n useLayoutEffect(() => {\n // Clear initial content after remote component renders\n if (childrenRef.current.length > 0 && remoteComponent) {\n childrenRef.current.forEach((el) => {\n el.remove();\n });\n childrenRef.current = [];\n }\n }, [remoteComponent]);\n\n useLayoutEffect(() => {\n if (shadowRoot && remoteComponent) {\n const resetStyles = shadowRoot.querySelectorAll(\n 'style[data-remote-components-reset]',\n );\n // ensure we only have one reset style in the shadow root\n if (resetStyles.length > 1) {\n resetStyles.forEach((style, index) => {\n if (\n index > 0 &&\n style.getAttribute('data-remote-components-reset') !== 'react'\n ) {\n style.remove();\n }\n });\n }\n\n // clear the html ref after hydration\n htmlRef.current = null;\n\n // clear all nodes except links and styles until the start marker\n // the marker gets only rendered on hydration\n let el: ChildNode | null = shadowRoot.childNodes[0] ?? null;\n while (el && (!('id' in el) || el.id !== `${name}_start`)) {\n const nextEl = el.nextSibling;\n if (el.nodeName !== 'LINK' && el.nodeName !== 'STYLE') {\n el.parentNode?.removeChild(el);\n }\n el = nextEl;\n }\n }\n }, [shadowRoot, remoteComponent, name]);\n\n useEffect(() => {\n if (src && src !== hostStateRef.current.prevSrc) {\n const previousSrc = hostStateRef.current.prevSrc;\n const previousName = hostStateRef.current.prevName;\n hostStateRef.current.prevSrc = src;\n\n if (previousSrc !== null) {\n htmlRef.current = null;\n }\n\n // Abort any in-progress load so the latest src always wins.\n hostStateRef.current.abortController?.abort();\n hostStateRef.current.abortController = new AbortController();\n const { signal } = hostStateRef.current.abortController;\n\n emitter.beforeLoad(src);\n hostStateRef.current.stage = 'loading';\n\n startTransition(async () => {\n try {\n let html = getRemoteComponentHtml(\n htmlRef.current ??\n (endTemplateRef.current?.previousElementSibling?.tagName === 'div'\n ? endTemplateRef.current.previousElementSibling.innerHTML\n : ''),\n );\n\n if (!html && src) {\n // fetch the remote component\n const fetchInit = {\n credentials,\n } as RequestInit;\n\n const resolvedUrl = new URL(\n resolveClientUrl?.(url.href) ?? url.href,\n location.href,\n );\n const res = await fetchWithHooks(resolvedUrl, fetchInit, {\n onRequest,\n onResponse,\n abortController: hostStateRef.current.abortController,\n });\n\n if (!res || !res.ok) {\n throw await errorFromFailedFetch(url.href, resolvedUrl, res);\n }\n\n // get the full HTML content as a string\n const remoteHtml = await res.text();\n if (signal.aborted) return;\n htmlRef.current = remoteHtml;\n html = getRemoteComponentHtml(remoteHtml);\n }\n\n if (signal.aborted) return;\n\n const userShared = await shared;\n if (signal.aborted) return;\n\n const prepared = preparePipeline({\n html,\n name,\n url,\n shared: userShared,\n resolveClientUrl,\n });\n const { doc, parsed } = prepared;\n const {\n component,\n name: remoteName,\n isRemoteComponent,\n metadata,\n rsc,\n remoteShared,\n links: linkElements,\n } = parsed;\n\n if (hostStateRef.current.prevIsRemoteComponent) {\n if (shadowRoot) {\n shadowRoot.innerHTML = '';\n }\n const prevUrl = hostStateRef.current.prevUrl;\n if (prevUrl && getNamespace().unmountFns[prevUrl.href]) {\n const unmountPromises = Promise.all(\n Array.from(unmountRef.current ?? []).map(async (unmount) =>\n unmount(\n shadowRoot ?? prevRemoteComponentContainerRef.current,\n ),\n ),\n );\n unmountRef.current = null;\n await unmountPromises;\n }\n }\n hostStateRef.current.prevIsRemoteComponent = isRemoteComponent;\n hostStateRef.current.prevUrl = url;\n hostStateRef.current.prevName = remoteName;\n\n const links = linkElements.map((link) => ({\n href: new URL(link.getAttribute('href') ?? link.href, url).href,\n ...link\n .getAttributeNames()\n .reduce<Record<string, string>>((acc, key) => {\n if (key !== 'href') {\n acc[attrToProp[key] ?? key] = link.getAttribute(key) ?? '';\n }\n return acc;\n }, {}),\n }));\n\n // handle inline scripts in the remote component\n const inlineScripts = (\n isRemoteComponent ? component : doc\n ).querySelectorAll(\n \"script:not([src]):not([data-src]):not([id*='_rsc']):not([id='__NEXT_DATA__']):not([id='__REMOTE_NEXT_DATA__'])\",\n );\n\n if (!isRemoteComponent) {\n // Next.js Script support\n const self = globalThis as typeof globalThis & {\n __next_s: [string, Record<string, string>][];\n };\n const prevNextScripts = self.__next_s;\n const nextScripts = [] as [string, Record<string, string>][];\n // eslint-disable-next-line camelcase\n self.__next_s = nextScripts;\n\n // TODO: needs to be cancellable with a singular listener for the abort signal https://linear.app/vercel/issue/MFES-1253/handle-abortcontroller-clean-up-scenarios\n await Promise.all(\n Array.from(inlineScripts)\n .filter(\n (script) =>\n !(\n script.id.endsWith('_shared') &&\n script.getAttribute('type') === 'application/json' &&\n typeof script.getAttribute(\n 'data-remote-components-shared',\n ) === 'string'\n ),\n )\n .map((script) => {\n return new Promise((resolve) => {\n // only handle inline scripts with content, but not Next.js RSC scripts\n if (\n script.textContent &&\n !script.textContent.includes('self.__next_f=') &&\n !script.textContent.includes('self.__next_f.push')\n ) {\n // if script is inline javascript, then execute using blob\n if (\n !script.getAttribute('type') ||\n script.getAttribute('type') === 'text/javascript' ||\n script.getAttribute('type') === 'application/javascript'\n ) {\n const newScript = document.createElement('script');\n\n // scripts loaded from external sources needs this workaround\n const blob = new Blob([script.textContent], {\n type: 'application/javascript',\n });\n const blobUrl = URL.createObjectURL(blob);\n\n newScript.onload = () => {\n resolve(undefined);\n // script executed and safe to remove\n URL.revokeObjectURL(blobUrl);\n newScript.remove();\n };\n // on error we still want to resolve to not block the remote component loading\n newScript.onerror = () => {\n URL.revokeObjectURL(blobUrl);\n newScript.remove();\n resolve(undefined);\n };\n\n newScript.src = blobUrl;\n // TODO: needs to be cancellable https://linear.app/vercel/issue/MFES-1253/handle-abortcontroller-clean-up-scenarios\n document.body.appendChild(newScript);\n } else {\n resolve(undefined);\n document.body.appendChild(script);\n }\n } else {\n resolve(undefined);\n }\n });\n }),\n );\n // process the remote component Next.js Script container\n nextScripts.forEach(([scriptSrc, props]) => {\n const script = document.createElement('script');\n // when we have a script src, apply it (inline scripts have `0` as src)\n if (scriptSrc) {\n script.src = scriptSrc;\n }\n // apply Script props\n if (typeof props.children === 'string') {\n script.textContent = props.children;\n }\n setAttributesFromProps(script, props);\n document.head.appendChild(script);\n });\n // restore previous Next.js Script container\n // eslint-disable-next-line camelcase\n self.__next_s = prevNextScripts;\n }\n\n const rscName = rsc\n ? `__remote_component_rsc_${escapeString(id)}_${escapeString(\n remoteName,\n )}`\n : undefined;\n if (rsc) {\n rsc.textContent =\n rsc.textContent?.replace(\n new RegExp(`self\\\\[\"${remoteName}\"\\\\]`, 'g'),\n `self[\"${rscName}\"]`,\n ) ?? '';\n document.body.appendChild(rsc);\n }\n\n const newData = {\n ...metadata,\n links,\n remoteShared,\n src: typeof src === 'string' ? src : src.href,\n serverUrl: url.href,\n data: rsc\n ? (rsc.textContent || '').split('\\n').filter(Boolean)\n : [],\n };\n\n componentHydrationHtml.current = `${Array.from(\n doc.querySelectorAll('link,style'),\n )\n .map((link) => link.outerHTML)\n .join('')}${\n reset\n ? `<style data-remote-components-reset=\"\">:host { all: initial; }</style>`\n : ''\n }${component.innerHTML}`;\n\n if (isRemoteComponent) {\n // Only call onChange when not on first load (matching HTML implementation)\n if (previousSrc !== undefined) {\n emitter.change({\n previousSrc: previousSrc ?? null,\n nextSrc: src,\n previousName,\n nextName: remoteName,\n });\n }\n setData(newData);\n if (shadowRoot) {\n const shadowRootHtml = reset\n ? `<style data-remote-components-reset=\"\">:host { all: initial; }</style>${component.innerHTML}`\n : component.innerHTML;\n shadowRoot.innerHTML = shadowRootHtml;\n htmlRef.current = null;\n setRemoteComponent(null);\n const { mount, unmount } = await loadStaticRemoteComponent(\n Array.from(shadowRoot.querySelectorAll('script')),\n url,\n resolveClientUrl,\n );\n unmountRef.current = unmount;\n await Promise.all(\n Array.from(mount).map((mountFn) => mountFn(shadowRoot)),\n );\n emitter.load(src);\n } else if (isolate === false) {\n setRemoteComponent(\n // TODO: remove wrapper div by converting HTML to RSC or React tree\n <div\n dangerouslySetInnerHTML={{ __html: component.innerHTML }}\n ref={prevRemoteComponentContainerRef}\n />,\n );\n htmlRef.current = null;\n const { mount, unmount } = await loadStaticRemoteComponent(\n Array.from(component.querySelectorAll('script')),\n url,\n resolveClientUrl,\n );\n unmountRef.current = unmount;\n await Promise.all(\n Array.from(mount).map((mountFn) =>\n mountFn(prevRemoteComponentContainerRef.current),\n ),\n );\n emitter.load(src);\n }\n hostStateRef.current.stage = 'loaded';\n } else {\n const result = await loadPrepared({\n prepared,\n url,\n signal,\n shared: userShared,\n resolveClientUrl,\n container: shadowRoot,\n rscName,\n });\n if (rsc) {\n rsc.remove();\n }\n\n setData(newData);\n // Only call onChange when not on first load (matching HTML implementation)\n if (previousSrc !== undefined) {\n emitter.change({\n previousSrc: previousSrc ?? null,\n nextSrc: src,\n previousName,\n nextName: remoteName,\n });\n }\n if (result.status === 'aborted') {\n return;\n }\n if (result.status === 'error') {\n hostStateRef.current.stage = 'error';\n setRemoteComponent(result.error);\n emitter.error(result.error);\n } else if (result.status === 'loaded') {\n hostStateRef.current.stage = 'loaded';\n setRemoteComponent(result.component);\n emitter.load(src);\n }\n }\n } catch (error) {\n // AbortError is expected when loading is cancelled - exit cleanly\n if (isAbortError(error)) {\n hostStateRef.current.stage = 'idle';\n return;\n }\n hostStateRef.current.stage = 'error';\n setRemoteComponent(error as Error);\n emitter.error(error);\n }\n });\n }\n }, [\n url,\n src,\n isolate,\n credentials,\n name,\n shared,\n shadowRoot,\n reset,\n id,\n emitter.beforeLoad,\n emitter.load,\n emitter.error,\n emitter.change,\n onRequest,\n onResponse,\n resolveClientUrl,\n ]);\n\n if (remoteComponent instanceof Error) {\n throw remoteComponent;\n }\n\n const metadataJson = (\n <script data-remote-component type=\"application/json\">\n {JSON.stringify({\n name: data?.name || name,\n bundle: data?.bundle || 'default',\n route: data?.route || DEFAULT_ROUTE,\n runtime: hostStateRef.current.prevIsRemoteComponent\n ? RUNTIME_SCRIPT\n : data?.runtime || RUNTIME_WEBPACK,\n })}\n </script>\n );\n const resetStyle = reset ? (\n <style data-remote-components-reset=\"react\">{`:host { all: initial; }`}</style>\n ) : null;\n const linksToRender: React.ReactNode[] | null =\n data?.links?.map((link) => (\n <link\n {...link}\n href={new URL(link.href as string, url).href}\n key={JSON.stringify(link)}\n />\n )) || null;\n const componentToRender = (\n <>\n {resetStyle}\n {linksToRender}\n {remoteComponent ?? children}\n </>\n );\n\n if (componentHydrationHtml.current && shadowRoot && !shadowRoot.innerHTML) {\n shadowRoot.innerHTML = componentHydrationHtml.current;\n componentHydrationHtml.current = null;\n\n if (hostStateRef.current.prevIsRemoteComponent) {\n // ensure we load static resources when hydrating a remote component in shadow DOM\n loadStaticRemoteComponent(\n Array.from(shadowRoot.querySelectorAll('script')),\n url,\n resolveClientUrl,\n )\n .then(({ mount }) => {\n return Promise.all(\n Array.from(mount).map((mountFn) => mountFn(shadowRoot)),\n );\n })\n .then(() => {\n if (src) {\n emitter.load(src);\n }\n })\n .catch((e) => {\n const error = new RemoteComponentsError(\n `Error mounting remote component from \"${url.href}\"`,\n {\n cause: e,\n },\n );\n setRemoteComponent(error);\n emitter.error(error);\n });\n }\n }\n\n if (isolate !== false) {\n const shadowRemoteComponentHtml =\n shadowRoot?.querySelector(`#__REMOTE_COMPONENT${name}`) ??\n shadowRoot?.querySelector('div[data-bundle][data-route]');\n if (shadowRemoteComponentHtml) {\n shadowRemoteComponentHtml.remove();\n }\n\n return (\n <>\n {metadataJson}\n <div\n data-remote-component-id={`shadowroot_${keySuffix}`}\n id={`shadowroot_${data?.name ?? name}`}\n ref={shadowRootContainerRef}\n >\n {typeof document === 'undefined' ? (\n // eslint-disable-next-line react/no-unknown-property\n <template shadowrootmode={mode}>\n {typeof document === 'undefined' ? (\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 // Capture the shadow root during SSR hydration so the client-side\n // useShadowRoot hook can find it.\n const root = el.getRootNode();\n globalThis.__remote_components_shadowroot_${keySuffix}=root;\n el.parentElement.remove();\n })(this)\"\n />`,\n }}\n />\n ) : null}\n {resetStyle}\n {linksToRender}\n {children}\n </template>\n ) : null}\n {shadowRoot && remoteComponent\n ? createPortal(\n <>\n <template id={`${name}_start`} />\n {resetStyle}\n {linksToRender}\n {remoteComponent}\n <template id={`${name}_end`} ref={endTemplateRef} />\n </>,\n shadowRoot,\n )\n : null}\n </div>\n </>\n );\n }\n htmlRef.current = null;\n\n // render start/end markers for the remote component\n return (\n <>\n <template id={`${name}_start`} />\n {metadataJson}\n {componentToRender}\n <template id={`${name}_end`} ref={endTemplateRef} />\n </>\n );\n}\n\nexport type {\n HookOptions,\n OnRequestHook,\n OnResponseHook,\n} from '#internal/host/shared/fetch-interceptors';\nexport type { RemoteNavigateEvent } from '#internal/host/shared/navigate-event';\nexport { useRemoteNavigate } from './hooks/use-remote-navigate';\n","// extracted from Next.js source at https://github.com/vercel/next.js/blob/canary/packages/next/src/client/set-attributes-from-props.ts\n\nconst DOMAttributeNames: Record<string, string> = {\n acceptCharset: 'accept-charset',\n className: 'class',\n htmlFor: 'for',\n httpEquiv: 'http-equiv',\n noModule: 'noModule',\n};\n\nconst ignoreProps = [\n 'onLoad',\n 'onReady',\n 'dangerouslySetInnerHTML',\n 'children',\n 'onError',\n 'strategy',\n 'stylesheets',\n];\n\nfunction isBooleanScriptAttribute(\n attr: string,\n): attr is 'async' | 'defer' | 'noModule' {\n return ['async', 'defer', 'noModule'].includes(attr);\n}\n\nexport function setAttributesFromProps(el: HTMLElement, props: object) {\n for (const [p, value] of Object.entries(props)) {\n if (!Object.hasOwn(props, p)) continue;\n if (ignoreProps.includes(p)) continue;\n\n // we don't render undefined props to the DOM\n if (value === undefined) {\n continue;\n }\n\n const attr = DOMAttributeNames[p] || p.toLowerCase();\n\n if (el.tagName === 'SCRIPT' && isBooleanScriptAttribute(attr)) {\n // Correctly assign boolean script attributes\n // https://github.com/vercel/next.js/pull/20748\n (el as HTMLScriptElement)[attr] = Boolean(value);\n } else {\n el.setAttribute(attr, String(value));\n }\n\n // Remove falsy non-zero boolean attributes so they are correctly interpreted\n // (e.g. if we set them to false, this coerces to the string \"false\", which the browser interprets as true)\n if (\n value === false ||\n (el.tagName === 'SCRIPT' &&\n isBooleanScriptAttribute(attr) &&\n (!value || value === 'false'))\n ) {\n // Call setAttribute before, as we need to set and unset the attribute to override force async:\n // https://html.spec.whatwg.org/multipage/scripting.html#script-force-async\n el.setAttribute(attr, '');\n el.removeAttribute(attr);\n }\n }\n}\n","import { useMemo } from 'react';\nimport { useRemoteComponentsContext } from '#internal/host/react/context';\nimport { bindResolveClientUrl } from '#internal/runtime/url/default-resolve-client-url';\nimport type { ResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\n\nexport function useResolveClientUrl(\n prop: ResolveClientUrl | undefined,\n urlHref: string,\n) {\n const { resolveClientUrl: contextValue } = useRemoteComponentsContext();\n const raw = prop ?? contextValue;\n return useMemo(() => bindResolveClientUrl(raw, urlHref), [raw, urlHref]);\n}\n","import { useLayoutEffect, useRef, useState } from 'react';\nimport { getNamespace } from '#internal/runtime/namespace';\n\ninterface UseShadowRootOptions {\n /** Whether CSS isolation is enabled */\n isolate: boolean | undefined;\n /** Shadow DOM mode */\n mode: 'open' | 'closed';\n /** Unique key suffix for identifying this shadow root */\n keySuffix: string;\n}\n\ninterface UseShadowRootResult {\n /** The shadow root element, or null if not isolated */\n shadowRoot: ShadowRoot | null;\n /** Ref to attach to the shadow host container element */\n shadowRootContainerRef: React.RefObject<HTMLDivElement | null>;\n}\n\n/**\n * Manages shadow root lifecycle for CSS isolation.\n *\n * Handles:\n * - Initial shadow root discovery from SSR or declarative shadow DOM\n * - Creating shadow root as fallback for browsers without declarative shadow DOM support\n * - Cleanup when isolation is disabled\n * - Re-attachment when isolation is re-enabled\n */\nexport function useShadowRoot({\n isolate,\n mode,\n keySuffix,\n}: UseShadowRootOptions): UseShadowRootResult {\n const shadowRootContainerRef = useRef<HTMLDivElement | null>(null);\n\n const [shadowRoot, setShadowRoot] = useState<ShadowRoot | null>(() => {\n const shadowRoots = getNamespace().shadowRoots;\n const ssrShadowRoot =\n typeof document !== 'undefined'\n ? (document.querySelector(\n `[data-remote-component-id=\"shadowroot_${keySuffix}\"]`,\n )?.shadowRoot ??\n shadowRoots[keySuffix] ??\n null)\n : null;\n // Clear the reference after reading it\n shadowRoots[keySuffix] = null;\n return ssrShadowRoot;\n });\n\n useLayoutEffect(() => {\n const shadowRoots = getNamespace().shadowRoots;\n if (\n isolate !== false &&\n typeof document !== 'undefined' &&\n (!shadowRoot || !shadowRoot.isConnected)\n ) {\n let shadowRootElement: ShadowRoot | null = null;\n const element = document.querySelector(\n `[data-remote-component-id=\"shadowroot_${keySuffix}\"]`,\n );\n shadowRootElement = shadowRoots[keySuffix] ?? element?.shadowRoot ?? 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 shadowRoots[keySuffix] = shadowRootElement;\n } catch {\n // Do nothing if attachShadow fails because of existing shadow root\n }\n }\n\n if (shadowRootElement) {\n // Remove all nodes from the shadow root except links (preserves stylesheets)\n shadowRootElement.querySelectorAll('*:not(link)').forEach((node) => {\n node.remove();\n });\n setShadowRoot(shadowRootElement);\n }\n } else if (isolate === false && shadowRoot) {\n shadowRoots[keySuffix] = null;\n setShadowRoot(null);\n }\n }, [isolate, shadowRoot, mode, keySuffix]);\n\n return { shadowRoot, shadowRootContainerRef };\n}\n","import { DEFAULT_COMPONENT_NAME } from '#internal/runtime/constants';\n\n/**\n * Dummy URL used as a fallback base for URL parsing when no real base URL is available.\n * This is used during SSR or when location is not defined.\n */\nexport const DUMMY_FALLBACK = 'http://remote-components-dummy-fallback';\n\n/**\n * Extracts the relevant HTML content from a remote component response.\n *\n * Handles multiple remote component formats:\n * - Next.js Pages Router SSR wrapper (`div[id^=\"__REMOTE_COMPONENT\"]`)\n * - App Router remote components (`div[data-bundle][data-route]`)\n * - Next.js pages (`div#__next`)\n * - Web component format (`remote-component:not([src])`)\n *\n * @param html - Raw HTML string from the remote component response\n * @returns Extracted HTML content with links and scripts, or empty string if not found\n */\nexport function getRemoteComponentHtml(html: string): string {\n if (typeof document === 'undefined') return html;\n\n const parser = new DOMParser();\n const temp = parser.parseFromString(html, 'text/html');\n\n // Used by the Next.js Pages Router remote as a wrapper\n const ssrRemoteComponentContainer = temp.querySelector(\n 'div[id^=\"__REMOTE_COMPONENT\"]',\n );\n if (ssrRemoteComponentContainer) {\n return ssrRemoteComponentContainer.innerHTML;\n }\n\n // Remote component content from various sources\n const remoteComponentContainer = temp.querySelectorAll(\n `div[data-bundle][data-route][data-runtime][id^=\"${DEFAULT_COMPONENT_NAME}\"],div[data-bundle][data-route],div#__next,remote-component:not([src])`,\n );\n if (remoteComponentContainer.length > 0) {\n return `${Array.from(temp.querySelectorAll('link,script'))\n .map((link) => link.outerHTML)\n .join('')}${Array.from(remoteComponentContainer)\n .map((container) => container.outerHTML)\n .join('')}`;\n }\n\n return '';\n}\n","import { useEffect, useRef } from 'react';\nimport { onRemoteNavigate } from '#internal/host/navigation';\nimport type { RemoteNavigateEvent } from '#internal/host/shared/navigate-event';\n\n/**\n * Subscribe to remote component navigations. The callback is captured in a ref\n * so the listener is registered once — no `useCallback` or dep array needed.\n *\n * @example React Router\n * ```tsx\n * const navigate = useNavigate();\n * // Always replace — the polyfill already pushed/replaced the browser history entry.\n * useRemoteNavigate((e) => navigate(e.pathname + e.search, { replace: true }));\n * ```\n */\nexport function useRemoteNavigate(\n callback: (event: RemoteNavigateEvent) => void,\n): void {\n const callbackRef = useRef(callback);\n // Written during render (not in an effect) — the standard useCallbackRef\n // pattern. Safe under concurrent rendering: navigation events are user-driven\n // and can't fire mid-render.\n callbackRef.current = callback;\n useEffect(() => onRemoteNavigate((event) => callbackRef.current(event)), []);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,EACA,aAAAA;AAAA,EACA;AAAA,EACA,mBAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,YAAAC;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,SAAS,8BAAAC,mCAAkC;;;ACR3C,IAAM,oBAA4C;AAAA,EAChD,eAAe;AAAA,EACf,WAAW;AAAA,EACX,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AACZ;AAEA,IAAM,cAAc;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,yBACP,MACwC;AACxC,SAA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,gBAAgB;AAAA,KACpD;AAEJ;","names":["useEffect","useLayoutEffect","useMemo","useRef","useState","useRemoteComponentsContext","useRef","useRef","useRemoteComponentsContext","useMemo","useState","useRef","useLayoutEffect","useEffect"]}
@@ -0,0 +1,25 @@
1
+ import {
2
+ REMOTE_NAVIGATE_EVENT,
3
+ parseRemoteNavigateDetail
4
+ } from "./chunk-STIJO4AG.js";
5
+
6
+ // src/host/navigation/index.ts
7
+ function onRemoteNavigate(callback) {
8
+ if (typeof window === "undefined") {
9
+ return () => {
10
+ };
11
+ }
12
+ const handler = (event) => {
13
+ const detail = event.detail;
14
+ callback(parseRemoteNavigateDetail(detail));
15
+ };
16
+ window.addEventListener(REMOTE_NAVIGATE_EVENT, handler);
17
+ return () => {
18
+ window.removeEventListener(REMOTE_NAVIGATE_EVENT, handler);
19
+ };
20
+ }
21
+
22
+ export {
23
+ onRemoteNavigate
24
+ };
25
+ //# sourceMappingURL=chunk-RHGEBXPL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/host/navigation/index.ts"],"sourcesContent":["import {\n parseRemoteNavigateDetail,\n REMOTE_NAVIGATE_EVENT,\n type RemoteNavigateDetail,\n type RemoteNavigateEvent,\n} from '#internal/host/shared/navigate-event';\n\nexport type { RemoteNavigateEvent } from '#internal/host/shared/navigate-event';\n\n/**\n * Subscribe to navigation requests from remote components. One subscription\n * handles every `<ConsumeRemoteComponent>` on the page. SSR-safe: no-op when\n * `window` is undefined.\n *\n * In React, prefer `useRemoteNavigate` from `remote-components/host/react` —\n * it avoids re-registering the listener on every render.\n *\n * @example React Router\n * ```ts\n * useEffect(\n * () =>\n * onRemoteNavigate((e) =>\n * navigate(e.pathname + e.search, { replace: e.type === 'replace' }),\n * ),\n * [navigate],\n * );\n * ```\n *\n * @example Plain HTML\n * ```ts\n * // Always replace — the polyfill already pushed/replaced the browser history entry.\n * onRemoteNavigate((e) => window.location.replace(e.url));\n * ```\n */\nexport function onRemoteNavigate(\n callback: (event: RemoteNavigateEvent) => void,\n): () => void {\n if (typeof window === 'undefined') {\n return () => {};\n }\n const handler = (event: Event) => {\n const detail = (event as CustomEvent<RemoteNavigateDetail>).detail;\n callback(parseRemoteNavigateDetail(detail));\n };\n window.addEventListener(REMOTE_NAVIGATE_EVENT, handler);\n return () => {\n window.removeEventListener(REMOTE_NAVIGATE_EVENT, handler);\n };\n}\n"],"mappings":";;;;;;AAkCO,SAAS,iBACd,UACY;AACZ,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AACA,QAAM,UAAU,CAAC,UAAiB;AAChC,UAAM,SAAU,MAA4C;AAC5D,aAAS,0BAA0B,MAAM,CAAC;AAAA,EAC5C;AACA,SAAO,iBAAiB,uBAAuB,OAAO;AACtD,SAAO,MAAM;AACX,WAAO,oBAAoB,uBAAuB,OAAO;AAAA,EAC3D;AACF;","names":[]}
@@ -1,6 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunk7MVFHOIPcjs = require('./chunk-7MVFHOIP.cjs');
3
+ var _chunkZ2SLBFQLcjs = require('./chunk-Z2SLBFQL.cjs');
4
+
5
+
6
+ var _chunk5KTAEO52cjs = require('./chunk-5KTAEO52.cjs');
4
7
 
5
8
 
6
9
 
@@ -42,7 +45,7 @@ function collapseDoubleSlashes(path) {
42
45
 
43
46
  // src/runtime/turbopack/remote-scope.ts
44
47
  function getRegistry() {
45
- return _chunk7MVFHOIPcjs.getNamespace.call(void 0, ).scopes;
48
+ return _chunkZ2SLBFQLcjs.getNamespace.call(void 0, ).scopes;
46
49
  }
47
50
  function createScope(name, url, runtime, resolveClientUrl) {
48
51
  const scopedName = computeScopedName(name, { remoteHost: url.host });
@@ -121,17 +124,24 @@ function createRemoteImageLoader(bundle, resolveClientUrl) {
121
124
 
122
125
  // src/host/shared/polyfill.tsx
123
126
  var _jsxruntime = require('react/jsx-runtime');
127
+ function dispatchRemoteNavigate(detail) {
128
+ window.dispatchEvent(
129
+ new CustomEvent(_chunk5KTAEO52cjs.REMOTE_NAVIGATE_EVENT, { detail })
130
+ );
131
+ }
124
132
  function sharedPolyfills(shared, resolveClientUrl) {
125
- const hostShared = _chunk7MVFHOIPcjs.getNamespace.call(void 0, ).hostSharedModules;
133
+ const hostShared = _chunkZ2SLBFQLcjs.getNamespace.call(void 0, ).hostSharedModules;
126
134
  const polyfill = {
127
135
  "next/dist/client/components/navigation": _nullishCoalesce(_nullishCoalesce(hostShared["next/navigation"], () => ( _optionalChain([shared, 'optionalAccess', _10 => _10["next/navigation"]]))), () => ( (() => Promise.resolve({
128
136
  useRouter() {
129
137
  return {
130
138
  push: (routerUrl) => {
131
139
  history.pushState({}, "", routerUrl);
140
+ dispatchRemoteNavigate({ url: routerUrl, type: "push" });
132
141
  },
133
142
  replace: (routerUrl) => {
134
143
  history.replaceState({}, "", routerUrl);
144
+ dispatchRemoteNavigate({ url: routerUrl, type: "replace" });
135
145
  },
136
146
  back: () => {
137
147
  history.back();
@@ -194,6 +204,10 @@ function sharedPolyfills(shared, resolveClientUrl) {
194
204
  } else {
195
205
  history.pushState({}, "", props.href);
196
206
  }
207
+ dispatchRemoteNavigate({
208
+ url: props.href,
209
+ type: replace ? "replace" : "push"
210
+ });
197
211
  },
198
212
  suppressHydrationWarning: true,
199
213
  children: _nullishCoalesce(children, () => ( null))
@@ -233,9 +247,11 @@ function sharedPolyfills(shared, resolveClientUrl) {
233
247
  return {
234
248
  push: (routerUrl) => {
235
249
  history.pushState({}, "", routerUrl);
250
+ dispatchRemoteNavigate({ url: routerUrl, type: "push" });
236
251
  },
237
252
  replace: (routerUrl) => {
238
253
  history.replaceState({}, "", routerUrl);
254
+ dispatchRemoteNavigate({ url: routerUrl, type: "replace" });
239
255
  },
240
256
  back: () => {
241
257
  history.back();
@@ -355,4 +371,4 @@ async function buildWebpackResolve(hostShared, remoteShared, bundle, reactModule
355
371
 
356
372
 
357
373
  exports.escapeString = escapeString; exports.attrToProp = attrToProp; exports.DEFAULT_BUNDLE_NAME = DEFAULT_BUNDLE_NAME; exports.DEFAULT_COMPONENT_NAME = DEFAULT_COMPONENT_NAME; exports.DEFAULT_ROUTE = DEFAULT_ROUTE; exports.RUNTIME_WEBPACK = RUNTIME_WEBPACK; exports.RUNTIME_TURBOPACK = RUNTIME_TURBOPACK; exports.RUNTIME_SCRIPT = RUNTIME_SCRIPT; exports.REMOTE_COMPONENT_REGEX = REMOTE_COMPONENT_REGEX; exports.NEXT_BUNDLE_PATH_RE = NEXT_BUNDLE_PATH_RE; exports.collapseDoubleSlashes = collapseDoubleSlashes; exports.createScope = createScope; exports.registerScope = registerScope; exports.getScope = getScope; exports.formatRemoteId = formatRemoteId; exports.parseRemoteId = parseRemoteId; exports.createRemoteImageLoader = createRemoteImageLoader; exports.CORE_REACT_SHARED_KEYS = CORE_REACT_SHARED_KEYS; exports.VENDOR_SHARED = VENDOR_SHARED; exports.buildCoreShared = buildCoreShared; exports.buildHostShared = buildHostShared; exports.buildWebpackResolve = buildWebpackResolve;
358
- //# sourceMappingURL=chunk-R4QFK5TN.cjs.map
374
+ //# sourceMappingURL=chunk-RLI4YTBJ.cjs.map