remote-components 0.0.22 → 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 (78) hide show
  1. package/dist/html/host.cjs +345 -80
  2. package/dist/html/host.cjs.map +1 -1
  3. package/dist/html/host.js +347 -79
  4. package/dist/html/host.js.map +1 -1
  5. package/dist/internal/next/host/app-router-client.cjs +205 -58
  6. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  7. package/dist/internal/next/host/app-router-client.d.ts +2 -2
  8. package/dist/internal/next/host/app-router-client.js +213 -59
  9. package/dist/internal/next/host/app-router-client.js.map +1 -1
  10. package/dist/internal/next/host/app-router-compat.cjs +114 -0
  11. package/dist/internal/next/host/app-router-compat.cjs.map +1 -0
  12. package/dist/internal/next/host/app-router-compat.d.ts +31 -0
  13. package/dist/internal/next/host/app-router-compat.js +79 -0
  14. package/dist/internal/next/host/app-router-compat.js.map +1 -0
  15. package/dist/internal/next/remote/render-client.cjs +10 -2
  16. package/dist/internal/next/remote/render-client.cjs.map +1 -1
  17. package/dist/internal/next/remote/render-client.js +10 -2
  18. package/dist/internal/next/remote/render-client.js.map +1 -1
  19. package/dist/internal/shared/client/apply-origin.cjs +61 -0
  20. package/dist/internal/shared/client/apply-origin.cjs.map +1 -0
  21. package/dist/internal/shared/client/apply-origin.d.ts +3 -0
  22. package/dist/internal/shared/client/apply-origin.js +37 -0
  23. package/dist/internal/shared/client/apply-origin.js.map +1 -0
  24. package/dist/internal/shared/client/polyfill.cjs +149 -0
  25. package/dist/internal/shared/client/polyfill.cjs.map +1 -0
  26. package/dist/internal/shared/client/polyfill.d.ts +6 -0
  27. package/dist/internal/shared/client/polyfill.js +124 -0
  28. package/dist/internal/shared/client/polyfill.js.map +1 -0
  29. package/dist/internal/shared/client/remote-component.cjs +3 -3
  30. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  31. package/dist/internal/shared/client/remote-component.d.ts +3 -1
  32. package/dist/internal/shared/client/remote-component.js +3 -3
  33. package/dist/internal/shared/client/remote-component.js.map +1 -1
  34. package/dist/internal/shared/ssr/dom-flight.cjs +49 -17
  35. package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
  36. package/dist/internal/shared/ssr/dom-flight.js +49 -17
  37. package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
  38. package/dist/internal/shared/ssr/fetch-remote-component.cjs +3 -2
  39. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  40. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +6 -0
  41. package/dist/internal/shared/ssr/fetch-remote-component.js +3 -2
  42. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  43. package/dist/next/config.cjs +50 -28
  44. package/dist/next/config.cjs.map +1 -1
  45. package/dist/next/config.js +50 -28
  46. package/dist/next/config.js.map +1 -1
  47. package/dist/next/host/app-router-server.cjs +4 -0
  48. package/dist/next/host/app-router-server.cjs.map +1 -1
  49. package/dist/next/host/app-router-server.d.ts +5 -1
  50. package/dist/next/host/app-router-server.js +4 -0
  51. package/dist/next/host/app-router-server.js.map +1 -1
  52. package/dist/next/host/client/index.cjs +16 -1
  53. package/dist/next/host/client/index.cjs.map +1 -1
  54. package/dist/next/host/client/index.d.ts +1 -1
  55. package/dist/next/host/client/index.js +16 -1
  56. package/dist/next/host/client/index.js.map +1 -1
  57. package/dist/next/host/pages-router-server.cjs +37 -16
  58. package/dist/next/host/pages-router-server.cjs.map +1 -1
  59. package/dist/next/host/pages-router-server.d.ts +3 -0
  60. package/dist/next/host/pages-router-server.js +37 -16
  61. package/dist/next/host/pages-router-server.js.map +1 -1
  62. package/dist/next/middleware.cjs +5 -2
  63. package/dist/next/middleware.cjs.map +1 -1
  64. package/dist/next/middleware.d.ts +1 -0
  65. package/dist/next/middleware.js +5 -2
  66. package/dist/next/middleware.js.map +1 -1
  67. package/dist/next/remote/pages-router.cjs +3 -1
  68. package/dist/next/remote/pages-router.cjs.map +1 -1
  69. package/dist/next/remote/pages-router.d.ts +1 -0
  70. package/dist/next/remote/pages-router.js +3 -1
  71. package/dist/next/remote/pages-router.js.map +1 -1
  72. package/dist/react/index.cjs +235 -156
  73. package/dist/react/index.cjs.map +1 -1
  74. package/dist/react/index.d.ts +7 -3
  75. package/dist/react/index.js +225 -146
  76. package/dist/react/index.js.map +1 -1
  77. package/dist/{types-7425dfe1.d.ts → types-b8210fd3.d.ts} +2 -0
  78. package/package.json +1 -1
@@ -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":"AAWM;AAVN,SAAS,aAAa,uBAAuB;AAE7C,SAAS,qCAAqC;AAEvC,SAAS,UACd,gBACA,QACA;AACA,QAAM,YAAY,SAAS,YAAY,OAAmB;AACxD,WACE;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACJ,KAAK,8BAA8B,QAAQ,MAAM,GAAG;AAAA;AAAA,IACtD;AAAA,EAEJ;AACA,YAAU,UAAU;AACpB,SAAO;AACT;AAEO,MAAM,aAAa,YAAY;AACpC,QAAM,EAAE,UAAU,IAAI,MAAM,OAAO,iBAAiB;AACpD,SAAO,QAAQ,QAAQ;AAAA,IACrB,WAAW,MAAM;AACf,YAAM,SAAS,UAAU;AACzB,YAAM,WAAW,YAAY;AAC7B,YAAM,eAAe,gBAAgB;AACrC,YAAM,QAAQ,OAAO,YAAY,aAAa,QAAQ,CAAC;AACvD,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA,QAAQ,aAAa,SAAS,IAC1B,GAAG,YAAY,aAAa,SAAS,MACrC;AAAA,QACJ,MAAM,CAAC,MAAc,GAAW,YAA8B;AAC5D,iBAAO,KAAK,MAAM,OAAO;AACzB,iBAAO,QAAQ,QAAQ,IAAI;AAAA,QAC7B;AAAA,QACA,SAAS,CAAC,MAAc,GAAW,YAA8B;AAC/D,iBAAO,QAAQ,MAAM,OAAO;AAC5B,iBAAO,QAAQ,QAAQ,IAAI;AAAA,QAC7B;AAAA,QACA,SAAS,MAAM,QAAQ,QAAQ,OAAO,QAAQ,CAAC;AAAA,QAC/C,UAAU,YAAY;AAEpB,kBAAQ;AAAA,YACN;AAAA,UACF;AACA,iBAAO,QAAQ,QAAQ;AAAA,QACzB;AAAA,QACA,MAAM,MAAM;AAEV,cAAI,OAAO,WAAW,aAAa;AACjC,mBAAO,QAAQ,KAAK;AAAA,UACtB;AAAA,QACF;AAAA,QACA,QAAQ,MAAM;AACZ,iBAAO,QAAQ;AAAA,QACjB;AAAA,QACA,gBAAgB,MAAM;AAAA,QAEtB;AAAA,QACA,QAAQ;AAAA,UACN,IAAI,MAAM;AAGR,oBAAQ;AAAA,cACN;AAAA,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":[]}
@@ -39,7 +39,7 @@ var import_jsx_runtime = (
39
39
  var import_react = require("react");
40
40
  async function tryImportShared() {
41
41
  try {
42
- const { shared } = await import("@remote-components/shared/remote");
42
+ const { shared } = await import("@remote-components/shared/remote/app");
43
43
  return shared;
44
44
  } catch {
45
45
  return {};
@@ -47,7 +47,15 @@ async function tryImportShared() {
47
47
  }
48
48
  const tryImportSharedPromise = tryImportShared();
49
49
  function RemoteComponentSharedRemote({ name }) {
50
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", { id: `${name}_shared`, type: "application/json", children: JSON.stringify((0, import_react.use)(tryImportSharedPromise)) });
50
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
51
+ "script",
52
+ {
53
+ "data-remote-components-shared": "",
54
+ id: `${name}_shared`,
55
+ type: "application/json",
56
+ children: JSON.stringify((0, import_react.use)(tryImportSharedPromise))
57
+ }
58
+ );
51
59
  }
52
60
  // Annotate the CommonJS export names for ESM import in node:
53
61
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/remote/render-client.tsx"],"sourcesContent":["'use client';\n\nimport { use } from 'react';\n\n// try to import the shared module from the remote application\n// use an empty object as a fallback if the import fails to avoid breaking the application\nasync function tryImportShared() {\n try {\n const { shared } = await import('@remote-components/shared/remote');\n return shared;\n } catch {\n return {};\n }\n}\n\n// create a promise singleton to import the shared module\nconst tryImportSharedPromise = tryImportShared();\n\nexport function RemoteComponentSharedRemote({ name }: { name: string }) {\n return (\n // render the shared module as a script tag\n <script id={`${name}_shared`} type=\"application/json\">\n {JSON.stringify(use(tryImportSharedPromise))}\n </script>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBI;AAAA;AAAA;AAAA;AAnBJ,mBAAoB;AAIpB,eAAe,kBAAkB;AAC/B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,kCAAkC;AAClE,WAAO;AAAA,EACT,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAGA,MAAM,yBAAyB,gBAAgB;AAExC,SAAS,4BAA4B,EAAE,KAAK,GAAqB;AACtE,SAEE,4CAAC,YAAO,IAAI,GAAG,eAAe,MAAK,oBAChC,eAAK,cAAU,kBAAI,sBAAsB,CAAC,GAC7C;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/next/remote/render-client.tsx"],"sourcesContent":["'use client';\n\nimport { use } from 'react';\n\n// try to import the shared module from the remote application\n// use an empty object as a fallback if the import fails to avoid breaking the application\nasync function tryImportShared() {\n try {\n const { shared } = await import('@remote-components/shared/remote/app');\n return shared;\n } catch {\n return {};\n }\n}\n\n// create a promise singleton to import the shared module\nconst tryImportSharedPromise = tryImportShared();\n\nexport function RemoteComponentSharedRemote({ name }: { name: string }) {\n return (\n // render the shared module as a script tag\n <script\n data-remote-components-shared=\"\"\n id={`${name}_shared`}\n type=\"application/json\"\n >\n {JSON.stringify(use(tryImportSharedPromise))}\n </script>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBI;AAAA;AAAA;AAAA;AAnBJ,mBAAoB;AAIpB,eAAe,kBAAkB;AAC/B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,sCAAsC;AACtE,WAAO;AAAA,EACT,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAGA,MAAM,yBAAyB,gBAAgB;AAExC,SAAS,4BAA4B,EAAE,KAAK,GAAqB;AACtE,SAEE;AAAA,IAAC;AAAA;AAAA,MACC,iCAA8B;AAAA,MAC9B,IAAI,GAAG;AAAA,MACP,MAAK;AAAA,MAEJ,eAAK,cAAU,kBAAI,sBAAsB,CAAC;AAAA;AAAA,EAC7C;AAEJ;","names":[]}
@@ -3,7 +3,7 @@ import { jsx } from "react/jsx-runtime";
3
3
  import { use } from "react";
4
4
  async function tryImportShared() {
5
5
  try {
6
- const { shared } = await import("@remote-components/shared/remote");
6
+ const { shared } = await import("@remote-components/shared/remote/app");
7
7
  return shared;
8
8
  } catch {
9
9
  return {};
@@ -13,7 +13,15 @@ const tryImportSharedPromise = tryImportShared();
13
13
  function RemoteComponentSharedRemote({ name }) {
14
14
  return (
15
15
  // render the shared module as a script tag
16
- /* @__PURE__ */ jsx("script", { id: `${name}_shared`, type: "application/json", children: JSON.stringify(use(tryImportSharedPromise)) })
16
+ /* @__PURE__ */ jsx(
17
+ "script",
18
+ {
19
+ "data-remote-components-shared": "",
20
+ id: `${name}_shared`,
21
+ type: "application/json",
22
+ children: JSON.stringify(use(tryImportSharedPromise))
23
+ }
24
+ )
17
25
  );
18
26
  }
19
27
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/remote/render-client.tsx"],"sourcesContent":["'use client';\n\nimport { use } from 'react';\n\n// try to import the shared module from the remote application\n// use an empty object as a fallback if the import fails to avoid breaking the application\nasync function tryImportShared() {\n try {\n const { shared } = await import('@remote-components/shared/remote');\n return shared;\n } catch {\n return {};\n }\n}\n\n// create a promise singleton to import the shared module\nconst tryImportSharedPromise = tryImportShared();\n\nexport function RemoteComponentSharedRemote({ name }: { name: string }) {\n return (\n // render the shared module as a script tag\n <script id={`${name}_shared`} type=\"application/json\">\n {JSON.stringify(use(tryImportSharedPromise))}\n </script>\n );\n}\n"],"mappings":";AAqBI;AAnBJ,SAAS,WAAW;AAIpB,eAAe,kBAAkB;AAC/B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,kCAAkC;AAClE,WAAO;AAAA,EACT,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAGA,MAAM,yBAAyB,gBAAgB;AAExC,SAAS,4BAA4B,EAAE,KAAK,GAAqB;AACtE;AAAA;AAAA,IAEE,oBAAC,YAAO,IAAI,GAAG,eAAe,MAAK,oBAChC,eAAK,UAAU,IAAI,sBAAsB,CAAC,GAC7C;AAAA;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/next/remote/render-client.tsx"],"sourcesContent":["'use client';\n\nimport { use } from 'react';\n\n// try to import the shared module from the remote application\n// use an empty object as a fallback if the import fails to avoid breaking the application\nasync function tryImportShared() {\n try {\n const { shared } = await import('@remote-components/shared/remote/app');\n return shared;\n } catch {\n return {};\n }\n}\n\n// create a promise singleton to import the shared module\nconst tryImportSharedPromise = tryImportShared();\n\nexport function RemoteComponentSharedRemote({ name }: { name: string }) {\n return (\n // render the shared module as a script tag\n <script\n data-remote-components-shared=\"\"\n id={`${name}_shared`}\n type=\"application/json\"\n >\n {JSON.stringify(use(tryImportSharedPromise))}\n </script>\n );\n}\n"],"mappings":";AAqBI;AAnBJ,SAAS,WAAW;AAIpB,eAAe,kBAAkB;AAC/B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,sCAAsC;AACtE,WAAO;AAAA,EACT,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAGA,MAAM,yBAAyB,gBAAgB;AAExC,SAAS,4BAA4B,EAAE,KAAK,GAAqB;AACtE;AAAA;AAAA,IAEE;AAAA,MAAC;AAAA;AAAA,QACC,iCAA8B;AAAA,QAC9B,IAAI,GAAG;AAAA,QACP,MAAK;AAAA,QAEJ,eAAK,UAAU,IAAI,sBAAsB,CAAC;AAAA;AAAA,IAC7C;AAAA;AAEJ;","names":[]}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var apply_origin_exports = {};
20
+ __export(apply_origin_exports, {
21
+ applyOriginToNodes: () => applyOriginToNodes
22
+ });
23
+ module.exports = __toCommonJS(apply_origin_exports);
24
+ const tagNames = [
25
+ "img",
26
+ "source",
27
+ "video",
28
+ "audio",
29
+ "track",
30
+ "iframe",
31
+ "embed",
32
+ "script",
33
+ "link"
34
+ ];
35
+ function applyOriginToNodes(doc, url) {
36
+ const nodes = doc.querySelectorAll(
37
+ tagNames.map((type) => `${type}[src],${type}[srcset]`).join(",")
38
+ );
39
+ nodes.forEach((node) => {
40
+ if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
41
+ node.src = new URL(node.getAttribute("src") ?? "/", url).href;
42
+ }
43
+ if (node.hasAttribute("srcset")) {
44
+ const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
45
+ const [urlPart, descriptor] = entry.trim().split(/\s+/);
46
+ if (!urlPart)
47
+ return entry;
48
+ const absoluteUrl = new URL(urlPart, url).href;
49
+ return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
50
+ }).join(", ");
51
+ if (srcSet) {
52
+ node.setAttribute("srcset", srcSet);
53
+ }
54
+ }
55
+ });
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ applyOriginToNodes
60
+ });
61
+ //# sourceMappingURL=apply-origin.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/shared/client/apply-origin.ts"],"sourcesContent":["const tagNames = [\n 'img',\n 'source',\n 'video',\n 'audio',\n 'track',\n 'iframe',\n 'embed',\n 'script',\n 'link',\n];\n\nexport function applyOriginToNodes(doc: Document | HTMLElement, url: URL) {\n const nodes = doc.querySelectorAll<HTMLImageElement>(\n tagNames.map((type) => `${type}[src],${type}[srcset]`).join(','),\n );\n nodes.forEach((node) => {\n if (\n node.hasAttribute('src') &&\n /^[./]+\\/?/.test(node.getAttribute('src') ?? '')\n ) {\n node.src = new URL(node.getAttribute('src') ?? '/', url).href;\n }\n if (node.hasAttribute('srcset')) {\n const srcSet = node\n .getAttribute('srcset')\n ?.split(',')\n .map((entry) => {\n const [urlPart, descriptor] = entry.trim().split(/\\s+/);\n if (!urlPart) return entry;\n\n const absoluteUrl = new URL(urlPart, url).href;\n return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;\n })\n .join(', ');\n if (srcSet) {\n node.setAttribute('srcset', srcSet);\n }\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,WAAW;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,mBAAmB,KAA6B,KAAU;AACxE,QAAM,QAAQ,IAAI;AAAA,IAChB,SAAS,IAAI,CAAC,SAAS,GAAG,aAAa,cAAc,EAAE,KAAK,GAAG;AAAA,EACjE;AACA,QAAM,QAAQ,CAAC,SAAS;AACtB,QACE,KAAK,aAAa,KAAK,KACvB,YAAY,KAAK,KAAK,aAAa,KAAK,KAAK,EAAE,GAC/C;AACA,WAAK,MAAM,IAAI,IAAI,KAAK,aAAa,KAAK,KAAK,KAAK,GAAG,EAAE;AAAA,IAC3D;AACA,QAAI,KAAK,aAAa,QAAQ,GAAG;AAC/B,YAAM,SAAS,KACZ,aAAa,QAAQ,GACpB,MAAM,GAAG,EACV,IAAI,CAAC,UAAU;AACd,cAAM,CAAC,SAAS,UAAU,IAAI,MAAM,KAAK,EAAE,MAAM,KAAK;AACtD,YAAI,CAAC;AAAS,iBAAO;AAErB,cAAM,cAAc,IAAI,IAAI,SAAS,GAAG,EAAE;AAC1C,eAAO,aAAa,GAAG,eAAe,eAAe;AAAA,MACvD,CAAC,EACA,KAAK,IAAI;AACZ,UAAI,QAAQ;AACV,aAAK,aAAa,UAAU,MAAM;AAAA,MACpC;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,3 @@
1
+ declare function applyOriginToNodes(doc: Document | HTMLElement, url: URL): void;
2
+
3
+ export { applyOriginToNodes };
@@ -0,0 +1,37 @@
1
+ const tagNames = [
2
+ "img",
3
+ "source",
4
+ "video",
5
+ "audio",
6
+ "track",
7
+ "iframe",
8
+ "embed",
9
+ "script",
10
+ "link"
11
+ ];
12
+ function applyOriginToNodes(doc, url) {
13
+ const nodes = doc.querySelectorAll(
14
+ tagNames.map((type) => `${type}[src],${type}[srcset]`).join(",")
15
+ );
16
+ nodes.forEach((node) => {
17
+ if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
18
+ node.src = new URL(node.getAttribute("src") ?? "/", url).href;
19
+ }
20
+ if (node.hasAttribute("srcset")) {
21
+ const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
22
+ const [urlPart, descriptor] = entry.trim().split(/\s+/);
23
+ if (!urlPart)
24
+ return entry;
25
+ const absoluteUrl = new URL(urlPart, url).href;
26
+ return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
27
+ }).join(", ");
28
+ if (srcSet) {
29
+ node.setAttribute("srcset", srcSet);
30
+ }
31
+ }
32
+ });
33
+ }
34
+ export {
35
+ applyOriginToNodes
36
+ };
37
+ //# sourceMappingURL=apply-origin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/shared/client/apply-origin.ts"],"sourcesContent":["const tagNames = [\n 'img',\n 'source',\n 'video',\n 'audio',\n 'track',\n 'iframe',\n 'embed',\n 'script',\n 'link',\n];\n\nexport function applyOriginToNodes(doc: Document | HTMLElement, url: URL) {\n const nodes = doc.querySelectorAll<HTMLImageElement>(\n tagNames.map((type) => `${type}[src],${type}[srcset]`).join(','),\n );\n nodes.forEach((node) => {\n if (\n node.hasAttribute('src') &&\n /^[./]+\\/?/.test(node.getAttribute('src') ?? '')\n ) {\n node.src = new URL(node.getAttribute('src') ?? '/', url).href;\n }\n if (node.hasAttribute('srcset')) {\n const srcSet = node\n .getAttribute('srcset')\n ?.split(',')\n .map((entry) => {\n const [urlPart, descriptor] = entry.trim().split(/\\s+/);\n if (!urlPart) return entry;\n\n const absoluteUrl = new URL(urlPart, url).href;\n return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;\n })\n .join(', ');\n if (srcSet) {\n node.setAttribute('srcset', srcSet);\n }\n }\n });\n}\n"],"mappings":"AAAA,MAAM,WAAW;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,mBAAmB,KAA6B,KAAU;AACxE,QAAM,QAAQ,IAAI;AAAA,IAChB,SAAS,IAAI,CAAC,SAAS,GAAG,aAAa,cAAc,EAAE,KAAK,GAAG;AAAA,EACjE;AACA,QAAM,QAAQ,CAAC,SAAS;AACtB,QACE,KAAK,aAAa,KAAK,KACvB,YAAY,KAAK,KAAK,aAAa,KAAK,KAAK,EAAE,GAC/C;AACA,WAAK,MAAM,IAAI,IAAI,KAAK,aAAa,KAAK,KAAK,KAAK,GAAG,EAAE;AAAA,IAC3D;AACA,QAAI,KAAK,aAAa,QAAQ,GAAG;AAC/B,YAAM,SAAS,KACZ,aAAa,QAAQ,GACpB,MAAM,GAAG,EACV,IAAI,CAAC,UAAU;AACd,cAAM,CAAC,SAAS,UAAU,IAAI,MAAM,KAAK,EAAE,MAAM,KAAK;AACtD,YAAI,CAAC;AAAS,iBAAO;AAErB,cAAM,cAAc,IAAI,IAAI,SAAS,GAAG,EAAE;AAC1C,eAAO,aAAa,GAAG,eAAe,eAAe;AAAA,MACvD,CAAC,EACA,KAAK,IAAI;AACZ,UAAI,QAAQ;AACV,aAAK,aAAa,UAAU,MAAM;AAAA,MACpC;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var polyfill_exports = {};
20
+ __export(polyfill_exports, {
21
+ applyBundleUrlToImagePropsSrc: () => applyBundleUrlToImagePropsSrc,
22
+ sharedPolyfills: () => sharedPolyfills
23
+ });
24
+ module.exports = __toCommonJS(polyfill_exports);
25
+ var import_jsx_runtime = (
26
+ // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
27
+ require("react/jsx-runtime")
28
+ );
29
+ function applyBundleUrlToSrc(bundle, src) {
30
+ const self = globalThis;
31
+ if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {
32
+ return src;
33
+ }
34
+ const { assetPrefix, path } = /^(?<assetPrefix>.*?)\/_next\/(?<path>.*)/.exec(src)?.groups ?? {};
35
+ if (!path) {
36
+ return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;
37
+ }
38
+ return `${self.__remote_bundle_url__?.[bundle]?.origin ?? ""}${assetPrefix}/_next/${path}`;
39
+ }
40
+ function applyBundleUrlToImagePropsSrc(bundle, src) {
41
+ if (typeof src === "string") {
42
+ return applyBundleUrlToSrc(bundle, src);
43
+ }
44
+ const propSrc = src;
45
+ return applyBundleUrlToSrc(bundle, propSrc.src);
46
+ }
47
+ const imageImpl = (bundle) => function RemoteImage({ priority: _, ...props }) {
48
+ const newSrc = applyBundleUrlToImagePropsSrc(
49
+ bundle,
50
+ typeof props.src === "string" ? props.src : props.src.src
51
+ );
52
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
53
+ "img",
54
+ {
55
+ decoding: "async",
56
+ style: { color: "transparent" },
57
+ ...props,
58
+ src: newSrc,
59
+ suppressHydrationWarning: true
60
+ }
61
+ );
62
+ };
63
+ function sharedPolyfills(shared) {
64
+ const self = globalThis;
65
+ const polyfill = {
66
+ "next/dist/client/components/navigation": self.__remote_component_host_shared_modules__?.["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
67
+ useRouter() {
68
+ return {
69
+ push: (routerUrl) => {
70
+ history.pushState({}, "", routerUrl);
71
+ },
72
+ replace: (routerUrl) => {
73
+ history.replaceState({}, "", routerUrl);
74
+ },
75
+ back: () => {
76
+ history.back();
77
+ }
78
+ };
79
+ },
80
+ useSearchParams() {
81
+ return new URLSearchParams(location.search);
82
+ },
83
+ __esModule: true
84
+ })),
85
+ "next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
86
+ default: ({
87
+ children,
88
+ ...props
89
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { ...props, href: props.href, suppressHydrationWarning: true, children: children ?? null }),
90
+ __esModule: true
91
+ })),
92
+ "next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
93
+ default: () => {
94
+ throw new Error("Next.js <Form> component not implemented");
95
+ },
96
+ __esModule: true
97
+ })),
98
+ "next/dist/client/image-component": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
99
+ Image: imageImpl(bundle),
100
+ __esModule: true
101
+ })),
102
+ "next/image": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
103
+ default: imageImpl(bundle),
104
+ getImageProps: (_imgProps) => {
105
+ throw new Error(
106
+ "Next.js getImageProps() is not implemented in remote components"
107
+ );
108
+ },
109
+ __esModule: true
110
+ })),
111
+ "next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
112
+ // TODO: implement <Script> component for non-Next.js host applications
113
+ // do not throw an error for now
114
+ default: () => null,
115
+ __esModule: true
116
+ })),
117
+ "next/router": self.__remote_component_host_shared_modules__?.["next/router"] ?? shared?.["next/router"] ?? (() => (
118
+ // TODO: incomplete implementation
119
+ Promise.resolve({
120
+ useRouter() {
121
+ return {
122
+ push: (routerUrl) => {
123
+ history.pushState({}, "", routerUrl);
124
+ },
125
+ replace: (routerUrl) => {
126
+ history.replaceState({}, "", routerUrl);
127
+ },
128
+ back: () => {
129
+ history.back();
130
+ }
131
+ };
132
+ },
133
+ __esModule: true
134
+ })
135
+ ))
136
+ };
137
+ polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
138
+ polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
139
+ polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
140
+ polyfill["next/dist/api/image"] = polyfill["next/dist/client/image-component"];
141
+ polyfill["next/script"] = polyfill["next/dist/client/script"];
142
+ return polyfill;
143
+ }
144
+ // Annotate the CommonJS export names for ESM import in node:
145
+ 0 && (module.exports = {
146
+ applyBundleUrlToImagePropsSrc,
147
+ sharedPolyfills
148
+ });
149
+ //# sourceMappingURL=polyfill.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/shared/client/polyfill.tsx"],"sourcesContent":["import type { LinkProps } from 'next/link';\nimport type { ImageProps, StaticImageData } from 'next/image';\n\nfunction applyBundleUrlToSrc(bundle: string, src: string) {\n const self = globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n };\n\n if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {\n return src;\n }\n\n const { assetPrefix, path } =\n /^(?<assetPrefix>.*?)\\/_next\\/(?<path>.*)/.exec(src)?.groups ?? {};\n if (!path) {\n return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;\n }\n return `${\n self.__remote_bundle_url__?.[bundle]?.origin ?? ''\n }${assetPrefix}/_next/${path}`;\n}\n\nexport function applyBundleUrlToImagePropsSrc(\n bundle: string,\n src: ImageProps['src'],\n) {\n if (typeof src === 'string') {\n return applyBundleUrlToSrc(bundle, src);\n }\n const propSrc = src as StaticImageData;\n return applyBundleUrlToSrc(bundle, propSrc.src);\n}\n\nconst imageImpl = (bundle: string) =>\n function RemoteImage({ priority: _, ...props }: ImageProps) {\n const newSrc = applyBundleUrlToImagePropsSrc(\n bundle,\n typeof props.src === 'string'\n ? props.src\n : (props.src as StaticImageData).src,\n );\n return (\n // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text\n <img\n decoding=\"async\"\n style={{ color: 'transparent' }}\n {...props}\n src={newSrc}\n suppressHydrationWarning\n />\n );\n };\n\n// polyfill Next.js App Router client API (minimal)\n// implementations are minimal and do not cover all use cases\n// developer can override these shared modules from configuration\nexport function sharedPolyfills(\n shared?: Record<string, () => Promise<unknown>>,\n) {\n const self = globalThis as typeof globalThis & {\n __remote_component_host_shared_modules__?: Record<\n string,\n () => Promise<unknown>\n >;\n };\n const polyfill = {\n 'next/dist/client/components/navigation':\n self.__remote_component_host_shared_modules__?.['next/navigation'] ??\n shared?.['next/navigation'] ??\n (() =>\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n useSearchParams() {\n return new URLSearchParams(location.search);\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/link':\n self.__remote_component_host_shared_modules__?.['next/link'] ??\n shared?.['next/link'] ??\n (() =>\n Promise.resolve({\n default: ({\n children,\n ...props\n }: React.PropsWithChildren<LinkProps>) => (\n <a {...props} href={props.href as string} suppressHydrationWarning>\n {children ?? null}\n </a>\n ),\n __esModule: true,\n })),\n 'next/dist/client/app-dir/form':\n self.__remote_component_host_shared_modules__?.['next/form'] ??\n shared?.['next/form'] ??\n (() =>\n Promise.resolve({\n default: () => {\n // TODO: implement <Form> component for non-Next.js host applications\n throw new Error('Next.js <Form> component not implemented');\n },\n __esModule: true,\n })),\n 'next/dist/client/image-component':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n Image: imageImpl(bundle),\n __esModule: true,\n })),\n 'next/image':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n default: imageImpl(bundle),\n getImageProps: (_imgProps: ImageProps) => {\n throw new Error(\n 'Next.js getImageProps() is not implemented in remote components',\n );\n },\n __esModule: true,\n })),\n 'next/dist/client/script':\n self.__remote_component_host_shared_modules__?.['next/script'] ??\n shared?.['next/script'] ??\n (() =>\n Promise.resolve({\n // TODO: implement <Script> component for non-Next.js host applications\n // do not throw an error for now\n default: () => null,\n __esModule: true,\n })),\n 'next/router':\n self.__remote_component_host_shared_modules__?.['next/router'] ??\n shared?.['next/router'] ??\n (() =>\n // TODO: incomplete implementation\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n __esModule: true,\n })),\n } as Record<string, () => Promise<unknown>>;\n\n polyfill['next/navigation'] = polyfill[\n 'next/dist/client/components/navigation'\n ] as () => Promise<unknown>;\n polyfill['next/link'] = polyfill[\n 'next/dist/client/app-dir/link'\n ] as () => Promise<unknown>;\n polyfill['next/form'] = polyfill[\n 'next/dist/client/app-dir/form'\n ] as () => Promise<unknown>;\n polyfill['next/dist/api/image'] = polyfill[\n 'next/dist/client/image-component'\n ] as () => Promise<unknown>;\n polyfill['next/script'] = polyfill[\n 'next/dist/client/script'\n ] as () => Promise<unknown>;\n\n return polyfill;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2CM;AAAA;AAAA;AAAA;AAxCN,SAAS,oBAAoB,QAAgB,KAAa;AACxD,QAAM,OAAO;AAIb,MAAI,KAAK,wBAAwB,MAAM,GAAG,WAAW,SAAS,QAAQ;AACpE,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,aAAa,KAAK,IACxB,2CAA2C,KAAK,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,aAAa,CAAC,GAAG,IAAI,SAAS;AAAA,YACxC;AAAA,YACA,MAAM,MAAM;AACV,sBAAQ,KAAK;AAAA,YACf;AAAA,UACF;AAAA,QACF;AAAA,QACA,YAAY;AAAA,MACd,CAAC;AAAA;AAAA,EACP;AAEA,WAAS,iBAAiB,IAAI,SAC5B,wCACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,qBAAqB,IAAI,SAChC,kCACF;AACA,WAAS,aAAa,IAAI,SACxB,yBACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,6 @@
1
+ import { ImageProps } from 'next/image';
2
+
3
+ declare function applyBundleUrlToImagePropsSrc(bundle: string, src: ImageProps['src']): string;
4
+ declare function sharedPolyfills(shared?: Record<string, () => Promise<unknown>>): Record<string, () => Promise<unknown>>;
5
+
6
+ export { applyBundleUrlToImagePropsSrc, sharedPolyfills };
@@ -0,0 +1,124 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ function applyBundleUrlToSrc(bundle, src) {
3
+ const self = globalThis;
4
+ if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {
5
+ return src;
6
+ }
7
+ const { assetPrefix, path } = /^(?<assetPrefix>.*?)\/_next\/(?<path>.*)/.exec(src)?.groups ?? {};
8
+ if (!path) {
9
+ return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;
10
+ }
11
+ return `${self.__remote_bundle_url__?.[bundle]?.origin ?? ""}${assetPrefix}/_next/${path}`;
12
+ }
13
+ function applyBundleUrlToImagePropsSrc(bundle, src) {
14
+ if (typeof src === "string") {
15
+ return applyBundleUrlToSrc(bundle, src);
16
+ }
17
+ const propSrc = src;
18
+ return applyBundleUrlToSrc(bundle, propSrc.src);
19
+ }
20
+ const imageImpl = (bundle) => function RemoteImage({ priority: _, ...props }) {
21
+ const newSrc = applyBundleUrlToImagePropsSrc(
22
+ bundle,
23
+ typeof props.src === "string" ? props.src : props.src.src
24
+ );
25
+ return (
26
+ // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
27
+ /* @__PURE__ */ jsx(
28
+ "img",
29
+ {
30
+ decoding: "async",
31
+ style: { color: "transparent" },
32
+ ...props,
33
+ src: newSrc,
34
+ suppressHydrationWarning: true
35
+ }
36
+ )
37
+ );
38
+ };
39
+ function sharedPolyfills(shared) {
40
+ const self = globalThis;
41
+ const polyfill = {
42
+ "next/dist/client/components/navigation": self.__remote_component_host_shared_modules__?.["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
43
+ useRouter() {
44
+ return {
45
+ push: (routerUrl) => {
46
+ history.pushState({}, "", routerUrl);
47
+ },
48
+ replace: (routerUrl) => {
49
+ history.replaceState({}, "", routerUrl);
50
+ },
51
+ back: () => {
52
+ history.back();
53
+ }
54
+ };
55
+ },
56
+ useSearchParams() {
57
+ return new URLSearchParams(location.search);
58
+ },
59
+ __esModule: true
60
+ })),
61
+ "next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
62
+ default: ({
63
+ children,
64
+ ...props
65
+ }) => /* @__PURE__ */ jsx("a", { ...props, href: props.href, suppressHydrationWarning: true, children: children ?? null }),
66
+ __esModule: true
67
+ })),
68
+ "next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
69
+ default: () => {
70
+ throw new Error("Next.js <Form> component not implemented");
71
+ },
72
+ __esModule: true
73
+ })),
74
+ "next/dist/client/image-component": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
75
+ Image: imageImpl(bundle),
76
+ __esModule: true
77
+ })),
78
+ "next/image": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
79
+ default: imageImpl(bundle),
80
+ getImageProps: (_imgProps) => {
81
+ throw new Error(
82
+ "Next.js getImageProps() is not implemented in remote components"
83
+ );
84
+ },
85
+ __esModule: true
86
+ })),
87
+ "next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
88
+ // TODO: implement <Script> component for non-Next.js host applications
89
+ // do not throw an error for now
90
+ default: () => null,
91
+ __esModule: true
92
+ })),
93
+ "next/router": self.__remote_component_host_shared_modules__?.["next/router"] ?? shared?.["next/router"] ?? (() => (
94
+ // TODO: incomplete implementation
95
+ Promise.resolve({
96
+ useRouter() {
97
+ return {
98
+ push: (routerUrl) => {
99
+ history.pushState({}, "", routerUrl);
100
+ },
101
+ replace: (routerUrl) => {
102
+ history.replaceState({}, "", routerUrl);
103
+ },
104
+ back: () => {
105
+ history.back();
106
+ }
107
+ };
108
+ },
109
+ __esModule: true
110
+ })
111
+ ))
112
+ };
113
+ polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
114
+ polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
115
+ polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
116
+ polyfill["next/dist/api/image"] = polyfill["next/dist/client/image-component"];
117
+ polyfill["next/script"] = polyfill["next/dist/client/script"];
118
+ return polyfill;
119
+ }
120
+ export {
121
+ applyBundleUrlToImagePropsSrc,
122
+ sharedPolyfills
123
+ };
124
+ //# sourceMappingURL=polyfill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/shared/client/polyfill.tsx"],"sourcesContent":["import type { LinkProps } from 'next/link';\nimport type { ImageProps, StaticImageData } from 'next/image';\n\nfunction applyBundleUrlToSrc(bundle: string, src: string) {\n const self = globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n };\n\n if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {\n return src;\n }\n\n const { assetPrefix, path } =\n /^(?<assetPrefix>.*?)\\/_next\\/(?<path>.*)/.exec(src)?.groups ?? {};\n if (!path) {\n return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;\n }\n return `${\n self.__remote_bundle_url__?.[bundle]?.origin ?? ''\n }${assetPrefix}/_next/${path}`;\n}\n\nexport function applyBundleUrlToImagePropsSrc(\n bundle: string,\n src: ImageProps['src'],\n) {\n if (typeof src === 'string') {\n return applyBundleUrlToSrc(bundle, src);\n }\n const propSrc = src as StaticImageData;\n return applyBundleUrlToSrc(bundle, propSrc.src);\n}\n\nconst imageImpl = (bundle: string) =>\n function RemoteImage({ priority: _, ...props }: ImageProps) {\n const newSrc = applyBundleUrlToImagePropsSrc(\n bundle,\n typeof props.src === 'string'\n ? props.src\n : (props.src as StaticImageData).src,\n );\n return (\n // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text\n <img\n decoding=\"async\"\n style={{ color: 'transparent' }}\n {...props}\n src={newSrc}\n suppressHydrationWarning\n />\n );\n };\n\n// polyfill Next.js App Router client API (minimal)\n// implementations are minimal and do not cover all use cases\n// developer can override these shared modules from configuration\nexport function sharedPolyfills(\n shared?: Record<string, () => Promise<unknown>>,\n) {\n const self = globalThis as typeof globalThis & {\n __remote_component_host_shared_modules__?: Record<\n string,\n () => Promise<unknown>\n >;\n };\n const polyfill = {\n 'next/dist/client/components/navigation':\n self.__remote_component_host_shared_modules__?.['next/navigation'] ??\n shared?.['next/navigation'] ??\n (() =>\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n useSearchParams() {\n return new URLSearchParams(location.search);\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/link':\n self.__remote_component_host_shared_modules__?.['next/link'] ??\n shared?.['next/link'] ??\n (() =>\n Promise.resolve({\n default: ({\n children,\n ...props\n }: React.PropsWithChildren<LinkProps>) => (\n <a {...props} href={props.href as string} suppressHydrationWarning>\n {children ?? null}\n </a>\n ),\n __esModule: true,\n })),\n 'next/dist/client/app-dir/form':\n self.__remote_component_host_shared_modules__?.['next/form'] ??\n shared?.['next/form'] ??\n (() =>\n Promise.resolve({\n default: () => {\n // TODO: implement <Form> component for non-Next.js host applications\n throw new Error('Next.js <Form> component not implemented');\n },\n __esModule: true,\n })),\n 'next/dist/client/image-component':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n Image: imageImpl(bundle),\n __esModule: true,\n })),\n 'next/image':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n default: imageImpl(bundle),\n getImageProps: (_imgProps: ImageProps) => {\n throw new Error(\n 'Next.js getImageProps() is not implemented in remote components',\n );\n },\n __esModule: true,\n })),\n 'next/dist/client/script':\n self.__remote_component_host_shared_modules__?.['next/script'] ??\n shared?.['next/script'] ??\n (() =>\n Promise.resolve({\n // TODO: implement <Script> component for non-Next.js host applications\n // do not throw an error for now\n default: () => null,\n __esModule: true,\n })),\n 'next/router':\n self.__remote_component_host_shared_modules__?.['next/router'] ??\n shared?.['next/router'] ??\n (() =>\n // TODO: incomplete implementation\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n __esModule: true,\n })),\n } as Record<string, () => Promise<unknown>>;\n\n polyfill['next/navigation'] = polyfill[\n 'next/dist/client/components/navigation'\n ] as () => Promise<unknown>;\n polyfill['next/link'] = polyfill[\n 'next/dist/client/app-dir/link'\n ] as () => Promise<unknown>;\n polyfill['next/form'] = polyfill[\n 'next/dist/client/app-dir/form'\n ] as () => Promise<unknown>;\n polyfill['next/dist/api/image'] = polyfill[\n 'next/dist/client/image-component'\n ] as () => Promise<unknown>;\n polyfill['next/script'] = polyfill[\n 'next/dist/client/script'\n ] as () => Promise<unknown>;\n\n return polyfill;\n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AAa,KAC7D,SAAS,aAAa,MACrB;AAAA;AAAA,MAEC,QAAQ,QAAQ;AAAA,QACd,YAAY;AACV,iBAAO;AAAA,YACL,MAAM,CAAC,cAAsB;AAC3B,sBAAQ,UAAU,CAAC,GAAG,IAAI,SAAS;AAAA,YACrC;AAAA,YACA,SAAS,CAAC,cAAsB;AAC9B,sBAAQ,aAAa,CAAC,GAAG,IAAI,SAAS;AAAA,YACxC;AAAA,YACA,MAAM,MAAM;AACV,sBAAQ,KAAK;AAAA,YACf;AAAA,UACF;AAAA,QACF;AAAA,QACA,YAAY;AAAA,MACd,CAAC;AAAA;AAAA,EACP;AAEA,WAAS,iBAAiB,IAAI,SAC5B,wCACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,qBAAqB,IAAI,SAChC,kCACF;AACA,WAAS,aAAa,IAAI,SACxB,yBACF;AAEA,SAAO;AACT;","names":[]}
@@ -401,7 +401,7 @@ function initializeSharedModules(bundle, shared = {}, remoteShared = {}) {
401
401
  Object.entries(remoteShared).map(async ([id, module2]) => {
402
402
  if (self.__remote_shared_modules__?.[bundle]) {
403
403
  if (shared[module2]) {
404
- self.__remote_shared_modules__[bundle][id.replace("[app-ssr]", "[app-client]")] = await shared[module2]();
404
+ self.__remote_shared_modules__[bundle][id.replace("[app-ssr]", "[app-client]")] = await shared[module2](bundle);
405
405
  } else {
406
406
  console.error(`Shared module "${module2}" not found for "${bundle}".`);
407
407
  }
@@ -414,7 +414,7 @@ function getSharedModule(bundle, id) {
414
414
  for (const [key, value] of Object.entries(
415
415
  self.__remote_shared_modules__?.[bundle] ?? {}
416
416
  )) {
417
- if (typeof id === "string" && id.includes(key) || id === key) {
417
+ if (typeof value !== "undefined" && (typeof id === "string" && id.includes(key) || id === key)) {
418
418
  return value;
419
419
  }
420
420
  }
@@ -686,7 +686,7 @@ async function loadRemoteComponent({
686
686
  await Promise.all(
687
687
  Object.entries(resolve).map(async ([key, value]) => {
688
688
  if (typeof value === "function") {
689
- resolve[key] = await value();
689
+ resolve[key] = await value(bundle);
690
690
  }
691
691
  return Promise.resolve(value);
692
692
  })