remote-components 0.0.36 → 0.0.38

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 (48) hide show
  1. package/dist/{component-loader-8951c052.d.ts → component-loader-2ca91ad8.d.ts} +4 -1
  2. package/dist/internal/next/host/app-router-client.cjs +55 -38
  3. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  4. package/dist/internal/next/host/app-router-client.d.ts +2 -2
  5. package/dist/internal/next/host/app-router-client.js +55 -38
  6. package/dist/internal/next/host/app-router-client.js.map +1 -1
  7. package/dist/internal/shared/client/get-client-src.cjs +39 -0
  8. package/dist/internal/shared/client/get-client-src.cjs.map +1 -0
  9. package/dist/internal/shared/client/get-client-src.d.ts +7 -0
  10. package/dist/internal/shared/client/get-client-src.js +15 -0
  11. package/dist/internal/shared/client/get-client-src.js.map +1 -0
  12. package/dist/internal/shared/client/remote-component.d.ts +2 -2
  13. package/dist/internal/shared/ssr/fetch-remote-component.cjs +26 -22
  14. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  15. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +1 -1
  16. package/dist/internal/shared/ssr/fetch-remote-component.js +26 -22
  17. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  18. package/dist/internal/shared/ssr/get-client-or-server-url.cjs +35 -0
  19. package/dist/internal/shared/ssr/get-client-or-server-url.cjs.map +1 -0
  20. package/dist/internal/shared/ssr/get-client-or-server-url.d.ts +3 -0
  21. package/dist/internal/shared/ssr/get-client-or-server-url.js +11 -0
  22. package/dist/internal/shared/ssr/get-client-or-server-url.js.map +1 -0
  23. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.cjs +34 -0
  24. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.cjs.map +1 -0
  25. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.d.ts +10 -0
  26. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.js +10 -0
  27. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.js.map +1 -0
  28. package/dist/next/host/app-router-server.cjs +3 -2
  29. package/dist/next/host/app-router-server.cjs.map +1 -1
  30. package/dist/next/host/app-router-server.js +3 -2
  31. package/dist/next/host/app-router-server.js.map +1 -1
  32. package/dist/next/host/client/index.cjs +31 -27
  33. package/dist/next/host/client/index.cjs.map +1 -1
  34. package/dist/next/host/client/index.d.ts +1 -1
  35. package/dist/next/host/client/index.js +31 -27
  36. package/dist/next/host/client/index.js.map +1 -1
  37. package/dist/next/host/pages-router-server.cjs +4 -8
  38. package/dist/next/host/pages-router-server.cjs.map +1 -1
  39. package/dist/next/host/pages-router-server.d.ts +0 -1
  40. package/dist/next/host/pages-router-server.js +4 -8
  41. package/dist/next/host/pages-router-server.js.map +1 -1
  42. package/dist/react/index.cjs +23 -27
  43. package/dist/react/index.cjs.map +1 -1
  44. package/dist/react/index.d.ts +1 -1
  45. package/dist/react/index.js +23 -27
  46. package/dist/react/index.js.map +1 -1
  47. package/dist/{types-4e7dea94.d.ts → types-235b68a5.d.ts} +4 -1
  48. package/package.json +1 -1
@@ -9,7 +9,10 @@ interface RemoteComponentMetadata {
9
9
  }
10
10
 
11
11
  interface RemoteComponentProps {
12
- url: string;
12
+ /** The src provided to the `<RemoteComponent>` component. May be relative or absolute URL. */
13
+ src: string;
14
+ /** The src converted to a URL object. For relative URLs, the VERCEL_URL is used as the origin. */
15
+ serverUrl: string;
13
16
  name: string;
14
17
  bundle: string;
15
18
  route?: string;
@@ -37,7 +37,9 @@ var Image = __toESM(require("next/image"), 1);
37
37
  var import_react = require("react");
38
38
  var import_react_dom = require("react-dom");
39
39
  var import_app_router_compat = require("#internal/next/host/app-router-compat");
40
+ var import_get_client_src = require("#internal/shared/client/get-client-src");
40
41
  var import_remote_component = require("#internal/shared/client/remote-component");
42
+ var import_get_client_or_server_url = require("#internal/shared/ssr/get-client-or-server-url");
41
43
  var import_utils = require("#internal/shared/utils");
42
44
  async function tryImportShared() {
43
45
  try {
@@ -48,7 +50,8 @@ async function tryImportShared() {
48
50
  }
49
51
  }
50
52
  function RemoteComponentClient({
51
- url,
53
+ src,
54
+ serverUrl,
52
55
  name,
53
56
  bundle,
54
57
  route = import_remote_component.DEFAULT_ROUTE,
@@ -66,11 +69,12 @@ function RemoteComponentClient({
66
69
  }) {
67
70
  const remoteComponentId = (0, import_react.useId)();
68
71
  const [component, setComponent] = (0, import_react.useState)(null);
72
+ const url = (0, import_get_client_or_server_url.getClientOrServerUrl)(src, serverUrl);
69
73
  const metadataRef = (0, import_react.useRef)({
70
74
  name,
71
75
  bundle,
72
76
  route,
73
- url,
77
+ url: url.href,
74
78
  loading: false
75
79
  });
76
80
  const startRef = (0, import_react.useRef)(null);
@@ -83,8 +87,11 @@ function RemoteComponentClient({
83
87
  // we don't use the provided static HTML
84
88
  // to mitigate layout shift when loading CSS using JavaScript on the client
85
89
  nextData?.buildId !== "development";
90
+ const keySuffix = `${(0, import_utils.escapeString)(bundle)}_${(0, import_utils.escapeString)(
91
+ url.pathname
92
+ )}_${(0, import_utils.escapeString)(name)}`;
86
93
  const self = globalThis;
87
- const shadowRootKey = `__remote_components_shadowroot_${(0, import_utils.escapeString)(new URL(url).href)}_${(0, import_utils.escapeString)(name)}`;
94
+ const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
88
95
  const shadowContainerRef = (0, import_react.useRef)(
89
96
  typeof document === "undefined" ? null : document.querySelector(
90
97
  `[data-remote-component-id="shadowroot_${remoteComponentId}"]`
@@ -175,20 +182,17 @@ function RemoteComponentClient({
175
182
  (0, import_react.useEffect)(() => {
176
183
  (0, import_react.startTransition)(async () => {
177
184
  try {
178
- if (!metadataRef.current.loading && !component && (isolate === false || shadowRootRef.current) || metadataRef.current.url !== url || metadataRef.current.name !== name || metadataRef.current.bundle !== bundle || metadataRef.current.route !== route) {
185
+ if (!metadataRef.current.loading && !component && (isolate === false || shadowRootRef.current) || metadataRef.current.url !== url.href || metadataRef.current.name !== name || metadataRef.current.bundle !== bundle || metadataRef.current.route !== route) {
179
186
  metadataRef.current = {
180
187
  name,
181
188
  bundle,
182
189
  route,
183
- url,
190
+ url: url.href,
184
191
  loading: true
185
192
  };
186
193
  if (type === "remote-component") {
187
194
  setComponent(children);
188
- (0, import_remote_component.loadStaticRemoteComponent)(
189
- scripts,
190
- new URL(url, location.origin)
191
- ).then(({ mount, unmount }) => {
195
+ (0, import_remote_component.loadStaticRemoteComponent)(scripts, url).then(({ mount, unmount }) => {
192
196
  if (mount.size > 0) {
193
197
  let root = shadowRootRef.current;
194
198
  try {
@@ -213,9 +217,9 @@ function RemoteComponentClient({
213
217
  });
214
218
  return;
215
219
  }
216
- const rscName = `__remote_components_rsc_${(0, import_utils.escapeString)(new URL(url).href)}_${(0, import_utils.escapeString)(name)}`;
220
+ const rscName = `__remote_components_rsc_${keySuffix}`;
217
221
  const result = await (0, import_remote_component.loadRemoteComponent)({
218
- url: new URL(url, location.origin),
222
+ url,
219
223
  name,
220
224
  bundle,
221
225
  route,
@@ -252,7 +256,6 @@ function RemoteComponentClient({
252
256
  }
253
257
  });
254
258
  }, [
255
- url,
256
259
  component,
257
260
  name,
258
261
  bundle,
@@ -264,7 +267,9 @@ function RemoteComponentClient({
264
267
  remoteShared,
265
268
  children,
266
269
  isolate,
267
- type
270
+ type,
271
+ keySuffix,
272
+ url
268
273
  ]);
269
274
  if (nextData?.buildId === "development" && shadowRootRef.current && isolate !== false && reset && !shadowRootRef.current.querySelector("[data-remote-components-reset]")) {
270
275
  const style = document.createElement("style");
@@ -282,37 +287,23 @@ function RemoteComponentClient({
282
287
  const linksToRender = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
283
288
  (!nextData || nextData.buildId !== "development") && isolate !== false && reset ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { "data-remote-components-reset": "", children: `:host { all: initial; }` }) : null,
284
289
  links.map((link) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
285
- "link",
290
+ RenderLink,
286
291
  {
287
- ...Object.entries(link).reduce(
288
- (acc, [key, value]) => {
289
- if (key !== "href" && key !== "precedence" && typeof value === "string") {
290
- acc[import_utils.attrToProp[key] ?? key] = value;
291
- }
292
- return acc;
293
- },
294
- {}
295
- ),
296
- "data-wait": link.rel === "stylesheet" && link.href ? "" : void 0,
297
- href: link.href ? new URL(link.href, url).href : void 0
292
+ link,
293
+ url,
294
+ serverUrl,
295
+ "data-wait": link.rel === "stylesheet" && link.href ? "" : void 0
298
296
  },
299
297
  JSON.stringify(link)
300
298
  )),
301
299
  links.filter((link) => link.rel === "stylesheet").map((link) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
302
- "link",
300
+ RenderLink,
303
301
  {
304
- ...Object.entries(link).reduce(
305
- (acc, [key, value]) => {
306
- if (key !== "href" && key !== "precedence" && typeof value === "string") {
307
- acc[import_utils.attrToProp[key] ?? key] = value;
308
- }
309
- return acc;
310
- },
311
- {}
312
- ),
302
+ link,
303
+ serverUrl,
304
+ url,
313
305
  as: "style",
314
306
  fetchPriority: "high",
315
- href: link.href ? new URL(link.href, url).href : void 0,
316
307
  precedence: bundle,
317
308
  rel: "preload"
318
309
  },
@@ -341,7 +332,7 @@ function RemoteComponentClient({
341
332
  src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="
342
333
  onload="(function(el){
343
334
  const root = el.getRootNode();
344
- globalThis.__remote_components_shadowroot_${(0, import_utils.escapeString)(new URL(url).href)}_${(0, import_utils.escapeString)(name)} = root;
335
+ globalThis.${shadowRootKey} = root;
345
336
  el.parentElement.remove();
346
337
  })(this)"
347
338
  />`
@@ -376,7 +367,10 @@ function RemoteComponentClient({
376
367
  nextData ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
377
368
  "script",
378
369
  {
379
- id: `${bundle}_${route.replace(/[^a-zA-Z0-9]+/g, "_")}${name}_next_data`,
370
+ id: `${bundle}_${route.replace(
371
+ /[^a-zA-Z0-9]+/g,
372
+ "_"
373
+ )}${name}_next_data`,
380
374
  type: "application/json",
381
375
  children: JSON.stringify(nextData)
382
376
  }
@@ -384,6 +378,29 @@ function RemoteComponentClient({
384
378
  isolate === false ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { id: `${name}_end`, ref: endRef }) : null
385
379
  ] });
386
380
  }
381
+ function RenderLink({
382
+ link,
383
+ url,
384
+ serverUrl,
385
+ ...rest
386
+ }) {
387
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
388
+ "link",
389
+ {
390
+ ...Object.entries(link).reduce(
391
+ (acc, [key, value]) => {
392
+ if (key !== "href" && key !== "precedence" && typeof value === "string") {
393
+ acc[import_utils.attrToProp[key] ?? key] = value;
394
+ }
395
+ return acc;
396
+ },
397
+ {}
398
+ ),
399
+ href: (0, import_get_client_src.getClientSrc)(link.href, serverUrl),
400
+ ...rest
401
+ }
402
+ );
403
+ }
387
404
  // Annotate the CommonJS export names for ESM import in node:
388
405
  0 && (module.exports = {
389
406
  RemoteComponentClient
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/host/app-router-client.tsx"],"sourcesContent":["'use client';\n\nimport * as Image from 'next/image';\nimport {\n startTransition,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { imageImpl, routerImpl } from '#internal/next/host/app-router-compat';\nimport type { RemoteComponentProps } from '#internal/shared/client/remote-component';\nimport {\n DEFAULT_ROUTE,\n loadRemoteComponent,\n loadStaticRemoteComponent,\n RUNTIME_WEBPACK,\n} from '#internal/shared/client/remote-component';\nimport type { MountOrUnmountFunction } from '#internal/shared/client/types';\nimport { attrToProp, escapeString } from '#internal/shared/utils';\n\n// patch react/jsx-runtime to support the shadowrootmode attribute on template elements\ndeclare module 'react/jsx-runtime' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace JSX {\n interface IntrinsicElements {\n template: {\n shadowrootmode?: 'open' | 'closed';\n id?: string;\n ref?: React.Ref<HTMLTemplateElement>;\n dangerouslySetInnerHTML?: {\n __html: string;\n };\n children?: React.ReactNode;\n };\n }\n }\n}\n\n// import { shared } from 'remote-components/shared/host';\nasync function tryImportShared() {\n try {\n const { shared } = await import('remote-components/shared/host/app');\n return shared;\n } catch {\n return {};\n }\n}\n\n/**\n * RemoteComponentClient - Main component for rendering remote components\n *\n * This component handles the loading and rendering of remote microfrontends.\n * It supports both RSC (React Server Components) and Next.js Pages Router based components.\n */\nexport function RemoteComponentClient({\n url,\n name,\n bundle,\n route = DEFAULT_ROUTE,\n runtime = RUNTIME_WEBPACK,\n data,\n nextData,\n scripts = [],\n links = [],\n remoteShared = {},\n isolate,\n mode = 'open',\n reset,\n type,\n children,\n}: RemoteComponentProps) {\n const remoteComponentId = useId();\n const [component, setComponent] = useState<React.ReactNode | Error>(null);\n const metadataRef = useRef<{\n name: string;\n bundle: string;\n route: string;\n url: string;\n loading: boolean;\n }>({\n name,\n bundle,\n route,\n url,\n loading: false,\n });\n const startRef = useRef<HTMLTemplateElement | null>(null);\n const endRef = useRef<HTMLTemplateElement | null>(null);\n const prevRemoteComponentUnmountRef = useRef<{\n unmount: Set<MountOrUnmountFunction>;\n root: ShadowRoot | DocumentFragment | null;\n } | null>(null);\n\n // Handle errors by re-throwing them\n if (component instanceof Error) {\n throw component;\n }\n\n // determine whether to use children or loaded component\n const shouldUseChildren =\n (!component ||\n (component &&\n !nextData &&\n type !== 'remote-component' &&\n typeof (component as unknown as Promise<unknown>).then !==\n 'function')) &&\n // if the remote Next.js Pages Router application is in development mode\n // we don't use the provided static HTML\n // to mitigate layout shift when loading CSS using JavaScript on the client\n nextData?.buildId !== 'development';\n\n const self = globalThis as Record<\n `__remote_components_shadowroot_${string}`,\n ShadowRoot | null\n > &\n Record<`__remote_components_container_${string}`, HTMLDivElement | null>;\n const shadowRootKey =\n `__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)}` as const;\n const shadowContainerRef = useRef<HTMLDivElement | null>(\n typeof document === 'undefined'\n ? null\n : document.querySelector(\n `[data-remote-component-id=\"shadowroot_${remoteComponentId}\"]`,\n ),\n );\n const shadowRootRef = useRef<ShadowRoot | null>(\n self[shadowRootKey] ?? shadowContainerRef.current?.shadowRoot ?? null,\n );\n const ssrShadowRootContentRef = useRef<NodeListOf<ChildNode> | null>(\n shadowRootRef.current?.querySelectorAll('*') ?? null,\n );\n const ssrLinksStylesRef = useRef<(HTMLLinkElement | HTMLStyleElement)[]>([]);\n\n if (self[shadowRootKey] && shadowRootRef.current) {\n self[shadowRootKey] = null;\n }\n\n useLayoutEffect(() => {\n if (\n !shadowContainerRef.current ||\n shadowContainerRef.current !== shadowRootRef.current?.host\n ) {\n shadowRootRef.current = null;\n }\n\n if (\n isolate !== false &&\n typeof document !== 'undefined' &&\n !shadowRootRef.current\n ) {\n let shadowRootElement: ShadowRoot | null = null;\n const element = shadowContainerRef.current;\n\n shadowRootElement = self[shadowRootKey] ?? element?.shadowRoot ?? null;\n self[shadowRootKey] = null;\n\n if (!shadowRootElement && element) {\n // create a shadow root if it doesn't exist\n // this is a fallback for browsers that don't support declarative shadow DOM\n try {\n shadowRootElement = element.attachShadow({ mode });\n } catch {\n // do nothing if attachShadow fails because of existing shadow root\n }\n }\n\n if (shadowRootElement) {\n shadowRootRef.current = shadowRootElement;\n }\n }\n\n if (\n shadowRootRef.current &&\n ssrShadowRootContentRef.current &&\n !shouldUseChildren\n ) {\n // remove all nodes from the shadow root except links\n ssrShadowRootContentRef.current.forEach((node) => {\n if (node.nodeName !== 'LINK' && node.nodeName !== 'STYLE') {\n node.parentNode?.removeChild(node);\n } else {\n ssrLinksStylesRef.current.push(\n node as HTMLLinkElement | HTMLStyleElement,\n );\n }\n });\n ssrShadowRootContentRef.current = null;\n }\n\n if (ssrLinksStylesRef.current.length > 0 && shadowRootRef.current) {\n const waitForLoad =\n shadowRootRef.current.querySelectorAll('link[data-wait]');\n if (waitForLoad.length > 0) {\n Promise.all(\n Array.from(waitForLoad).map(\n (link) =>\n new Promise<void>((resolve) => {\n link.addEventListener('load', () => resolve());\n link.addEventListener('error', () => resolve());\n }),\n ),\n )\n .then(() => {\n waitForLoad.forEach((el) => {\n el.removeAttribute('data-wait');\n });\n\n // remove SSR injected styles and links\n ssrLinksStylesRef.current.forEach((el) => {\n el.parentNode?.removeChild(el);\n });\n ssrLinksStylesRef.current = [];\n })\n .catch((e) => {\n // eslint-disable-next-line no-console\n console.error(e);\n });\n }\n }\n }, [isolate, mode, self, shadowRootKey, shouldUseChildren]);\n\n useEffect(() => {\n // run unmount functions when the component changes or unmounts\n if (prevRemoteComponentUnmountRef.current && component !== children) {\n const { unmount, root } = prevRemoteComponentUnmountRef.current;\n prevRemoteComponentUnmountRef.current = null;\n Promise.all(\n Array.from(unmount).map(async (unmountFn) => {\n try {\n await unmountFn(root);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(e);\n }\n }),\n ).catch((e) => {\n // eslint-disable-next-line no-console\n console.error(e);\n });\n }\n }, [component, children]);\n\n useEffect(() => {\n startTransition(async () => {\n try {\n // if we have a component, we don't need to load it again\n if (\n (!metadataRef.current.loading &&\n !component &&\n (isolate === false || shadowRootRef.current)) ||\n metadataRef.current.url !== url ||\n metadataRef.current.name !== name ||\n metadataRef.current.bundle !== bundle ||\n metadataRef.current.route !== route\n ) {\n metadataRef.current = {\n name,\n bundle,\n route,\n url,\n loading: true,\n };\n\n // use the children as the component when type is remote-component\n if (type === 'remote-component') {\n setComponent(children);\n // load static scripts and execute mount functions\n // run this async but don't await it as we render children immediately\n loadStaticRemoteComponent(\n scripts as HTMLScriptElement[],\n new URL(url, location.origin),\n )\n .then(({ mount, unmount }) => {\n if (mount.size > 0) {\n let root: ShadowRoot | DocumentFragment | null =\n shadowRootRef.current;\n try {\n if (!root && startRef.current && endRef.current) {\n root = document.querySelectorAll(\n `#${startRef.current.id} ~ *:not(#${endRef.current.id}):has(~ #${endRef.current.id})`,\n ) as unknown as DocumentFragment;\n }\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(e);\n }\n if (unmount.size > 0) {\n prevRemoteComponentUnmountRef.current = { unmount, root };\n }\n return Promise.all(\n Array.from(mount).map((mountFn) => mountFn(root)),\n );\n }\n })\n .catch((e) => {\n // eslint-disable-next-line no-console\n console.error(e);\n setComponent(e as Error);\n });\n return;\n }\n\n const rscName = `__remote_components_rsc_${escapeString(new URL(url).href)}_${escapeString(name)}`;\n const result = await loadRemoteComponent({\n url: new URL(url, location.origin),\n name,\n bundle,\n route,\n runtime,\n rscName,\n data,\n nextData,\n scripts,\n shared: (async () => {\n const shared = await tryImportShared();\n\n if ('__remote_components_missing_shared__' in shared) {\n await shared.__remote_components_missing_shared__();\n }\n\n return {\n 'next/router': routerImpl,\n ...shared,\n 'next/image': () =>\n Promise.resolve(imageImpl(Image.default, bundle)),\n 'next/dist/client/image-component': () =>\n Promise.resolve({ Image: imageImpl(Image.default, bundle) }),\n };\n })(),\n remoteShared,\n container: shadowRootRef.current,\n });\n metadataRef.current.loading = false;\n if (result.error) {\n setComponent(result.error);\n } else {\n setComponent(result.component);\n }\n }\n } catch (error: unknown) {\n metadataRef.current.loading = false;\n setComponent(error as Error);\n }\n });\n }, [\n url,\n component,\n name,\n bundle,\n route,\n runtime,\n scripts,\n data,\n nextData,\n remoteShared,\n children,\n isolate,\n type,\n ]);\n\n if (\n nextData?.buildId === 'development' &&\n shadowRootRef.current &&\n isolate !== false &&\n reset &&\n !shadowRootRef.current.querySelector('[data-remote-components-reset]')\n ) {\n // inject reset styles into the shadow root\n const style = document.createElement('style');\n style.setAttribute('data-remote-components-reset', '');\n style.textContent = `:host { all: initial; }`;\n shadowRootRef.current.insertBefore(style, shadowRootRef.current.firstChild);\n } else if (\n shadowRootRef.current &&\n isolate !== false &&\n !reset &&\n shadowRootRef.current.querySelector('[data-remote-components-reset]')\n ) {\n // ensure reset styles are the first child in the shadow root\n const style = shadowRootRef.current.querySelector(\n '[data-remote-components-reset]',\n );\n if (style && shadowRootRef.current.firstChild !== style) {\n shadowRootRef.current.removeChild(style);\n }\n }\n\n const linksToRender = (\n <>\n {(!nextData || nextData.buildId !== 'development') &&\n isolate !== false &&\n reset ? (\n <style data-remote-components-reset=\"\">{`:host { all: initial; }`}</style>\n ) : null}\n {links.map((link) => (\n <link\n key={JSON.stringify(link)}\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n data-wait={link.rel === 'stylesheet' && link.href ? '' : undefined}\n href={link.href ? new URL(link.href as string, url).href : undefined}\n />\n ))}\n {links\n .filter((link) => link.rel === 'stylesheet')\n .map((link) => (\n <link\n key={JSON.stringify(link)}\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n as=\"style\"\n fetchPriority=\"high\"\n href={\n link.href ? new URL(link.href as string, url).href : undefined\n }\n precedence={bundle}\n rel=\"preload\"\n />\n ))}\n </>\n );\n\n let componentToRender = shouldUseChildren\n ? children\n : (component as React.ReactNode);\n\n if (isolate !== false) {\n componentToRender = (\n <div\n data-remote-component-id={`shadowroot_${remoteComponentId}`}\n data-remote-component-isolation-root=\"\"\n id={`shadowroot_${name}`}\n ref={shadowContainerRef}\n >\n {typeof document === 'undefined' ? (\n // eslint-disable-next-line react/no-unknown-property\n <template shadowrootmode={mode}>\n {mode === 'closed' ? (\n <div\n dangerouslySetInnerHTML={{\n __html: `<img\n alt=\"\" decoding=\"async\" style=\"display:none\"\n src=\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==\"\n onload=\"(function(el){\n const root = el.getRootNode();\n globalThis.__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)} = root;\n el.parentElement.remove();\n })(this)\"\n />`,\n }}\n />\n ) : null}\n {linksToRender}\n {shouldUseChildren ? children : null}\n </template>\n ) : null}\n {typeof document !== 'undefined' &&\n shadowRootRef.current &&\n !shouldUseChildren\n ? createPortal(\n <>\n {linksToRender}\n {componentToRender}\n </>,\n shadowRootRef.current,\n )\n : null}\n </div>\n );\n }\n\n return (\n <>\n {isolate === false ? (\n <template id={`${name}_start`} ref={startRef} />\n ) : null}\n <script data-remote-component type=\"application/json\">\n {JSON.stringify({\n name,\n bundle,\n route,\n runtime,\n })}\n </script>\n {isolate === false ? linksToRender : null}\n {componentToRender}\n {nextData ? (\n <script\n id={`${bundle}_${route.replace(/[^a-zA-Z0-9]+/g, '_')}${name}_next_data`}\n type=\"application/json\"\n >\n {JSON.stringify(nextData)}\n </script>\n ) : null}\n {isolate === false ? <template id={`${name}_end`} ref={endRef} /> : null}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuYI;AArYJ,YAAuB;AACvB,mBAOO;AACP,uBAA6B;AAC7B,+BAAsC;AAEtC,8BAKO;AAEP,mBAAyC;AAqBzC,eAAe,kBAAkB;AAC/B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,mCAAmC;AACnE,WAAO;AAAA,EACT,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAQO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,UAAU,CAAC;AAAA,EACX,QAAQ,CAAC;AAAA,EACT,eAAe,CAAC;AAAA,EAChB;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,wBAAoB,oBAAM;AAChC,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAkC,IAAI;AACx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AS,IAAI,GAAG,cAAc,KAAK,UAAU,IAC5C;AAAA,IACJ,4CAAC,YAAO,yBAAqB,MAAC,MAAK,oBAChC,eAAK,UAAU;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC,GACH;AAAA,IACC,YAAY,QAAQ,gBAAgB;AAAA,IACpC;AAAA,IACA,WACC;AAAA,MAAC;AAAA;AAAA,QACC,IAAI,GAAG,UAAU,MAAM,QAAQ,kBAAkB,GAAG,IAAI;AAAA,QACxD,MAAK;AAAA,QAEJ,eAAK,UAAU,QAAQ;AAAA;AAAA,IAC1B,IACE;AAAA,IACH,YAAY,QAAQ,4CAAC,cAAS,IAAI,GAAG,YAAY,KAAK,QAAQ,IAAK;AAAA,KACtE;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/next/host/app-router-client.tsx"],"sourcesContent":["'use client';\n\nimport * as Image from 'next/image';\nimport {\n startTransition,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { imageImpl, routerImpl } from '#internal/next/host/app-router-compat';\nimport { getClientSrc } from '#internal/shared/client/get-client-src';\nimport type { RemoteComponentProps } from '#internal/shared/client/remote-component';\nimport {\n DEFAULT_ROUTE,\n loadRemoteComponent,\n loadStaticRemoteComponent,\n RUNTIME_WEBPACK,\n} from '#internal/shared/client/remote-component';\nimport type { MountOrUnmountFunction } from '#internal/shared/client/types';\nimport { getClientOrServerUrl } from '#internal/shared/ssr/get-client-or-server-url';\nimport { attrToProp, escapeString } from '#internal/shared/utils';\n\n// patch react/jsx-runtime to support the shadowrootmode attribute on template elements\ndeclare module 'react/jsx-runtime' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace JSX {\n interface IntrinsicElements {\n template: {\n shadowrootmode?: 'open' | 'closed';\n id?: string;\n ref?: React.Ref<HTMLTemplateElement>;\n dangerouslySetInnerHTML?: {\n __html: string;\n };\n children?: React.ReactNode;\n };\n }\n }\n}\n\n// import { shared } from 'remote-components/shared/host';\nasync function tryImportShared() {\n try {\n const { shared } = await import('remote-components/shared/host/app');\n return shared;\n } catch {\n return {};\n }\n}\n\n/**\n * RemoteComponentClient - Main component for rendering remote components\n *\n * This component handles the loading and rendering of remote microfrontends.\n * It supports both RSC (React Server Components) and Next.js Pages Router based components.\n */\nexport function RemoteComponentClient({\n src,\n serverUrl,\n name,\n bundle,\n route = DEFAULT_ROUTE,\n runtime = RUNTIME_WEBPACK,\n data,\n nextData,\n scripts = [],\n links = [],\n remoteShared = {},\n isolate,\n mode = 'open',\n reset,\n type,\n children,\n}: RemoteComponentProps) {\n const remoteComponentId = useId();\n const [component, setComponent] = useState<React.ReactNode | Error>(null);\n const url = getClientOrServerUrl(src, serverUrl);\n const metadataRef = useRef<{\n name: string;\n bundle: string;\n route: string;\n url: string;\n loading: boolean;\n }>({\n name,\n bundle,\n route,\n url: url.href,\n loading: false,\n });\n const startRef = useRef<HTMLTemplateElement | null>(null);\n const endRef = useRef<HTMLTemplateElement | null>(null);\n const prevRemoteComponentUnmountRef = useRef<{\n unmount: Set<MountOrUnmountFunction>;\n root: ShadowRoot | DocumentFragment | null;\n } | null>(null);\n\n // Handle errors by re-throwing them\n if (component instanceof Error) {\n throw component;\n }\n\n // determine whether to use children or loaded component\n const shouldUseChildren =\n (!component ||\n (component &&\n !nextData &&\n type !== 'remote-component' &&\n typeof (component as unknown as Promise<unknown>).then !==\n 'function')) &&\n // if the remote Next.js Pages Router application is in development mode\n // we don't use the provided static HTML\n // to mitigate layout shift when loading CSS using JavaScript on the client\n nextData?.buildId !== 'development';\n\n // The pathname is used so this URL is the same across server and client requests for relative src's\n const keySuffix = `${escapeString(bundle)}_${escapeString(\n url.pathname,\n )}_${escapeString(name)}`;\n\n const self = globalThis as Record<\n `__remote_components_shadowroot_${string}`,\n ShadowRoot | null\n > &\n Record<`__remote_components_container_${string}`, HTMLDivElement | null>;\n const shadowRootKey = `__remote_components_shadowroot_${keySuffix}` as const;\n const shadowContainerRef = useRef<HTMLDivElement | null>(\n typeof document === 'undefined'\n ? null\n : document.querySelector(\n `[data-remote-component-id=\"shadowroot_${remoteComponentId}\"]`,\n ),\n );\n const shadowRootRef = useRef<ShadowRoot | null>(\n self[shadowRootKey] ?? shadowContainerRef.current?.shadowRoot ?? null,\n );\n const ssrShadowRootContentRef = useRef<NodeListOf<ChildNode> | null>(\n shadowRootRef.current?.querySelectorAll('*') ?? null,\n );\n const ssrLinksStylesRef = useRef<(HTMLLinkElement | HTMLStyleElement)[]>([]);\n\n if (self[shadowRootKey] && shadowRootRef.current) {\n self[shadowRootKey] = null;\n }\n\n useLayoutEffect(() => {\n if (\n !shadowContainerRef.current ||\n shadowContainerRef.current !== shadowRootRef.current?.host\n ) {\n shadowRootRef.current = null;\n }\n\n if (\n isolate !== false &&\n typeof document !== 'undefined' &&\n !shadowRootRef.current\n ) {\n let shadowRootElement: ShadowRoot | null = null;\n const element = shadowContainerRef.current;\n\n shadowRootElement = self[shadowRootKey] ?? element?.shadowRoot ?? null;\n self[shadowRootKey] = null;\n\n if (!shadowRootElement && element) {\n // create a shadow root if it doesn't exist\n // this is a fallback for browsers that don't support declarative shadow DOM\n try {\n shadowRootElement = element.attachShadow({ mode });\n } catch {\n // do nothing if attachShadow fails because of existing shadow root\n }\n }\n\n if (shadowRootElement) {\n shadowRootRef.current = shadowRootElement;\n }\n }\n\n if (\n shadowRootRef.current &&\n ssrShadowRootContentRef.current &&\n !shouldUseChildren\n ) {\n // remove all nodes from the shadow root except links\n ssrShadowRootContentRef.current.forEach((node) => {\n if (node.nodeName !== 'LINK' && node.nodeName !== 'STYLE') {\n node.parentNode?.removeChild(node);\n } else {\n ssrLinksStylesRef.current.push(\n node as HTMLLinkElement | HTMLStyleElement,\n );\n }\n });\n ssrShadowRootContentRef.current = null;\n }\n\n if (ssrLinksStylesRef.current.length > 0 && shadowRootRef.current) {\n const waitForLoad =\n shadowRootRef.current.querySelectorAll('link[data-wait]');\n if (waitForLoad.length > 0) {\n Promise.all(\n Array.from(waitForLoad).map(\n (link) =>\n new Promise<void>((resolve) => {\n link.addEventListener('load', () => resolve());\n link.addEventListener('error', () => resolve());\n }),\n ),\n )\n .then(() => {\n waitForLoad.forEach((el) => {\n el.removeAttribute('data-wait');\n });\n\n // remove SSR injected styles and links\n ssrLinksStylesRef.current.forEach((el) => {\n el.parentNode?.removeChild(el);\n });\n ssrLinksStylesRef.current = [];\n })\n .catch((e) => {\n // eslint-disable-next-line no-console\n console.error(e);\n });\n }\n }\n }, [isolate, mode, self, shadowRootKey, shouldUseChildren]);\n\n useEffect(() => {\n // run unmount functions when the component changes or unmounts\n if (prevRemoteComponentUnmountRef.current && component !== children) {\n const { unmount, root } = prevRemoteComponentUnmountRef.current;\n prevRemoteComponentUnmountRef.current = null;\n Promise.all(\n Array.from(unmount).map(async (unmountFn) => {\n try {\n await unmountFn(root);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(e);\n }\n }),\n ).catch((e) => {\n // eslint-disable-next-line no-console\n console.error(e);\n });\n }\n }, [component, children]);\n\n useEffect(() => {\n startTransition(async () => {\n try {\n // if we have a component, we don't need to load it again\n if (\n (!metadataRef.current.loading &&\n !component &&\n (isolate === false || shadowRootRef.current)) ||\n metadataRef.current.url !== url.href ||\n metadataRef.current.name !== name ||\n metadataRef.current.bundle !== bundle ||\n metadataRef.current.route !== route\n ) {\n metadataRef.current = {\n name,\n bundle,\n route,\n url: url.href,\n loading: true,\n };\n\n // use the children as the component when type is remote-component\n if (type === 'remote-component') {\n setComponent(children);\n // load static scripts and execute mount functions\n // run this async but don't await it as we render children immediately\n loadStaticRemoteComponent(scripts as HTMLScriptElement[], url)\n .then(({ mount, unmount }) => {\n if (mount.size > 0) {\n let root: ShadowRoot | DocumentFragment | null =\n shadowRootRef.current;\n try {\n if (!root && startRef.current && endRef.current) {\n root = document.querySelectorAll(\n `#${startRef.current.id} ~ *:not(#${endRef.current.id}):has(~ #${endRef.current.id})`,\n ) as unknown as DocumentFragment;\n }\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(e);\n }\n if (unmount.size > 0) {\n prevRemoteComponentUnmountRef.current = { unmount, root };\n }\n return Promise.all(\n Array.from(mount).map((mountFn) => mountFn(root)),\n );\n }\n })\n .catch((e) => {\n // eslint-disable-next-line no-console\n console.error(e);\n setComponent(e as Error);\n });\n return;\n }\n\n const rscName = `__remote_components_rsc_${keySuffix}`;\n const result = await loadRemoteComponent({\n url,\n name,\n bundle,\n route,\n runtime,\n rscName,\n data,\n nextData,\n scripts,\n shared: (async () => {\n const shared = await tryImportShared();\n\n if ('__remote_components_missing_shared__' in shared) {\n await shared.__remote_components_missing_shared__();\n }\n\n return {\n 'next/router': routerImpl,\n ...shared,\n 'next/image': () =>\n Promise.resolve(imageImpl(Image.default, bundle)),\n 'next/dist/client/image-component': () =>\n Promise.resolve({ Image: imageImpl(Image.default, bundle) }),\n };\n })(),\n remoteShared,\n container: shadowRootRef.current,\n });\n metadataRef.current.loading = false;\n if (result.error) {\n setComponent(result.error);\n } else {\n setComponent(result.component);\n }\n }\n } catch (error: unknown) {\n metadataRef.current.loading = false;\n setComponent(error as Error);\n }\n });\n }, [\n component,\n name,\n bundle,\n route,\n runtime,\n scripts,\n data,\n nextData,\n remoteShared,\n children,\n isolate,\n type,\n keySuffix,\n url,\n ]);\n\n if (\n nextData?.buildId === 'development' &&\n shadowRootRef.current &&\n isolate !== false &&\n reset &&\n !shadowRootRef.current.querySelector('[data-remote-components-reset]')\n ) {\n // inject reset styles into the shadow root\n const style = document.createElement('style');\n style.setAttribute('data-remote-components-reset', '');\n style.textContent = `:host { all: initial; }`;\n shadowRootRef.current.insertBefore(style, shadowRootRef.current.firstChild);\n } else if (\n shadowRootRef.current &&\n isolate !== false &&\n !reset &&\n shadowRootRef.current.querySelector('[data-remote-components-reset]')\n ) {\n // ensure reset styles are the first child in the shadow root\n const style = shadowRootRef.current.querySelector(\n '[data-remote-components-reset]',\n );\n if (style && shadowRootRef.current.firstChild !== style) {\n shadowRootRef.current.removeChild(style);\n }\n }\n\n const linksToRender = (\n <>\n {(!nextData || nextData.buildId !== 'development') &&\n isolate !== false &&\n reset ? (\n <style data-remote-components-reset=\"\">{`:host { all: initial; }`}</style>\n ) : null}\n {links.map((link) => (\n <RenderLink\n key={JSON.stringify(link)}\n link={link}\n url={url}\n serverUrl={serverUrl}\n data-wait={link.rel === 'stylesheet' && link.href ? '' : undefined}\n />\n ))}\n {links\n .filter((link) => link.rel === 'stylesheet')\n .map((link) => (\n <RenderLink\n key={JSON.stringify(link)}\n link={link}\n serverUrl={serverUrl}\n url={url}\n as=\"style\"\n fetchPriority=\"high\"\n precedence={bundle}\n rel=\"preload\"\n />\n ))}\n </>\n );\n\n let componentToRender = shouldUseChildren\n ? children\n : (component as React.ReactNode);\n\n if (isolate !== false) {\n componentToRender = (\n <div\n data-remote-component-id={`shadowroot_${remoteComponentId}`}\n data-remote-component-isolation-root=\"\"\n id={`shadowroot_${name}`}\n ref={shadowContainerRef}\n >\n {typeof document === 'undefined' ? (\n // eslint-disable-next-line react/no-unknown-property\n <template shadowrootmode={mode}>\n {mode === 'closed' ? (\n <div\n dangerouslySetInnerHTML={{\n __html: `<img\n alt=\"\" decoding=\"async\" style=\"display:none\"\n src=\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==\"\n onload=\"(function(el){\n const root = el.getRootNode();\n globalThis.${shadowRootKey} = root;\n el.parentElement.remove();\n })(this)\"\n />`,\n }}\n />\n ) : null}\n {linksToRender}\n {shouldUseChildren ? children : null}\n </template>\n ) : null}\n {typeof document !== 'undefined' &&\n shadowRootRef.current &&\n !shouldUseChildren\n ? createPortal(\n <>\n {linksToRender}\n {componentToRender}\n </>,\n shadowRootRef.current,\n )\n : null}\n </div>\n );\n }\n\n return (\n <>\n {isolate === false ? (\n <template id={`${name}_start`} ref={startRef} />\n ) : null}\n <script data-remote-component type=\"application/json\">\n {JSON.stringify({\n name,\n bundle,\n route,\n runtime,\n })}\n </script>\n {isolate === false ? linksToRender : null}\n {componentToRender}\n {nextData ? (\n <script\n id={`${bundle}_${route.replace(\n /[^a-zA-Z0-9]+/g,\n '_',\n )}${name}_next_data`}\n type=\"application/json\"\n >\n {JSON.stringify(nextData)}\n </script>\n ) : null}\n {isolate === false ? <template id={`${name}_end`} ref={endRef} /> : null}\n </>\n );\n}\n\nfunction RenderLink({\n link,\n url,\n serverUrl,\n ...rest\n}: {\n link: Record<string, string | boolean | undefined>;\n url: URL;\n serverUrl: string;\n} & React.LinkHTMLAttributes<HTMLLinkElement>) {\n return (\n <link\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[attrToProp[key] ?? key] = value;\n }\n return acc;\n },\n {},\n )}\n href={getClientSrc(link.href, serverUrl)}\n {...rest}\n />\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA6YI;AA3YJ,YAAuB;AACvB,mBAOO;AACP,uBAA6B;AAC7B,+BAAsC;AACtC,4BAA6B;AAE7B,8BAKO;AAEP,sCAAqC;AACrC,mBAAyC;AAqBzC,eAAe,kBAAkB;AAC/B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,mCAAmC;AACnE,WAAO;AAAA,EACT,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAQO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,UAAU,CAAC;AAAA,EACX,QAAQ,CAAC;AAAA,EACT,eAAe,CAAC;AAAA,EAChB;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,wBAAoB,oBAAM;AAChC,QAAM,CAAC,WA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QAAQ,IAAI,EAAE;AAAA,QACvB,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AACrB,cACE,QAAQ,UACR,QAAQ,gBACR,OAAO,UAAU,UACjB;AACA,gBAAI,wBAAW,GAAG,KAAK,GAAG,IAAI;AAAA,UAChC;AACA,iBAAO;AAAA,QACT;AAAA,QACA,CAAC;AAAA,MACH;AAAA,MACA,UAAM,oCAAa,KAAK,MAAM,SAAS;AAAA,MACtC,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { R as RemoteComponentProps } from '../../../types-4e7dea94.js';
2
+ import { R as RemoteComponentProps } from '../../../types-235b68a5.js';
3
3
  import 'react';
4
4
  import '../../../types-cbf6c34f.js';
5
5
 
@@ -24,6 +24,6 @@ declare module 'react/jsx-runtime' {
24
24
  * This component handles the loading and rendering of remote microfrontends.
25
25
  * It supports both RSC (React Server Components) and Next.js Pages Router based components.
26
26
  */
27
- declare function RemoteComponentClient({ url, name, bundle, route, runtime, data, nextData, scripts, links, remoteShared, isolate, mode, reset, type, children, }: RemoteComponentProps): react_jsx_runtime.JSX.Element;
27
+ declare function RemoteComponentClient({ src, serverUrl, name, bundle, route, runtime, data, nextData, scripts, links, remoteShared, isolate, mode, reset, type, children, }: RemoteComponentProps): react_jsx_runtime.JSX.Element;
28
28
 
29
29
  export { RemoteComponentClient };
@@ -11,12 +11,14 @@ import {
11
11
  } from "react";
12
12
  import { createPortal } from "react-dom";
13
13
  import { imageImpl, routerImpl } from "#internal/next/host/app-router-compat";
14
+ import { getClientSrc } from "#internal/shared/client/get-client-src";
14
15
  import {
15
16
  DEFAULT_ROUTE,
16
17
  loadRemoteComponent,
17
18
  loadStaticRemoteComponent,
18
19
  RUNTIME_WEBPACK
19
20
  } from "#internal/shared/client/remote-component";
21
+ import { getClientOrServerUrl } from "#internal/shared/ssr/get-client-or-server-url";
20
22
  import { attrToProp, escapeString } from "#internal/shared/utils";
21
23
  async function tryImportShared() {
22
24
  try {
@@ -27,7 +29,8 @@ async function tryImportShared() {
27
29
  }
28
30
  }
29
31
  function RemoteComponentClient({
30
- url,
32
+ src,
33
+ serverUrl,
31
34
  name,
32
35
  bundle,
33
36
  route = DEFAULT_ROUTE,
@@ -45,11 +48,12 @@ function RemoteComponentClient({
45
48
  }) {
46
49
  const remoteComponentId = useId();
47
50
  const [component, setComponent] = useState(null);
51
+ const url = getClientOrServerUrl(src, serverUrl);
48
52
  const metadataRef = useRef({
49
53
  name,
50
54
  bundle,
51
55
  route,
52
- url,
56
+ url: url.href,
53
57
  loading: false
54
58
  });
55
59
  const startRef = useRef(null);
@@ -62,8 +66,11 @@ function RemoteComponentClient({
62
66
  // we don't use the provided static HTML
63
67
  // to mitigate layout shift when loading CSS using JavaScript on the client
64
68
  nextData?.buildId !== "development";
69
+ const keySuffix = `${escapeString(bundle)}_${escapeString(
70
+ url.pathname
71
+ )}_${escapeString(name)}`;
65
72
  const self = globalThis;
66
- const shadowRootKey = `__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)}`;
73
+ const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
67
74
  const shadowContainerRef = useRef(
68
75
  typeof document === "undefined" ? null : document.querySelector(
69
76
  `[data-remote-component-id="shadowroot_${remoteComponentId}"]`
@@ -154,20 +161,17 @@ function RemoteComponentClient({
154
161
  useEffect(() => {
155
162
  startTransition(async () => {
156
163
  try {
157
- if (!metadataRef.current.loading && !component && (isolate === false || shadowRootRef.current) || metadataRef.current.url !== url || metadataRef.current.name !== name || metadataRef.current.bundle !== bundle || metadataRef.current.route !== route) {
164
+ if (!metadataRef.current.loading && !component && (isolate === false || shadowRootRef.current) || metadataRef.current.url !== url.href || metadataRef.current.name !== name || metadataRef.current.bundle !== bundle || metadataRef.current.route !== route) {
158
165
  metadataRef.current = {
159
166
  name,
160
167
  bundle,
161
168
  route,
162
- url,
169
+ url: url.href,
163
170
  loading: true
164
171
  };
165
172
  if (type === "remote-component") {
166
173
  setComponent(children);
167
- loadStaticRemoteComponent(
168
- scripts,
169
- new URL(url, location.origin)
170
- ).then(({ mount, unmount }) => {
174
+ loadStaticRemoteComponent(scripts, url).then(({ mount, unmount }) => {
171
175
  if (mount.size > 0) {
172
176
  let root = shadowRootRef.current;
173
177
  try {
@@ -192,9 +196,9 @@ function RemoteComponentClient({
192
196
  });
193
197
  return;
194
198
  }
195
- const rscName = `__remote_components_rsc_${escapeString(new URL(url).href)}_${escapeString(name)}`;
199
+ const rscName = `__remote_components_rsc_${keySuffix}`;
196
200
  const result = await loadRemoteComponent({
197
- url: new URL(url, location.origin),
201
+ url,
198
202
  name,
199
203
  bundle,
200
204
  route,
@@ -231,7 +235,6 @@ function RemoteComponentClient({
231
235
  }
232
236
  });
233
237
  }, [
234
- url,
235
238
  component,
236
239
  name,
237
240
  bundle,
@@ -243,7 +246,9 @@ function RemoteComponentClient({
243
246
  remoteShared,
244
247
  children,
245
248
  isolate,
246
- type
249
+ type,
250
+ keySuffix,
251
+ url
247
252
  ]);
248
253
  if (nextData?.buildId === "development" && shadowRootRef.current && isolate !== false && reset && !shadowRootRef.current.querySelector("[data-remote-components-reset]")) {
249
254
  const style = document.createElement("style");
@@ -261,37 +266,23 @@ function RemoteComponentClient({
261
266
  const linksToRender = /* @__PURE__ */ jsxs(Fragment, { children: [
262
267
  (!nextData || nextData.buildId !== "development") && isolate !== false && reset ? /* @__PURE__ */ jsx("style", { "data-remote-components-reset": "", children: `:host { all: initial; }` }) : null,
263
268
  links.map((link) => /* @__PURE__ */ jsx(
264
- "link",
269
+ RenderLink,
265
270
  {
266
- ...Object.entries(link).reduce(
267
- (acc, [key, value]) => {
268
- if (key !== "href" && key !== "precedence" && typeof value === "string") {
269
- acc[attrToProp[key] ?? key] = value;
270
- }
271
- return acc;
272
- },
273
- {}
274
- ),
275
- "data-wait": link.rel === "stylesheet" && link.href ? "" : void 0,
276
- href: link.href ? new URL(link.href, url).href : void 0
271
+ link,
272
+ url,
273
+ serverUrl,
274
+ "data-wait": link.rel === "stylesheet" && link.href ? "" : void 0
277
275
  },
278
276
  JSON.stringify(link)
279
277
  )),
280
278
  links.filter((link) => link.rel === "stylesheet").map((link) => /* @__PURE__ */ jsx(
281
- "link",
279
+ RenderLink,
282
280
  {
283
- ...Object.entries(link).reduce(
284
- (acc, [key, value]) => {
285
- if (key !== "href" && key !== "precedence" && typeof value === "string") {
286
- acc[attrToProp[key] ?? key] = value;
287
- }
288
- return acc;
289
- },
290
- {}
291
- ),
281
+ link,
282
+ serverUrl,
283
+ url,
292
284
  as: "style",
293
285
  fetchPriority: "high",
294
- href: link.href ? new URL(link.href, url).href : void 0,
295
286
  precedence: bundle,
296
287
  rel: "preload"
297
288
  },
@@ -320,7 +311,7 @@ function RemoteComponentClient({
320
311
  src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="
321
312
  onload="(function(el){
322
313
  const root = el.getRootNode();
323
- globalThis.__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)} = root;
314
+ globalThis.${shadowRootKey} = root;
324
315
  el.parentElement.remove();
325
316
  })(this)"
326
317
  />`
@@ -355,7 +346,10 @@ function RemoteComponentClient({
355
346
  nextData ? /* @__PURE__ */ jsx(
356
347
  "script",
357
348
  {
358
- id: `${bundle}_${route.replace(/[^a-zA-Z0-9]+/g, "_")}${name}_next_data`,
349
+ id: `${bundle}_${route.replace(
350
+ /[^a-zA-Z0-9]+/g,
351
+ "_"
352
+ )}${name}_next_data`,
359
353
  type: "application/json",
360
354
  children: JSON.stringify(nextData)
361
355
  }
@@ -363,6 +357,29 @@ function RemoteComponentClient({
363
357
  isolate === false ? /* @__PURE__ */ jsx("template", { id: `${name}_end`, ref: endRef }) : null
364
358
  ] });
365
359
  }
360
+ function RenderLink({
361
+ link,
362
+ url,
363
+ serverUrl,
364
+ ...rest
365
+ }) {
366
+ return /* @__PURE__ */ jsx(
367
+ "link",
368
+ {
369
+ ...Object.entries(link).reduce(
370
+ (acc, [key, value]) => {
371
+ if (key !== "href" && key !== "precedence" && typeof value === "string") {
372
+ acc[attrToProp[key] ?? key] = value;
373
+ }
374
+ return acc;
375
+ },
376
+ {}
377
+ ),
378
+ href: getClientSrc(link.href, serverUrl),
379
+ ...rest
380
+ }
381
+ );
382
+ }
366
383
  export {
367
384
  RemoteComponentClient
368
385
  };