remote-components 0.0.23 → 0.0.24

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 (69) hide show
  1. package/dist/html/host.cjs +297 -82
  2. package/dist/html/host.cjs.map +1 -1
  3. package/dist/html/host.js +300 -82
  4. package/dist/html/host.js.map +1 -1
  5. package/dist/internal/next/host/app-router-client.cjs +176 -70
  6. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  7. package/dist/internal/next/host/app-router-client.js +184 -71
  8. package/dist/internal/next/host/app-router-client.js.map +1 -1
  9. package/dist/internal/next/host/app-router-compat.cjs +114 -0
  10. package/dist/internal/next/host/app-router-compat.cjs.map +1 -0
  11. package/dist/internal/next/host/app-router-compat.d.ts +31 -0
  12. package/dist/internal/next/host/app-router-compat.js +79 -0
  13. package/dist/internal/next/host/app-router-compat.js.map +1 -0
  14. package/dist/internal/next/remote/render-client.cjs +10 -2
  15. package/dist/internal/next/remote/render-client.cjs.map +1 -1
  16. package/dist/internal/next/remote/render-client.js +10 -2
  17. package/dist/internal/next/remote/render-client.js.map +1 -1
  18. package/dist/internal/shared/client/apply-origin.cjs +61 -0
  19. package/dist/internal/shared/client/apply-origin.cjs.map +1 -0
  20. package/dist/internal/shared/client/apply-origin.d.ts +3 -0
  21. package/dist/internal/shared/client/apply-origin.js +37 -0
  22. package/dist/internal/shared/client/apply-origin.js.map +1 -0
  23. package/dist/internal/shared/client/polyfill.cjs +149 -0
  24. package/dist/internal/shared/client/polyfill.cjs.map +1 -0
  25. package/dist/internal/shared/client/polyfill.d.ts +6 -0
  26. package/dist/internal/shared/client/polyfill.js +124 -0
  27. package/dist/internal/shared/client/polyfill.js.map +1 -0
  28. package/dist/internal/shared/client/remote-component.cjs +3 -3
  29. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  30. package/dist/internal/shared/client/remote-component.d.ts +1 -1
  31. package/dist/internal/shared/client/remote-component.js +3 -3
  32. package/dist/internal/shared/client/remote-component.js.map +1 -1
  33. package/dist/internal/shared/ssr/dom-flight.cjs +40 -0
  34. package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
  35. package/dist/internal/shared/ssr/dom-flight.js +40 -0
  36. package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
  37. package/dist/internal/shared/ssr/fetch-remote-component.cjs +1 -1
  38. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  39. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +6 -0
  40. package/dist/internal/shared/ssr/fetch-remote-component.js +1 -1
  41. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  42. package/dist/next/config.cjs +50 -28
  43. package/dist/next/config.cjs.map +1 -1
  44. package/dist/next/config.js +50 -28
  45. package/dist/next/config.js.map +1 -1
  46. package/dist/next/host/client/index.cjs +16 -1
  47. package/dist/next/host/client/index.cjs.map +1 -1
  48. package/dist/next/host/client/index.js +16 -1
  49. package/dist/next/host/client/index.js.map +1 -1
  50. package/dist/next/host/pages-router-server.cjs +27 -13
  51. package/dist/next/host/pages-router-server.cjs.map +1 -1
  52. package/dist/next/host/pages-router-server.js +27 -13
  53. package/dist/next/host/pages-router-server.js.map +1 -1
  54. package/dist/next/middleware.cjs +5 -2
  55. package/dist/next/middleware.cjs.map +1 -1
  56. package/dist/next/middleware.d.ts +1 -0
  57. package/dist/next/middleware.js +5 -2
  58. package/dist/next/middleware.js.map +1 -1
  59. package/dist/next/remote/pages-router.cjs +3 -1
  60. package/dist/next/remote/pages-router.cjs.map +1 -1
  61. package/dist/next/remote/pages-router.d.ts +1 -0
  62. package/dist/next/remote/pages-router.js +3 -1
  63. package/dist/next/remote/pages-router.js.map +1 -1
  64. package/dist/react/index.cjs +203 -159
  65. package/dist/react/index.cjs.map +1 -1
  66. package/dist/react/index.d.ts +1 -1
  67. package/dist/react/index.js +192 -148
  68. package/dist/react/index.js.map +1 -1
  69. package/package.json +1 -1
@@ -35,7 +35,9 @@ module.exports = __toCommonJS(app_router_client_exports);
35
35
  var import_jsx_runtime = require("react/jsx-runtime");
36
36
  var import_react = require("react");
37
37
  var import_react_dom = require("react-dom");
38
+ var Image = __toESM(require("next/image"), 1);
38
39
  var import_remote_component = require("#internal/shared/client/remote-component");
40
+ var import_app_router_compat = require("#internal/next/host/app-router-compat");
39
41
  async function tryImportShared() {
40
42
  try {
41
43
  const { shared } = await import("@remote-components/shared/host/app");
@@ -60,12 +62,14 @@ function RemoteComponentClient({
60
62
  reset,
61
63
  children
62
64
  }) {
65
+ const remoteComponentId = (0, import_react.useId)();
63
66
  const [component, setComponent] = (0, import_react.useState)(null);
64
67
  const metadataRef = (0, import_react.useRef)({
65
68
  name,
66
69
  bundle,
67
70
  route,
68
- url
71
+ url,
72
+ loading: false
69
73
  });
70
74
  if (component instanceof Error) {
71
75
  throw component;
@@ -74,15 +78,30 @@ function RemoteComponentClient({
74
78
  // we don't use the provided static HTML
75
79
  // to mitigate layout shift when loading CSS using JavaScript on the client
76
80
  nextData?.buildId !== "development";
77
- const [shadowRoot, setShadowRoot] = (0, import_react.useState)(null);
81
+ const self = globalThis;
82
+ const shadowRootKey = `__remote_components_shadowroot_${new URL(url).href.replace(/[^a-z0-9]/g, "_")}_${name.replace(/[^a-z0-9]/g, "_")}`;
83
+ const shadowContainerRef = (0, import_react.useRef)(
84
+ typeof document === "undefined" ? null : document.querySelector(
85
+ `[data-remote-component-id="shadowroot_${remoteComponentId}"]`
86
+ )
87
+ );
88
+ const shadowRootRef = (0, import_react.useRef)(
89
+ self[shadowRootKey] ?? shadowContainerRef.current?.shadowRoot ?? null
90
+ );
91
+ const ssrShadowRootContentRef = (0, import_react.useRef)(
92
+ shadowRootRef.current?.querySelectorAll("*") ?? null
93
+ );
94
+ const ssrLinksStylesRef = (0, import_react.useRef)([]);
95
+ if (self[shadowRootKey] && shadowRootRef.current) {
96
+ self[shadowRootKey] = null;
97
+ }
78
98
  (0, import_react.useLayoutEffect)(() => {
79
- if (isolate !== false && typeof document !== "undefined" && !shadowRoot) {
99
+ if (!shadowContainerRef.current || shadowContainerRef.current !== shadowRootRef.current?.host) {
100
+ shadowRootRef.current = null;
101
+ }
102
+ if (isolate !== false && typeof document !== "undefined" && !shadowRootRef.current) {
80
103
  let shadowRootElement = null;
81
- const element = document.getElementById(
82
- `shadowroot_${new URL(url).href.replace(/[^a-z0-9]/g, "_")}_${name.replace(/[^a-z0-9]/g, "_")}`
83
- );
84
- const self = globalThis;
85
- const shadowRootKey = `__remote_components_shadowroot_${new URL(url).href.replace(/[^a-z0-9]/g, "_")}_${name.replace(/[^a-z0-9]/g, "_")}`;
104
+ const element = shadowContainerRef.current;
86
105
  shadowRootElement = self[shadowRootKey] ?? element?.shadowRoot ?? null;
87
106
  self[shadowRootKey] = null;
88
107
  if (!shadowRootElement && element) {
@@ -92,51 +111,98 @@ function RemoteComponentClient({
92
111
  }
93
112
  }
94
113
  if (shadowRootElement) {
95
- shadowRootElement.querySelectorAll("*:not(link)").forEach((node) => {
96
- node.remove();
114
+ shadowRootRef.current = shadowRootElement;
115
+ }
116
+ }
117
+ if (shadowRootRef.current && ssrShadowRootContentRef.current && !shouldUseChildren) {
118
+ ssrShadowRootContentRef.current.forEach((node) => {
119
+ if (node.nodeName !== "LINK" && node.nodeName !== "STYLE") {
120
+ node.parentNode?.removeChild(node);
121
+ } else {
122
+ ssrLinksStylesRef.current.push(
123
+ node
124
+ );
125
+ }
126
+ });
127
+ ssrShadowRootContentRef.current = null;
128
+ }
129
+ if (ssrLinksStylesRef.current.length > 0 && shadowRootRef.current) {
130
+ const waitForLoad = shadowRootRef.current.querySelectorAll("link[data-wait]");
131
+ if (waitForLoad.length > 0) {
132
+ Promise.all(
133
+ Array.from(waitForLoad).map(
134
+ (link) => new Promise((resolve) => {
135
+ link.addEventListener("load", () => resolve());
136
+ link.addEventListener("error", () => resolve());
137
+ })
138
+ )
139
+ ).then(() => {
140
+ waitForLoad.forEach((el) => {
141
+ el.removeAttribute("data-wait");
142
+ });
143
+ ssrLinksStylesRef.current.forEach((el) => {
144
+ el.parentNode?.removeChild(el);
145
+ });
146
+ ssrLinksStylesRef.current = [];
147
+ }).catch((e) => {
148
+ console.error(e);
97
149
  });
98
- setShadowRoot(shadowRootElement);
99
150
  }
100
151
  }
101
- }, [name, isolate, shadowRoot, links, url, mode]);
152
+ }, [
153
+ name,
154
+ isolate,
155
+ links,
156
+ url,
157
+ mode,
158
+ self,
159
+ shadowRootKey,
160
+ shouldUseChildren,
161
+ remoteComponentId
162
+ ]);
102
163
  (0, import_react.useEffect)(() => {
103
- let mounted = true;
104
- if (!component && (isolate === false || shadowRoot) || metadataRef.current.url !== url || metadataRef.current.name !== name || metadataRef.current.bundle !== bundle || metadataRef.current.route !== route) {
105
- metadataRef.current = {
106
- name,
107
- bundle,
108
- route,
109
- url
110
- };
111
- (0, import_remote_component.loadRemoteComponent)({
112
- url: new URL(url, location.origin),
113
- name,
114
- bundle,
115
- route,
116
- runtime,
117
- data,
118
- nextData,
119
- scripts,
120
- shared: tryImportShared(),
121
- remoteShared,
122
- container: shadowRoot
123
- }).then((result) => {
124
- if (mounted) {
164
+ (0, import_react.startTransition)(async () => {
165
+ try {
166
+ 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) {
167
+ metadataRef.current = {
168
+ name,
169
+ bundle,
170
+ route,
171
+ url,
172
+ loading: true
173
+ };
174
+ const result = await (0, import_remote_component.loadRemoteComponent)({
175
+ url: new URL(url, location.origin),
176
+ name,
177
+ bundle,
178
+ route,
179
+ runtime,
180
+ data,
181
+ nextData,
182
+ scripts,
183
+ shared: (async () => {
184
+ return {
185
+ "next/router": import_app_router_compat.routerImpl,
186
+ ...await tryImportShared(),
187
+ "next/image": () => Promise.resolve((0, import_app_router_compat.imageImpl)(Image.default, bundle)),
188
+ "next/dist/client/image-component": () => Promise.resolve({ Image: (0, import_app_router_compat.imageImpl)(Image.default, bundle) })
189
+ };
190
+ })(),
191
+ remoteShared,
192
+ container: shadowRootRef.current
193
+ });
194
+ metadataRef.current.loading = false;
125
195
  if (result.error) {
126
196
  setComponent(result.error);
127
197
  } else {
128
198
  setComponent(result.component);
129
199
  }
130
200
  }
131
- }).catch((error) => {
132
- if (mounted) {
133
- setComponent(error);
134
- }
135
- });
136
- }
137
- return () => {
138
- mounted = false;
139
- };
201
+ } catch (error) {
202
+ metadataRef.current.loading = false;
203
+ setComponent(error);
204
+ }
205
+ });
140
206
  }, [
141
207
  url,
142
208
  component,
@@ -150,30 +216,75 @@ function RemoteComponentClient({
150
216
  remoteShared,
151
217
  children,
152
218
  links,
153
- isolate,
154
- shadowRoot
219
+ isolate
155
220
  ]);
156
- const resetStyle = reset ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { "data-remote-components-reset": true, children: `:host { all: initial; }` }) : null;
157
- let componentToRender = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: shouldUseChildren ? children : component });
158
- let linksToRender = links.map((link) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
159
- "link",
160
- {
161
- as: link.as,
162
- href: new URL(link.href, url || location.origin).href,
163
- rel: link.rel
164
- },
165
- `${link.href}_${link.rel}`
166
- ));
221
+ if (nextData?.buildId === "development" && shadowRootRef.current && isolate !== false && reset && !shadowRootRef.current.querySelector("[data-remote-components-reset]")) {
222
+ const style = document.createElement("style");
223
+ style.setAttribute("data-remote-components-reset", "");
224
+ style.textContent = `:host { all: initial; }`;
225
+ shadowRootRef.current.insertBefore(style, shadowRootRef.current.firstChild);
226
+ } else if (shadowRootRef.current && isolate !== false && !reset && shadowRootRef.current.querySelector("[data-remote-components-reset]")) {
227
+ const style = shadowRootRef.current.querySelector(
228
+ "[data-remote-components-reset]"
229
+ );
230
+ if (style && shadowRootRef.current.firstChild !== style) {
231
+ shadowRootRef.current.removeChild(style);
232
+ }
233
+ }
234
+ const linksToRender = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
235
+ (!nextData || nextData.buildId !== "development") && isolate !== false && reset ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { "data-remote-components-reset": "", children: `:host { all: initial; }` }) : null,
236
+ links.map((link) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
237
+ "link",
238
+ {
239
+ ...Object.entries(link).reduce(
240
+ (acc, [key, value]) => {
241
+ if (key !== "href" && key !== "precedence" && typeof value === "string") {
242
+ acc[key] = value;
243
+ }
244
+ return acc;
245
+ },
246
+ {}
247
+ ),
248
+ "data-wait": link.rel === "stylesheet" && link.href ? "" : void 0,
249
+ href: new URL(link.href, url).href
250
+ },
251
+ JSON.stringify(link)
252
+ )),
253
+ links.filter((link) => link.rel === "stylesheet").map((link) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
254
+ "link",
255
+ {
256
+ ...Object.entries(link).reduce(
257
+ (acc, [key, value]) => {
258
+ if (key !== "href" && key !== "precedence" && typeof value === "string") {
259
+ acc[key] = value;
260
+ }
261
+ return acc;
262
+ },
263
+ {}
264
+ ),
265
+ as: "style",
266
+ fetchPriority: "high",
267
+ href: new URL(link.href, url).href,
268
+ precedence: bundle,
269
+ rel: "preload"
270
+ },
271
+ JSON.stringify(link)
272
+ ))
273
+ ] });
274
+ let componentToRender = shouldUseChildren ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children }) : component;
167
275
  if (isolate !== false) {
168
276
  componentToRender = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
169
277
  "div",
170
278
  {
171
- id: `shadowroot_${new URL(url).href.replace(/[^a-z0-9]/g, "_")}_${name.replace(/[^a-z0-9]/g, "_")}`,
279
+ "data-remote-component-id": `shadowroot_${remoteComponentId}`,
280
+ "data-remote-component-isolation-root": "",
281
+ id: `shadowroot_${name}`,
282
+ ref: shadowContainerRef,
172
283
  children: [
173
284
  typeof document === "undefined" ? (
174
285
  // eslint-disable-next-line react/no-unknown-property
175
286
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("template", { shadowrootmode: mode, children: [
176
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
287
+ mode === "closed" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
177
288
  "div",
178
289
  {
179
290
  dangerouslySetInnerHTML: {
@@ -188,36 +299,31 @@ function RemoteComponentClient({
188
299
  />`
189
300
  }
190
301
  }
191
- ),
192
- resetStyle,
302
+ ) : null,
193
303
  linksToRender,
194
- componentToRender
304
+ shouldUseChildren ? children : null
195
305
  ] })
196
306
  ) : null,
197
- shadowRoot ? (0, import_react_dom.createPortal)(
198
- shadowRoot.querySelectorAll("link").length !== links.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
199
- resetStyle,
307
+ typeof document !== "undefined" && shadowRootRef.current && !shouldUseChildren ? (0, import_react_dom.createPortal)(
308
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
200
309
  linksToRender,
201
310
  componentToRender
202
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
203
- resetStyle,
204
- componentToRender
205
311
  ] }),
206
- shadowRoot
312
+ shadowRootRef.current
207
313
  ) : null
208
314
  ]
209
315
  }
210
316
  );
211
- linksToRender = null;
212
317
  }
213
318
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
319
+ isolate === false ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { id: `${name}_start` }) : null,
214
320
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
215
321
  name,
216
322
  bundle,
217
323
  route,
218
324
  runtime
219
325
  }) }),
220
- linksToRender,
326
+ isolate === false ? linksToRender : null,
221
327
  componentToRender,
222
328
  nextData ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
223
329
  "script",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/host/app-router-client.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useState, useLayoutEffect, useRef } from 'react';\nimport { createPortal } from 'react-dom';\nimport {\n loadRemoteComponent,\n DEFAULT_ROUTE,\n RUNTIME_WEBPACK,\n} from '#internal/shared/client/remote-component';\nimport type { RemoteComponentProps } from '#internal/shared/client/remote-component';\n\n// patch react/jsx-runtime to support the shadowrootmode attribute on template elements\ndeclare module 'react/jsx-runtime' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace JSX {\n interface IntrinsicElements {\n template: {\n shadowrootmode?: 'open' | 'closed';\n id?: string;\n ref?: React.Ref<HTMLTemplateElement>;\n dangerouslySetInnerHTML?: {\n __html: string;\n };\n children?: React.ReactNode;\n };\n }\n }\n}\n\n// import { shared } from '@remote-components/shared/host';\nasync function tryImportShared() {\n try {\n const { shared } = await import('@remote-components/shared/host/app');\n return shared;\n } catch {\n return {};\n }\n}\n\n/**\n * RemoteComponentClient - Main component for rendering remote components\n *\n * This component handles the loading and rendering of remote microfrontends.\n * It supports both RSC (React Server Components) and Next.js Pages Router based components.\n */\nexport function RemoteComponentClient({\n url,\n name,\n bundle,\n route = DEFAULT_ROUTE,\n runtime = RUNTIME_WEBPACK,\n data,\n nextData,\n scripts = [],\n links = [],\n remoteShared = {},\n isolate,\n mode = 'open',\n reset,\n children,\n}: RemoteComponentProps) {\n const [component, setComponent] = useState<React.ReactNode | Error>(null);\n const metadataRef = useRef<{\n name: string;\n bundle: string;\n route: string;\n url: string;\n }>({\n name,\n bundle,\n route,\n url,\n });\n\n // Handle errors by re-throwing them\n if (component instanceof Error) {\n throw component;\n }\n\n // determine whether to use children or loaded component\n const shouldUseChildren =\n (!component ||\n (component &&\n !nextData &&\n typeof (component as unknown as Promise<unknown>).then !==\n 'function')) &&\n // if the remote Next.js Pages Router application is in development mode\n // we don't use the provided static HTML\n // to mitigate layout shift when loading CSS using JavaScript on the client\n nextData?.buildId !== 'development';\n\n const [shadowRoot, setShadowRoot] = useState<ShadowRoot | null>(null);\n\n useLayoutEffect(() => {\n if (isolate !== false && typeof document !== 'undefined' && !shadowRoot) {\n let shadowRootElement: ShadowRoot | null = null;\n const element = document.getElementById(\n `shadowroot_${new URL(url).href.replace(/[^a-z0-9]/g, '_')}_${name.replace(/[^a-z0-9]/g, '_')}`,\n );\n const self = globalThis as Record<\n `__remote_components_shadowroot_${string}`,\n ShadowRoot | null\n >;\n const shadowRootKey =\n `__remote_components_shadowroot_${new URL(url).href.replace(/[^a-z0-9]/g, '_')}_${name.replace(/[^a-z0-9]/g, '_')}` as const;\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 // remove all nodes from the shadow root except links\n shadowRootElement.querySelectorAll('*:not(link)').forEach((node) => {\n node.remove();\n });\n setShadowRoot(shadowRootElement);\n }\n }\n }, [name, isolate, shadowRoot, links, url, mode]);\n\n useEffect(() => {\n let mounted = true;\n\n // if we have a component, we don't need to load it again\n if (\n (!component && (isolate === false || shadowRoot)) ||\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 };\n loadRemoteComponent({\n url: new URL(url, location.origin),\n name,\n bundle,\n route,\n runtime,\n data,\n nextData,\n scripts,\n shared: tryImportShared(),\n remoteShared,\n container: shadowRoot,\n })\n .then((result) => {\n if (mounted) {\n if (result.error) {\n setComponent(result.error);\n } else {\n setComponent(result.component);\n }\n }\n })\n .catch((error: Error) => {\n if (mounted) {\n setComponent(error);\n }\n });\n }\n\n return () => {\n mounted = false;\n };\n }, [\n url,\n component,\n name,\n bundle,\n route,\n runtime,\n scripts,\n data,\n nextData,\n remoteShared,\n children,\n links,\n isolate,\n shadowRoot,\n ]);\n\n const resetStyle = reset ? (\n <style data-remote-components-reset>{`:host { all: initial; }`}</style>\n ) : null;\n let componentToRender = (\n <>{shouldUseChildren ? children : (component as React.ReactNode)}</>\n );\n let linksToRender: React.ReactNode[] | null = links.map((link) => (\n <link\n as={link.as as string}\n href={new URL(link.href as string, url || location.origin).href}\n key={`${link.href as string}_${link.rel}`}\n rel={link.rel as string}\n />\n ));\n\n if (isolate !== false) {\n componentToRender = (\n <div\n id={`shadowroot_${new URL(url).href.replace(/[^a-z0-9]/g, '_')}_${name.replace(/[^a-z0-9]/g, '_')}`}\n >\n {typeof document === 'undefined' ? (\n // eslint-disable-next-line react/no-unknown-property\n <template shadowrootmode={mode}>\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_${new URL(url).href.replace(/[^a-z0-9]/g, '_')}_${name.replace(/[^a-z0-9]/g, '_')} = root;\n el.parentElement.remove();\n })(this)\"\n />`,\n }}\n />\n {resetStyle}\n {linksToRender}\n {componentToRender}\n </template>\n ) : null}\n {shadowRoot\n ? createPortal(\n shadowRoot.querySelectorAll('link').length !== links.length ? (\n <>\n {resetStyle}\n {linksToRender}\n {componentToRender}\n </>\n ) : (\n <>\n {resetStyle}\n {componentToRender}\n </>\n ),\n shadowRoot,\n )\n : null}\n </div>\n );\n linksToRender = null;\n }\n\n return (\n <>\n <script data-remote-component type=\"application/json\">\n {JSON.stringify({\n name,\n bundle,\n route,\n runtime,\n })}\n </script>\n {linksToRender}\n {componentToRender}\n {nextData ? (\n <script\n id={`${bundle}_${route.replace(/[^a-zA-Z0-9]+/g, '_')}${name}_next_data`}\n type=\"application/json\"\n >\n {JSON.stringify(nextData)}\n </script>\n ) : null}\n {isolate === false ? <template id={`${name}_end`} /> : null}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmMI;AAjMJ,mBAA6D;AAC7D,uBAA6B;AAC7B,8BAIO;AAsBP,eAAe,kBAAkB;AAC/B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,oCAAoC;AACpE,WAAO;AAAA,EACT,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAQO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,UAAU,CAAC;AAAA,EACX,QAAQ,CAAC;AAAA,EACT,eAAe,CAAC;AAAA,EAChB;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAkC,IAAI;AACxE,QAAM,kBAAc,qBAKjB;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAGD,MAAI,qBAAqB,OAAO;AAC9B,UAAM;AAAA,EACR;AAGA,QAAM,qBACH,CAAC,aACC,aACC,CAAC,YACD,OAAQ,UAA0C,SAChD;AAAA;AAAA;AAAA,EAIN,UAAU,YAAY;AAExB,QAAM,CAAC,YAAY,aAAa,QAAI,uBAA4B,IAAI;AAEpE,oCAAgB,MAAM;AACpB,QAAI,YAAY,SAAS,OAAO,aAAa,eAAe,CAAC,YAAY;AACvE,UAAI,oBAAuC;AAC3C,YAAM,UAAU,SAAS;AAAA,QACvB,cAAc,IAAI,IAAI,GAAG,EAAE,KAAK,QAAQ,cAAc,GAAG,KAAK,KAAK,QAAQ,cAAc,GAAG;AAAA,MAC9F;AACA,YAAM,OAAO;AAIb,YAAM,gBACJ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AA,eACH,IAEA,4EACG;AAAA;AAAA,cACA;AAAA,eACH;AAAA,YAEF;AAAA,UACF,IACA;AAAA;AAAA;AAAA,IACN;AAEF,oBAAgB;AAAA,EAClB;AAEA,SACE,4EACE;AAAA,gDAAC,YAAO,yBAAqB,MAAC,MAAK,oBAChC,eAAK,UAAU;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC,GACH;AAAA,IACC;AAAA,IACA;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,IAAK;AAAA,KACzD;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/next/host/app-router-client.tsx"],"sourcesContent":["'use client';\n\nimport {\n useId,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n startTransition,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport * as Image from 'next/image';\nimport {\n loadRemoteComponent,\n DEFAULT_ROUTE,\n RUNTIME_WEBPACK,\n} from '#internal/shared/client/remote-component';\nimport type { RemoteComponentProps } from '#internal/shared/client/remote-component';\nimport { imageImpl, routerImpl } from '#internal/next/host/app-router-compat';\n\n// patch react/jsx-runtime to support the shadowrootmode attribute on template elements\ndeclare module 'react/jsx-runtime' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace JSX {\n interface IntrinsicElements {\n template: {\n shadowrootmode?: 'open' | 'closed';\n id?: string;\n ref?: React.Ref<HTMLTemplateElement>;\n dangerouslySetInnerHTML?: {\n __html: string;\n };\n children?: React.ReactNode;\n };\n }\n }\n}\n\n// import { shared } from '@remote-components/shared/host';\nasync function tryImportShared() {\n try {\n const { shared } = await import('@remote-components/shared/host/app');\n return shared;\n } catch {\n return {};\n }\n}\n\n/**\n * RemoteComponentClient - Main component for rendering remote components\n *\n * This component handles the loading and rendering of remote microfrontends.\n * It supports both RSC (React Server Components) and Next.js Pages Router based components.\n */\nexport function RemoteComponentClient({\n url,\n name,\n bundle,\n route = DEFAULT_ROUTE,\n runtime = RUNTIME_WEBPACK,\n data,\n nextData,\n scripts = [],\n links = [],\n remoteShared = {},\n isolate,\n mode = 'open',\n reset,\n children,\n}: RemoteComponentProps) {\n const remoteComponentId = useId();\n const [component, setComponent] = useState<React.ReactNode | Error>(null);\n const metadataRef = useRef<{\n name: string;\n bundle: string;\n route: string;\n url: string;\n loading: boolean;\n }>({\n name,\n bundle,\n route,\n url,\n loading: false,\n });\n\n // Handle errors by re-throwing them\n if (component instanceof Error) {\n throw component;\n }\n\n // determine whether to use children or loaded component\n const shouldUseChildren =\n (!component ||\n (component &&\n !nextData &&\n typeof (component as unknown as Promise<unknown>).then !==\n 'function')) &&\n // if the remote Next.js Pages Router application is in development mode\n // we don't use the provided static HTML\n // to mitigate layout shift when loading CSS using JavaScript on the client\n nextData?.buildId !== 'development';\n\n const self = globalThis as Record<\n `__remote_components_shadowroot_${string}`,\n ShadowRoot | null\n > &\n Record<`__remote_components_container_${string}`, HTMLDivElement | null>;\n const shadowRootKey =\n `__remote_components_shadowroot_${new URL(url).href.replace(/[^a-z0-9]/g, '_')}_${name.replace(/[^a-z0-9]/g, '_')}` as const;\n const shadowContainerRef = useRef<HTMLDivElement | null>(\n typeof document === 'undefined'\n ? null\n : document.querySelector(\n `[data-remote-component-id=\"shadowroot_${remoteComponentId}\"]`,\n ),\n );\n const shadowRootRef = useRef<ShadowRoot | null>(\n self[shadowRootKey] ?? shadowContainerRef.current?.shadowRoot ?? null,\n );\n const ssrShadowRootContentRef = useRef<NodeListOf<ChildNode> | null>(\n shadowRootRef.current?.querySelectorAll('*') ?? null,\n );\n const ssrLinksStylesRef = useRef<(HTMLLinkElement | HTMLStyleElement)[]>([]);\n\n if (self[shadowRootKey] && shadowRootRef.current) {\n self[shadowRootKey] = null;\n }\n\n useLayoutEffect(() => {\n if (\n !shadowContainerRef.current ||\n shadowContainerRef.current !== shadowRootRef.current?.host\n ) {\n shadowRootRef.current = null;\n }\n\n if (\n isolate !== false &&\n typeof document !== 'undefined' &&\n !shadowRootRef.current\n ) {\n let shadowRootElement: ShadowRoot | null = null;\n const element = shadowContainerRef.current;\n\n shadowRootElement = self[shadowRootKey] ?? element?.shadowRoot ?? null;\n self[shadowRootKey] = null;\n\n if (!shadowRootElement && element) {\n // create a shadow root if it doesn't exist\n // this is a fallback for browsers that don't support declarative shadow DOM\n try {\n shadowRootElement = element.attachShadow({ mode });\n } catch {\n // do nothing if attachShadow fails because of existing shadow root\n }\n }\n\n if (shadowRootElement) {\n shadowRootRef.current = shadowRootElement;\n }\n }\n\n if (\n shadowRootRef.current &&\n ssrShadowRootContentRef.current &&\n !shouldUseChildren\n ) {\n // remove all nodes from the shadow root except links\n ssrShadowRootContentRef.current.forEach((node) => {\n if (node.nodeName !== 'LINK' && node.nodeName !== 'STYLE') {\n node.parentNode?.removeChild(node);\n } else {\n ssrLinksStylesRef.current.push(\n node as HTMLLinkElement | HTMLStyleElement,\n );\n }\n });\n ssrShadowRootContentRef.current = null;\n }\n\n if (ssrLinksStylesRef.current.length > 0 && shadowRootRef.current) {\n const waitForLoad =\n shadowRootRef.current.querySelectorAll('link[data-wait]');\n if (waitForLoad.length > 0) {\n Promise.all(\n Array.from(waitForLoad).map(\n (link) =>\n new Promise<void>((resolve) => {\n link.addEventListener('load', () => resolve());\n link.addEventListener('error', () => resolve());\n }),\n ),\n )\n .then(() => {\n waitForLoad.forEach((el) => {\n el.removeAttribute('data-wait');\n });\n\n // remove SSR injected styles and links\n ssrLinksStylesRef.current.forEach((el) => {\n el.parentNode?.removeChild(el);\n });\n ssrLinksStylesRef.current = [];\n })\n .catch((e) => {\n // eslint-disable-next-line no-console\n console.error(e);\n });\n }\n }\n }, [\n name,\n isolate,\n links,\n url,\n mode,\n self,\n shadowRootKey,\n shouldUseChildren,\n remoteComponentId,\n ]);\n\n useEffect(() => {\n startTransition(async () => {\n try {\n // if we have a component, we don't need to load it again\n if (\n (!metadataRef.current.loading &&\n !component &&\n (isolate === false || shadowRootRef.current)) ||\n metadataRef.current.url !== url ||\n metadataRef.current.name !== name ||\n metadataRef.current.bundle !== bundle ||\n metadataRef.current.route !== route\n ) {\n metadataRef.current = {\n name,\n bundle,\n route,\n url,\n loading: true,\n };\n const result = await loadRemoteComponent({\n url: new URL(url, location.origin),\n name,\n bundle,\n route,\n runtime,\n data,\n nextData,\n scripts,\n shared: (async () => {\n return {\n 'next/router': routerImpl,\n ...(await tryImportShared()),\n 'next/image': () =>\n Promise.resolve(imageImpl(Image.default, bundle)),\n 'next/dist/client/image-component': () =>\n Promise.resolve({ Image: imageImpl(Image.default, bundle) }),\n };\n })(),\n remoteShared,\n container: shadowRootRef.current,\n });\n metadataRef.current.loading = false;\n if (result.error) {\n setComponent(result.error);\n } else {\n setComponent(result.component);\n }\n }\n } catch (error: unknown) {\n metadataRef.current.loading = false;\n setComponent(error as Error);\n }\n });\n }, [\n url,\n component,\n name,\n bundle,\n route,\n runtime,\n scripts,\n data,\n nextData,\n remoteShared,\n children,\n links,\n isolate,\n ]);\n\n if (\n nextData?.buildId === 'development' &&\n shadowRootRef.current &&\n isolate !== false &&\n reset &&\n !shadowRootRef.current.querySelector('[data-remote-components-reset]')\n ) {\n // inject reset styles into the shadow root\n const style = document.createElement('style');\n style.setAttribute('data-remote-components-reset', '');\n style.textContent = `:host { all: initial; }`;\n shadowRootRef.current.insertBefore(style, shadowRootRef.current.firstChild);\n } else if (\n shadowRootRef.current &&\n isolate !== false &&\n !reset &&\n shadowRootRef.current.querySelector('[data-remote-components-reset]')\n ) {\n // ensure reset styles are the first child in the shadow root\n const style = shadowRootRef.current.querySelector(\n '[data-remote-components-reset]',\n );\n if (style && shadowRootRef.current.firstChild !== style) {\n shadowRootRef.current.removeChild(style);\n }\n }\n\n const linksToRender = (\n <>\n {(!nextData || nextData.buildId !== 'development') &&\n isolate !== false &&\n reset ? (\n <style data-remote-components-reset=\"\">{`:host { all: initial; }`}</style>\n ) : null}\n {links.map((link) => (\n <link\n key={JSON.stringify(link)}\n {...Object.entries(link).reduce<Record<string, string>>(\n (acc, [key, value]) => {\n if (\n key !== 'href' &&\n key !== 'precedence' &&\n typeof value === 'string'\n ) {\n acc[key] = value;\n }\n return acc;\n },\n {},\n )}\n data-wait={link.rel === 'stylesheet' && link.href ? '' : undefined}\n href={new URL(link.href as string, url).href}\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[key] = value;\n }\n return acc;\n },\n {},\n )}\n as=\"style\"\n fetchPriority=\"high\"\n href={new URL(link.href as string, url).href}\n precedence={bundle}\n rel=\"preload\"\n />\n ))}\n </>\n );\n\n let componentToRender = shouldUseChildren ? (\n <>{children}</>\n ) : (\n (component as React.ReactNode)\n );\n\n if (isolate !== false) {\n componentToRender = (\n <div\n data-remote-component-id={`shadowroot_${remoteComponentId}`}\n data-remote-component-isolation-root=\"\"\n id={`shadowroot_${name}`}\n ref={shadowContainerRef}\n >\n {typeof document === 'undefined' ? (\n // eslint-disable-next-line react/no-unknown-property\n <template shadowrootmode={mode}>\n {mode === 'closed' ? (\n <div\n dangerouslySetInnerHTML={{\n __html: `<img\n alt=\"\" decoding=\"async\" style=\"display:none\"\n src=\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==\"\n onload=\"(function(el){\n const root = el.getRootNode();\n globalThis.__remote_components_shadowroot_${new URL(url).href.replace(/[^a-z0-9]/g, '_')}_${name.replace(/[^a-z0-9]/g, '_')} = root;\n el.parentElement.remove();\n })(this)\"\n />`,\n }}\n />\n ) : null}\n {linksToRender}\n {shouldUseChildren ? children : null}\n </template>\n ) : null}\n {typeof document !== 'undefined' &&\n shadowRootRef.current &&\n !shouldUseChildren\n ? createPortal(\n <>\n {linksToRender}\n {componentToRender}\n </>,\n shadowRootRef.current,\n )\n : null}\n </div>\n );\n }\n\n return (\n <>\n {isolate === false ? <template id={`${name}_start`} /> : null}\n <script data-remote-component type=\"application/json\">\n {JSON.stringify({\n name,\n bundle,\n route,\n runtime,\n })}\n </script>\n {isolate === false ? linksToRender : null}\n {componentToRender}\n {nextData ? (\n <script\n id={`${bundle}_${route.replace(/[^a-zA-Z0-9]+/g, '_')}${name}_next_data`}\n type=\"application/json\"\n >\n {JSON.stringify(nextData)}\n </script>\n ) : null}\n {isolate === false ? <template id={`${name}_end`} /> : null}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiUI;AA/TJ,mBAOO;AACP,uBAA6B;AAC7B,YAAuB;AACvB,8BAIO;AAEP,+BAAsC;AAqBtC,eAAe,kBAAkB;AAC/B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,oCAAoC;AACpE,WAAO;AAAA,EACT,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAQO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,UAAU,CAAC;AAAA,EACX,QAAQ,CAAC;AAAA,EACT,eAAe,CAAC;AAAA,EAChB;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,wBAAoB,oBAAM;AAChC,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAkC,IAAI;AACxE,QAAM,kBAAc,qBAMjB;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX,CAAC;AAGD,MAAI,qBAAqB,OAAO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