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
@@ -1,12 +1,21 @@
1
1
  "use client";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
- import { useEffect, useState, useLayoutEffect, useRef } from "react";
3
+ import {
4
+ useId,
5
+ useEffect,
6
+ useLayoutEffect,
7
+ useRef,
8
+ useState,
9
+ startTransition
10
+ } from "react";
4
11
  import { createPortal } from "react-dom";
12
+ import * as Image from "next/image";
5
13
  import {
6
14
  loadRemoteComponent,
7
15
  DEFAULT_ROUTE,
8
16
  RUNTIME_WEBPACK
9
17
  } from "#internal/shared/client/remote-component";
18
+ import { imageImpl, routerImpl } from "#internal/next/host/app-router-compat";
10
19
  async function tryImportShared() {
11
20
  try {
12
21
  const { shared } = await import("@remote-components/shared/host/app");
@@ -31,12 +40,14 @@ function RemoteComponentClient({
31
40
  reset,
32
41
  children
33
42
  }) {
43
+ const remoteComponentId = useId();
34
44
  const [component, setComponent] = useState(null);
35
45
  const metadataRef = useRef({
36
46
  name,
37
47
  bundle,
38
48
  route,
39
- url
49
+ url,
50
+ loading: false
40
51
  });
41
52
  if (component instanceof Error) {
42
53
  throw component;
@@ -45,15 +56,30 @@ function RemoteComponentClient({
45
56
  // we don't use the provided static HTML
46
57
  // to mitigate layout shift when loading CSS using JavaScript on the client
47
58
  nextData?.buildId !== "development";
48
- const [shadowRoot, setShadowRoot] = useState(null);
59
+ const self = globalThis;
60
+ const shadowRootKey = `__remote_components_shadowroot_${new URL(url).href.replace(/[^a-z0-9]/g, "_")}_${name.replace(/[^a-z0-9]/g, "_")}`;
61
+ const shadowContainerRef = useRef(
62
+ typeof document === "undefined" ? null : document.querySelector(
63
+ `[data-remote-component-id="shadowroot_${remoteComponentId}"]`
64
+ )
65
+ );
66
+ const shadowRootRef = useRef(
67
+ self[shadowRootKey] ?? shadowContainerRef.current?.shadowRoot ?? null
68
+ );
69
+ const ssrShadowRootContentRef = useRef(
70
+ shadowRootRef.current?.querySelectorAll("*") ?? null
71
+ );
72
+ const ssrLinksStylesRef = useRef([]);
73
+ if (self[shadowRootKey] && shadowRootRef.current) {
74
+ self[shadowRootKey] = null;
75
+ }
49
76
  useLayoutEffect(() => {
50
- if (isolate !== false && typeof document !== "undefined" && !shadowRoot) {
77
+ if (!shadowContainerRef.current || shadowContainerRef.current !== shadowRootRef.current?.host) {
78
+ shadowRootRef.current = null;
79
+ }
80
+ if (isolate !== false && typeof document !== "undefined" && !shadowRootRef.current) {
51
81
  let shadowRootElement = null;
52
- const element = document.getElementById(
53
- `shadowroot_${new URL(url).href.replace(/[^a-z0-9]/g, "_")}_${name.replace(/[^a-z0-9]/g, "_")}`
54
- );
55
- const self = globalThis;
56
- const shadowRootKey = `__remote_components_shadowroot_${new URL(url).href.replace(/[^a-z0-9]/g, "_")}_${name.replace(/[^a-z0-9]/g, "_")}`;
82
+ const element = shadowContainerRef.current;
57
83
  shadowRootElement = self[shadowRootKey] ?? element?.shadowRoot ?? null;
58
84
  self[shadowRootKey] = null;
59
85
  if (!shadowRootElement && element) {
@@ -63,51 +89,98 @@ function RemoteComponentClient({
63
89
  }
64
90
  }
65
91
  if (shadowRootElement) {
66
- shadowRootElement.querySelectorAll("*:not(link)").forEach((node) => {
67
- node.remove();
92
+ shadowRootRef.current = shadowRootElement;
93
+ }
94
+ }
95
+ if (shadowRootRef.current && ssrShadowRootContentRef.current && !shouldUseChildren) {
96
+ ssrShadowRootContentRef.current.forEach((node) => {
97
+ if (node.nodeName !== "LINK" && node.nodeName !== "STYLE") {
98
+ node.parentNode?.removeChild(node);
99
+ } else {
100
+ ssrLinksStylesRef.current.push(
101
+ node
102
+ );
103
+ }
104
+ });
105
+ ssrShadowRootContentRef.current = null;
106
+ }
107
+ if (ssrLinksStylesRef.current.length > 0 && shadowRootRef.current) {
108
+ const waitForLoad = shadowRootRef.current.querySelectorAll("link[data-wait]");
109
+ if (waitForLoad.length > 0) {
110
+ Promise.all(
111
+ Array.from(waitForLoad).map(
112
+ (link) => new Promise((resolve) => {
113
+ link.addEventListener("load", () => resolve());
114
+ link.addEventListener("error", () => resolve());
115
+ })
116
+ )
117
+ ).then(() => {
118
+ waitForLoad.forEach((el) => {
119
+ el.removeAttribute("data-wait");
120
+ });
121
+ ssrLinksStylesRef.current.forEach((el) => {
122
+ el.parentNode?.removeChild(el);
123
+ });
124
+ ssrLinksStylesRef.current = [];
125
+ }).catch((e) => {
126
+ console.error(e);
68
127
  });
69
- setShadowRoot(shadowRootElement);
70
128
  }
71
129
  }
72
- }, [name, isolate, shadowRoot, links, url, mode]);
130
+ }, [
131
+ name,
132
+ isolate,
133
+ links,
134
+ url,
135
+ mode,
136
+ self,
137
+ shadowRootKey,
138
+ shouldUseChildren,
139
+ remoteComponentId
140
+ ]);
73
141
  useEffect(() => {
74
- let mounted = true;
75
- if (!component && (isolate === false || shadowRoot) || metadataRef.current.url !== url || metadataRef.current.name !== name || metadataRef.current.bundle !== bundle || metadataRef.current.route !== route) {
76
- metadataRef.current = {
77
- name,
78
- bundle,
79
- route,
80
- url
81
- };
82
- loadRemoteComponent({
83
- url: new URL(url, location.origin),
84
- name,
85
- bundle,
86
- route,
87
- runtime,
88
- data,
89
- nextData,
90
- scripts,
91
- shared: tryImportShared(),
92
- remoteShared,
93
- container: shadowRoot
94
- }).then((result) => {
95
- if (mounted) {
142
+ startTransition(async () => {
143
+ try {
144
+ 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) {
145
+ metadataRef.current = {
146
+ name,
147
+ bundle,
148
+ route,
149
+ url,
150
+ loading: true
151
+ };
152
+ const result = await loadRemoteComponent({
153
+ url: new URL(url, location.origin),
154
+ name,
155
+ bundle,
156
+ route,
157
+ runtime,
158
+ data,
159
+ nextData,
160
+ scripts,
161
+ shared: (async () => {
162
+ return {
163
+ "next/router": routerImpl,
164
+ ...await tryImportShared(),
165
+ "next/image": () => Promise.resolve(imageImpl(Image.default, bundle)),
166
+ "next/dist/client/image-component": () => Promise.resolve({ Image: imageImpl(Image.default, bundle) })
167
+ };
168
+ })(),
169
+ remoteShared,
170
+ container: shadowRootRef.current
171
+ });
172
+ metadataRef.current.loading = false;
96
173
  if (result.error) {
97
174
  setComponent(result.error);
98
175
  } else {
99
176
  setComponent(result.component);
100
177
  }
101
178
  }
102
- }).catch((error) => {
103
- if (mounted) {
104
- setComponent(error);
105
- }
106
- });
107
- }
108
- return () => {
109
- mounted = false;
110
- };
179
+ } catch (error) {
180
+ metadataRef.current.loading = false;
181
+ setComponent(error);
182
+ }
183
+ });
111
184
  }, [
112
185
  url,
113
186
  component,
@@ -121,30 +194,75 @@ function RemoteComponentClient({
121
194
  remoteShared,
122
195
  children,
123
196
  links,
124
- isolate,
125
- shadowRoot
197
+ isolate
126
198
  ]);
127
- const resetStyle = reset ? /* @__PURE__ */ jsx("style", { "data-remote-components-reset": true, children: `:host { all: initial; }` }) : null;
128
- let componentToRender = /* @__PURE__ */ jsx(Fragment, { children: shouldUseChildren ? children : component });
129
- let linksToRender = links.map((link) => /* @__PURE__ */ jsx(
130
- "link",
131
- {
132
- as: link.as,
133
- href: new URL(link.href, url || location.origin).href,
134
- rel: link.rel
135
- },
136
- `${link.href}_${link.rel}`
137
- ));
199
+ if (nextData?.buildId === "development" && shadowRootRef.current && isolate !== false && reset && !shadowRootRef.current.querySelector("[data-remote-components-reset]")) {
200
+ const style = document.createElement("style");
201
+ style.setAttribute("data-remote-components-reset", "");
202
+ style.textContent = `:host { all: initial; }`;
203
+ shadowRootRef.current.insertBefore(style, shadowRootRef.current.firstChild);
204
+ } else if (shadowRootRef.current && isolate !== false && !reset && shadowRootRef.current.querySelector("[data-remote-components-reset]")) {
205
+ const style = shadowRootRef.current.querySelector(
206
+ "[data-remote-components-reset]"
207
+ );
208
+ if (style && shadowRootRef.current.firstChild !== style) {
209
+ shadowRootRef.current.removeChild(style);
210
+ }
211
+ }
212
+ const linksToRender = /* @__PURE__ */ jsxs(Fragment, { children: [
213
+ (!nextData || nextData.buildId !== "development") && isolate !== false && reset ? /* @__PURE__ */ jsx("style", { "data-remote-components-reset": "", children: `:host { all: initial; }` }) : null,
214
+ links.map((link) => /* @__PURE__ */ jsx(
215
+ "link",
216
+ {
217
+ ...Object.entries(link).reduce(
218
+ (acc, [key, value]) => {
219
+ if (key !== "href" && key !== "precedence" && typeof value === "string") {
220
+ acc[key] = value;
221
+ }
222
+ return acc;
223
+ },
224
+ {}
225
+ ),
226
+ "data-wait": link.rel === "stylesheet" && link.href ? "" : void 0,
227
+ href: new URL(link.href, url).href
228
+ },
229
+ JSON.stringify(link)
230
+ )),
231
+ links.filter((link) => link.rel === "stylesheet").map((link) => /* @__PURE__ */ jsx(
232
+ "link",
233
+ {
234
+ ...Object.entries(link).reduce(
235
+ (acc, [key, value]) => {
236
+ if (key !== "href" && key !== "precedence" && typeof value === "string") {
237
+ acc[key] = value;
238
+ }
239
+ return acc;
240
+ },
241
+ {}
242
+ ),
243
+ as: "style",
244
+ fetchPriority: "high",
245
+ href: new URL(link.href, url).href,
246
+ precedence: bundle,
247
+ rel: "preload"
248
+ },
249
+ JSON.stringify(link)
250
+ ))
251
+ ] });
252
+ let componentToRender = shouldUseChildren ? /* @__PURE__ */ jsx(Fragment, { children }) : component;
138
253
  if (isolate !== false) {
139
254
  componentToRender = /* @__PURE__ */ jsxs(
140
255
  "div",
141
256
  {
142
- id: `shadowroot_${new URL(url).href.replace(/[^a-z0-9]/g, "_")}_${name.replace(/[^a-z0-9]/g, "_")}`,
257
+ "data-remote-component-id": `shadowroot_${remoteComponentId}`,
258
+ "data-remote-component-isolation-root": "",
259
+ id: `shadowroot_${name}`,
260
+ ref: shadowContainerRef,
143
261
  children: [
144
262
  typeof document === "undefined" ? (
145
263
  // eslint-disable-next-line react/no-unknown-property
146
264
  /* @__PURE__ */ jsxs("template", { shadowrootmode: mode, children: [
147
- /* @__PURE__ */ jsx(
265
+ mode === "closed" ? /* @__PURE__ */ jsx(
148
266
  "div",
149
267
  {
150
268
  dangerouslySetInnerHTML: {
@@ -159,36 +277,31 @@ function RemoteComponentClient({
159
277
  />`
160
278
  }
161
279
  }
162
- ),
163
- resetStyle,
280
+ ) : null,
164
281
  linksToRender,
165
- componentToRender
282
+ shouldUseChildren ? children : null
166
283
  ] })
167
284
  ) : null,
168
- shadowRoot ? createPortal(
169
- shadowRoot.querySelectorAll("link").length !== links.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
170
- resetStyle,
285
+ typeof document !== "undefined" && shadowRootRef.current && !shouldUseChildren ? createPortal(
286
+ /* @__PURE__ */ jsxs(Fragment, { children: [
171
287
  linksToRender,
172
288
  componentToRender
173
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
174
- resetStyle,
175
- componentToRender
176
289
  ] }),
177
- shadowRoot
290
+ shadowRootRef.current
178
291
  ) : null
179
292
  ]
180
293
  }
181
294
  );
182
- linksToRender = null;
183
295
  }
184
296
  return /* @__PURE__ */ jsxs(Fragment, { children: [
297
+ isolate === false ? /* @__PURE__ */ jsx("template", { id: `${name}_start` }) : null,
185
298
  /* @__PURE__ */ jsx("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
186
299
  name,
187
300
  bundle,
188
301
  route,
189
302
  runtime
190
303
  }) }),
191
- linksToRender,
304
+ isolate === false ? linksToRender : null,
192
305
  componentToRender,
193
306
  nextData ? /* @__PURE__ */ jsx(
194
307
  "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":";AAmMI,SAGA,UAHA,KAqBM,YArBN;AAjMJ,SAAS,WAAW,UAAU,iBAAiB,cAAc;AAC7D,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;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;AA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AU,QAAQ;AAAA;AAAA,IAC1B,IACE;AAAA,IACH,YAAY,QAAQ,oBAAC,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":";AAiUI,mBAII,KAJJ;AA/TJ;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,YAAY,WAAW;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,WAAW,kBAAkB;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,oBAAoB,MAAM;AAChC,QAAM,CAAC,WAAW,YAAY,IAAI,SAAkC,IAAI;AACxE,QAAM,cAAc,OAMjB;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX,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,OAAO;AAKb,QAAM,gBACJ,kCAAkC,IAAI,IAAI,GAAG,EAAE,KAAK,QAAQ,cAAc,GAAG,KAAK,KAAK,QAAQ,cAAc,GAAG;AAClH,QAAM,qBAAqB;AAAA,IACzB,OAAO,aAAa,cAChB,OACA,SAAS;AAAA,MACP,yCAAyC;AAAA,IAC3C;AAAA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vB;AAAA,uBAAS,WACR;AAAA,gBAAC;AAAA;AAAA,kBACC,yBAAyB;AAAA,oBACvB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA,oDAK0B,IAAI,IAAI,GAAG,EAAE,KAAK,QAAQ,cAAc,GAAG,KAAK,KAAK,QAAQ,cAAc,GAAG;AAAA;AAAA;AAAA;AAAA,kBAIlH;AAAA;AAAA,cACF,IACE;AAAA,cACH;AAAA,cACA,oBAAoB,WAAW;AAAA,eAClC;AAAA,cACE;AAAA,UACH,OAAO,aAAa,eACrB,cAAc,WACd,CAAC,oBACG;AAAA,YACE,iCACG;AAAA;AAAA,cACA;AAAA,eACH;AAAA,YACA,cAAc;AAAA,UAChB,IACA;AAAA;AAAA;AAAA,IACN;AAAA,EAEJ;AAEA,SACE,iCACG;AAAA,gBAAY,QAAQ,oBAAC,cAAS,IAAI,GAAG,cAAc,IAAK;AAAA,IACzD,oBAAC,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,oBAAC,cAAS,IAAI,GAAG,YAAY,IAAK;AAAA,KACzD;AAEJ;","names":[]}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var app_router_compat_exports = {};
30
+ __export(app_router_compat_exports, {
31
+ imageImpl: () => imageImpl,
32
+ routerImpl: () => routerImpl
33
+ });
34
+ module.exports = __toCommonJS(app_router_compat_exports);
35
+ var import_jsx_runtime = require("react/jsx-runtime");
36
+ var import_navigation = require("next/navigation");
37
+ var import_polyfill = require("#internal/shared/client/polyfill");
38
+ function imageImpl(ImageComponent, bundle) {
39
+ const component = function RemoteImage(props) {
40
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
41
+ ImageComponent,
42
+ {
43
+ ...props,
44
+ src: (0, import_polyfill.applyBundleUrlToImagePropsSrc)(bundle, props.src)
45
+ }
46
+ );
47
+ };
48
+ component.default = component;
49
+ return component;
50
+ }
51
+ const routerImpl = async () => {
52
+ const { useRouter } = await import("next/navigation");
53
+ return Promise.resolve({
54
+ useRouter: () => {
55
+ const router = useRouter();
56
+ const pathname = (0, import_navigation.usePathname)();
57
+ const searchParams = (0, import_navigation.useSearchParams)();
58
+ const query = Object.fromEntries(searchParams.entries());
59
+ return {
60
+ pathname,
61
+ query,
62
+ asPath: searchParams.toString() ? `${pathname}?${searchParams.toString()}` : pathname,
63
+ push: (href, _, options) => {
64
+ router.push(href, options);
65
+ return Promise.resolve(true);
66
+ },
67
+ replace: (href, _, options) => {
68
+ router.replace(href, options);
69
+ return Promise.resolve(true);
70
+ },
71
+ refresh: () => Promise.resolve(router.refresh()),
72
+ prefetch: async () => {
73
+ console.warn(
74
+ "You are using router.prefetch() in a remote component loaded in the Next.js App Router. prefetch() is a no-op in the App Router."
75
+ );
76
+ return Promise.resolve();
77
+ },
78
+ back: () => {
79
+ if (typeof window !== "undefined") {
80
+ window.history.back();
81
+ }
82
+ },
83
+ reload: () => {
84
+ router.refresh();
85
+ },
86
+ beforePopState: () => {
87
+ },
88
+ events: {
89
+ on: () => {
90
+ console.warn(
91
+ "You are using router.events.on() in a remote component loaded in the Next.js App Router. events.on() is a no-op in the App Router."
92
+ );
93
+ },
94
+ off: () => {
95
+ console.warn(
96
+ "You are using router.events.off() in a remote component loaded in the Next.js App Router. events.off() is a no-op in the App Router."
97
+ );
98
+ },
99
+ emit: () => {
100
+ console.warn(
101
+ "You are using router.events.emit() in a remote component loaded in the Next.js App Router. events.emit() is a no-op in the App Router."
102
+ );
103
+ }
104
+ }
105
+ };
106
+ }
107
+ });
108
+ };
109
+ // Annotate the CommonJS export names for ESM import in node:
110
+ 0 && (module.exports = {
111
+ imageImpl,
112
+ routerImpl
113
+ });
114
+ //# sourceMappingURL=app-router-compat.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/next/host/app-router-compat.tsx"],"sourcesContent":["import type { default as ImageComponentType, ImageProps } from 'next/image';\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport type { NavigateOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime';\nimport { applyBundleUrlToImagePropsSrc } from '#internal/shared/client/polyfill';\n\nexport function imageImpl(\n ImageComponent: typeof ImageComponentType,\n bundle: string,\n) {\n const component = function RemoteImage(props: ImageProps) {\n return (\n <ImageComponent\n {...props}\n src={applyBundleUrlToImagePropsSrc(bundle, props.src)}\n />\n );\n };\n component.default = component;\n return component;\n}\n\nexport const routerImpl = async () => {\n const { useRouter } = await import('next/navigation');\n return Promise.resolve({\n useRouter: () => {\n const router = useRouter();\n const pathname = usePathname();\n const searchParams = useSearchParams();\n const query = Object.fromEntries(searchParams.entries());\n return {\n pathname,\n query,\n asPath: searchParams.toString()\n ? `${pathname}?${searchParams.toString()}`\n : pathname,\n push: (href: string, _: string, options?: NavigateOptions) => {\n router.push(href, options);\n return Promise.resolve(true);\n },\n replace: (href: string, _: string, options?: NavigateOptions) => {\n router.replace(href, options);\n return Promise.resolve(true);\n },\n refresh: () => Promise.resolve(router.refresh()),\n prefetch: async () => {\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.prefetch() in a remote component loaded in the Next.js App Router. prefetch() is a no-op in the App Router.',\n );\n return Promise.resolve();\n },\n back: () => {\n // there's no back() in the App Router\n if (typeof window !== 'undefined') {\n window.history.back();\n }\n },\n reload: () => {\n router.refresh();\n },\n beforePopState: () => {\n // there's no beforePopState() in the App Router\n },\n events: {\n on: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.on() in a remote component loaded in the Next.js App Router. events.on() is a no-op in the App Router.',\n );\n },\n off: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.off() in a remote component loaded in the Next.js App Router. events.off() is a no-op in the App Router.',\n );\n },\n emit: () => {\n // there's no router.events in the App Router\n // eslint-disable-next-line no-console\n console.warn(\n 'You are using router.events.emit() in a remote component loaded in the Next.js App Router. events.emit() is a no-op in the App Router.',\n );\n },\n },\n };\n },\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWM;AAVN,wBAA6C;AAE7C,sBAA8C;AAEvC,SAAS,UAC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,YACF;AAAA,UACF;AAAA,UACA,KAAK,MAAM;AAGT,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,UACA,MAAM,MAAM;AAGV,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,31 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import ImageComponentType, { ImageProps } from 'next/image';
3
+ import { NavigateOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime';
4
+
5
+ declare function imageImpl(ImageComponent: typeof ImageComponentType, bundle: string): {
6
+ (props: ImageProps): react_jsx_runtime.JSX.Element;
7
+ default: /*elided*/ any;
8
+ };
9
+ declare const routerImpl: () => Promise<{
10
+ useRouter: () => {
11
+ pathname: string;
12
+ query: {
13
+ [k: string]: string;
14
+ };
15
+ asPath: string;
16
+ push: (href: string, _: string, options?: NavigateOptions) => Promise<boolean>;
17
+ replace: (href: string, _: string, options?: NavigateOptions) => Promise<boolean>;
18
+ refresh: () => Promise<void>;
19
+ prefetch: () => Promise<void>;
20
+ back: () => void;
21
+ reload: () => void;
22
+ beforePopState: () => void;
23
+ events: {
24
+ on: () => void;
25
+ off: () => void;
26
+ emit: () => void;
27
+ };
28
+ };
29
+ }>;
30
+
31
+ export { imageImpl, routerImpl };
@@ -0,0 +1,79 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { usePathname, useSearchParams } from "next/navigation";
3
+ import { applyBundleUrlToImagePropsSrc } from "#internal/shared/client/polyfill";
4
+ function imageImpl(ImageComponent, bundle) {
5
+ const component = function RemoteImage(props) {
6
+ return /* @__PURE__ */ jsx(
7
+ ImageComponent,
8
+ {
9
+ ...props,
10
+ src: applyBundleUrlToImagePropsSrc(bundle, props.src)
11
+ }
12
+ );
13
+ };
14
+ component.default = component;
15
+ return component;
16
+ }
17
+ const routerImpl = async () => {
18
+ const { useRouter } = await import("next/navigation");
19
+ return Promise.resolve({
20
+ useRouter: () => {
21
+ const router = useRouter();
22
+ const pathname = usePathname();
23
+ const searchParams = useSearchParams();
24
+ const query = Object.fromEntries(searchParams.entries());
25
+ return {
26
+ pathname,
27
+ query,
28
+ asPath: searchParams.toString() ? `${pathname}?${searchParams.toString()}` : pathname,
29
+ push: (href, _, options) => {
30
+ router.push(href, options);
31
+ return Promise.resolve(true);
32
+ },
33
+ replace: (href, _, options) => {
34
+ router.replace(href, options);
35
+ return Promise.resolve(true);
36
+ },
37
+ refresh: () => Promise.resolve(router.refresh()),
38
+ prefetch: async () => {
39
+ console.warn(
40
+ "You are using router.prefetch() in a remote component loaded in the Next.js App Router. prefetch() is a no-op in the App Router."
41
+ );
42
+ return Promise.resolve();
43
+ },
44
+ back: () => {
45
+ if (typeof window !== "undefined") {
46
+ window.history.back();
47
+ }
48
+ },
49
+ reload: () => {
50
+ router.refresh();
51
+ },
52
+ beforePopState: () => {
53
+ },
54
+ events: {
55
+ on: () => {
56
+ console.warn(
57
+ "You are using router.events.on() in a remote component loaded in the Next.js App Router. events.on() is a no-op in the App Router."
58
+ );
59
+ },
60
+ off: () => {
61
+ console.warn(
62
+ "You are using router.events.off() in a remote component loaded in the Next.js App Router. events.off() is a no-op in the App Router."
63
+ );
64
+ },
65
+ emit: () => {
66
+ console.warn(
67
+ "You are using router.events.emit() in a remote component loaded in the Next.js App Router. events.emit() is a no-op in the App Router."
68
+ );
69
+ }
70
+ }
71
+ };
72
+ }
73
+ });
74
+ };
75
+ export {
76
+ imageImpl,
77
+ routerImpl
78
+ };
79
+ //# sourceMappingURL=app-router-compat.js.map