remote-components 0.0.35 → 0.0.37

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 (38) 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 +51 -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 +51 -38
  6. package/dist/internal/next/host/app-router-client.js.map +1 -1
  7. package/dist/internal/shared/client/remote-component.d.ts +2 -2
  8. package/dist/internal/shared/ssr/fetch-remote-component.cjs +16 -16
  9. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  10. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +1 -1
  11. package/dist/internal/shared/ssr/fetch-remote-component.js +16 -16
  12. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  13. package/dist/internal/shared/ssr/get-client-or-server-url.cjs +35 -0
  14. package/dist/internal/shared/ssr/get-client-or-server-url.cjs.map +1 -0
  15. package/dist/internal/shared/ssr/get-client-or-server-url.d.ts +3 -0
  16. package/dist/internal/shared/ssr/get-client-or-server-url.js +11 -0
  17. package/dist/internal/shared/ssr/get-client-or-server-url.js.map +1 -0
  18. package/dist/next/host/app-router-server.cjs +3 -2
  19. package/dist/next/host/app-router-server.cjs.map +1 -1
  20. package/dist/next/host/app-router-server.js +3 -2
  21. package/dist/next/host/app-router-server.js.map +1 -1
  22. package/dist/next/host/client/index.cjs +31 -27
  23. package/dist/next/host/client/index.cjs.map +1 -1
  24. package/dist/next/host/client/index.d.ts +1 -1
  25. package/dist/next/host/client/index.js +31 -27
  26. package/dist/next/host/client/index.js.map +1 -1
  27. package/dist/next/host/pages-router-server.cjs +4 -8
  28. package/dist/next/host/pages-router-server.cjs.map +1 -1
  29. package/dist/next/host/pages-router-server.d.ts +0 -1
  30. package/dist/next/host/pages-router-server.js +4 -8
  31. package/dist/next/host/pages-router-server.js.map +1 -1
  32. package/dist/react/index.cjs +23 -27
  33. package/dist/react/index.cjs.map +1 -1
  34. package/dist/react/index.d.ts +1 -1
  35. package/dist/react/index.js +23 -27
  36. package/dist/react/index.js.map +1 -1
  37. package/dist/{types-4e7dea94.d.ts → types-235b68a5.d.ts} +4 -1
  38. 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;
@@ -38,6 +38,7 @@ 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
40
  var import_remote_component = require("#internal/shared/client/remote-component");
41
+ var import_get_client_or_server_url = require("#internal/shared/ssr/get-client-or-server-url");
41
42
  var import_utils = require("#internal/shared/utils");
42
43
  async function tryImportShared() {
43
44
  try {
@@ -48,7 +49,8 @@ async function tryImportShared() {
48
49
  }
49
50
  }
50
51
  function RemoteComponentClient({
51
- url,
52
+ src,
53
+ serverUrl,
52
54
  name,
53
55
  bundle,
54
56
  route = import_remote_component.DEFAULT_ROUTE,
@@ -66,11 +68,12 @@ function RemoteComponentClient({
66
68
  }) {
67
69
  const remoteComponentId = (0, import_react.useId)();
68
70
  const [component, setComponent] = (0, import_react.useState)(null);
71
+ const url = (0, import_get_client_or_server_url.getClientOrServerUrl)(src, serverUrl);
69
72
  const metadataRef = (0, import_react.useRef)({
70
73
  name,
71
74
  bundle,
72
75
  route,
73
- url,
76
+ url: url.href,
74
77
  loading: false
75
78
  });
76
79
  const startRef = (0, import_react.useRef)(null);
@@ -83,8 +86,11 @@ function RemoteComponentClient({
83
86
  // we don't use the provided static HTML
84
87
  // to mitigate layout shift when loading CSS using JavaScript on the client
85
88
  nextData?.buildId !== "development";
89
+ const keySuffix = `${(0, import_utils.escapeString)(bundle)}_${(0, import_utils.escapeString)(
90
+ url.pathname
91
+ )}_${(0, import_utils.escapeString)(name)}`;
86
92
  const self = globalThis;
87
- const shadowRootKey = `__remote_components_shadowroot_${(0, import_utils.escapeString)(new URL(url).href)}_${(0, import_utils.escapeString)(name)}`;
93
+ const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
88
94
  const shadowContainerRef = (0, import_react.useRef)(
89
95
  typeof document === "undefined" ? null : document.querySelector(
90
96
  `[data-remote-component-id="shadowroot_${remoteComponentId}"]`
@@ -175,20 +181,17 @@ function RemoteComponentClient({
175
181
  (0, import_react.useEffect)(() => {
176
182
  (0, import_react.startTransition)(async () => {
177
183
  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) {
184
+ 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
185
  metadataRef.current = {
180
186
  name,
181
187
  bundle,
182
188
  route,
183
- url,
189
+ url: url.href,
184
190
  loading: true
185
191
  };
186
192
  if (type === "remote-component") {
187
193
  setComponent(children);
188
- (0, import_remote_component.loadStaticRemoteComponent)(
189
- scripts,
190
- new URL(url, location.origin)
191
- ).then(({ mount, unmount }) => {
194
+ (0, import_remote_component.loadStaticRemoteComponent)(scripts, url).then(({ mount, unmount }) => {
192
195
  if (mount.size > 0) {
193
196
  let root = shadowRootRef.current;
194
197
  try {
@@ -213,9 +216,9 @@ function RemoteComponentClient({
213
216
  });
214
217
  return;
215
218
  }
216
- const rscName = `__remote_components_rsc_${(0, import_utils.escapeString)(new URL(url).href)}_${(0, import_utils.escapeString)(name)}`;
219
+ const rscName = `__remote_components_rsc_${keySuffix}`;
217
220
  const result = await (0, import_remote_component.loadRemoteComponent)({
218
- url: new URL(url, location.origin),
221
+ url,
219
222
  name,
220
223
  bundle,
221
224
  route,
@@ -252,7 +255,6 @@ function RemoteComponentClient({
252
255
  }
253
256
  });
254
257
  }, [
255
- url,
256
258
  component,
257
259
  name,
258
260
  bundle,
@@ -264,7 +266,9 @@ function RemoteComponentClient({
264
266
  remoteShared,
265
267
  children,
266
268
  isolate,
267
- type
269
+ type,
270
+ keySuffix,
271
+ url
268
272
  ]);
269
273
  if (nextData?.buildId === "development" && shadowRootRef.current && isolate !== false && reset && !shadowRootRef.current.querySelector("[data-remote-components-reset]")) {
270
274
  const style = document.createElement("style");
@@ -282,37 +286,21 @@ function RemoteComponentClient({
282
286
  const linksToRender = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
283
287
  (!nextData || nextData.buildId !== "development") && isolate !== false && reset ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { "data-remote-components-reset": "", children: `:host { all: initial; }` }) : null,
284
288
  links.map((link) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
285
- "link",
289
+ RenderLink,
286
290
  {
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
291
+ link,
292
+ url,
293
+ "data-wait": link.rel === "stylesheet" && link.href ? "" : void 0
298
294
  },
299
295
  JSON.stringify(link)
300
296
  )),
301
297
  links.filter((link) => link.rel === "stylesheet").map((link) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
302
- "link",
298
+ RenderLink,
303
299
  {
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
- ),
300
+ link,
301
+ url,
313
302
  as: "style",
314
303
  fetchPriority: "high",
315
- href: link.href ? new URL(link.href, url).href : void 0,
316
304
  precedence: bundle,
317
305
  rel: "preload"
318
306
  },
@@ -341,7 +329,7 @@ function RemoteComponentClient({
341
329
  src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="
342
330
  onload="(function(el){
343
331
  const root = el.getRootNode();
344
- globalThis.__remote_components_shadowroot_${(0, import_utils.escapeString)(new URL(url).href)}_${(0, import_utils.escapeString)(name)} = root;
332
+ globalThis.${shadowRootKey} = root;
345
333
  el.parentElement.remove();
346
334
  })(this)"
347
335
  />`
@@ -376,7 +364,10 @@ function RemoteComponentClient({
376
364
  nextData ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
377
365
  "script",
378
366
  {
379
- id: `${bundle}_${route.replace(/[^a-zA-Z0-9]+/g, "_")}${name}_next_data`,
367
+ id: `${bundle}_${route.replace(
368
+ /[^a-zA-Z0-9]+/g,
369
+ "_"
370
+ )}${name}_next_data`,
380
371
  type: "application/json",
381
372
  children: JSON.stringify(nextData)
382
373
  }
@@ -384,6 +375,28 @@ function RemoteComponentClient({
384
375
  isolate === false ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { id: `${name}_end`, ref: endRef }) : null
385
376
  ] });
386
377
  }
378
+ function RenderLink({
379
+ link,
380
+ url,
381
+ ...rest
382
+ }) {
383
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
384
+ "link",
385
+ {
386
+ ...Object.entries(link).reduce(
387
+ (acc, [key, value]) => {
388
+ if (key !== "href" && key !== "precedence" && typeof value === "string") {
389
+ acc[import_utils.attrToProp[key] ?? key] = value;
390
+ }
391
+ return acc;
392
+ },
393
+ {}
394
+ ),
395
+ href: typeof link.href === "string" ? new URL(link.href, url).href : void 0,
396
+ ...rest
397
+ }
398
+ );
399
+ }
387
400
  // Annotate the CommonJS export names for ESM import in node:
388
401
  0 && (module.exports = {
389
402
  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}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AAAA,MAAC;AAAA;AAAA,QACC,4BAA0B,cAAc;AAAA,QACxC,wCAAqC;AAAA,QACrC,IAAI,cAAc;AAAA,QAClB,KAAK;AAAA,QAEJ;AAAA,iBAAO,aAAa;AAAA;AAAA,YAEnB,6CAAC,cAAS,gBAAgB,MACvB;AAAA,uBAAS,WACR;AAAA,gBAAC;AAAA;AAAA,kBACC,yBAAyB;AAAA,oBACvB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA,wDAK0B,2BAAa,IAAI,IAAI,GAAG,EAAE,IAAI,SAAK,2BAAa,IAAI;AAAA;AAAA;AAAA;AAAA,kBAIxF;AAAA;AAAA,cACF,IACE;AAAA,cACH;AAAA,cACA,oBAAoB,WAAW;AAAA,eAClC;AAAA,cACE;AAAA,UACH,OAAO,aAAa,eACrB,cAAc,WACd,CAAC,wBACG;AAAA,YACE,4EACG;AAAA;AAAA,cACA;AAAA,eACH;AAAA,YACA,cAAc;AAAA,UAChB,IACA;AAAA;AAAA;AAAA,IACN;AAAA,EAEJ;AAEA,SACE,4EACG;AAAA,gBAAY,QACX,4CAAC,cAAS,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 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 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 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 ...rest\n}: {\n link: Record<string, string | boolean | undefined>;\n url: URL;\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={\n typeof link.href === 'string' ? new URL(link.href, url).href : undefined\n }\n {...rest}\n />\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA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CAAC,YAAO,yBAAqB,MAAC,MAAK,oBAChC,eAAK,UAAU;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC,GACH;AAAA,IACC,YAAY,QAAQ,gBAAgB;AAAA,IACpC;AAAA,IACA,WACC;AAAA,MAAC;AAAA;AAAA,QACC,IAAI,GAAG,UAAU,MAAM;AAAA,UACrB;AAAA,UACA;AAAA,QACF,IAAI;AAAA,QACJ,MAAK;AAAA,QAEJ,eAAK,UAAU,QAAQ;AAAA;AAAA,IAC1B,IACE;AAAA,IACH,YAAY,QAAQ,4CAAC,cAAS,IAAI,GAAG,YAAY,KAAK,QAAQ,IAAK;AAAA,KACtE;AAEJ;AAEA,SAAS,WAAW;AAAA,EAClB;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAG+C;AAC7C,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG,OAAO,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,MACE,OAAO,KAAK,SAAS,WAAW,IAAI,IAAI,KAAK,MAAM,GAAG,EAAE,OAAO;AAAA,MAEhE,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 };
@@ -17,6 +17,7 @@ import {
17
17
  loadStaticRemoteComponent,
18
18
  RUNTIME_WEBPACK
19
19
  } from "#internal/shared/client/remote-component";
20
+ import { getClientOrServerUrl } from "#internal/shared/ssr/get-client-or-server-url";
20
21
  import { attrToProp, escapeString } from "#internal/shared/utils";
21
22
  async function tryImportShared() {
22
23
  try {
@@ -27,7 +28,8 @@ async function tryImportShared() {
27
28
  }
28
29
  }
29
30
  function RemoteComponentClient({
30
- url,
31
+ src,
32
+ serverUrl,
31
33
  name,
32
34
  bundle,
33
35
  route = DEFAULT_ROUTE,
@@ -45,11 +47,12 @@ function RemoteComponentClient({
45
47
  }) {
46
48
  const remoteComponentId = useId();
47
49
  const [component, setComponent] = useState(null);
50
+ const url = getClientOrServerUrl(src, serverUrl);
48
51
  const metadataRef = useRef({
49
52
  name,
50
53
  bundle,
51
54
  route,
52
- url,
55
+ url: url.href,
53
56
  loading: false
54
57
  });
55
58
  const startRef = useRef(null);
@@ -62,8 +65,11 @@ function RemoteComponentClient({
62
65
  // we don't use the provided static HTML
63
66
  // to mitigate layout shift when loading CSS using JavaScript on the client
64
67
  nextData?.buildId !== "development";
68
+ const keySuffix = `${escapeString(bundle)}_${escapeString(
69
+ url.pathname
70
+ )}_${escapeString(name)}`;
65
71
  const self = globalThis;
66
- const shadowRootKey = `__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)}`;
72
+ const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
67
73
  const shadowContainerRef = useRef(
68
74
  typeof document === "undefined" ? null : document.querySelector(
69
75
  `[data-remote-component-id="shadowroot_${remoteComponentId}"]`
@@ -154,20 +160,17 @@ function RemoteComponentClient({
154
160
  useEffect(() => {
155
161
  startTransition(async () => {
156
162
  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) {
163
+ 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
164
  metadataRef.current = {
159
165
  name,
160
166
  bundle,
161
167
  route,
162
- url,
168
+ url: url.href,
163
169
  loading: true
164
170
  };
165
171
  if (type === "remote-component") {
166
172
  setComponent(children);
167
- loadStaticRemoteComponent(
168
- scripts,
169
- new URL(url, location.origin)
170
- ).then(({ mount, unmount }) => {
173
+ loadStaticRemoteComponent(scripts, url).then(({ mount, unmount }) => {
171
174
  if (mount.size > 0) {
172
175
  let root = shadowRootRef.current;
173
176
  try {
@@ -192,9 +195,9 @@ function RemoteComponentClient({
192
195
  });
193
196
  return;
194
197
  }
195
- const rscName = `__remote_components_rsc_${escapeString(new URL(url).href)}_${escapeString(name)}`;
198
+ const rscName = `__remote_components_rsc_${keySuffix}`;
196
199
  const result = await loadRemoteComponent({
197
- url: new URL(url, location.origin),
200
+ url,
198
201
  name,
199
202
  bundle,
200
203
  route,
@@ -231,7 +234,6 @@ function RemoteComponentClient({
231
234
  }
232
235
  });
233
236
  }, [
234
- url,
235
237
  component,
236
238
  name,
237
239
  bundle,
@@ -243,7 +245,9 @@ function RemoteComponentClient({
243
245
  remoteShared,
244
246
  children,
245
247
  isolate,
246
- type
248
+ type,
249
+ keySuffix,
250
+ url
247
251
  ]);
248
252
  if (nextData?.buildId === "development" && shadowRootRef.current && isolate !== false && reset && !shadowRootRef.current.querySelector("[data-remote-components-reset]")) {
249
253
  const style = document.createElement("style");
@@ -261,37 +265,21 @@ function RemoteComponentClient({
261
265
  const linksToRender = /* @__PURE__ */ jsxs(Fragment, { children: [
262
266
  (!nextData || nextData.buildId !== "development") && isolate !== false && reset ? /* @__PURE__ */ jsx("style", { "data-remote-components-reset": "", children: `:host { all: initial; }` }) : null,
263
267
  links.map((link) => /* @__PURE__ */ jsx(
264
- "link",
268
+ RenderLink,
265
269
  {
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
270
+ link,
271
+ url,
272
+ "data-wait": link.rel === "stylesheet" && link.href ? "" : void 0
277
273
  },
278
274
  JSON.stringify(link)
279
275
  )),
280
276
  links.filter((link) => link.rel === "stylesheet").map((link) => /* @__PURE__ */ jsx(
281
- "link",
277
+ RenderLink,
282
278
  {
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
- ),
279
+ link,
280
+ url,
292
281
  as: "style",
293
282
  fetchPriority: "high",
294
- href: link.href ? new URL(link.href, url).href : void 0,
295
283
  precedence: bundle,
296
284
  rel: "preload"
297
285
  },
@@ -320,7 +308,7 @@ function RemoteComponentClient({
320
308
  src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="
321
309
  onload="(function(el){
322
310
  const root = el.getRootNode();
323
- globalThis.__remote_components_shadowroot_${escapeString(new URL(url).href)}_${escapeString(name)} = root;
311
+ globalThis.${shadowRootKey} = root;
324
312
  el.parentElement.remove();
325
313
  })(this)"
326
314
  />`
@@ -355,7 +343,10 @@ function RemoteComponentClient({
355
343
  nextData ? /* @__PURE__ */ jsx(
356
344
  "script",
357
345
  {
358
- id: `${bundle}_${route.replace(/[^a-zA-Z0-9]+/g, "_")}${name}_next_data`,
346
+ id: `${bundle}_${route.replace(
347
+ /[^a-zA-Z0-9]+/g,
348
+ "_"
349
+ )}${name}_next_data`,
359
350
  type: "application/json",
360
351
  children: JSON.stringify(nextData)
361
352
  }
@@ -363,6 +354,28 @@ function RemoteComponentClient({
363
354
  isolate === false ? /* @__PURE__ */ jsx("template", { id: `${name}_end`, ref: endRef }) : null
364
355
  ] });
365
356
  }
357
+ function RenderLink({
358
+ link,
359
+ url,
360
+ ...rest
361
+ }) {
362
+ return /* @__PURE__ */ jsx(
363
+ "link",
364
+ {
365
+ ...Object.entries(link).reduce(
366
+ (acc, [key, value]) => {
367
+ if (key !== "href" && key !== "precedence" && typeof value === "string") {
368
+ acc[attrToProp[key] ?? key] = value;
369
+ }
370
+ return acc;
371
+ },
372
+ {}
373
+ ),
374
+ href: typeof link.href === "string" ? new URL(link.href, url).href : void 0,
375
+ ...rest
376
+ }
377
+ );
378
+ }
366
379
  export {
367
380
  RemoteComponentClient
368
381
  };