remote-components 0.0.33 → 0.0.35
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.
- package/dist/{component-loader-28ad0083.d.ts → component-loader-8951c052.d.ts} +6 -4
- package/dist/html/host.cjs +353 -129
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +353 -129
- package/dist/html/host.js.map +1 -1
- package/dist/html/remote.cjs +199 -0
- package/dist/html/remote.cjs.map +1 -0
- package/dist/html/remote.d.ts +2 -0
- package/dist/html/remote.js +198 -0
- package/dist/html/remote.js.map +1 -0
- package/dist/internal/next/host/app-router-client.cjs +60 -19
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.d.ts +3 -3
- package/dist/internal/next/host/app-router-client.js +65 -23
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/next/host/app-router-compat.cjs.map +1 -1
- package/dist/internal/next/host/app-router-compat.d.ts +1 -1
- package/dist/internal/next/host/app-router-compat.js.map +1 -1
- package/dist/internal/next/remote/render-server.cjs +1 -1
- package/dist/internal/next/remote/render-server.cjs.map +1 -1
- package/dist/internal/next/remote/render-server.js +1 -1
- package/dist/internal/next/remote/render-server.js.map +1 -1
- package/dist/internal/shared/client/polyfill.cjs.map +1 -1
- package/dist/internal/shared/client/polyfill.js.map +1 -1
- package/dist/internal/shared/client/remote-component.cjs +237 -133
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +29 -22
- package/dist/internal/shared/client/remote-component.js +235 -133
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/error.cjs +1 -1
- package/dist/internal/shared/error.cjs.map +1 -1
- package/dist/internal/shared/error.d.ts +1 -1
- package/dist/internal/shared/error.js +1 -1
- package/dist/internal/shared/error.js.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.cjs +24 -8
- package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
- package/dist/internal/shared/ssr/dom-flight.js +24 -8
- package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.cjs +8 -4
- package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.d.ts +2 -1
- package/dist/internal/shared/ssr/fetch-remote-component.js +9 -5
- package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
- package/dist/next/config.cjs +100 -86
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +100 -86
- package/dist/next/config.js.map +1 -1
- package/dist/next/host/app-router-server.cjs +1 -0
- package/dist/next/host/app-router-server.cjs.map +1 -1
- package/dist/next/host/app-router-server.js +2 -1
- package/dist/next/host/app-router-server.js.map +1 -1
- package/dist/next/host/client/index.cjs +1381 -1187
- package/dist/next/host/client/index.cjs.map +1 -1
- package/dist/next/host/client/index.d.ts +1 -1
- package/dist/next/host/client/index.js +682 -490
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs +4 -4
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.js +4 -4
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/next/{middleware.cjs → proxy.cjs} +24 -14
- package/dist/next/proxy.cjs.map +1 -0
- package/dist/next/proxy.d.ts +29 -0
- package/dist/next/{middleware.js → proxy.js} +21 -11
- package/dist/next/proxy.js.map +1 -0
- package/dist/react/index.cjs +201 -107
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +206 -112
- package/dist/react/index.js.map +1 -1
- package/dist/{types-7c207455.d.ts → types-4e7dea94.d.ts} +2 -1
- package/dist/{types-e4a3fa37.d.ts → types-cbf6c34f.d.ts} +2 -2
- package/package.json +22 -9
- package/dist/next/middleware.cjs.map +0 -1
- package/dist/next/middleware.d.ts +0 -29
- package/dist/next/middleware.js.map +0 -1
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __esm = (fn, res) => function __init() {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
};
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/shared/error.ts
|
|
13
|
+
var RemoteComponentsError;
|
|
14
|
+
var init_error = __esm({
|
|
15
|
+
"src/shared/error.ts"() {
|
|
16
|
+
"use strict";
|
|
17
|
+
RemoteComponentsError = class extends Error {
|
|
18
|
+
code = "REMOTE_COMPONENTS_ERROR";
|
|
19
|
+
constructor(message, options) {
|
|
20
|
+
super(message, options);
|
|
21
|
+
this.name = "RemoteComponentsError";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// src/shared/client/static-loader.ts
|
|
28
|
+
var static_loader_exports = {};
|
|
29
|
+
__export(static_loader_exports, {
|
|
30
|
+
loadStaticRemoteComponent: () => loadStaticRemoteComponent
|
|
31
|
+
});
|
|
32
|
+
async function loadStaticRemoteComponent(scripts, url) {
|
|
33
|
+
const self = globalThis;
|
|
34
|
+
if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
35
|
+
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
36
|
+
}
|
|
37
|
+
if (self.__remote_script_entrypoint_unmount__?.[url.href]) {
|
|
38
|
+
self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
|
|
39
|
+
}
|
|
40
|
+
const mountUnmountSets = await Promise.all(
|
|
41
|
+
scripts.map(async (script) => {
|
|
42
|
+
try {
|
|
43
|
+
let src = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
|
|
44
|
+
if (!src && script.textContent) {
|
|
45
|
+
const blob = new Blob(
|
|
46
|
+
[
|
|
47
|
+
script.textContent.replace(
|
|
48
|
+
/import\.meta\.url/g,
|
|
49
|
+
JSON.stringify(url)
|
|
50
|
+
)
|
|
51
|
+
],
|
|
52
|
+
{
|
|
53
|
+
type: "text/javascript"
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
src = URL.createObjectURL(blob);
|
|
57
|
+
}
|
|
58
|
+
const mod = await import(
|
|
59
|
+
/* @vite-ignore */
|
|
60
|
+
/* webpackIgnore: true */
|
|
61
|
+
new URL(src, url).href
|
|
62
|
+
);
|
|
63
|
+
if (src.startsWith("blob:")) {
|
|
64
|
+
URL.revokeObjectURL(src);
|
|
65
|
+
}
|
|
66
|
+
if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
|
|
67
|
+
if (!self.__remote_script_entrypoint_mount__) {
|
|
68
|
+
self.__remote_script_entrypoint_mount__ = {};
|
|
69
|
+
}
|
|
70
|
+
if (!self.__remote_script_entrypoint_mount__[url.href]) {
|
|
71
|
+
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
72
|
+
}
|
|
73
|
+
self.__remote_script_entrypoint_mount__[url.href]?.add(
|
|
74
|
+
mod.mount || mod.default?.mount || (() => {
|
|
75
|
+
})
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
|
|
79
|
+
if (!self.__remote_script_entrypoint_unmount__) {
|
|
80
|
+
self.__remote_script_entrypoint_unmount__ = {};
|
|
81
|
+
}
|
|
82
|
+
if (!self.__remote_script_entrypoint_unmount__[url.href]) {
|
|
83
|
+
self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
|
|
84
|
+
}
|
|
85
|
+
self.__remote_script_entrypoint_unmount__[url.href]?.add(
|
|
86
|
+
mod.unmount || mod.default?.unmount || (() => {
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
mount: mod.mount || mod.default?.mount,
|
|
92
|
+
unmount: mod.unmount || mod.default?.unmount
|
|
93
|
+
};
|
|
94
|
+
} catch (e) {
|
|
95
|
+
console.error(
|
|
96
|
+
new RemoteComponentsError(
|
|
97
|
+
`Error loading remote component script from "${script.src || url.href}".`,
|
|
98
|
+
{ cause: e }
|
|
99
|
+
)
|
|
100
|
+
);
|
|
101
|
+
return {
|
|
102
|
+
mount: void 0,
|
|
103
|
+
unmount: void 0
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
);
|
|
108
|
+
return mountUnmountSets.reduce(
|
|
109
|
+
(acc, { mount, unmount }) => {
|
|
110
|
+
if (typeof mount === "function") {
|
|
111
|
+
acc.mount.add(mount);
|
|
112
|
+
}
|
|
113
|
+
if (typeof unmount === "function") {
|
|
114
|
+
acc.unmount.add(unmount);
|
|
115
|
+
}
|
|
116
|
+
return acc;
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
mount: /* @__PURE__ */ new Set(),
|
|
120
|
+
unmount: /* @__PURE__ */ new Set()
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
var init_static_loader = __esm({
|
|
125
|
+
"src/shared/client/static-loader.ts"() {
|
|
126
|
+
"use strict";
|
|
127
|
+
init_error();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// src/html/remote/index.tsx
|
|
132
|
+
init_error();
|
|
133
|
+
if (typeof HTMLElement !== "undefined") {
|
|
134
|
+
class RemoteComponent extends HTMLElement {
|
|
135
|
+
name;
|
|
136
|
+
root = null;
|
|
137
|
+
unmount = null;
|
|
138
|
+
constructor() {
|
|
139
|
+
super();
|
|
140
|
+
const html = this.innerHTML;
|
|
141
|
+
this.root = this.attachShadow({
|
|
142
|
+
mode: this.getAttribute("mode") === "closed" ? "closed" : "open"
|
|
143
|
+
});
|
|
144
|
+
this.root.innerHTML = html;
|
|
145
|
+
(async () => {
|
|
146
|
+
const { loadStaticRemoteComponent: loadStaticRemoteComponent2 } = await Promise.resolve().then(() => (init_static_loader(), static_loader_exports));
|
|
147
|
+
loadStaticRemoteComponent2(
|
|
148
|
+
Array.from(this.root?.querySelectorAll("script") ?? []),
|
|
149
|
+
new URL(location.href)
|
|
150
|
+
).then(({ mount, unmount }) => {
|
|
151
|
+
this.unmount = unmount;
|
|
152
|
+
return Promise.all(
|
|
153
|
+
Array.from(mount).map((mountFn) => mountFn(this.root))
|
|
154
|
+
);
|
|
155
|
+
}).catch((e) => {
|
|
156
|
+
console.error(
|
|
157
|
+
new RemoteComponentsError("Error mounting remote component.", {
|
|
158
|
+
cause: e
|
|
159
|
+
})
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
})().catch((e) => {
|
|
163
|
+
console.error(
|
|
164
|
+
new RemoteComponentsError("Error mounting remote component.", {
|
|
165
|
+
cause: e
|
|
166
|
+
})
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
disconnectedCallback() {
|
|
171
|
+
(async () => {
|
|
172
|
+
if (this.unmount) {
|
|
173
|
+
await Promise.all(
|
|
174
|
+
Array.from(this.unmount).map(async (unmount) => {
|
|
175
|
+
try {
|
|
176
|
+
await unmount(this.root);
|
|
177
|
+
} catch (e) {
|
|
178
|
+
console.error(
|
|
179
|
+
new RemoteComponentsError(
|
|
180
|
+
"Error unmounting remote component.",
|
|
181
|
+
{ cause: e }
|
|
182
|
+
)
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
})().catch((e) => {
|
|
189
|
+
console.error(
|
|
190
|
+
new RemoteComponentsError("Error unmounting remote component.", {
|
|
191
|
+
cause: e
|
|
192
|
+
})
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
customElements.define("remote-component", RemoteComponent);
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=remote.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shared/error.ts","../../src/shared/client/static-loader.ts","../../src/html/remote/index.tsx"],"sourcesContent":["export class RemoteComponentsError extends Error {\n code = 'REMOTE_COMPONENTS_ERROR';\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = 'RemoteComponentsError';\n }\n}\n\nexport function multipleRemoteComponentsError(url: string | undefined) {\n return new Error(\n `Multiple Remote Components found at \"${url}\". When a page exposes multiple Remote Components you must specify the \"name\" prop to select which one to load.`,\n );\n}\n\nexport function failedToFetchRemoteComponentError(url: string, error: unknown) {\n return new RemoteComponentsError(\n `Failed to fetch Remote Component from \"${url}\". Is the URL correct and accessible?`,\n { cause: error instanceof Error ? error : new Error(String(error)) },\n );\n}\n","import { RemoteComponentsError } from '../error';\nimport type {\n MountOrUnmountFunction,\n RemoteComponentMountUnmount,\n} from './types';\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n) {\n const self = globalThis as typeof globalThis & RemoteComponentMountUnmount;\n if (self.__remote_script_entrypoint_mount__?.[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n if (self.__remote_script_entrypoint_unmount__?.[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n let src =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n // if there's no src attribute but there is inline script content, create a blob URL for it\n if (!src && script.textContent) {\n const blob = new Blob(\n [\n script.textContent.replace(\n /import\\.meta\\.url/g,\n JSON.stringify(url),\n ),\n ],\n {\n type: 'text/javascript',\n },\n );\n src = URL.createObjectURL(blob);\n }\n const mod = (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ new URL(src, url).href\n )) as {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n };\n // revoke the object URL if we created one\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_mount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_mount__ = {};\n }\n if (!self.__remote_script_entrypoint_mount__[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_mount__[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_unmount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_unmount__ = {};\n }\n if (!self.__remote_script_entrypoint_unmount__[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_unmount__[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(\n `Error loading remote component script from \"${script.src || url.href}\".`,\n { cause: e },\n ),\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmountFunction>(),\n },\n );\n}\n","import type { MountOrUnmountFunction } from '../../shared/client/types';\nimport { RemoteComponentsError } from '../../shared/error';\n\nif (typeof HTMLElement !== 'undefined') {\n class RemoteComponent extends HTMLElement {\n name?: string;\n root?: ShadowRoot | null = null;\n unmount?: Set<MountOrUnmountFunction> | null = null;\n\n constructor() {\n super();\n\n const html = this.innerHTML;\n this.root = this.attachShadow({\n mode: this.getAttribute('mode') === 'closed' ? 'closed' : 'open',\n });\n this.root.innerHTML = html;\n\n // run the mount functions for any scripts inside the shadow root asynchronously\n (async () => {\n const { loadStaticRemoteComponent } = await import(\n '../../shared/client/static-loader'\n );\n loadStaticRemoteComponent(\n Array.from(this.root?.querySelectorAll('script') ?? []),\n new URL(location.href),\n )\n .then(({ mount, unmount }) => {\n this.unmount = unmount;\n return Promise.all(\n Array.from(mount).map((mountFn) => mountFn(this.root)),\n );\n })\n .catch((e) => {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError('Error mounting remote component.', {\n cause: e,\n }),\n );\n });\n })().catch((e) => {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError('Error mounting remote component.', {\n cause: e,\n }),\n );\n });\n }\n\n disconnectedCallback() {\n // run the unmount functions for any scripts inside the shadow root asynchronously\n (async () => {\n if (this.unmount) {\n await Promise.all(\n Array.from(this.unmount).map(async (unmount) => {\n try {\n await unmount(this.root);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(\n 'Error unmounting remote component.',\n { cause: e },\n ),\n );\n }\n }),\n );\n }\n })().catch((e) => {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError('Error unmounting remote component.', {\n cause: e,\n }),\n );\n });\n }\n }\n\n // register the custom element\n customElements.define('remote-component', RemoteComponent);\n}\n"],"mappings":";;;;;;;;;;;;AAAA,IAAa;AAAb;AAAA;AAAA;AAAO,IAAM,wBAAN,cAAoC,MAAM;AAAA,MAC/C,OAAO;AAAA,MAEP,YAAY,SAAiB,SAA+B;AAC1D,cAAM,SAAS,OAAO;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AAA,YACF,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF,GAAG,EAAE,MAAM,CAAC,MAAM;AAEhB,gBAAQ;AAAA,UACN,IAAI,sBAAsB,sCAAsC;AAAA,YAC9D,OAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAGA,iBAAe,OAAO,oBAAoB,eAAe;AAC3D;","names":["loadStaticRemoteComponent"]}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __esm = (fn, res) => function __init() {
|
|
4
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
|
+
};
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/shared/error.ts
|
|
12
|
+
var RemoteComponentsError;
|
|
13
|
+
var init_error = __esm({
|
|
14
|
+
"src/shared/error.ts"() {
|
|
15
|
+
"use strict";
|
|
16
|
+
RemoteComponentsError = class extends Error {
|
|
17
|
+
code = "REMOTE_COMPONENTS_ERROR";
|
|
18
|
+
constructor(message, options) {
|
|
19
|
+
super(message, options);
|
|
20
|
+
this.name = "RemoteComponentsError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// src/shared/client/static-loader.ts
|
|
27
|
+
var static_loader_exports = {};
|
|
28
|
+
__export(static_loader_exports, {
|
|
29
|
+
loadStaticRemoteComponent: () => loadStaticRemoteComponent
|
|
30
|
+
});
|
|
31
|
+
async function loadStaticRemoteComponent(scripts, url) {
|
|
32
|
+
const self = globalThis;
|
|
33
|
+
if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
34
|
+
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
35
|
+
}
|
|
36
|
+
if (self.__remote_script_entrypoint_unmount__?.[url.href]) {
|
|
37
|
+
self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
|
|
38
|
+
}
|
|
39
|
+
const mountUnmountSets = await Promise.all(
|
|
40
|
+
scripts.map(async (script) => {
|
|
41
|
+
try {
|
|
42
|
+
let src = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
|
|
43
|
+
if (!src && script.textContent) {
|
|
44
|
+
const blob = new Blob(
|
|
45
|
+
[
|
|
46
|
+
script.textContent.replace(
|
|
47
|
+
/import\.meta\.url/g,
|
|
48
|
+
JSON.stringify(url)
|
|
49
|
+
)
|
|
50
|
+
],
|
|
51
|
+
{
|
|
52
|
+
type: "text/javascript"
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
src = URL.createObjectURL(blob);
|
|
56
|
+
}
|
|
57
|
+
const mod = await import(
|
|
58
|
+
/* @vite-ignore */
|
|
59
|
+
/* webpackIgnore: true */
|
|
60
|
+
new URL(src, url).href
|
|
61
|
+
);
|
|
62
|
+
if (src.startsWith("blob:")) {
|
|
63
|
+
URL.revokeObjectURL(src);
|
|
64
|
+
}
|
|
65
|
+
if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
|
|
66
|
+
if (!self.__remote_script_entrypoint_mount__) {
|
|
67
|
+
self.__remote_script_entrypoint_mount__ = {};
|
|
68
|
+
}
|
|
69
|
+
if (!self.__remote_script_entrypoint_mount__[url.href]) {
|
|
70
|
+
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
71
|
+
}
|
|
72
|
+
self.__remote_script_entrypoint_mount__[url.href]?.add(
|
|
73
|
+
mod.mount || mod.default?.mount || (() => {
|
|
74
|
+
})
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
|
|
78
|
+
if (!self.__remote_script_entrypoint_unmount__) {
|
|
79
|
+
self.__remote_script_entrypoint_unmount__ = {};
|
|
80
|
+
}
|
|
81
|
+
if (!self.__remote_script_entrypoint_unmount__[url.href]) {
|
|
82
|
+
self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
|
|
83
|
+
}
|
|
84
|
+
self.__remote_script_entrypoint_unmount__[url.href]?.add(
|
|
85
|
+
mod.unmount || mod.default?.unmount || (() => {
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
mount: mod.mount || mod.default?.mount,
|
|
91
|
+
unmount: mod.unmount || mod.default?.unmount
|
|
92
|
+
};
|
|
93
|
+
} catch (e) {
|
|
94
|
+
console.error(
|
|
95
|
+
new RemoteComponentsError(
|
|
96
|
+
`Error loading remote component script from "${script.src || url.href}".`,
|
|
97
|
+
{ cause: e }
|
|
98
|
+
)
|
|
99
|
+
);
|
|
100
|
+
return {
|
|
101
|
+
mount: void 0,
|
|
102
|
+
unmount: void 0
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
);
|
|
107
|
+
return mountUnmountSets.reduce(
|
|
108
|
+
(acc, { mount, unmount }) => {
|
|
109
|
+
if (typeof mount === "function") {
|
|
110
|
+
acc.mount.add(mount);
|
|
111
|
+
}
|
|
112
|
+
if (typeof unmount === "function") {
|
|
113
|
+
acc.unmount.add(unmount);
|
|
114
|
+
}
|
|
115
|
+
return acc;
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
mount: /* @__PURE__ */ new Set(),
|
|
119
|
+
unmount: /* @__PURE__ */ new Set()
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
var init_static_loader = __esm({
|
|
124
|
+
"src/shared/client/static-loader.ts"() {
|
|
125
|
+
"use strict";
|
|
126
|
+
init_error();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// src/html/remote/index.tsx
|
|
131
|
+
init_error();
|
|
132
|
+
if (typeof HTMLElement !== "undefined") {
|
|
133
|
+
class RemoteComponent extends HTMLElement {
|
|
134
|
+
name;
|
|
135
|
+
root = null;
|
|
136
|
+
unmount = null;
|
|
137
|
+
constructor() {
|
|
138
|
+
super();
|
|
139
|
+
const html = this.innerHTML;
|
|
140
|
+
this.root = this.attachShadow({
|
|
141
|
+
mode: this.getAttribute("mode") === "closed" ? "closed" : "open"
|
|
142
|
+
});
|
|
143
|
+
this.root.innerHTML = html;
|
|
144
|
+
(async () => {
|
|
145
|
+
const { loadStaticRemoteComponent: loadStaticRemoteComponent2 } = await Promise.resolve().then(() => (init_static_loader(), static_loader_exports));
|
|
146
|
+
loadStaticRemoteComponent2(
|
|
147
|
+
Array.from(this.root?.querySelectorAll("script") ?? []),
|
|
148
|
+
new URL(location.href)
|
|
149
|
+
).then(({ mount, unmount }) => {
|
|
150
|
+
this.unmount = unmount;
|
|
151
|
+
return Promise.all(
|
|
152
|
+
Array.from(mount).map((mountFn) => mountFn(this.root))
|
|
153
|
+
);
|
|
154
|
+
}).catch((e) => {
|
|
155
|
+
console.error(
|
|
156
|
+
new RemoteComponentsError("Error mounting remote component.", {
|
|
157
|
+
cause: e
|
|
158
|
+
})
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
})().catch((e) => {
|
|
162
|
+
console.error(
|
|
163
|
+
new RemoteComponentsError("Error mounting remote component.", {
|
|
164
|
+
cause: e
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
disconnectedCallback() {
|
|
170
|
+
(async () => {
|
|
171
|
+
if (this.unmount) {
|
|
172
|
+
await Promise.all(
|
|
173
|
+
Array.from(this.unmount).map(async (unmount) => {
|
|
174
|
+
try {
|
|
175
|
+
await unmount(this.root);
|
|
176
|
+
} catch (e) {
|
|
177
|
+
console.error(
|
|
178
|
+
new RemoteComponentsError(
|
|
179
|
+
"Error unmounting remote component.",
|
|
180
|
+
{ cause: e }
|
|
181
|
+
)
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
})().catch((e) => {
|
|
188
|
+
console.error(
|
|
189
|
+
new RemoteComponentsError("Error unmounting remote component.", {
|
|
190
|
+
cause: e
|
|
191
|
+
})
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
customElements.define("remote-component", RemoteComponent);
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=remote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shared/error.ts","../../src/shared/client/static-loader.ts","../../src/html/remote/index.tsx"],"sourcesContent":["export class RemoteComponentsError extends Error {\n code = 'REMOTE_COMPONENTS_ERROR';\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = 'RemoteComponentsError';\n }\n}\n\nexport function multipleRemoteComponentsError(url: string | undefined) {\n return new Error(\n `Multiple Remote Components found at \"${url}\". When a page exposes multiple Remote Components you must specify the \"name\" prop to select which one to load.`,\n );\n}\n\nexport function failedToFetchRemoteComponentError(url: string, error: unknown) {\n return new RemoteComponentsError(\n `Failed to fetch Remote Component from \"${url}\". Is the URL correct and accessible?`,\n { cause: error instanceof Error ? error : new Error(String(error)) },\n );\n}\n","import { RemoteComponentsError } from '../error';\nimport type {\n MountOrUnmountFunction,\n RemoteComponentMountUnmount,\n} from './types';\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n) {\n const self = globalThis as typeof globalThis & RemoteComponentMountUnmount;\n if (self.__remote_script_entrypoint_mount__?.[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n if (self.__remote_script_entrypoint_unmount__?.[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n let src =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n // if there's no src attribute but there is inline script content, create a blob URL for it\n if (!src && script.textContent) {\n const blob = new Blob(\n [\n script.textContent.replace(\n /import\\.meta\\.url/g,\n JSON.stringify(url),\n ),\n ],\n {\n type: 'text/javascript',\n },\n );\n src = URL.createObjectURL(blob);\n }\n const mod = (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ new URL(src, url).href\n )) as {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n };\n // revoke the object URL if we created one\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_mount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_mount__ = {};\n }\n if (!self.__remote_script_entrypoint_mount__[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_mount__[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_unmount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_unmount__ = {};\n }\n if (!self.__remote_script_entrypoint_unmount__[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_unmount__[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(\n `Error loading remote component script from \"${script.src || url.href}\".`,\n { cause: e },\n ),\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmountFunction>(),\n },\n );\n}\n","import type { MountOrUnmountFunction } from '../../shared/client/types';\nimport { RemoteComponentsError } from '../../shared/error';\n\nif (typeof HTMLElement !== 'undefined') {\n class RemoteComponent extends HTMLElement {\n name?: string;\n root?: ShadowRoot | null = null;\n unmount?: Set<MountOrUnmountFunction> | null = null;\n\n constructor() {\n super();\n\n const html = this.innerHTML;\n this.root = this.attachShadow({\n mode: this.getAttribute('mode') === 'closed' ? 'closed' : 'open',\n });\n this.root.innerHTML = html;\n\n // run the mount functions for any scripts inside the shadow root asynchronously\n (async () => {\n const { loadStaticRemoteComponent } = await import(\n '../../shared/client/static-loader'\n );\n loadStaticRemoteComponent(\n Array.from(this.root?.querySelectorAll('script') ?? []),\n new URL(location.href),\n )\n .then(({ mount, unmount }) => {\n this.unmount = unmount;\n return Promise.all(\n Array.from(mount).map((mountFn) => mountFn(this.root)),\n );\n })\n .catch((e) => {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError('Error mounting remote component.', {\n cause: e,\n }),\n );\n });\n })().catch((e) => {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError('Error mounting remote component.', {\n cause: e,\n }),\n );\n });\n }\n\n disconnectedCallback() {\n // run the unmount functions for any scripts inside the shadow root asynchronously\n (async () => {\n if (this.unmount) {\n await Promise.all(\n Array.from(this.unmount).map(async (unmount) => {\n try {\n await unmount(this.root);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(\n 'Error unmounting remote component.',\n { cause: e },\n ),\n );\n }\n }),\n );\n }\n })().catch((e) => {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError('Error unmounting remote component.', {\n cause: e,\n }),\n );\n });\n }\n }\n\n // register the custom element\n customElements.define('remote-component', RemoteComponent);\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAa;AAAb;AAAA;AAAA;AAAO,IAAM,wBAAN,cAAoC,MAAM;AAAA,MAC/C,OAAO;AAAA,MAEP,YAAY,SAAiB,SAA+B;AAC1D,cAAM,SAAS,OAAO;AACtB,aAAK,OAAO;AAAA,MACd;AAAA,IACF;AAAA;AAAA;;;ACPA;AAAA;AAAA;AAAA;AAMA,eAAsB,0BACpB,SACA,KACA;AACA,QAAM,OAAO;AACb,MAAI,KAAK,qCAAqC,IAAI,IAAI,GAAG;AACvD,SAAK,mCAAmC,IAAI,IAAI,IAAI,oBAAI,IAAI;AAAA,EAC9D;AACA,MAAI,KAAK,uCAAuC,IAAI,IAAI,GAAG;AACzD,SAAK,qCAAqC,IAAI,IAAI,IAAI,oBAAI,IAAI;AAAA,EAChE;AACA,QAAM,mBAAmB,MAAM,QAAQ;AAAA,IACrC,QAAQ,IAAI,OAAO,WAAW;AAC5B,UAAI;AACF,YAAI,MACF,OAAO,OAAO,iBAAiB,aAC1B,OAAO,aAAa,KAAK,KAAK,OAAO,MACtC,OAAO;AAEb,YAAI,CAAC,OAAO,OAAO,aAAa;AAC9B,gBAAM,OAAO,IAAI;AAAA,YACf;AAAA,cACE,OAAO,YAAY;AAAA,gBACjB;AAAA,gBACA,KAAK,UAAU,GAAG;AAAA,cACpB;AAAA,YACF;AAAA,YACA;AAAA,cACE,MAAM;AAAA,YACR;AAAA,UACF;AACA,gBAAM,IAAI,gBAAgB,IAAI;AAAA,QAChC;AACA,cAAM,MAAO,MAAM;AAAA;AAAA;AAAA,UAES,IAAI,IAAI,KAAK,GAAG,EAAE;AAAA;AAU9C,YAAI,IAAI,WAAW,OAAO,GAAG;AAC3B,cAAI,gBAAgB,GAAG;AAAA,QACzB;AACA,YACE,OAAO,IAAI,UAAU,cACrB,OAAO,IAAI,SAAS,UAAU,YAC9B;AACA,cAAI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ACZ,MAAM,KAAK,KAAK,OAAO,EAAE,IAAI,OAAO,YAAY;AAC9C,kBAAI;AACF,sBAAM,QAAQ,KAAK,IAAI;AAAA,cACzB,SAAS,GAAP;AAEA,wBAAQ;AAAA,kBACN,IAAI;AAAA,oBACF;AAAA,oBACA,EAAE,OAAO,EAAE;AAAA,kBACb;AAAA,gBACF;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF,GAAG,EAAE,MAAM,CAAC,MAAM;AAEhB,gBAAQ;AAAA,UACN,IAAI,sBAAsB,sCAAsC;AAAA,YAC9D,OAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAGA,iBAAe,OAAO,oBAAoB,eAAe;AAC3D;","names":["loadStaticRemoteComponent"]}
|
|
@@ -33,11 +33,11 @@ __export(app_router_client_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(app_router_client_exports);
|
|
35
35
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
var Image = __toESM(require("next/image"), 1);
|
|
36
37
|
var import_react = require("react");
|
|
37
38
|
var import_react_dom = require("react-dom");
|
|
38
|
-
var Image = __toESM(require("next/image"), 1);
|
|
39
|
-
var import_remote_component = require("#internal/shared/client/remote-component");
|
|
40
39
|
var import_app_router_compat = require("#internal/next/host/app-router-compat");
|
|
40
|
+
var import_remote_component = require("#internal/shared/client/remote-component");
|
|
41
41
|
var import_utils = require("#internal/shared/utils");
|
|
42
42
|
async function tryImportShared() {
|
|
43
43
|
try {
|
|
@@ -61,6 +61,7 @@ function RemoteComponentClient({
|
|
|
61
61
|
isolate,
|
|
62
62
|
mode = "open",
|
|
63
63
|
reset,
|
|
64
|
+
type,
|
|
64
65
|
children
|
|
65
66
|
}) {
|
|
66
67
|
const remoteComponentId = (0, import_react.useId)();
|
|
@@ -72,10 +73,13 @@ function RemoteComponentClient({
|
|
|
72
73
|
url,
|
|
73
74
|
loading: false
|
|
74
75
|
});
|
|
76
|
+
const startRef = (0, import_react.useRef)(null);
|
|
77
|
+
const endRef = (0, import_react.useRef)(null);
|
|
78
|
+
const prevRemoteComponentUnmountRef = (0, import_react.useRef)(null);
|
|
75
79
|
if (component instanceof Error) {
|
|
76
80
|
throw component;
|
|
77
81
|
}
|
|
78
|
-
const shouldUseChildren = (!component || component && !nextData && typeof component.then !== "function") && // if the remote Next.js Pages Router application is in development mode
|
|
82
|
+
const shouldUseChildren = (!component || component && !nextData && type !== "remote-component" && typeof component.then !== "function") && // if the remote Next.js Pages Router application is in development mode
|
|
79
83
|
// we don't use the provided static HTML
|
|
80
84
|
// to mitigate layout shift when loading CSS using JavaScript on the client
|
|
81
85
|
nextData?.buildId !== "development";
|
|
@@ -150,17 +154,24 @@ function RemoteComponentClient({
|
|
|
150
154
|
});
|
|
151
155
|
}
|
|
152
156
|
}
|
|
153
|
-
}, [
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
157
|
+
}, [isolate, mode, self, shadowRootKey, shouldUseChildren]);
|
|
158
|
+
(0, import_react.useEffect)(() => {
|
|
159
|
+
if (prevRemoteComponentUnmountRef.current && component !== children) {
|
|
160
|
+
const { unmount, root } = prevRemoteComponentUnmountRef.current;
|
|
161
|
+
prevRemoteComponentUnmountRef.current = null;
|
|
162
|
+
Promise.all(
|
|
163
|
+
Array.from(unmount).map(async (unmountFn) => {
|
|
164
|
+
try {
|
|
165
|
+
await unmountFn(root);
|
|
166
|
+
} catch (e) {
|
|
167
|
+
console.error(e);
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
).catch((e) => {
|
|
171
|
+
console.error(e);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}, [component, children]);
|
|
164
175
|
(0, import_react.useEffect)(() => {
|
|
165
176
|
(0, import_react.startTransition)(async () => {
|
|
166
177
|
try {
|
|
@@ -172,6 +183,36 @@ function RemoteComponentClient({
|
|
|
172
183
|
url,
|
|
173
184
|
loading: true
|
|
174
185
|
};
|
|
186
|
+
if (type === "remote-component") {
|
|
187
|
+
setComponent(children);
|
|
188
|
+
(0, import_remote_component.loadStaticRemoteComponent)(
|
|
189
|
+
scripts,
|
|
190
|
+
new URL(url, location.origin)
|
|
191
|
+
).then(({ mount, unmount }) => {
|
|
192
|
+
if (mount.size > 0) {
|
|
193
|
+
let root = shadowRootRef.current;
|
|
194
|
+
try {
|
|
195
|
+
if (!root && startRef.current && endRef.current) {
|
|
196
|
+
root = document.querySelectorAll(
|
|
197
|
+
`#${startRef.current.id} ~ *:not(#${endRef.current.id}):has(~ #${endRef.current.id})`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
} catch (e) {
|
|
201
|
+
console.error(e);
|
|
202
|
+
}
|
|
203
|
+
if (unmount.size > 0) {
|
|
204
|
+
prevRemoteComponentUnmountRef.current = { unmount, root };
|
|
205
|
+
}
|
|
206
|
+
return Promise.all(
|
|
207
|
+
Array.from(mount).map((mountFn) => mountFn(root))
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
}).catch((e) => {
|
|
211
|
+
console.error(e);
|
|
212
|
+
setComponent(e);
|
|
213
|
+
});
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
175
216
|
const rscName = `__remote_components_rsc_${(0, import_utils.escapeString)(new URL(url).href)}_${(0, import_utils.escapeString)(name)}`;
|
|
176
217
|
const result = await (0, import_remote_component.loadRemoteComponent)({
|
|
177
218
|
url: new URL(url, location.origin),
|
|
@@ -222,8 +263,8 @@ function RemoteComponentClient({
|
|
|
222
263
|
nextData,
|
|
223
264
|
remoteShared,
|
|
224
265
|
children,
|
|
225
|
-
|
|
226
|
-
|
|
266
|
+
isolate,
|
|
267
|
+
type
|
|
227
268
|
]);
|
|
228
269
|
if (nextData?.buildId === "development" && shadowRootRef.current && isolate !== false && reset && !shadowRootRef.current.querySelector("[data-remote-components-reset]")) {
|
|
229
270
|
const style = document.createElement("style");
|
|
@@ -278,7 +319,7 @@ function RemoteComponentClient({
|
|
|
278
319
|
JSON.stringify(link)
|
|
279
320
|
))
|
|
280
321
|
] });
|
|
281
|
-
let componentToRender = shouldUseChildren ?
|
|
322
|
+
let componentToRender = shouldUseChildren ? children : component;
|
|
282
323
|
if (isolate !== false) {
|
|
283
324
|
componentToRender = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
284
325
|
"div",
|
|
@@ -323,7 +364,7 @@ function RemoteComponentClient({
|
|
|
323
364
|
);
|
|
324
365
|
}
|
|
325
366
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
326
|
-
isolate === false ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { id: `${name}_start
|
|
367
|
+
isolate === false ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { id: `${name}_start`, ref: startRef }) : null,
|
|
327
368
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
|
|
328
369
|
name,
|
|
329
370
|
bundle,
|
|
@@ -340,7 +381,7 @@ function RemoteComponentClient({
|
|
|
340
381
|
children: JSON.stringify(nextData)
|
|
341
382
|
}
|
|
342
383
|
) : null,
|
|
343
|
-
isolate === false ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { id: `${name}_end
|
|
384
|
+
isolate === false ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { id: `${name}_end`, ref: endRef }) : null
|
|
344
385
|
] });
|
|
345
386
|
}
|
|
346
387
|
// Annotate the CommonJS export names for ESM import in node:
|