remote-components 0.0.51 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/dist/{component-loader-1838f572.d.ts → component-loader-21865da3.d.ts} +142 -16
  2. package/dist/host-config-58cdccea.d.ts +87 -0
  3. package/dist/html/host.cjs +589 -377
  4. package/dist/html/host.cjs.map +1 -1
  5. package/dist/html/host.d.ts +2 -0
  6. package/dist/html/host.js +588 -377
  7. package/dist/html/host.js.map +1 -1
  8. package/dist/html/remote.cjs +65 -57
  9. package/dist/html/remote.cjs.map +1 -1
  10. package/dist/html/remote.js +65 -57
  11. package/dist/html/remote.js.map +1 -1
  12. package/dist/internal/next/host/app-router-client.cjs +21 -10
  13. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  14. package/dist/internal/next/host/app-router-client.d.ts +36 -14
  15. package/dist/internal/next/host/app-router-client.js +21 -10
  16. package/dist/internal/next/host/app-router-client.js.map +1 -1
  17. package/dist/internal/next/remote/render-server.cjs.map +1 -1
  18. package/dist/internal/next/remote/render-server.d.ts +13 -14
  19. package/dist/internal/next/remote/render-server.js.map +1 -1
  20. package/dist/internal/react/context.cjs +43 -0
  21. package/dist/internal/react/context.cjs.map +1 -0
  22. package/dist/internal/react/context.d.ts +20 -0
  23. package/dist/internal/react/context.js +18 -0
  24. package/dist/internal/react/context.js.map +1 -0
  25. package/dist/internal/react/hooks/use-resolve-client-url.cjs +39 -0
  26. package/dist/internal/react/hooks/use-resolve-client-url.cjs.map +1 -0
  27. package/dist/internal/react/hooks/use-resolve-client-url.d.ts +5 -0
  28. package/dist/internal/react/hooks/use-resolve-client-url.js +15 -0
  29. package/dist/internal/react/hooks/use-resolve-client-url.js.map +1 -0
  30. package/dist/internal/shared/client/apply-origin.cjs +10 -5
  31. package/dist/internal/shared/client/apply-origin.cjs.map +1 -1
  32. package/dist/internal/shared/client/apply-origin.d.ts +3 -1
  33. package/dist/internal/shared/client/apply-origin.js +10 -5
  34. package/dist/internal/shared/client/apply-origin.js.map +1 -1
  35. package/dist/internal/shared/client/default-resolve-client-url.cjs +32 -0
  36. package/dist/internal/shared/client/default-resolve-client-url.cjs.map +1 -0
  37. package/dist/internal/shared/client/default-resolve-client-url.d.ts +5 -0
  38. package/dist/internal/shared/client/default-resolve-client-url.js +10 -0
  39. package/dist/internal/shared/client/default-resolve-client-url.js.map +1 -0
  40. package/dist/internal/shared/client/protected-rc-fallback.cjs +11 -2
  41. package/dist/internal/shared/client/protected-rc-fallback.cjs.map +1 -1
  42. package/dist/internal/shared/client/protected-rc-fallback.d.ts +2 -1
  43. package/dist/internal/shared/client/protected-rc-fallback.js +9 -1
  44. package/dist/internal/shared/client/protected-rc-fallback.js.map +1 -1
  45. package/dist/internal/shared/client/proxy-through-host.cjs +65 -0
  46. package/dist/internal/shared/client/proxy-through-host.cjs.map +1 -0
  47. package/dist/internal/shared/client/proxy-through-host.d.ts +62 -0
  48. package/dist/internal/shared/client/proxy-through-host.js +40 -0
  49. package/dist/internal/shared/client/proxy-through-host.js.map +1 -0
  50. package/dist/internal/shared/client/remote-component.cjs +121 -137
  51. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  52. package/dist/internal/shared/client/remote-component.d.ts +7 -5
  53. package/dist/internal/shared/client/remote-component.js +120 -137
  54. package/dist/internal/shared/client/remote-component.js.map +1 -1
  55. package/dist/internal/shared/constants.cjs +3 -0
  56. package/dist/internal/shared/constants.cjs.map +1 -1
  57. package/dist/internal/shared/constants.d.ts +2 -1
  58. package/dist/internal/shared/constants.js +2 -0
  59. package/dist/internal/shared/constants.js.map +1 -1
  60. package/dist/internal/shared/contract/host-state.cjs +38 -0
  61. package/dist/internal/shared/contract/host-state.cjs.map +1 -0
  62. package/dist/internal/shared/contract/host-state.d.ts +53 -0
  63. package/dist/internal/shared/contract/host-state.js +14 -0
  64. package/dist/internal/shared/contract/host-state.js.map +1 -0
  65. package/dist/internal/shared/contract/resolve-name-from-src.cjs +40 -0
  66. package/dist/internal/shared/contract/resolve-name-from-src.cjs.map +1 -0
  67. package/dist/internal/shared/contract/resolve-name-from-src.d.ts +13 -0
  68. package/dist/internal/shared/contract/resolve-name-from-src.js +16 -0
  69. package/dist/internal/shared/contract/resolve-name-from-src.js.map +1 -0
  70. package/dist/internal/shared/error.cjs +70 -0
  71. package/dist/internal/shared/error.cjs.map +1 -1
  72. package/dist/internal/shared/error.d.ts +3 -1
  73. package/dist/internal/shared/error.js +71 -0
  74. package/dist/internal/shared/error.js.map +1 -1
  75. package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
  76. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  77. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +1 -1
  78. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  79. package/dist/internal/shared/ssr/fetch-with-hooks.cjs +7 -2
  80. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
  81. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +1 -1
  82. package/dist/internal/shared/ssr/fetch-with-hooks.js +7 -2
  83. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
  84. package/dist/internal/shared/utils/logger.cjs +26 -10
  85. package/dist/internal/shared/utils/logger.cjs.map +1 -1
  86. package/dist/internal/shared/utils/logger.d.ts +6 -1
  87. package/dist/internal/shared/utils/logger.js +24 -9
  88. package/dist/internal/shared/utils/logger.js.map +1 -1
  89. package/dist/next/config.cjs +2 -2
  90. package/dist/next/config.cjs.map +1 -1
  91. package/dist/next/config.js +2 -2
  92. package/dist/next/config.js.map +1 -1
  93. package/dist/next/host/app-router-server.cjs.map +1 -1
  94. package/dist/next/host/app-router-server.d.ts +11 -41
  95. package/dist/next/host/app-router-server.js.map +1 -1
  96. package/dist/next/host/client/index.cjs +467 -298
  97. package/dist/next/host/client/index.cjs.map +1 -1
  98. package/dist/next/host/client/index.d.ts +3 -1
  99. package/dist/next/host/client/index.js +445 -277
  100. package/dist/next/host/client/index.js.map +1 -1
  101. package/dist/next/host/pages-router-client.cjs +15 -2
  102. package/dist/next/host/pages-router-client.cjs.map +1 -1
  103. package/dist/next/host/pages-router-client.d.ts +14 -26
  104. package/dist/next/host/pages-router-client.js +15 -2
  105. package/dist/next/host/pages-router-client.js.map +1 -1
  106. package/dist/next/host/pages-router-server.cjs +2 -0
  107. package/dist/next/host/pages-router-server.cjs.map +1 -1
  108. package/dist/next/host/pages-router-server.d.ts +17 -31
  109. package/dist/next/host/pages-router-server.js +2 -0
  110. package/dist/next/host/pages-router-server.js.map +1 -1
  111. package/dist/next/index.cjs.map +1 -1
  112. package/dist/next/index.d.ts +13 -39
  113. package/dist/next/index.js.map +1 -1
  114. package/dist/next/proxy.cjs +33 -6
  115. package/dist/next/proxy.cjs.map +1 -1
  116. package/dist/next/proxy.js +33 -6
  117. package/dist/next/proxy.js.map +1 -1
  118. package/dist/next/remote/server.d.ts +4 -0
  119. package/dist/proxy-through-host-a676a522.d.ts +52 -0
  120. package/dist/react/index.cjs +486 -298
  121. package/dist/react/index.cjs.map +1 -1
  122. package/dist/react/index.d.ts +27 -40
  123. package/dist/react/index.js +463 -277
  124. package/dist/react/index.js.map +1 -1
  125. package/dist/shared/host/proxy.cjs +32 -6
  126. package/dist/shared/host/proxy.cjs.map +1 -1
  127. package/dist/shared/host/proxy.js +36 -7
  128. package/dist/shared/host/proxy.js.map +1 -1
  129. package/dist/{types-cbe44b51.d.ts → types-2b26a246.d.ts} +23 -6
  130. package/package.json +1 -1
  131. package/dist/internal/shared/client/fetch-with-protected-rc-fallback.cjs +0 -65
  132. package/dist/internal/shared/client/fetch-with-protected-rc-fallback.cjs.map +0 -1
  133. package/dist/internal/shared/client/fetch-with-protected-rc-fallback.d.ts +0 -13
  134. package/dist/internal/shared/client/fetch-with-protected-rc-fallback.js +0 -41
  135. package/dist/internal/shared/client/fetch-with-protected-rc-fallback.js.map +0 -1
@@ -42,7 +42,8 @@ function RemoteComponent({
42
42
  onError,
43
43
  onLoad,
44
44
  onRequest,
45
- onResponse
45
+ onResponse,
46
+ resolveClientUrl
46
47
  }) {
47
48
  const elementRef = (0, import_react.useRef)(null);
48
49
  (0, import_react.useEffect)(() => {
@@ -60,6 +61,9 @@ function RemoteComponent({
60
61
  if (onResponse) {
61
62
  element.onResponse = onResponse;
62
63
  }
64
+ if (resolveClientUrl !== void 0) {
65
+ element.resolveClientUrl = resolveClientUrl;
66
+ }
63
67
  const handleBeforeLoad = (e) => {
64
68
  const customEvent = e;
65
69
  onBeforeLoad?.(customEvent.src ?? src);
@@ -99,7 +103,16 @@ function RemoteComponent({
99
103
  if (onChange)
100
104
  element.removeEventListener("change", handleChange);
101
105
  };
102
- }, [src, onBeforeLoad, onChange, onError, onLoad, onRequest, onResponse]);
106
+ }, [
107
+ src,
108
+ onBeforeLoad,
109
+ onChange,
110
+ onError,
111
+ onLoad,
112
+ onRequest,
113
+ onResponse,
114
+ resolveClientUrl
115
+ ]);
103
116
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("remote-component", { ref: elementRef, src, children });
104
117
  }
105
118
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/next/host/pages-router-client.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { shared } from 'remote-components/shared/host/pages';\nimport type { OnRequestHook, OnResponseHook } from '#internal/shared/ssr/types';\n\n// patch react/jsx-runtime to support the remote-component custom element\ndeclare module 'react/jsx-runtime' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace JSX {\n interface IntrinsicElements {\n 'remote-component': {\n src?: string;\n ref?: React.Ref<HTMLElement>;\n children: React.ReactNode;\n };\n }\n }\n}\n\n// Extend HTMLElement to include onRequest/onResponse properties from the custom element\ninterface RemoteComponentElement extends HTMLElement {\n onRequest?: OnRequestHook;\n onResponse?: OnResponseHook;\n}\n\nexport interface RemoteComponentProps {\n src: string;\n children?: React.ReactNode;\n /** Called right before a new remote component load starts. */\n onBeforeLoad?: (src: string | URL) => void;\n /** Called when the remote component has been successfully loaded and mounted. */\n onLoad?: (src: string | URL) => void;\n /** Called when an error occurs while loading or mounting the remote component. */\n onError?: (error: unknown) => void;\n /** Called when a different remote component is loaded into the same wrapper. */\n onChange?: (info: {\n previousSrc: string | URL | null;\n nextSrc: string | URL | null;\n previousName: string | undefined;\n nextName: string | undefined;\n }) => void;\n /**\n * Called when a fetch request is made to retrieve the remote component payload.\n * Can be used to intercept requests, modify headers, or provide a custom response.\n */\n onRequest?: OnRequestHook;\n /**\n * Called after a fetch completes to retrieve the remote component payload.\n * Can be used to inspect the response (e.g., check for redirects) or transform it.\n */\n onResponse?: OnResponseHook;\n}\n\nexport function RemoteComponent({\n src,\n children,\n onBeforeLoad,\n onChange,\n onError,\n onLoad,\n onRequest,\n onResponse,\n}: RemoteComponentProps) {\n const elementRef = useRef<RemoteComponentElement>(null);\n\n useEffect(() => {\n const self = globalThis as typeof globalThis & {\n __remote_component_shared__?: Record<string, () => Promise<unknown>>;\n };\n // eslint-disable-next-line camelcase\n self.__remote_component_shared__ = shared;\n import('remote-components/html/host');\n }, []);\n\n useEffect(() => {\n const element = elementRef.current;\n if (!element) return;\n\n // Set onRequest/onResponse properties on the element before it loads\n if (onRequest) {\n element.onRequest = onRequest;\n }\n if (onResponse) {\n element.onResponse = onResponse;\n }\n\n // Set up event listeners for lifecycle hooks\n const handleBeforeLoad = (e: Event) => {\n const customEvent = e as CustomEvent & { src?: string };\n onBeforeLoad?.(customEvent.src ?? src);\n };\n const handleLoad = (e: Event) => {\n const customEvent = e as CustomEvent & { src?: string };\n onLoad?.(customEvent.src ?? src);\n };\n const handleError = (e: Event) => {\n const customEvent = e as CustomEvent & { error?: unknown };\n onError?.(customEvent.error);\n };\n const handleChange = (e: Event) => {\n const customEvent = e as CustomEvent & {\n previousSrc?: string | null;\n nextSrc?: string | null;\n previousName?: string;\n nextName?: string;\n };\n onChange?.({\n previousSrc: customEvent.previousSrc ?? null,\n nextSrc: customEvent.nextSrc ?? null,\n previousName: customEvent.previousName,\n nextName: customEvent.nextName,\n });\n };\n\n if (onBeforeLoad) element.addEventListener('beforeload', handleBeforeLoad);\n if (onLoad) element.addEventListener('load', handleLoad);\n if (onError) element.addEventListener('error', handleError);\n if (onChange) element.addEventListener('change', handleChange);\n\n return () => {\n if (onBeforeLoad)\n element.removeEventListener('beforeload', handleBeforeLoad);\n if (onLoad) element.removeEventListener('load', handleLoad);\n if (onError) element.removeEventListener('error', handleError);\n if (onChange) element.removeEventListener('change', handleChange);\n };\n }, [src, onBeforeLoad, onChange, onError, onLoad, onRequest, onResponse]);\n\n return (\n <remote-component ref={elementRef} src={src}>\n {children}\n </remote-component>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgII;AAhIJ,mBAAkC;AAClC,mBAAuB;AAmDhB,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,iBAAa,qBAA+B,IAAI;AAEtD,8BAAU,MAAM;AACd,UAAM,OAAO;AAIb,SAAK,8BAA8B;AACnC,WAAO,6BAA6B;AAAA,EACtC,GAAG,CAAC,CAAC;AAEL,8BAAU,MAAM;AACd,UAAM,UAAU,WAAW;AAC3B,QAAI,CAAC;AAAS;AAGd,QAAI,WAAW;AACb,cAAQ,YAAY;AAAA,IACtB;AACA,QAAI,YAAY;AACd,cAAQ,aAAa;AAAA,IACvB;AAGA,UAAM,mBAAmB,CAAC,MAAa;AACrC,YAAM,cAAc;AACpB,qBAAe,YAAY,OAAO,GAAG;AAAA,IACvC;AACA,UAAM,aAAa,CAAC,MAAa;AAC/B,YAAM,cAAc;AACpB,eAAS,YAAY,OAAO,GAAG;AAAA,IACjC;AACA,UAAM,cAAc,CAAC,MAAa;AAChC,YAAM,cAAc;AACpB,gBAAU,YAAY,KAAK;AAAA,IAC7B;AACA,UAAM,eAAe,CAAC,MAAa;AACjC,YAAM,cAAc;AAMpB,iBAAW;AAAA,QACT,aAAa,YAAY,eAAe;AAAA,QACxC,SAAS,YAAY,WAAW;AAAA,QAChC,cAAc,YAAY;AAAA,QAC1B,UAAU,YAAY;AAAA,MACxB,CAAC;AAAA,IACH;AAEA,QAAI;AAAc,cAAQ,iBAAiB,cAAc,gBAAgB;AACzE,QAAI;AAAQ,cAAQ,iBAAiB,QAAQ,UAAU;AACvD,QAAI;AAAS,cAAQ,iBAAiB,SAAS,WAAW;AAC1D,QAAI;AAAU,cAAQ,iBAAiB,UAAU,YAAY;AAE7D,WAAO,MAAM;AACX,UAAI;AACF,gBAAQ,oBAAoB,cAAc,gBAAgB;AAC5D,UAAI;AAAQ,gBAAQ,oBAAoB,QAAQ,UAAU;AAC1D,UAAI;AAAS,gBAAQ,oBAAoB,SAAS,WAAW;AAC7D,UAAI;AAAU,gBAAQ,oBAAoB,UAAU,YAAY;AAAA,IAClE;AAAA,EACF,GAAG,CAAC,KAAK,cAAc,UAAU,SAAS,QAAQ,WAAW,UAAU,CAAC;AAExE,SACE,4CAAC,sBAAiB,KAAK,YAAY,KAChC,UACH;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/next/host/pages-router-client.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { shared } from 'remote-components/shared/host/pages';\nimport type { ResolveClientUrl } from '#internal/shared/client/proxy-through-host';\nimport type {\n ClientHostConfig,\n HostConfig,\n HostLifecycleCallbacks,\n} from '#internal/shared/contract/host-config';\nimport type { OnRequestHook, OnResponseHook } from '#internal/shared/ssr/types';\n\n// patch react/jsx-runtime to support the remote-component custom element\ndeclare module 'react/jsx-runtime' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace JSX {\n interface IntrinsicElements {\n 'remote-component': {\n src?: string;\n ref?: React.Ref<HTMLElement>;\n children: React.ReactNode;\n };\n }\n }\n}\n\n// Extend HTMLElement to include onRequest/onResponse/resolveClientUrl properties from the custom element\ninterface RemoteComponentElement extends HTMLElement {\n onRequest?: OnRequestHook;\n onResponse?: OnResponseHook;\n resolveClientUrl?: ResolveClientUrl;\n}\n\n/**\n * Props for the Pages Router client-side remote component wrapper.\n *\n * Extends {@link HostConfig}, {@link ClientHostConfig}, and\n * {@link HostLifecycleCallbacks}. The `src` prop is required since\n * the client always needs a source URL to load from.\n */\nexport interface RemoteComponentProps\n extends HostConfig,\n ClientHostConfig,\n HostLifecycleCallbacks {\n /** The source URL of the remote component. Required for client-side loading. */\n src: string;\n /** Loading fallback content displayed while the remote component is being fetched. */\n children?: React.ReactNode;\n}\n\nexport function RemoteComponent({\n src,\n children,\n onBeforeLoad,\n onChange,\n onError,\n onLoad,\n onRequest,\n onResponse,\n resolveClientUrl,\n}: RemoteComponentProps) {\n const elementRef = useRef<RemoteComponentElement>(null);\n\n useEffect(() => {\n const self = globalThis as typeof globalThis & {\n __remote_component_shared__?: Record<string, () => Promise<unknown>>;\n };\n // eslint-disable-next-line camelcase\n self.__remote_component_shared__ = shared;\n import('remote-components/html/host');\n }, []);\n\n useEffect(() => {\n const element = elementRef.current;\n if (!element) return;\n\n // Set onRequest/onResponse/resolveClientUrl properties on the element before it loads\n if (onRequest) {\n element.onRequest = onRequest;\n }\n if (onResponse) {\n element.onResponse = onResponse;\n }\n if (resolveClientUrl !== undefined) {\n element.resolveClientUrl = resolveClientUrl;\n }\n\n // Set up event listeners for lifecycle hooks\n const handleBeforeLoad = (e: Event) => {\n const customEvent = e as CustomEvent & { src?: string };\n onBeforeLoad?.(customEvent.src ?? src);\n };\n const handleLoad = (e: Event) => {\n const customEvent = e as CustomEvent & { src?: string };\n onLoad?.(customEvent.src ?? src);\n };\n const handleError = (e: Event) => {\n const customEvent = e as CustomEvent & { error?: unknown };\n onError?.(customEvent.error);\n };\n const handleChange = (e: Event) => {\n const customEvent = e as CustomEvent & {\n previousSrc?: string | null;\n nextSrc?: string | null;\n previousName?: string;\n nextName?: string;\n };\n onChange?.({\n previousSrc: customEvent.previousSrc ?? null,\n nextSrc: customEvent.nextSrc ?? null,\n previousName: customEvent.previousName,\n nextName: customEvent.nextName,\n });\n };\n\n if (onBeforeLoad) element.addEventListener('beforeload', handleBeforeLoad);\n if (onLoad) element.addEventListener('load', handleLoad);\n if (onError) element.addEventListener('error', handleError);\n if (onChange) element.addEventListener('change', handleChange);\n\n return () => {\n if (onBeforeLoad)\n element.removeEventListener('beforeload', handleBeforeLoad);\n if (onLoad) element.removeEventListener('load', handleLoad);\n if (onError) element.removeEventListener('error', handleError);\n if (onChange) element.removeEventListener('change', handleChange);\n };\n }, [\n src,\n onBeforeLoad,\n onChange,\n onError,\n onLoad,\n onRequest,\n onResponse,\n resolveClientUrl,\n ]);\n\n return (\n <remote-component ref={elementRef} src={src}>\n {children}\n </remote-component>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyII;AAzIJ,mBAAkC;AAClC,mBAAuB;AA+ChB,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,iBAAa,qBAA+B,IAAI;AAEtD,8BAAU,MAAM;AACd,UAAM,OAAO;AAIb,SAAK,8BAA8B;AACnC,WAAO,6BAA6B;AAAA,EACtC,GAAG,CAAC,CAAC;AAEL,8BAAU,MAAM;AACd,UAAM,UAAU,WAAW;AAC3B,QAAI,CAAC;AAAS;AAGd,QAAI,WAAW;AACb,cAAQ,YAAY;AAAA,IACtB;AACA,QAAI,YAAY;AACd,cAAQ,aAAa;AAAA,IACvB;AACA,QAAI,qBAAqB,QAAW;AAClC,cAAQ,mBAAmB;AAAA,IAC7B;AAGA,UAAM,mBAAmB,CAAC,MAAa;AACrC,YAAM,cAAc;AACpB,qBAAe,YAAY,OAAO,GAAG;AAAA,IACvC;AACA,UAAM,aAAa,CAAC,MAAa;AAC/B,YAAM,cAAc;AACpB,eAAS,YAAY,OAAO,GAAG;AAAA,IACjC;AACA,UAAM,cAAc,CAAC,MAAa;AAChC,YAAM,cAAc;AACpB,gBAAU,YAAY,KAAK;AAAA,IAC7B;AACA,UAAM,eAAe,CAAC,MAAa;AACjC,YAAM,cAAc;AAMpB,iBAAW;AAAA,QACT,aAAa,YAAY,eAAe;AAAA,QACxC,SAAS,YAAY,WAAW;AAAA,QAChC,cAAc,YAAY;AAAA,QAC1B,UAAU,YAAY;AAAA,MACxB,CAAC;AAAA,IACH;AAEA,QAAI;AAAc,cAAQ,iBAAiB,cAAc,gBAAgB;AACzE,QAAI;AAAQ,cAAQ,iBAAiB,QAAQ,UAAU;AACvD,QAAI;AAAS,cAAQ,iBAAiB,SAAS,WAAW;AAC1D,QAAI;AAAU,cAAQ,iBAAiB,UAAU,YAAY;AAE7D,WAAO,MAAM;AACX,UAAI;AACF,gBAAQ,oBAAoB,cAAc,gBAAgB;AAC5D,UAAI;AAAQ,gBAAQ,oBAAoB,QAAQ,UAAU;AAC1D,UAAI;AAAS,gBAAQ,oBAAoB,SAAS,WAAW;AAC7D,UAAI;AAAU,gBAAQ,oBAAoB,UAAU,YAAY;AAAA,IAClE;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,SACE,4CAAC,sBAAiB,KAAK,YAAY,KAChC,UACH;AAEJ;","names":[]}
@@ -1,5 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { O as OnRequestHook, a as OnResponseHook } from '../../types-cbe44b51.js';
2
+ import { H as HostConfig, C as ClientHostConfig, a as HostLifecycleCallbacks } from '../../host-config-58cdccea.js';
3
+ import '../../internal/shared/client/proxy-through-host.js';
4
+ import '../../types-2b26a246.js';
3
5
  import 'parse5/dist/tree-adapters/default';
4
6
 
5
7
  declare module 'react/jsx-runtime' {
@@ -13,33 +15,19 @@ declare module 'react/jsx-runtime' {
13
15
  }
14
16
  }
15
17
  }
16
- interface RemoteComponentProps {
18
+ /**
19
+ * Props for the Pages Router client-side remote component wrapper.
20
+ *
21
+ * Extends {@link HostConfig}, {@link ClientHostConfig}, and
22
+ * {@link HostLifecycleCallbacks}. The `src` prop is required since
23
+ * the client always needs a source URL to load from.
24
+ */
25
+ interface RemoteComponentProps extends HostConfig, ClientHostConfig, HostLifecycleCallbacks {
26
+ /** The source URL of the remote component. Required for client-side loading. */
17
27
  src: string;
28
+ /** Loading fallback content displayed while the remote component is being fetched. */
18
29
  children?: React.ReactNode;
19
- /** Called right before a new remote component load starts. */
20
- onBeforeLoad?: (src: string | URL) => void;
21
- /** Called when the remote component has been successfully loaded and mounted. */
22
- onLoad?: (src: string | URL) => void;
23
- /** Called when an error occurs while loading or mounting the remote component. */
24
- onError?: (error: unknown) => void;
25
- /** Called when a different remote component is loaded into the same wrapper. */
26
- onChange?: (info: {
27
- previousSrc: string | URL | null;
28
- nextSrc: string | URL | null;
29
- previousName: string | undefined;
30
- nextName: string | undefined;
31
- }) => void;
32
- /**
33
- * Called when a fetch request is made to retrieve the remote component payload.
34
- * Can be used to intercept requests, modify headers, or provide a custom response.
35
- */
36
- onRequest?: OnRequestHook;
37
- /**
38
- * Called after a fetch completes to retrieve the remote component payload.
39
- * Can be used to inspect the response (e.g., check for redirects) or transform it.
40
- */
41
- onResponse?: OnResponseHook;
42
30
  }
43
- declare function RemoteComponent({ src, children, onBeforeLoad, onChange, onError, onLoad, onRequest, onResponse, }: RemoteComponentProps): react_jsx_runtime.JSX.Element;
31
+ declare function RemoteComponent({ src, children, onBeforeLoad, onChange, onError, onLoad, onRequest, onResponse, resolveClientUrl, }: RemoteComponentProps): react_jsx_runtime.JSX.Element;
44
32
 
45
33
  export { RemoteComponent, RemoteComponentProps };
@@ -9,7 +9,8 @@ function RemoteComponent({
9
9
  onError,
10
10
  onLoad,
11
11
  onRequest,
12
- onResponse
12
+ onResponse,
13
+ resolveClientUrl
13
14
  }) {
14
15
  const elementRef = useRef(null);
15
16
  useEffect(() => {
@@ -27,6 +28,9 @@ function RemoteComponent({
27
28
  if (onResponse) {
28
29
  element.onResponse = onResponse;
29
30
  }
31
+ if (resolveClientUrl !== void 0) {
32
+ element.resolveClientUrl = resolveClientUrl;
33
+ }
30
34
  const handleBeforeLoad = (e) => {
31
35
  const customEvent = e;
32
36
  onBeforeLoad?.(customEvent.src ?? src);
@@ -66,7 +70,16 @@ function RemoteComponent({
66
70
  if (onChange)
67
71
  element.removeEventListener("change", handleChange);
68
72
  };
69
- }, [src, onBeforeLoad, onChange, onError, onLoad, onRequest, onResponse]);
73
+ }, [
74
+ src,
75
+ onBeforeLoad,
76
+ onChange,
77
+ onError,
78
+ onLoad,
79
+ onRequest,
80
+ onResponse,
81
+ resolveClientUrl
82
+ ]);
70
83
  return /* @__PURE__ */ jsx("remote-component", { ref: elementRef, src, children });
71
84
  }
72
85
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/next/host/pages-router-client.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { shared } from 'remote-components/shared/host/pages';\nimport type { OnRequestHook, OnResponseHook } from '#internal/shared/ssr/types';\n\n// patch react/jsx-runtime to support the remote-component custom element\ndeclare module 'react/jsx-runtime' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace JSX {\n interface IntrinsicElements {\n 'remote-component': {\n src?: string;\n ref?: React.Ref<HTMLElement>;\n children: React.ReactNode;\n };\n }\n }\n}\n\n// Extend HTMLElement to include onRequest/onResponse properties from the custom element\ninterface RemoteComponentElement extends HTMLElement {\n onRequest?: OnRequestHook;\n onResponse?: OnResponseHook;\n}\n\nexport interface RemoteComponentProps {\n src: string;\n children?: React.ReactNode;\n /** Called right before a new remote component load starts. */\n onBeforeLoad?: (src: string | URL) => void;\n /** Called when the remote component has been successfully loaded and mounted. */\n onLoad?: (src: string | URL) => void;\n /** Called when an error occurs while loading or mounting the remote component. */\n onError?: (error: unknown) => void;\n /** Called when a different remote component is loaded into the same wrapper. */\n onChange?: (info: {\n previousSrc: string | URL | null;\n nextSrc: string | URL | null;\n previousName: string | undefined;\n nextName: string | undefined;\n }) => void;\n /**\n * Called when a fetch request is made to retrieve the remote component payload.\n * Can be used to intercept requests, modify headers, or provide a custom response.\n */\n onRequest?: OnRequestHook;\n /**\n * Called after a fetch completes to retrieve the remote component payload.\n * Can be used to inspect the response (e.g., check for redirects) or transform it.\n */\n onResponse?: OnResponseHook;\n}\n\nexport function RemoteComponent({\n src,\n children,\n onBeforeLoad,\n onChange,\n onError,\n onLoad,\n onRequest,\n onResponse,\n}: RemoteComponentProps) {\n const elementRef = useRef<RemoteComponentElement>(null);\n\n useEffect(() => {\n const self = globalThis as typeof globalThis & {\n __remote_component_shared__?: Record<string, () => Promise<unknown>>;\n };\n // eslint-disable-next-line camelcase\n self.__remote_component_shared__ = shared;\n import('remote-components/html/host');\n }, []);\n\n useEffect(() => {\n const element = elementRef.current;\n if (!element) return;\n\n // Set onRequest/onResponse properties on the element before it loads\n if (onRequest) {\n element.onRequest = onRequest;\n }\n if (onResponse) {\n element.onResponse = onResponse;\n }\n\n // Set up event listeners for lifecycle hooks\n const handleBeforeLoad = (e: Event) => {\n const customEvent = e as CustomEvent & { src?: string };\n onBeforeLoad?.(customEvent.src ?? src);\n };\n const handleLoad = (e: Event) => {\n const customEvent = e as CustomEvent & { src?: string };\n onLoad?.(customEvent.src ?? src);\n };\n const handleError = (e: Event) => {\n const customEvent = e as CustomEvent & { error?: unknown };\n onError?.(customEvent.error);\n };\n const handleChange = (e: Event) => {\n const customEvent = e as CustomEvent & {\n previousSrc?: string | null;\n nextSrc?: string | null;\n previousName?: string;\n nextName?: string;\n };\n onChange?.({\n previousSrc: customEvent.previousSrc ?? null,\n nextSrc: customEvent.nextSrc ?? null,\n previousName: customEvent.previousName,\n nextName: customEvent.nextName,\n });\n };\n\n if (onBeforeLoad) element.addEventListener('beforeload', handleBeforeLoad);\n if (onLoad) element.addEventListener('load', handleLoad);\n if (onError) element.addEventListener('error', handleError);\n if (onChange) element.addEventListener('change', handleChange);\n\n return () => {\n if (onBeforeLoad)\n element.removeEventListener('beforeload', handleBeforeLoad);\n if (onLoad) element.removeEventListener('load', handleLoad);\n if (onError) element.removeEventListener('error', handleError);\n if (onChange) element.removeEventListener('change', handleChange);\n };\n }, [src, onBeforeLoad, onChange, onError, onLoad, onRequest, onResponse]);\n\n return (\n <remote-component ref={elementRef} src={src}>\n {children}\n </remote-component>\n );\n}\n"],"mappings":"AAgII;AAhIJ,SAAS,WAAW,cAAc;AAClC,SAAS,cAAc;AAmDhB,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,aAAa,OAA+B,IAAI;AAEtD,YAAU,MAAM;AACd,UAAM,OAAO;AAIb,SAAK,8BAA8B;AACnC,WAAO,6BAA6B;AAAA,EACtC,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,UAAM,UAAU,WAAW;AAC3B,QAAI,CAAC;AAAS;AAGd,QAAI,WAAW;AACb,cAAQ,YAAY;AAAA,IACtB;AACA,QAAI,YAAY;AACd,cAAQ,aAAa;AAAA,IACvB;AAGA,UAAM,mBAAmB,CAAC,MAAa;AACrC,YAAM,cAAc;AACpB,qBAAe,YAAY,OAAO,GAAG;AAAA,IACvC;AACA,UAAM,aAAa,CAAC,MAAa;AAC/B,YAAM,cAAc;AACpB,eAAS,YAAY,OAAO,GAAG;AAAA,IACjC;AACA,UAAM,cAAc,CAAC,MAAa;AAChC,YAAM,cAAc;AACpB,gBAAU,YAAY,KAAK;AAAA,IAC7B;AACA,UAAM,eAAe,CAAC,MAAa;AACjC,YAAM,cAAc;AAMpB,iBAAW;AAAA,QACT,aAAa,YAAY,eAAe;AAAA,QACxC,SAAS,YAAY,WAAW;AAAA,QAChC,cAAc,YAAY;AAAA,QAC1B,UAAU,YAAY;AAAA,MACxB,CAAC;AAAA,IACH;AAEA,QAAI;AAAc,cAAQ,iBAAiB,cAAc,gBAAgB;AACzE,QAAI;AAAQ,cAAQ,iBAAiB,QAAQ,UAAU;AACvD,QAAI;AAAS,cAAQ,iBAAiB,SAAS,WAAW;AAC1D,QAAI;AAAU,cAAQ,iBAAiB,UAAU,YAAY;AAE7D,WAAO,MAAM;AACX,UAAI;AACF,gBAAQ,oBAAoB,cAAc,gBAAgB;AAC5D,UAAI;AAAQ,gBAAQ,oBAAoB,QAAQ,UAAU;AAC1D,UAAI;AAAS,gBAAQ,oBAAoB,SAAS,WAAW;AAC7D,UAAI;AAAU,gBAAQ,oBAAoB,UAAU,YAAY;AAAA,IAClE;AAAA,EACF,GAAG,CAAC,KAAK,cAAc,UAAU,SAAS,QAAQ,WAAW,UAAU,CAAC;AAExE,SACE,oBAAC,sBAAiB,KAAK,YAAY,KAChC,UACH;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/next/host/pages-router-client.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { shared } from 'remote-components/shared/host/pages';\nimport type { ResolveClientUrl } from '#internal/shared/client/proxy-through-host';\nimport type {\n ClientHostConfig,\n HostConfig,\n HostLifecycleCallbacks,\n} from '#internal/shared/contract/host-config';\nimport type { OnRequestHook, OnResponseHook } from '#internal/shared/ssr/types';\n\n// patch react/jsx-runtime to support the remote-component custom element\ndeclare module 'react/jsx-runtime' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace JSX {\n interface IntrinsicElements {\n 'remote-component': {\n src?: string;\n ref?: React.Ref<HTMLElement>;\n children: React.ReactNode;\n };\n }\n }\n}\n\n// Extend HTMLElement to include onRequest/onResponse/resolveClientUrl properties from the custom element\ninterface RemoteComponentElement extends HTMLElement {\n onRequest?: OnRequestHook;\n onResponse?: OnResponseHook;\n resolveClientUrl?: ResolveClientUrl;\n}\n\n/**\n * Props for the Pages Router client-side remote component wrapper.\n *\n * Extends {@link HostConfig}, {@link ClientHostConfig}, and\n * {@link HostLifecycleCallbacks}. The `src` prop is required since\n * the client always needs a source URL to load from.\n */\nexport interface RemoteComponentProps\n extends HostConfig,\n ClientHostConfig,\n HostLifecycleCallbacks {\n /** The source URL of the remote component. Required for client-side loading. */\n src: string;\n /** Loading fallback content displayed while the remote component is being fetched. */\n children?: React.ReactNode;\n}\n\nexport function RemoteComponent({\n src,\n children,\n onBeforeLoad,\n onChange,\n onError,\n onLoad,\n onRequest,\n onResponse,\n resolveClientUrl,\n}: RemoteComponentProps) {\n const elementRef = useRef<RemoteComponentElement>(null);\n\n useEffect(() => {\n const self = globalThis as typeof globalThis & {\n __remote_component_shared__?: Record<string, () => Promise<unknown>>;\n };\n // eslint-disable-next-line camelcase\n self.__remote_component_shared__ = shared;\n import('remote-components/html/host');\n }, []);\n\n useEffect(() => {\n const element = elementRef.current;\n if (!element) return;\n\n // Set onRequest/onResponse/resolveClientUrl properties on the element before it loads\n if (onRequest) {\n element.onRequest = onRequest;\n }\n if (onResponse) {\n element.onResponse = onResponse;\n }\n if (resolveClientUrl !== undefined) {\n element.resolveClientUrl = resolveClientUrl;\n }\n\n // Set up event listeners for lifecycle hooks\n const handleBeforeLoad = (e: Event) => {\n const customEvent = e as CustomEvent & { src?: string };\n onBeforeLoad?.(customEvent.src ?? src);\n };\n const handleLoad = (e: Event) => {\n const customEvent = e as CustomEvent & { src?: string };\n onLoad?.(customEvent.src ?? src);\n };\n const handleError = (e: Event) => {\n const customEvent = e as CustomEvent & { error?: unknown };\n onError?.(customEvent.error);\n };\n const handleChange = (e: Event) => {\n const customEvent = e as CustomEvent & {\n previousSrc?: string | null;\n nextSrc?: string | null;\n previousName?: string;\n nextName?: string;\n };\n onChange?.({\n previousSrc: customEvent.previousSrc ?? null,\n nextSrc: customEvent.nextSrc ?? null,\n previousName: customEvent.previousName,\n nextName: customEvent.nextName,\n });\n };\n\n if (onBeforeLoad) element.addEventListener('beforeload', handleBeforeLoad);\n if (onLoad) element.addEventListener('load', handleLoad);\n if (onError) element.addEventListener('error', handleError);\n if (onChange) element.addEventListener('change', handleChange);\n\n return () => {\n if (onBeforeLoad)\n element.removeEventListener('beforeload', handleBeforeLoad);\n if (onLoad) element.removeEventListener('load', handleLoad);\n if (onError) element.removeEventListener('error', handleError);\n if (onChange) element.removeEventListener('change', handleChange);\n };\n }, [\n src,\n onBeforeLoad,\n onChange,\n onError,\n onLoad,\n onRequest,\n onResponse,\n resolveClientUrl,\n ]);\n\n return (\n <remote-component ref={elementRef} src={src}>\n {children}\n </remote-component>\n );\n}\n"],"mappings":"AAyII;AAzIJ,SAAS,WAAW,cAAc;AAClC,SAAS,cAAc;AA+ChB,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,aAAa,OAA+B,IAAI;AAEtD,YAAU,MAAM;AACd,UAAM,OAAO;AAIb,SAAK,8BAA8B;AACnC,WAAO,6BAA6B;AAAA,EACtC,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,UAAM,UAAU,WAAW;AAC3B,QAAI,CAAC;AAAS;AAGd,QAAI,WAAW;AACb,cAAQ,YAAY;AAAA,IACtB;AACA,QAAI,YAAY;AACd,cAAQ,aAAa;AAAA,IACvB;AACA,QAAI,qBAAqB,QAAW;AAClC,cAAQ,mBAAmB;AAAA,IAC7B;AAGA,UAAM,mBAAmB,CAAC,MAAa;AACrC,YAAM,cAAc;AACpB,qBAAe,YAAY,OAAO,GAAG;AAAA,IACvC;AACA,UAAM,aAAa,CAAC,MAAa;AAC/B,YAAM,cAAc;AACpB,eAAS,YAAY,OAAO,GAAG;AAAA,IACjC;AACA,UAAM,cAAc,CAAC,MAAa;AAChC,YAAM,cAAc;AACpB,gBAAU,YAAY,KAAK;AAAA,IAC7B;AACA,UAAM,eAAe,CAAC,MAAa;AACjC,YAAM,cAAc;AAMpB,iBAAW;AAAA,QACT,aAAa,YAAY,eAAe;AAAA,QACxC,SAAS,YAAY,WAAW;AAAA,QAChC,cAAc,YAAY;AAAA,QAC1B,UAAU,YAAY;AAAA,MACxB,CAAC;AAAA,IACH;AAEA,QAAI;AAAc,cAAQ,iBAAiB,cAAc,gBAAgB;AACzE,QAAI;AAAQ,cAAQ,iBAAiB,QAAQ,UAAU;AACvD,QAAI;AAAS,cAAQ,iBAAiB,SAAS,WAAW;AAC1D,QAAI;AAAU,cAAQ,iBAAiB,UAAU,YAAY;AAE7D,WAAO,MAAM;AACX,UAAI;AACF,gBAAQ,oBAAoB,cAAc,gBAAgB;AAC5D,UAAI;AAAQ,gBAAQ,oBAAoB,QAAQ,UAAU;AAC1D,UAAI;AAAS,gBAAQ,oBAAoB,SAAS,WAAW;AAC7D,UAAI;AAAU,gBAAQ,oBAAoB,UAAU,YAAY;AAAA,IAClE;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,SACE,oBAAC,sBAAiB,KAAK,YAAY,KAChC,UACH;AAEJ;","names":[]}
@@ -148,6 +148,7 @@ function RemoteComponent(props) {
148
148
  onLoad: props.onLoad,
149
149
  onRequest: props.onRequest,
150
150
  onResponse: props.onResponse,
151
+ resolveClientUrl: props.resolveClientUrl,
151
152
  reset: props.reset,
152
153
  shared: shared(props.bundle ?? "default"),
153
154
  src: props.src,
@@ -167,6 +168,7 @@ function RemoteComponent(props) {
167
168
  onLoad: props.onLoad,
168
169
  onRequest: props.onRequest,
169
170
  onResponse: props.onResponse,
171
+ resolveClientUrl: props.resolveClientUrl,
170
172
  reset: props.reset,
171
173
  shared: shared(props.bundle ?? "default"),
172
174
  src: props.src,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/next/host/pages-router-server.tsx"],"sourcesContent":["import * as Form from 'next/form';\nimport * as Image from 'next/image';\nimport * as Link from 'next/link';\nimport * as Router from 'next/router';\nimport * as Script from 'next/script';\nimport { useEffect } from 'react';\nimport { shared as _shared } from 'remote-components/shared/host/pages';\nimport { RemoteComponentsError } from '#internal/shared/client/remote-component';\nimport { fetchRemoteComponent } from '#internal/shared/ssr/fetch-remote-component';\nimport type { OnRequestHook, OnResponseHook } from '#internal/shared/ssr/types';\nimport { RemoteComponent as RemoteComponentReact } from '#remote-components/react/index';\n\nconst navigationImpl = {\n useRouter: () => Router.useRouter(),\n useSearchParams: () => {\n const router = Router.useRouter();\n return {\n get: (key: string) => router.query[key],\n has: (key: string) => key in router.query,\n };\n },\n};\n\nconst sharedCache = new Map<string, Record<string, () => Promise<unknown>>>();\nconst shared = (bundle: string) => {\n if (sharedCache.has(bundle)) {\n return sharedCache.get(bundle);\n }\n\n const remoteLoader = ({ src, width, quality }: Image.ImageLoaderProps) => {\n const self = globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n };\n const { assetPrefix } =\n /^(?<assetPrefix>.*?)\\/_next\\//.exec(src)?.groups ?? {};\n return `${\n self.__remote_bundle_url__?.[bundle]?.origin ?? ''\n }${assetPrefix}/_next/image?url=${encodeURIComponent(src)}&w=${width}&q=${\n quality || 75\n }`;\n };\n\n const imageImpl = (ImageComponent: typeof Image.default) => {\n function RemoteImage(props: Image.ImageProps) {\n return <ImageComponent loader={remoteLoader} {...props} />;\n }\n RemoteImage.default = RemoteImage;\n RemoteImage.getImageProps = Image.getImageProps;\n return RemoteImage;\n };\n\n return {\n // polyfill Next.js App Router client API (minimal)\n // some API methods are not available when using a Next.js Pages Router application as host\n 'next/navigation': () =>\n Promise.resolve(navigationImpl) as Promise<unknown>,\n 'next/dist/client/components/navigation': () =>\n Promise.resolve(navigationImpl) as Promise<unknown>,\n 'next/dist/client/app-dir/link': () =>\n Promise.resolve(Link.default) as Promise<unknown>,\n 'next/link': () => Promise.resolve(Link.default) as Promise<unknown>,\n 'next/dist/client/app-dir/form': () =>\n Promise.resolve(Form.default) as Promise<unknown>,\n 'next/form': () => Promise.resolve(Form.default) as Promise<unknown>,\n 'next/dist/client/script': () =>\n Promise.resolve(Script.default) as Promise<unknown>,\n 'next/script': () => Promise.resolve(Script.default) as Promise<unknown>,\n 'next/dist/client/image-component': () =>\n Promise.resolve({\n // @ts-expect-error default.default\n // eslint-disable-next-line\n Image: imageImpl(Image.default.default ?? Image.default),\n }) as Promise<unknown>,\n 'next/dist/api/image': () =>\n Promise.resolve({\n // @ts-expect-error default.default\n // eslint-disable-next-line\n default: imageImpl(Image.default.default ?? Image.default),\n getImageProps: Image.getImageProps,\n }) as Promise<unknown>,\n 'next/router': () => Promise.resolve(Router) as Promise<unknown>,\n ..._shared,\n // always override next/image to use the remote loader\n 'next/image': () =>\n Promise.resolve(\n // @ts-expect-error default.default\n // eslint-disable-next-line\n imageImpl(Image.default.default ?? Image.default),\n ) as Promise<unknown>,\n };\n};\n\n// internal symbols to access global store\nconst REMOTE_COMPONENT_STORE = Symbol('REMOTE_COMPONENT_STORE');\nconst REMOTE_COMPONENT_KEY = '__REMOTE_COMPONENT_KEY__';\n\n// temporary global store for remote component HTML\n// the store is used to save the HTML of remote components for SSR without sending the content to the client\nconst self = globalThis as typeof globalThis & {\n [REMOTE_COMPONENT_STORE]?: Map<string, React.ReactNode>;\n};\n\nfunction getKey({\n bundle,\n route,\n name,\n}: {\n bundle?: string;\n route?: string;\n name?: string;\n}): string {\n return `${bundle ?? '__next'}:${route ?? '/'}:${\n name ?? '__vercel_remote_component'\n }__${crypto.randomUUID()}`;\n}\n\nfunction setComponent(key: string, component: React.ReactNode): void {\n if (!self[REMOTE_COMPONENT_STORE]) {\n self[REMOTE_COMPONENT_STORE] = new Map();\n }\n self[REMOTE_COMPONENT_STORE].set(key, component);\n}\n\nfunction getComponent(key: string): React.ReactNode | undefined {\n const component = self[REMOTE_COMPONENT_STORE]?.get(key);\n // remove the component from the store after retrieving it to prevent memory leaks\n // storing the HTML in the global store is only needed for SSR and it's temporary only used for a single render\n self[REMOTE_COMPONENT_STORE]?.delete(key);\n return component;\n}\n\nexport interface RemoteComponentProps {\n src: string;\n bundle?: string;\n route?: string;\n name?: string;\n isolate?: boolean;\n mode?: 'open' | 'closed';\n reset?: boolean;\n /** Called right before a new remote component load starts. */\n onBeforeLoad?: (src: string | URL) => void;\n /** Called when the remote component has been successfully loaded and mounted. */\n onLoad?: (src: string | URL) => void;\n /** Called when an error occurs while loading or mounting the remote component. */\n onError?: (error: unknown) => void;\n /** Called when a different remote component is loaded into the same wrapper. */\n onChange?: (info: {\n previousSrc: string | URL | null;\n nextSrc: string | URL | null;\n previousName: string | undefined;\n nextName: string | undefined;\n }) => void;\n /**\n * Called when a fetch request is made to retrieve the remote component payload.\n * Can be used to intercept requests, modify headers, or provide a custom response.\n */\n onRequest?: OnRequestHook;\n /**\n * Called after a fetch completes to retrieve the remote component payload.\n * Can be used to inspect the response (e.g., check for redirects) or transform it.\n */\n onResponse?: OnResponseHook;\n [REMOTE_COMPONENT_KEY]?: string;\n children?: React.ReactNode;\n}\n\n/**\n * This component handles the rendering of remote microfrontends.\n *\n * @param props - The properties for the remote component.\n * @returns A React component that renders the remote component.\n */\nexport function RemoteComponent(props: RemoteComponentProps) {\n const remoteComponent =\n typeof document !== 'undefined'\n ? null\n : // retrieve the HTML from the global store\n getComponent(\n props[REMOTE_COMPONENT_KEY] ?? '__vercel_remote_component',\n );\n\n useEffect(() => {\n const clientSelf = globalThis as typeof globalThis & {\n __remote_component_shared__?: Record<string, () => Promise<unknown>>;\n };\n // eslint-disable-next-line camelcase\n clientSelf.__remote_component_shared__ = shared(props.bundle ?? 'default');\n }, [props.bundle]);\n\n if (!props[REMOTE_COMPONENT_KEY]) {\n return (\n <RemoteComponentReact\n isolate={props.isolate}\n mode={props.mode}\n name={props.name}\n onBeforeLoad={props.onBeforeLoad}\n onChange={props.onChange}\n onError={props.onError}\n onLoad={props.onLoad}\n onRequest={props.onRequest}\n onResponse={props.onResponse}\n reset={props.reset}\n shared={shared(props.bundle ?? 'default')}\n src={props.src}\n >\n {props.children}\n </RemoteComponentReact>\n );\n }\n\n return (\n <RemoteComponentReact\n isolate={props.isolate}\n mode={props.mode}\n name={props.name}\n onBeforeLoad={props.onBeforeLoad}\n onChange={props.onChange}\n onError={props.onError}\n onLoad={props.onLoad}\n onRequest={props.onRequest}\n onResponse={props.onResponse}\n reset={props.reset}\n shared={shared(props.bundle ?? 'default')}\n src={props.src}\n >\n {remoteComponent}\n </RemoteComponentReact>\n );\n}\n\n/**\n * Fetches the remote component properties from the server. You need to pass these properties to the `<RemoteComponent>` component to render the fetched remote component.\n *\n * @param src - The source URL of the remote component. When using the Vercel Microfrontends solution, you can use relative paths, e.g. `/nextjs-app-remote/components/header`. Absolute URLs are also supported.\n * @param headers - The HTTP headers used for supporting the Vercel Microfrontends proxy.\n * @returns The properties of the remote component.\n *\n * @example\n *\n * ```tsx\n * import { getRemoteComponentProps } from 'remote-components/next/host/pages';\n * import type { GetServerSideProps } from 'next';\n *\n * export const getServerSideProps: GetServerSideProps<PageProps> = async function getServerSideProps({ req }) {\n * const myRemoteComponent = await getRemoteComponentProps(\n * '/nextjs-app-remote/components/header',\n * req.headers,\n * );\n * return {\n * props: {\n * remoteComponents: {\n * myRemoteComponent,\n * },\n * },\n * };\n * }\n * ```\n */\nexport async function getRemoteComponentProps(\n src: string,\n options?: {\n /**\n * Called when a fetch request is made to retrieve the remote component payload.\n * Can be used to intercept requests, modify headers, or provide a custom response.\n */\n onRequest?: OnRequestHook;\n /**\n * Called after a fetch completes to retrieve the remote component payload.\n * Can be used to inspect the response (e.g., check for redirects) or transform it.\n */\n onResponse?: OnResponseHook;\n /**\n * The name of the exposed remote component. Used to identify the remote component\n * when multiple remote components are exposed on a page.\n */\n name?: string;\n },\n): Promise<RemoteComponentProps> {\n if (typeof document !== 'undefined') {\n throw new RemoteComponentsError(\n '`getRemoteComponentProps()` can only be used on the server side.',\n );\n }\n\n const {\n metadata: { bundle, route },\n name,\n links,\n component,\n nextData,\n remoteShared,\n } = await fetchRemoteComponent(src, {\n rsc: true,\n ...options,\n });\n\n const props: RemoteComponentProps = {\n src,\n bundle,\n name,\n route,\n };\n\n const key = getKey(props);\n\n // do not render the HTML in development mode when remote is using Next.js Pages Router\n // this behavior is emulating the Next.js Pages Router FOUC as the styles are only applied on the client when running in development mode\n if (nextData?.buildId !== 'development') {\n // store the HTML in a global store\n setComponent(\n key,\n <>\n <script\n data-remote-components-shared=\"\"\n id={`${name}_shared`}\n type=\"application/json\"\n >\n {JSON.stringify(remoteShared)}\n </script>\n {links.map((link) => (\n <link\n key={`${link.as}_${link.href}`}\n {...link}\n precedence={undefined}\n />\n ))}\n {component}\n </>,\n );\n }\n\n return {\n ...props,\n // add remote component key to the props\n [REMOTE_COMPONENT_KEY]: key,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4Ca;AA5Cb,WAAsB;AACtB,YAAuB;AACvB,WAAsB;AACtB,aAAwB;AACxB,aAAwB;AACxB,mBAA0B;AAC1B,mBAAkC;AAClC,8BAAsC;AACtC,oCAAqC;AAErC,IAAAA,gBAAwD;AAExD,MAAM,iBAAiB;AAAA,EACrB,WAAW,MAAM,OAAO,UAAU;AAAA,EAClC,iBAAiB,MAAM;AACrB,UAAM,SAAS,OAAO,UAAU;AAChC,WAAO;AAAA,MACL,KAAK,CAAC,QAAgB,OAAO,MAAM,GAAG;AAAA,MACtC,KAAK,CAAC,QAAgB,OAAO,OAAO;AAAA,IACtC;AAAA,EACF;AACF;AAEA,MAAM,cAAc,oBAAI,IAAoD;AAC5E,MAAM,SAAS,CAAC,WAAmB;AACjC,MAAI,YAAY,IAAI,MAAM,GAAG;AAC3B,WAAO,YAAY,IAAI,MAAM;AAAA,EAC/B;AAEA,QAAM,eAAe,CAAC,EAAE,KAAK,OAAO,QAAQ,M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AA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA;AAAA,IAEH,CAAC,oBAAoB,GAAG;AAAA,EAC1B;AACF;","names":["import_react","self","_shared","RemoteComponentReact"]}
1
+ {"version":3,"sources":["../../../src/next/host/pages-router-server.tsx"],"sourcesContent":["import * as Form from 'next/form';\nimport * as Image from 'next/image';\nimport * as Link from 'next/link';\nimport * as Router from 'next/router';\nimport * as Script from 'next/script';\nimport { useEffect } from 'react';\nimport { shared as _shared } from 'remote-components/shared/host/pages';\nimport { RemoteComponentsError } from '#internal/shared/client/remote-component';\nimport type {\n ClientHostConfig,\n HostConfig,\n HostLifecycleCallbacks,\n} from '#internal/shared/contract/host-config';\nimport { fetchRemoteComponent } from '#internal/shared/ssr/fetch-remote-component';\nimport type { OnRequestHook, OnResponseHook } from '#internal/shared/ssr/types';\nimport { RemoteComponent as RemoteComponentReact } from '#remote-components/react/index';\n\nconst navigationImpl = {\n useRouter: () => Router.useRouter(),\n useSearchParams: () => {\n const router = Router.useRouter();\n return {\n get: (key: string) => router.query[key],\n has: (key: string) => key in router.query,\n };\n },\n};\n\nconst sharedCache = new Map<string, Record<string, () => Promise<unknown>>>();\nconst shared = (bundle: string) => {\n if (sharedCache.has(bundle)) {\n return sharedCache.get(bundle);\n }\n\n const remoteLoader = ({ src, width, quality }: Image.ImageLoaderProps) => {\n const self = globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n };\n const { assetPrefix } =\n /^(?<assetPrefix>.*?)\\/_next\\//.exec(src)?.groups ?? {};\n return `${\n self.__remote_bundle_url__?.[bundle]?.origin ?? ''\n }${assetPrefix}/_next/image?url=${encodeURIComponent(src)}&w=${width}&q=${\n quality || 75\n }`;\n };\n\n const imageImpl = (ImageComponent: typeof Image.default) => {\n function RemoteImage(props: Image.ImageProps) {\n return <ImageComponent loader={remoteLoader} {...props} />;\n }\n RemoteImage.default = RemoteImage;\n RemoteImage.getImageProps = Image.getImageProps;\n return RemoteImage;\n };\n\n return {\n // polyfill Next.js App Router client API (minimal)\n // some API methods are not available when using a Next.js Pages Router application as host\n 'next/navigation': () =>\n Promise.resolve(navigationImpl) as Promise<unknown>,\n 'next/dist/client/components/navigation': () =>\n Promise.resolve(navigationImpl) as Promise<unknown>,\n 'next/dist/client/app-dir/link': () =>\n Promise.resolve(Link.default) as Promise<unknown>,\n 'next/link': () => Promise.resolve(Link.default) as Promise<unknown>,\n 'next/dist/client/app-dir/form': () =>\n Promise.resolve(Form.default) as Promise<unknown>,\n 'next/form': () => Promise.resolve(Form.default) as Promise<unknown>,\n 'next/dist/client/script': () =>\n Promise.resolve(Script.default) as Promise<unknown>,\n 'next/script': () => Promise.resolve(Script.default) as Promise<unknown>,\n 'next/dist/client/image-component': () =>\n Promise.resolve({\n // @ts-expect-error default.default\n // eslint-disable-next-line\n Image: imageImpl(Image.default.default ?? Image.default),\n }) as Promise<unknown>,\n 'next/dist/api/image': () =>\n Promise.resolve({\n // @ts-expect-error default.default\n // eslint-disable-next-line\n default: imageImpl(Image.default.default ?? Image.default),\n getImageProps: Image.getImageProps,\n }) as Promise<unknown>,\n 'next/router': () => Promise.resolve(Router) as Promise<unknown>,\n ..._shared,\n // always override next/image to use the remote loader\n 'next/image': () =>\n Promise.resolve(\n // @ts-expect-error default.default\n // eslint-disable-next-line\n imageImpl(Image.default.default ?? Image.default),\n ) as Promise<unknown>,\n };\n};\n\n// internal symbols to access global store\nconst REMOTE_COMPONENT_STORE = Symbol('REMOTE_COMPONENT_STORE');\nconst REMOTE_COMPONENT_KEY = '__REMOTE_COMPONENT_KEY__';\n\n// temporary global store for remote component HTML\n// the store is used to save the HTML of remote components for SSR without sending the content to the client\nconst self = globalThis as typeof globalThis & {\n [REMOTE_COMPONENT_STORE]?: Map<string, React.ReactNode>;\n};\n\nfunction getKey({\n bundle,\n route,\n name,\n}: {\n bundle?: string;\n route?: string;\n name?: string;\n}): string {\n return `${bundle ?? '__next'}:${route ?? '/'}:${\n name ?? '__vercel_remote_component'\n }__${crypto.randomUUID()}`;\n}\n\nfunction setComponent(key: string, component: React.ReactNode): void {\n if (!self[REMOTE_COMPONENT_STORE]) {\n self[REMOTE_COMPONENT_STORE] = new Map();\n }\n self[REMOTE_COMPONENT_STORE].set(key, component);\n}\n\nfunction getComponent(key: string): React.ReactNode | undefined {\n const component = self[REMOTE_COMPONENT_STORE]?.get(key);\n // remove the component from the store after retrieving it to prevent memory leaks\n // storing the HTML in the global store is only needed for SSR and it's temporary only used for a single render\n self[REMOTE_COMPONENT_STORE]?.delete(key);\n return component;\n}\n\n/**\n * Props for the Next.js Pages Router remote component host.\n *\n * Extends {@link HostConfig}, {@link ClientHostConfig}, and\n * {@link HostLifecycleCallbacks}. Adds Pages Router–specific `bundle` and\n * `route` props used for SSR hydration.\n */\nexport interface RemoteComponentProps\n extends HostConfig,\n ClientHostConfig,\n HostLifecycleCallbacks {\n /** The source URL of the remote component. Required for server rendering. */\n src: string | URL;\n /** The Webpack bundle name for the remote component. */\n bundle?: string;\n /** The page route of the remote component. */\n route?: string;\n /** Loading fallback content displayed while the remote component is being fetched. */\n children?: React.ReactNode;\n [REMOTE_COMPONENT_KEY]?: string;\n}\n\n/**\n * This component handles the rendering of remote microfrontends.\n *\n * @param props - The properties for the remote component.\n * @returns A React component that renders the remote component.\n */\nexport function RemoteComponent(props: RemoteComponentProps) {\n const remoteComponent =\n typeof document !== 'undefined'\n ? null\n : // retrieve the HTML from the global store\n getComponent(\n props[REMOTE_COMPONENT_KEY] ?? '__vercel_remote_component',\n );\n\n useEffect(() => {\n const clientSelf = globalThis as typeof globalThis & {\n __remote_component_shared__?: Record<string, () => Promise<unknown>>;\n };\n // eslint-disable-next-line camelcase\n clientSelf.__remote_component_shared__ = shared(props.bundle ?? 'default');\n }, [props.bundle]);\n\n if (!props[REMOTE_COMPONENT_KEY]) {\n return (\n <RemoteComponentReact\n isolate={props.isolate}\n mode={props.mode}\n name={props.name}\n onBeforeLoad={props.onBeforeLoad}\n onChange={props.onChange}\n onError={props.onError}\n onLoad={props.onLoad}\n onRequest={props.onRequest}\n onResponse={props.onResponse}\n resolveClientUrl={props.resolveClientUrl}\n reset={props.reset}\n shared={shared(props.bundle ?? 'default')}\n src={props.src}\n >\n {props.children}\n </RemoteComponentReact>\n );\n }\n\n return (\n <RemoteComponentReact\n isolate={props.isolate}\n mode={props.mode}\n name={props.name}\n onBeforeLoad={props.onBeforeLoad}\n onChange={props.onChange}\n onError={props.onError}\n onLoad={props.onLoad}\n onRequest={props.onRequest}\n onResponse={props.onResponse}\n resolveClientUrl={props.resolveClientUrl}\n reset={props.reset}\n shared={shared(props.bundle ?? 'default')}\n src={props.src}\n >\n {remoteComponent}\n </RemoteComponentReact>\n );\n}\n\n/**\n * Fetches the remote component properties from the server. You need to pass these properties to the `<RemoteComponent>` component to render the fetched remote component.\n *\n * @param src - The source URL of the remote component. When using the Vercel Microfrontends solution, you can use relative paths, e.g. `/nextjs-app-remote/components/header`. Absolute URLs are also supported.\n * @param headers - The HTTP headers used for supporting the Vercel Microfrontends proxy.\n * @returns The properties of the remote component.\n *\n * @example\n *\n * ```tsx\n * import { getRemoteComponentProps } from 'remote-components/next/host/pages';\n * import type { GetServerSideProps } from 'next';\n *\n * export const getServerSideProps: GetServerSideProps<PageProps> = async function getServerSideProps({ req }) {\n * const myRemoteComponent = await getRemoteComponentProps(\n * '/nextjs-app-remote/components/header',\n * req.headers,\n * );\n * return {\n * props: {\n * remoteComponents: {\n * myRemoteComponent,\n * },\n * },\n * };\n * }\n * ```\n */\nexport async function getRemoteComponentProps(\n src: string,\n options?: {\n /**\n * Called when a fetch request is made to retrieve the remote component payload.\n * Can be used to intercept requests, modify headers, or provide a custom response.\n */\n onRequest?: OnRequestHook;\n /**\n * Called after a fetch completes to retrieve the remote component payload.\n * Can be used to inspect the response (e.g., check for redirects) or transform it.\n */\n onResponse?: OnResponseHook;\n /**\n * The name of the exposed remote component. Used to identify the remote component\n * when multiple remote components are exposed on a page.\n */\n name?: string;\n },\n): Promise<RemoteComponentProps> {\n if (typeof document !== 'undefined') {\n throw new RemoteComponentsError(\n '`getRemoteComponentProps()` can only be used on the server side.',\n );\n }\n\n const {\n metadata: { bundle, route },\n name,\n links,\n component,\n nextData,\n remoteShared,\n } = await fetchRemoteComponent(src, {\n rsc: true,\n ...options,\n });\n\n const props: RemoteComponentProps = {\n src,\n bundle,\n name,\n route,\n };\n\n const key = getKey(props);\n\n // do not render the HTML in development mode when remote is using Next.js Pages Router\n // this behavior is emulating the Next.js Pages Router FOUC as the styles are only applied on the client when running in development mode\n if (nextData?.buildId !== 'development') {\n // store the HTML in a global store\n setComponent(\n key,\n <>\n <script\n data-remote-components-shared=\"\"\n id={`${name}_shared`}\n type=\"application/json\"\n >\n {JSON.stringify(remoteShared)}\n </script>\n {links.map((link) => (\n <link\n key={`${link.as}_${link.href}`}\n {...link}\n precedence={undefined}\n />\n ))}\n {component}\n </>,\n );\n }\n\n return {\n ...props,\n // add remote component key to the props\n [REMOTE_COMPONENT_KEY]: key,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiDa;AAjDb,WAAsB;AACtB,YAAuB;AACvB,WAAsB;AACtB,aAAwB;AACxB,aAAwB;AACxB,mBAA0B;AAC1B,mBAAkC;AAClC,8BAAsC;AAMtC,oCAAqC;AAErC,IAAAA,gBAAwD;AAExD,MAAM,iBAAiB;AAAA,EACrB,WAAW,MAAM,OAAO,UAAU;AAAA,EAClC,iBAAiB,MAAM;AACrB,UAAM,SAAS,OAAO,UAAU;AAChC,WAAO;AAAA,MACL,KAAK,CAAC,QAAgB,OAAO,MAAM,GAAG;AAAA,MACtC,KAAK,CAAC,QAAgB,OAAO,OAAO;AAAA,IACtC;AAAA,EACF;AACF;AAEA,MAAM,cAAc,oBAAI,IAAoD;AAC5E,MAAM,SAAS,CAAC,WAAmB;AACjC,MAAI,YAAY,IAAI,MAAM,GAAG;AAC3B,WAAO,YAAY,IAAI,MAAM;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AG;AAAA,YACJ,YAAY;AAAA;AAAA,UAFP,GAAG,KAAK,MAAM,KAAK;AAAA,QAG1B,CACD;AAAA,QACA;AAAA,SACH;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA;AAAA,IAEH,CAAC,oBAAoB,GAAG;AAAA,EAC1B;AACF;","names":["import_react","self","_shared","RemoteComponentReact"]}
@@ -1,41 +1,27 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { O as OnRequestHook, a as OnResponseHook } from '../../types-cbe44b51.js';
2
+ import { H as HostConfig, C as ClientHostConfig, a as HostLifecycleCallbacks } from '../../host-config-58cdccea.js';
3
+ import { O as OnRequestHook, a as OnResponseHook } from '../../types-2b26a246.js';
4
+ import '../../internal/shared/client/proxy-through-host.js';
3
5
  import 'parse5/dist/tree-adapters/default';
4
6
 
5
7
  declare const REMOTE_COMPONENT_KEY = "__REMOTE_COMPONENT_KEY__";
6
- interface RemoteComponentProps {
7
- src: string;
8
+ /**
9
+ * Props for the Next.js Pages Router remote component host.
10
+ *
11
+ * Extends {@link HostConfig}, {@link ClientHostConfig}, and
12
+ * {@link HostLifecycleCallbacks}. Adds Pages Router–specific `bundle` and
13
+ * `route` props used for SSR hydration.
14
+ */
15
+ interface RemoteComponentProps extends HostConfig, ClientHostConfig, HostLifecycleCallbacks {
16
+ /** The source URL of the remote component. Required for server rendering. */
17
+ src: string | URL;
18
+ /** The Webpack bundle name for the remote component. */
8
19
  bundle?: string;
20
+ /** The page route of the remote component. */
9
21
  route?: string;
10
- name?: string;
11
- isolate?: boolean;
12
- mode?: 'open' | 'closed';
13
- reset?: boolean;
14
- /** Called right before a new remote component load starts. */
15
- onBeforeLoad?: (src: string | URL) => void;
16
- /** Called when the remote component has been successfully loaded and mounted. */
17
- onLoad?: (src: string | URL) => void;
18
- /** Called when an error occurs while loading or mounting the remote component. */
19
- onError?: (error: unknown) => void;
20
- /** Called when a different remote component is loaded into the same wrapper. */
21
- onChange?: (info: {
22
- previousSrc: string | URL | null;
23
- nextSrc: string | URL | null;
24
- previousName: string | undefined;
25
- nextName: string | undefined;
26
- }) => void;
27
- /**
28
- * Called when a fetch request is made to retrieve the remote component payload.
29
- * Can be used to intercept requests, modify headers, or provide a custom response.
30
- */
31
- onRequest?: OnRequestHook;
32
- /**
33
- * Called after a fetch completes to retrieve the remote component payload.
34
- * Can be used to inspect the response (e.g., check for redirects) or transform it.
35
- */
36
- onResponse?: OnResponseHook;
37
- [REMOTE_COMPONENT_KEY]?: string;
22
+ /** Loading fallback content displayed while the remote component is being fetched. */
38
23
  children?: React.ReactNode;
24
+ [REMOTE_COMPONENT_KEY]?: string;
39
25
  }
40
26
  /**
41
27
  * This component handles the rendering of remote microfrontends.
@@ -114,6 +114,7 @@ function RemoteComponent(props) {
114
114
  onLoad: props.onLoad,
115
115
  onRequest: props.onRequest,
116
116
  onResponse: props.onResponse,
117
+ resolveClientUrl: props.resolveClientUrl,
117
118
  reset: props.reset,
118
119
  shared: shared(props.bundle ?? "default"),
119
120
  src: props.src,
@@ -133,6 +134,7 @@ function RemoteComponent(props) {
133
134
  onLoad: props.onLoad,
134
135
  onRequest: props.onRequest,
135
136
  onResponse: props.onResponse,
137
+ resolveClientUrl: props.resolveClientUrl,
136
138
  reset: props.reset,
137
139
  shared: shared(props.bundle ?? "default"),
138
140
  src: props.src,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/next/host/pages-router-server.tsx"],"sourcesContent":["import * as Form from 'next/form';\nimport * as Image from 'next/image';\nimport * as Link from 'next/link';\nimport * as Router from 'next/router';\nimport * as Script from 'next/script';\nimport { useEffect } from 'react';\nimport { shared as _shared } from 'remote-components/shared/host/pages';\nimport { RemoteComponentsError } from '#internal/shared/client/remote-component';\nimport { fetchRemoteComponent } from '#internal/shared/ssr/fetch-remote-component';\nimport type { OnRequestHook, OnResponseHook } from '#internal/shared/ssr/types';\nimport { RemoteComponent as RemoteComponentReact } from '#remote-components/react/index';\n\nconst navigationImpl = {\n useRouter: () => Router.useRouter(),\n useSearchParams: () => {\n const router = Router.useRouter();\n return {\n get: (key: string) => router.query[key],\n has: (key: string) => key in router.query,\n };\n },\n};\n\nconst sharedCache = new Map<string, Record<string, () => Promise<unknown>>>();\nconst shared = (bundle: string) => {\n if (sharedCache.has(bundle)) {\n return sharedCache.get(bundle);\n }\n\n const remoteLoader = ({ src, width, quality }: Image.ImageLoaderProps) => {\n const self = globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n };\n const { assetPrefix } =\n /^(?<assetPrefix>.*?)\\/_next\\//.exec(src)?.groups ?? {};\n return `${\n self.__remote_bundle_url__?.[bundle]?.origin ?? ''\n }${assetPrefix}/_next/image?url=${encodeURIComponent(src)}&w=${width}&q=${\n quality || 75\n }`;\n };\n\n const imageImpl = (ImageComponent: typeof Image.default) => {\n function RemoteImage(props: Image.ImageProps) {\n return <ImageComponent loader={remoteLoader} {...props} />;\n }\n RemoteImage.default = RemoteImage;\n RemoteImage.getImageProps = Image.getImageProps;\n return RemoteImage;\n };\n\n return {\n // polyfill Next.js App Router client API (minimal)\n // some API methods are not available when using a Next.js Pages Router application as host\n 'next/navigation': () =>\n Promise.resolve(navigationImpl) as Promise<unknown>,\n 'next/dist/client/components/navigation': () =>\n Promise.resolve(navigationImpl) as Promise<unknown>,\n 'next/dist/client/app-dir/link': () =>\n Promise.resolve(Link.default) as Promise<unknown>,\n 'next/link': () => Promise.resolve(Link.default) as Promise<unknown>,\n 'next/dist/client/app-dir/form': () =>\n Promise.resolve(Form.default) as Promise<unknown>,\n 'next/form': () => Promise.resolve(Form.default) as Promise<unknown>,\n 'next/dist/client/script': () =>\n Promise.resolve(Script.default) as Promise<unknown>,\n 'next/script': () => Promise.resolve(Script.default) as Promise<unknown>,\n 'next/dist/client/image-component': () =>\n Promise.resolve({\n // @ts-expect-error default.default\n // eslint-disable-next-line\n Image: imageImpl(Image.default.default ?? Image.default),\n }) as Promise<unknown>,\n 'next/dist/api/image': () =>\n Promise.resolve({\n // @ts-expect-error default.default\n // eslint-disable-next-line\n default: imageImpl(Image.default.default ?? Image.default),\n getImageProps: Image.getImageProps,\n }) as Promise<unknown>,\n 'next/router': () => Promise.resolve(Router) as Promise<unknown>,\n ..._shared,\n // always override next/image to use the remote loader\n 'next/image': () =>\n Promise.resolve(\n // @ts-expect-error default.default\n // eslint-disable-next-line\n imageImpl(Image.default.default ?? Image.default),\n ) as Promise<unknown>,\n };\n};\n\n// internal symbols to access global store\nconst REMOTE_COMPONENT_STORE = Symbol('REMOTE_COMPONENT_STORE');\nconst REMOTE_COMPONENT_KEY = '__REMOTE_COMPONENT_KEY__';\n\n// temporary global store for remote component HTML\n// the store is used to save the HTML of remote components for SSR without sending the content to the client\nconst self = globalThis as typeof globalThis & {\n [REMOTE_COMPONENT_STORE]?: Map<string, React.ReactNode>;\n};\n\nfunction getKey({\n bundle,\n route,\n name,\n}: {\n bundle?: string;\n route?: string;\n name?: string;\n}): string {\n return `${bundle ?? '__next'}:${route ?? '/'}:${\n name ?? '__vercel_remote_component'\n }__${crypto.randomUUID()}`;\n}\n\nfunction setComponent(key: string, component: React.ReactNode): void {\n if (!self[REMOTE_COMPONENT_STORE]) {\n self[REMOTE_COMPONENT_STORE] = new Map();\n }\n self[REMOTE_COMPONENT_STORE].set(key, component);\n}\n\nfunction getComponent(key: string): React.ReactNode | undefined {\n const component = self[REMOTE_COMPONENT_STORE]?.get(key);\n // remove the component from the store after retrieving it to prevent memory leaks\n // storing the HTML in the global store is only needed for SSR and it's temporary only used for a single render\n self[REMOTE_COMPONENT_STORE]?.delete(key);\n return component;\n}\n\nexport interface RemoteComponentProps {\n src: string;\n bundle?: string;\n route?: string;\n name?: string;\n isolate?: boolean;\n mode?: 'open' | 'closed';\n reset?: boolean;\n /** Called right before a new remote component load starts. */\n onBeforeLoad?: (src: string | URL) => void;\n /** Called when the remote component has been successfully loaded and mounted. */\n onLoad?: (src: string | URL) => void;\n /** Called when an error occurs while loading or mounting the remote component. */\n onError?: (error: unknown) => void;\n /** Called when a different remote component is loaded into the same wrapper. */\n onChange?: (info: {\n previousSrc: string | URL | null;\n nextSrc: string | URL | null;\n previousName: string | undefined;\n nextName: string | undefined;\n }) => void;\n /**\n * Called when a fetch request is made to retrieve the remote component payload.\n * Can be used to intercept requests, modify headers, or provide a custom response.\n */\n onRequest?: OnRequestHook;\n /**\n * Called after a fetch completes to retrieve the remote component payload.\n * Can be used to inspect the response (e.g., check for redirects) or transform it.\n */\n onResponse?: OnResponseHook;\n [REMOTE_COMPONENT_KEY]?: string;\n children?: React.ReactNode;\n}\n\n/**\n * This component handles the rendering of remote microfrontends.\n *\n * @param props - The properties for the remote component.\n * @returns A React component that renders the remote component.\n */\nexport function RemoteComponent(props: RemoteComponentProps) {\n const remoteComponent =\n typeof document !== 'undefined'\n ? null\n : // retrieve the HTML from the global store\n getComponent(\n props[REMOTE_COMPONENT_KEY] ?? '__vercel_remote_component',\n );\n\n useEffect(() => {\n const clientSelf = globalThis as typeof globalThis & {\n __remote_component_shared__?: Record<string, () => Promise<unknown>>;\n };\n // eslint-disable-next-line camelcase\n clientSelf.__remote_component_shared__ = shared(props.bundle ?? 'default');\n }, [props.bundle]);\n\n if (!props[REMOTE_COMPONENT_KEY]) {\n return (\n <RemoteComponentReact\n isolate={props.isolate}\n mode={props.mode}\n name={props.name}\n onBeforeLoad={props.onBeforeLoad}\n onChange={props.onChange}\n onError={props.onError}\n onLoad={props.onLoad}\n onRequest={props.onRequest}\n onResponse={props.onResponse}\n reset={props.reset}\n shared={shared(props.bundle ?? 'default')}\n src={props.src}\n >\n {props.children}\n </RemoteComponentReact>\n );\n }\n\n return (\n <RemoteComponentReact\n isolate={props.isolate}\n mode={props.mode}\n name={props.name}\n onBeforeLoad={props.onBeforeLoad}\n onChange={props.onChange}\n onError={props.onError}\n onLoad={props.onLoad}\n onRequest={props.onRequest}\n onResponse={props.onResponse}\n reset={props.reset}\n shared={shared(props.bundle ?? 'default')}\n src={props.src}\n >\n {remoteComponent}\n </RemoteComponentReact>\n );\n}\n\n/**\n * Fetches the remote component properties from the server. You need to pass these properties to the `<RemoteComponent>` component to render the fetched remote component.\n *\n * @param src - The source URL of the remote component. When using the Vercel Microfrontends solution, you can use relative paths, e.g. `/nextjs-app-remote/components/header`. Absolute URLs are also supported.\n * @param headers - The HTTP headers used for supporting the Vercel Microfrontends proxy.\n * @returns The properties of the remote component.\n *\n * @example\n *\n * ```tsx\n * import { getRemoteComponentProps } from 'remote-components/next/host/pages';\n * import type { GetServerSideProps } from 'next';\n *\n * export const getServerSideProps: GetServerSideProps<PageProps> = async function getServerSideProps({ req }) {\n * const myRemoteComponent = await getRemoteComponentProps(\n * '/nextjs-app-remote/components/header',\n * req.headers,\n * );\n * return {\n * props: {\n * remoteComponents: {\n * myRemoteComponent,\n * },\n * },\n * };\n * }\n * ```\n */\nexport async function getRemoteComponentProps(\n src: string,\n options?: {\n /**\n * Called when a fetch request is made to retrieve the remote component payload.\n * Can be used to intercept requests, modify headers, or provide a custom response.\n */\n onRequest?: OnRequestHook;\n /**\n * Called after a fetch completes to retrieve the remote component payload.\n * Can be used to inspect the response (e.g., check for redirects) or transform it.\n */\n onResponse?: OnResponseHook;\n /**\n * The name of the exposed remote component. Used to identify the remote component\n * when multiple remote components are exposed on a page.\n */\n name?: string;\n },\n): Promise<RemoteComponentProps> {\n if (typeof document !== 'undefined') {\n throw new RemoteComponentsError(\n '`getRemoteComponentProps()` can only be used on the server side.',\n );\n }\n\n const {\n metadata: { bundle, route },\n name,\n links,\n component,\n nextData,\n remoteShared,\n } = await fetchRemoteComponent(src, {\n rsc: true,\n ...options,\n });\n\n const props: RemoteComponentProps = {\n src,\n bundle,\n name,\n route,\n };\n\n const key = getKey(props);\n\n // do not render the HTML in development mode when remote is using Next.js Pages Router\n // this behavior is emulating the Next.js Pages Router FOUC as the styles are only applied on the client when running in development mode\n if (nextData?.buildId !== 'development') {\n // store the HTML in a global store\n setComponent(\n key,\n <>\n <script\n data-remote-components-shared=\"\"\n id={`${name}_shared`}\n type=\"application/json\"\n >\n {JSON.stringify(remoteShared)}\n </script>\n {links.map((link) => (\n <link\n key={`${link.as}_${link.href}`}\n {...link}\n precedence={undefined}\n />\n ))}\n {component}\n </>,\n );\n }\n\n return {\n ...props,\n // add remote component key to the props\n [REMOTE_COMPONENT_KEY]: key,\n };\n}\n"],"mappings":"AA4Ca,SA2QP,UA3QO,KA2QP,YA3QO;AA5Cb,YAAY,UAAU;AACtB,YAAY,WAAW;AACvB,YAAY,UAAU;AACtB,YAAY,YAAY;AACxB,YAAY,YAAY;AACxB,SAAS,iBAAiB;AAC1B,SAAS,UAAU,eAAe;AAClC,SAAS,6BAA6B;AACtC,SAAS,4BAA4B;AAErC,SAAS,mBAAmB,4BAA4B;AAExD,MAAM,iBAAiB;AAAA,EACrB,WAAW,MAAM,OAAO,UAAU;AAAA,EAClC,iBAAiB,MAAM;AACrB,UAAM,SAAS,OAAO,UAAU;AAChC,WAAO;AAAA,MACL,KAAK,CAAC,QAAgB,OAAO,MAAM,GAAG;AAAA,MACtC,KAAK,CAAC,QAAgB,OAAO,OAAO;AAAA,IACtC;AAAA,EACF;AACF;AAEA,MAAM,cAAc,oBAAI,IAAoD;AAC5E,MAAM,SAAS,CAAC,WAAmB;AACjC,MAAI,YAAY,IAAI,MAAM,GAAG;AAC3B,WAAO,YAAY,IAAI,MAAM;AAAA,EAC/B;AAEA,QAAM,eAAe,CAAC,EAAE,KAAK,OAAO,QAAQ,MAA8B;AACxE,UAAMA,QAAO;AAGb,UAAM,EAAE,YAAY,IAClB,gCAAgC,KAAK,GAAG,GAAG,UAAU,CAAC;AACxD,WAAO,GACLA,MAAK,wBAAwB,MAAM,GAAG,UAAU,KAC/C,+BAA+B,mBAAmB,GAAG,OAAO,WAC7D,WAAW;AAAA,EAEf;AAEA,QAAM,YAAY,CAAC,mBAAyC;AAC1D,aAAS,YAAY,OAAyB;AAC5C,aAAO,oBAAC,kBAAe,QAAQ,cAAe,GAAG,OAAO;AAA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AM,UAAU,SAAS;AAAA,MACxC,KAAK,MAAM;AAAA,MAEV;AAAA;AAAA,EACH;AAEJ;AA8BA,eAAsB,wBACpB,KACA,SAiB+B;AAC/B,MAAI,OAAO,aAAa,aAAa;AACnC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM;AAAA,IACJ,UAAU,EAAE,QAAQ,MAAM;AAAA,IAC1B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,MAAM,qBAAqB,KAAK;AAAA,IAClC,KAAK;AAAA,IACL,GAAG;AAAA,EACL,CAAC;AAED,QAAM,QAA8B;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,QAAM,MAAM,OAAO,KAAK;AAIxB,MAAI,UAAU,YAAY,eAAe;AAEvC;AAAA,MACE;AAAA,MACA,iCACE;AAAA;AAAA,UAAC;AAAA;AAAA,YACC,iCAA8B;AAAA,YAC9B,IAAI,GAAG;AAAA,YACP,MAAK;AAAA,YAEJ,eAAK,UAAU,YAAY;AAAA;AAAA,QAC9B;AAAA,QACC,MAAM,IAAI,CAAC,SACV;AAAA,UAAC;AAAA;AAAA,YAEE,GAAG;AAAA,YACJ,YAAY;AAAA;AAAA,UAFP,GAAG,KAAK,MAAM,KAAK;AAAA,QAG1B,CACD;AAAA,QACA;AAAA,SACH;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA;AAAA,IAEH,CAAC,oBAAoB,GAAG;AAAA,EAC1B;AACF;","names":["self"]}
1
+ {"version":3,"sources":["../../../src/next/host/pages-router-server.tsx"],"sourcesContent":["import * as Form from 'next/form';\nimport * as Image from 'next/image';\nimport * as Link from 'next/link';\nimport * as Router from 'next/router';\nimport * as Script from 'next/script';\nimport { useEffect } from 'react';\nimport { shared as _shared } from 'remote-components/shared/host/pages';\nimport { RemoteComponentsError } from '#internal/shared/client/remote-component';\nimport type {\n ClientHostConfig,\n HostConfig,\n HostLifecycleCallbacks,\n} from '#internal/shared/contract/host-config';\nimport { fetchRemoteComponent } from '#internal/shared/ssr/fetch-remote-component';\nimport type { OnRequestHook, OnResponseHook } from '#internal/shared/ssr/types';\nimport { RemoteComponent as RemoteComponentReact } from '#remote-components/react/index';\n\nconst navigationImpl = {\n useRouter: () => Router.useRouter(),\n useSearchParams: () => {\n const router = Router.useRouter();\n return {\n get: (key: string) => router.query[key],\n has: (key: string) => key in router.query,\n };\n },\n};\n\nconst sharedCache = new Map<string, Record<string, () => Promise<unknown>>>();\nconst shared = (bundle: string) => {\n if (sharedCache.has(bundle)) {\n return sharedCache.get(bundle);\n }\n\n const remoteLoader = ({ src, width, quality }: Image.ImageLoaderProps) => {\n const self = globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n };\n const { assetPrefix } =\n /^(?<assetPrefix>.*?)\\/_next\\//.exec(src)?.groups ?? {};\n return `${\n self.__remote_bundle_url__?.[bundle]?.origin ?? ''\n }${assetPrefix}/_next/image?url=${encodeURIComponent(src)}&w=${width}&q=${\n quality || 75\n }`;\n };\n\n const imageImpl = (ImageComponent: typeof Image.default) => {\n function RemoteImage(props: Image.ImageProps) {\n return <ImageComponent loader={remoteLoader} {...props} />;\n }\n RemoteImage.default = RemoteImage;\n RemoteImage.getImageProps = Image.getImageProps;\n return RemoteImage;\n };\n\n return {\n // polyfill Next.js App Router client API (minimal)\n // some API methods are not available when using a Next.js Pages Router application as host\n 'next/navigation': () =>\n Promise.resolve(navigationImpl) as Promise<unknown>,\n 'next/dist/client/components/navigation': () =>\n Promise.resolve(navigationImpl) as Promise<unknown>,\n 'next/dist/client/app-dir/link': () =>\n Promise.resolve(Link.default) as Promise<unknown>,\n 'next/link': () => Promise.resolve(Link.default) as Promise<unknown>,\n 'next/dist/client/app-dir/form': () =>\n Promise.resolve(Form.default) as Promise<unknown>,\n 'next/form': () => Promise.resolve(Form.default) as Promise<unknown>,\n 'next/dist/client/script': () =>\n Promise.resolve(Script.default) as Promise<unknown>,\n 'next/script': () => Promise.resolve(Script.default) as Promise<unknown>,\n 'next/dist/client/image-component': () =>\n Promise.resolve({\n // @ts-expect-error default.default\n // eslint-disable-next-line\n Image: imageImpl(Image.default.default ?? Image.default),\n }) as Promise<unknown>,\n 'next/dist/api/image': () =>\n Promise.resolve({\n // @ts-expect-error default.default\n // eslint-disable-next-line\n default: imageImpl(Image.default.default ?? Image.default),\n getImageProps: Image.getImageProps,\n }) as Promise<unknown>,\n 'next/router': () => Promise.resolve(Router) as Promise<unknown>,\n ..._shared,\n // always override next/image to use the remote loader\n 'next/image': () =>\n Promise.resolve(\n // @ts-expect-error default.default\n // eslint-disable-next-line\n imageImpl(Image.default.default ?? Image.default),\n ) as Promise<unknown>,\n };\n};\n\n// internal symbols to access global store\nconst REMOTE_COMPONENT_STORE = Symbol('REMOTE_COMPONENT_STORE');\nconst REMOTE_COMPONENT_KEY = '__REMOTE_COMPONENT_KEY__';\n\n// temporary global store for remote component HTML\n// the store is used to save the HTML of remote components for SSR without sending the content to the client\nconst self = globalThis as typeof globalThis & {\n [REMOTE_COMPONENT_STORE]?: Map<string, React.ReactNode>;\n};\n\nfunction getKey({\n bundle,\n route,\n name,\n}: {\n bundle?: string;\n route?: string;\n name?: string;\n}): string {\n return `${bundle ?? '__next'}:${route ?? '/'}:${\n name ?? '__vercel_remote_component'\n }__${crypto.randomUUID()}`;\n}\n\nfunction setComponent(key: string, component: React.ReactNode): void {\n if (!self[REMOTE_COMPONENT_STORE]) {\n self[REMOTE_COMPONENT_STORE] = new Map();\n }\n self[REMOTE_COMPONENT_STORE].set(key, component);\n}\n\nfunction getComponent(key: string): React.ReactNode | undefined {\n const component = self[REMOTE_COMPONENT_STORE]?.get(key);\n // remove the component from the store after retrieving it to prevent memory leaks\n // storing the HTML in the global store is only needed for SSR and it's temporary only used for a single render\n self[REMOTE_COMPONENT_STORE]?.delete(key);\n return component;\n}\n\n/**\n * Props for the Next.js Pages Router remote component host.\n *\n * Extends {@link HostConfig}, {@link ClientHostConfig}, and\n * {@link HostLifecycleCallbacks}. Adds Pages Router–specific `bundle` and\n * `route` props used for SSR hydration.\n */\nexport interface RemoteComponentProps\n extends HostConfig,\n ClientHostConfig,\n HostLifecycleCallbacks {\n /** The source URL of the remote component. Required for server rendering. */\n src: string | URL;\n /** The Webpack bundle name for the remote component. */\n bundle?: string;\n /** The page route of the remote component. */\n route?: string;\n /** Loading fallback content displayed while the remote component is being fetched. */\n children?: React.ReactNode;\n [REMOTE_COMPONENT_KEY]?: string;\n}\n\n/**\n * This component handles the rendering of remote microfrontends.\n *\n * @param props - The properties for the remote component.\n * @returns A React component that renders the remote component.\n */\nexport function RemoteComponent(props: RemoteComponentProps) {\n const remoteComponent =\n typeof document !== 'undefined'\n ? null\n : // retrieve the HTML from the global store\n getComponent(\n props[REMOTE_COMPONENT_KEY] ?? '__vercel_remote_component',\n );\n\n useEffect(() => {\n const clientSelf = globalThis as typeof globalThis & {\n __remote_component_shared__?: Record<string, () => Promise<unknown>>;\n };\n // eslint-disable-next-line camelcase\n clientSelf.__remote_component_shared__ = shared(props.bundle ?? 'default');\n }, [props.bundle]);\n\n if (!props[REMOTE_COMPONENT_KEY]) {\n return (\n <RemoteComponentReact\n isolate={props.isolate}\n mode={props.mode}\n name={props.name}\n onBeforeLoad={props.onBeforeLoad}\n onChange={props.onChange}\n onError={props.onError}\n onLoad={props.onLoad}\n onRequest={props.onRequest}\n onResponse={props.onResponse}\n resolveClientUrl={props.resolveClientUrl}\n reset={props.reset}\n shared={shared(props.bundle ?? 'default')}\n src={props.src}\n >\n {props.children}\n </RemoteComponentReact>\n );\n }\n\n return (\n <RemoteComponentReact\n isolate={props.isolate}\n mode={props.mode}\n name={props.name}\n onBeforeLoad={props.onBeforeLoad}\n onChange={props.onChange}\n onError={props.onError}\n onLoad={props.onLoad}\n onRequest={props.onRequest}\n onResponse={props.onResponse}\n resolveClientUrl={props.resolveClientUrl}\n reset={props.reset}\n shared={shared(props.bundle ?? 'default')}\n src={props.src}\n >\n {remoteComponent}\n </RemoteComponentReact>\n );\n}\n\n/**\n * Fetches the remote component properties from the server. You need to pass these properties to the `<RemoteComponent>` component to render the fetched remote component.\n *\n * @param src - The source URL of the remote component. When using the Vercel Microfrontends solution, you can use relative paths, e.g. `/nextjs-app-remote/components/header`. Absolute URLs are also supported.\n * @param headers - The HTTP headers used for supporting the Vercel Microfrontends proxy.\n * @returns The properties of the remote component.\n *\n * @example\n *\n * ```tsx\n * import { getRemoteComponentProps } from 'remote-components/next/host/pages';\n * import type { GetServerSideProps } from 'next';\n *\n * export const getServerSideProps: GetServerSideProps<PageProps> = async function getServerSideProps({ req }) {\n * const myRemoteComponent = await getRemoteComponentProps(\n * '/nextjs-app-remote/components/header',\n * req.headers,\n * );\n * return {\n * props: {\n * remoteComponents: {\n * myRemoteComponent,\n * },\n * },\n * };\n * }\n * ```\n */\nexport async function getRemoteComponentProps(\n src: string,\n options?: {\n /**\n * Called when a fetch request is made to retrieve the remote component payload.\n * Can be used to intercept requests, modify headers, or provide a custom response.\n */\n onRequest?: OnRequestHook;\n /**\n * Called after a fetch completes to retrieve the remote component payload.\n * Can be used to inspect the response (e.g., check for redirects) or transform it.\n */\n onResponse?: OnResponseHook;\n /**\n * The name of the exposed remote component. Used to identify the remote component\n * when multiple remote components are exposed on a page.\n */\n name?: string;\n },\n): Promise<RemoteComponentProps> {\n if (typeof document !== 'undefined') {\n throw new RemoteComponentsError(\n '`getRemoteComponentProps()` can only be used on the server side.',\n );\n }\n\n const {\n metadata: { bundle, route },\n name,\n links,\n component,\n nextData,\n remoteShared,\n } = await fetchRemoteComponent(src, {\n rsc: true,\n ...options,\n });\n\n const props: RemoteComponentProps = {\n src,\n bundle,\n name,\n route,\n };\n\n const key = getKey(props);\n\n // do not render the HTML in development mode when remote is using Next.js Pages Router\n // this behavior is emulating the Next.js Pages Router FOUC as the styles are only applied on the client when running in development mode\n if (nextData?.buildId !== 'development') {\n // store the HTML in a global store\n setComponent(\n key,\n <>\n <script\n data-remote-components-shared=\"\"\n id={`${name}_shared`}\n type=\"application/json\"\n >\n {JSON.stringify(remoteShared)}\n </script>\n {links.map((link) => (\n <link\n key={`${link.as}_${link.href}`}\n {...link}\n precedence={undefined}\n />\n ))}\n {component}\n </>,\n );\n }\n\n return {\n ...props,\n // add remote component key to the props\n [REMOTE_COMPONENT_KEY]: key,\n };\n}\n"],"mappings":"AAiDa,SAgQP,UAhQO,KAgQP,YAhQO;AAjDb,YAAY,UAAU;AACtB,YAAY,WAAW;AACvB,YAAY,UAAU;AACtB,YAAY,YAAY;AACxB,YAAY,YAAY;AACxB,SAAS,iBAAiB;AAC1B,SAAS,UAAU,eAAe;AAClC,SAAS,6BAA6B;AAMtC,SAAS,4BAA4B;AAErC,SAAS,mBAAmB,4BAA4B;AAExD,MAAM,iBAAiB;AAAA,EACrB,WAAW,MAAM,OAAO,UAAU;AAAA,EAClC,iBAAiB,MAAM;AACrB,UAAM,SAAS,OAAO,UAAU;AAChC,WAAO;AAAA,MACL,KAAK,CAAC,QAAgB,OAAO,MAAM,GAAG;AAAA,MACtC,KAAK,CAAC,QAAgB,OAAO,OAAO;AAAA,IACtC;AAAA,EACF;AACF;AAEA,MAAM,cAAc,oBAAI,IAAoD;AAC5E,MAAM,SAAS,CAAC,WAAmB;AACjC,MAAI,YAAY,IAAI,MAAM,GAAG;AAC3B,WAAO,YAAY,IAAI,MAAM;AAAA,EAC/B;AAEA,QAAM,eAAe,CAAC,EAAE,KAAK,OAAO,QAAQ,MAA8B;AACxE,UAAMA,QAAO;AAGb,UAAM,EAAE,YAAY,IAClB,gCAAgC,KAAK,GAAG,GAAG,UAAU,CAAC;AACxD,WAAO,GACLA,MAAK,wBAAwB,MAAM,GAAG,UAAU,KAC/C,+BAA+B,mBAAmB,GAAG,OAAO,WAC7D,WAAW;AAAA,EAEf;AAEA,QAAM,YAAY,CAAC,mBAAyC;AAC1D,aAAS,YAAY,OAAyB;AAC5C,aAAO,oBAAC,kBAAe,QA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M;AAAA,MAClB,kBAAkB,MAAM;AAAA,MACxB,OAAO,MAAM;AAAA,MACb,QAAQ,OAAO,MAAM,UAAU,SAAS;AAAA,MACxC,KAAK,MAAM;AAAA,MAEV;AAAA;AAAA,EACH;AAEJ;AA8BA,eAAsB,wBACpB,KACA,SAiB+B;AAC/B,MAAI,OAAO,aAAa,aAAa;AACnC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM;AAAA,IACJ,UAAU,EAAE,QAAQ,MAAM;AAAA,IAC1B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,MAAM,qBAAqB,KAAK;AAAA,IAClC,KAAK;AAAA,IACL,GAAG;AAAA,EACL,CAAC;AAED,QAAM,QAA8B;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,QAAM,MAAM,OAAO,KAAK;AAIxB,MAAI,UAAU,YAAY,eAAe;AAEvC;AAAA,MACE;AAAA,MACA,iCACE;AAAA;AAAA,UAAC;AAAA;AAAA,YACC,iCAA8B;AAAA,YAC9B,IAAI,GAAG;AAAA,YACP,MAAK;AAAA,YAEJ,eAAK,UAAU,YAAY;AAAA;AAAA,QAC9B;AAAA,QACC,MAAM,IAAI,CAAC,SACV;AAAA,UAAC;AAAA;AAAA,YAEE,GAAG;AAAA,YACJ,YAAY;AAAA;AAAA,UAFP,GAAG,KAAK,MAAM,KAAK;AAAA,QAG1B,CACD;AAAA,QACA;AAAA,SACH;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA;AAAA,IAEH,CAAC,oBAAoB,GAAG;AAAA,EAC1B;AACF;","names":["self"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/index.tsx"],"sourcesContent":["import 'remote-components/shared/remote/wrapper';\nimport type { RemoteComponent as RemoteComponentRenderType } from '#internal/next/remote/render-server';\nimport { RemoteComponentsError } from '#internal/shared/error';\nimport type { RemoteComponent as RemoteComponentAppServerType } from '#remote-components/next/host/app-router-server';\n\ntype RemoteComponentAppServerProps = Parameters<\n typeof RemoteComponentAppServerType\n>[0];\ntype RemoteComponentRenderProps = Parameters<\n typeof RemoteComponentRenderType\n>[0];\ntype RemoteComponentProps =\n | RemoteComponentAppServerProps\n | RemoteComponentRenderProps;\n\n/**\n * RemoteComponent is a Next.js component that exposes or consumes a remote component\n * that can be used in a host application.\n *\n * @param src - [host] The source URL of the remote component. Use this to consume a remote component from another application.\n * @param name - [host & remote] The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param isolate - [host] Whether to isolate the remote component's styles and scripts. Defaults to true.\n * @param mode - [host] The mode of the Shadow DOM. Defaults to `open`.\n * @param reset - [host] Whether to include a CSS reset style in the shadow DOM. Defaults to `false`.\n * @param children - [host & remote] Either the content of the remote component. Or when src is supplied, the fallback content to display while the remote component is being fetched.\n * @returns Either a React component that renders the remote component or a Next.js component that exposes the children as a 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 without the `src` prop:\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 *\n * Use the `<RemoteComponent>` in your Next.js App Router application to consume a remote component from another application with the `src` prop:\n *\n * ```tsx\n * import { RemoteComponent } from 'remote-components/next';\n *\n * export default function MyPage() {\n * return (\n * <>\n * <RemoteComponent src=\"https://example.com/remote-component\" />\n * </>\n * );\n * }\n * ```\n *\n * The `children` of the `<RemoteComponent>` will be exposed as a remote component or it will be used as the loading fallback when consuming a remote component.\n */\nexport async function RemoteComponent(\n props: RemoteComponentProps,\n): Promise<React.ReactElement> {\n if ('src' in props) {\n const { RemoteComponent: RemoteComponentAppServer } = await import(\n '#remote-components/next/host/app-router-server'\n );\n return RemoteComponentAppServer(props);\n }\n\n if ('children' in props) {\n const { RemoteComponent: RemoteComponentRender } = await import(\n '#internal/next/remote/render-server'\n );\n return RemoteComponentRender(props);\n }\n\n throw new RemoteComponentsError(\n 'Invalid props passed to <RemoteComponent>. Expected either \"src\" or \"children\".',\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAO;AAEP,mBAAsC;AA0DtC,eAAsB,gBACpB,OAC6B;AAC7B,MAAI,SAAS,OAAO;AAClB,UAAM,EAAE,iBAAiB,yBAAyB,IAAI,MAAM,OAC1D,gDACF;AACA,WAAO,yBAAyB,KAAK;AAAA,EACvC;AAEA,MAAI,cAAc,OAAO;AACvB,UAAM,EAAE,iBAAiB,sBAAsB,IAAI,MAAM,OACvD,qCACF;AACA,WAAO,sBAAsB,KAAK;AAAA,EACpC;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/next/index.tsx"],"sourcesContent":["import 'remote-components/shared/remote/wrapper';\nimport type { RemoteComponent as RemoteComponentRenderType } from '#internal/next/remote/render-server';\nimport { RemoteComponentsError } from '#internal/shared/error';\nimport type { RemoteComponent as RemoteComponentAppServerType } from '#remote-components/next/host/app-router-server';\n\ntype RemoteComponentAppServerProps = Parameters<\n typeof RemoteComponentAppServerType\n>[0];\ntype RemoteComponentRenderProps = Parameters<\n typeof RemoteComponentRenderType\n>[0];\ntype RemoteComponentProps =\n | RemoteComponentAppServerProps\n | RemoteComponentRenderProps;\n\n/**\n * Dual-purpose Next.js App Router component: **host** (with `src`) or\n * **remote** (with `children` only). Props are documented on the underlying\n * types see {@link RemoteComponentAppServerProps} and\n * {@link RemoteComponentRenderProps}.\n *\n * @example\n * ```tsx\n * // Host consume a remote component\n * <RemoteComponent src=\"/other-app/components/header\" />\n *\n * // Remote expose children as a remote component\n * <RemoteComponent>\n * <h1>Hello from the remote!</h1>\n * </RemoteComponent>\n * ```\n */\nexport async function RemoteComponent(\n props: RemoteComponentProps,\n): Promise<React.ReactElement> {\n if ('src' in props) {\n const { RemoteComponent: RemoteComponentAppServer } = await import(\n '#remote-components/next/host/app-router-server'\n );\n return RemoteComponentAppServer(props);\n }\n\n if ('children' in props) {\n const { RemoteComponent: RemoteComponentRender } = await import(\n '#internal/next/remote/render-server'\n );\n return RemoteComponentRender(props);\n }\n\n throw new RemoteComponentsError(\n 'Invalid props passed to <RemoteComponent>. Expected either \"src\" or \"children\".',\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAO;AAEP,mBAAsC;AA8BtC,eAAsB,gBACpB,OAC6B;AAC7B,MAAI,SAAS,OAAO;AAClB,UAAM,EAAE,iBAAiB,yBAAyB,IAAI,MAAM,OAC1D,gDACF;AACA,WAAO,yBAAyB,KAAK;AAAA,EACvC;AAEA,MAAI,cAAc,OAAO;AACvB,UAAM,EAAE,iBAAiB,sBAAsB,IAAI,MAAM,OACvD,qCACF;AACA,WAAO,sBAAsB,KAAK;AAAA,EACpC;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
@@ -1,55 +1,29 @@
1
1
  import { RemoteComponent as RemoteComponent$2 } from '../internal/next/remote/render-server.js';
2
2
  import { RemoteComponent as RemoteComponent$1 } from './host/app-router-server.js';
3
- import '../types-cbe44b51.js';
3
+ import '../host-config-58cdccea.js';
4
+ import '../internal/shared/client/proxy-through-host.js';
5
+ import '../types-2b26a246.js';
4
6
  import 'parse5/dist/tree-adapters/default';
5
7
 
6
8
  type RemoteComponentAppServerProps = Parameters<typeof RemoteComponent$1>[0];
7
9
  type RemoteComponentRenderProps = Parameters<typeof RemoteComponent$2>[0];
8
10
  type RemoteComponentProps = RemoteComponentAppServerProps | RemoteComponentRenderProps;
9
11
  /**
10
- * RemoteComponent is a Next.js component that exposes or consumes a remote component
11
- * that can be used in a host application.
12
- *
13
- * @param src - [host] The source URL of the remote component. Use this to consume a remote component from another application.
14
- * @param name - [host & remote] The name of the remote component. Use a unique name to expose multiple remote components from the same page.
15
- * @param isolate - [host] Whether to isolate the remote component's styles and scripts. Defaults to true.
16
- * @param mode - [host] The mode of the Shadow DOM. Defaults to `open`.
17
- * @param reset - [host] Whether to include a CSS reset style in the shadow DOM. Defaults to `false`.
18
- * @param children - [host & remote] Either the content of the remote component. Or when src is supplied, the fallback content to display while the remote component is being fetched.
19
- * @returns Either a React component that renders the remote component or a Next.js component that exposes the children as a remote component.
12
+ * Dual-purpose Next.js App Router component: **host** (with `src`) or
13
+ * **remote** (with `children` only). Props are documented on the underlying
14
+ * types — see {@link RemoteComponentAppServerProps} and
15
+ * {@link RemoteComponentRenderProps}.
20
16
  *
21
17
  * @example
22
- *
23
- * Use the `<RemoteComponent>` in your Next.js App Router application to expose the children as a remote component without the `src` prop:
24
- *
25
18
  * ```tsx
26
- * import { RemoteComponent } from 'remote-components/next';
19
+ * // Host consume a remote component
20
+ * <RemoteComponent src="/other-app/components/header" />
27
21
  *
28
- * export default function MyPage() {
29
- * return (
30
- * <RemoteComponent>
31
- * <h1>Hello from the remote component!</h1>
32
- * <p>This is a remote component that can be used in a host application.</p>
33
- * </RemoteComponent>
34
- * );
35
- * }
22
+ * // Remote expose children as a remote component
23
+ * <RemoteComponent>
24
+ * <h1>Hello from the remote!</h1>
25
+ * </RemoteComponent>
36
26
  * ```
37
- *
38
- * Use the `<RemoteComponent>` in your Next.js App Router application to consume a remote component from another application with the `src` prop:
39
- *
40
- * ```tsx
41
- * import { RemoteComponent } from 'remote-components/next';
42
- *
43
- * export default function MyPage() {
44
- * return (
45
- * <>
46
- * <RemoteComponent src="https://example.com/remote-component" />
47
- * </>
48
- * );
49
- * }
50
- * ```
51
- *
52
- * The `children` of the `<RemoteComponent>` will be exposed as a remote component or it will be used as the loading fallback when consuming a remote component.
53
27
  */
54
28
  declare function RemoteComponent(props: RemoteComponentProps): Promise<React.ReactElement>;
55
29
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/index.tsx"],"sourcesContent":["import 'remote-components/shared/remote/wrapper';\nimport type { RemoteComponent as RemoteComponentRenderType } from '#internal/next/remote/render-server';\nimport { RemoteComponentsError } from '#internal/shared/error';\nimport type { RemoteComponent as RemoteComponentAppServerType } from '#remote-components/next/host/app-router-server';\n\ntype RemoteComponentAppServerProps = Parameters<\n typeof RemoteComponentAppServerType\n>[0];\ntype RemoteComponentRenderProps = Parameters<\n typeof RemoteComponentRenderType\n>[0];\ntype RemoteComponentProps =\n | RemoteComponentAppServerProps\n | RemoteComponentRenderProps;\n\n/**\n * RemoteComponent is a Next.js component that exposes or consumes a remote component\n * that can be used in a host application.\n *\n * @param src - [host] The source URL of the remote component. Use this to consume a remote component from another application.\n * @param name - [host & remote] The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param isolate - [host] Whether to isolate the remote component's styles and scripts. Defaults to true.\n * @param mode - [host] The mode of the Shadow DOM. Defaults to `open`.\n * @param reset - [host] Whether to include a CSS reset style in the shadow DOM. Defaults to `false`.\n * @param children - [host & remote] Either the content of the remote component. Or when src is supplied, the fallback content to display while the remote component is being fetched.\n * @returns Either a React component that renders the remote component or a Next.js component that exposes the children as a 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 without the `src` prop:\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 *\n * Use the `<RemoteComponent>` in your Next.js App Router application to consume a remote component from another application with the `src` prop:\n *\n * ```tsx\n * import { RemoteComponent } from 'remote-components/next';\n *\n * export default function MyPage() {\n * return (\n * <>\n * <RemoteComponent src=\"https://example.com/remote-component\" />\n * </>\n * );\n * }\n * ```\n *\n * The `children` of the `<RemoteComponent>` will be exposed as a remote component or it will be used as the loading fallback when consuming a remote component.\n */\nexport async function RemoteComponent(\n props: RemoteComponentProps,\n): Promise<React.ReactElement> {\n if ('src' in props) {\n const { RemoteComponent: RemoteComponentAppServer } = await import(\n '#remote-components/next/host/app-router-server'\n );\n return RemoteComponentAppServer(props);\n }\n\n if ('children' in props) {\n const { RemoteComponent: RemoteComponentRender } = await import(\n '#internal/next/remote/render-server'\n );\n return RemoteComponentRender(props);\n }\n\n throw new RemoteComponentsError(\n 'Invalid props passed to <RemoteComponent>. Expected either \"src\" or \"children\".',\n );\n}\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,6BAA6B;AA0DtC,eAAsB,gBACpB,OAC6B;AAC7B,MAAI,SAAS,OAAO;AAClB,UAAM,EAAE,iBAAiB,yBAAyB,IAAI,MAAM,OAC1D,gDACF;AACA,WAAO,yBAAyB,KAAK;AAAA,EACvC;AAEA,MAAI,cAAc,OAAO;AACvB,UAAM,EAAE,iBAAiB,sBAAsB,IAAI,MAAM,OACvD,qCACF;AACA,WAAO,sBAAsB,KAAK;AAAA,EACpC;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/next/index.tsx"],"sourcesContent":["import 'remote-components/shared/remote/wrapper';\nimport type { RemoteComponent as RemoteComponentRenderType } from '#internal/next/remote/render-server';\nimport { RemoteComponentsError } from '#internal/shared/error';\nimport type { RemoteComponent as RemoteComponentAppServerType } from '#remote-components/next/host/app-router-server';\n\ntype RemoteComponentAppServerProps = Parameters<\n typeof RemoteComponentAppServerType\n>[0];\ntype RemoteComponentRenderProps = Parameters<\n typeof RemoteComponentRenderType\n>[0];\ntype RemoteComponentProps =\n | RemoteComponentAppServerProps\n | RemoteComponentRenderProps;\n\n/**\n * Dual-purpose Next.js App Router component: **host** (with `src`) or\n * **remote** (with `children` only). Props are documented on the underlying\n * types see {@link RemoteComponentAppServerProps} and\n * {@link RemoteComponentRenderProps}.\n *\n * @example\n * ```tsx\n * // Host consume a remote component\n * <RemoteComponent src=\"/other-app/components/header\" />\n *\n * // Remote expose children as a remote component\n * <RemoteComponent>\n * <h1>Hello from the remote!</h1>\n * </RemoteComponent>\n * ```\n */\nexport async function RemoteComponent(\n props: RemoteComponentProps,\n): Promise<React.ReactElement> {\n if ('src' in props) {\n const { RemoteComponent: RemoteComponentAppServer } = await import(\n '#remote-components/next/host/app-router-server'\n );\n return RemoteComponentAppServer(props);\n }\n\n if ('children' in props) {\n const { RemoteComponent: RemoteComponentRender } = await import(\n '#internal/next/remote/render-server'\n );\n return RemoteComponentRender(props);\n }\n\n throw new RemoteComponentsError(\n 'Invalid props passed to <RemoteComponent>. Expected either \"src\" or \"children\".',\n );\n}\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,6BAA6B;AA8BtC,eAAsB,gBACpB,OAC6B;AAC7B,MAAI,SAAS,OAAO;AAClB,UAAM,EAAE,iBAAiB,yBAAyB,IAAI,MAAM,OAC1D,gDACF;AACA,WAAO,yBAAyB,KAAK;AAAA,EACvC;AAEA,MAAI,cAAc,OAAO;AACvB,UAAM,EAAE,iBAAiB,sBAAsB,IAAI,MAAM,OACvD,qCACF;AACA,WAAO,sBAAsB,KAAK;AAAA,EACpC;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;","names":[]}