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.
- package/dist/html/host.cjs +345 -80
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +347 -79
- package/dist/html/host.js.map +1 -1
- package/dist/internal/next/host/app-router-client.cjs +205 -58
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.d.ts +2 -2
- package/dist/internal/next/host/app-router-client.js +213 -59
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/next/host/app-router-compat.cjs +114 -0
- package/dist/internal/next/host/app-router-compat.cjs.map +1 -0
- package/dist/internal/next/host/app-router-compat.d.ts +31 -0
- package/dist/internal/next/host/app-router-compat.js +79 -0
- package/dist/internal/next/host/app-router-compat.js.map +1 -0
- package/dist/internal/next/remote/render-client.cjs +10 -2
- package/dist/internal/next/remote/render-client.cjs.map +1 -1
- package/dist/internal/next/remote/render-client.js +10 -2
- package/dist/internal/next/remote/render-client.js.map +1 -1
- package/dist/internal/shared/client/apply-origin.cjs +61 -0
- package/dist/internal/shared/client/apply-origin.cjs.map +1 -0
- package/dist/internal/shared/client/apply-origin.d.ts +3 -0
- package/dist/internal/shared/client/apply-origin.js +37 -0
- package/dist/internal/shared/client/apply-origin.js.map +1 -0
- package/dist/internal/shared/client/polyfill.cjs +149 -0
- package/dist/internal/shared/client/polyfill.cjs.map +1 -0
- package/dist/internal/shared/client/polyfill.d.ts +6 -0
- package/dist/internal/shared/client/polyfill.js +124 -0
- package/dist/internal/shared/client/polyfill.js.map +1 -0
- package/dist/internal/shared/client/remote-component.cjs +3 -3
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +3 -1
- package/dist/internal/shared/client/remote-component.js +3 -3
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.cjs +49 -17
- package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.js +49 -17
- package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.cjs +3 -2
- package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.d.ts +6 -0
- package/dist/internal/shared/ssr/fetch-remote-component.js +3 -2
- package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
- package/dist/next/config.cjs +50 -28
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +50 -28
- package/dist/next/config.js.map +1 -1
- package/dist/next/host/app-router-server.cjs +4 -0
- package/dist/next/host/app-router-server.cjs.map +1 -1
- package/dist/next/host/app-router-server.d.ts +5 -1
- package/dist/next/host/app-router-server.js +4 -0
- package/dist/next/host/app-router-server.js.map +1 -1
- package/dist/next/host/client/index.cjs +16 -1
- 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 +16 -1
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs +37 -16
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.d.ts +3 -0
- package/dist/next/host/pages-router-server.js +37 -16
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/next/middleware.cjs +5 -2
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +1 -0
- package/dist/next/middleware.js +5 -2
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/remote/pages-router.cjs +3 -1
- package/dist/next/remote/pages-router.cjs.map +1 -1
- package/dist/next/remote/pages-router.d.ts +1 -0
- package/dist/next/remote/pages-router.js +3 -1
- package/dist/next/remote/pages-router.js.map +1 -1
- package/dist/react/index.cjs +235 -156
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +7 -3
- package/dist/react/index.js +225 -146
- package/dist/react/index.js.map +1 -1
- package/dist/{types-7425dfe1.d.ts → types-b8210fd3.d.ts} +2 -0
- package/package.json +1 -1
package/dist/react/index.cjs
CHANGED
|
@@ -23,13 +23,16 @@ __export(react_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(react_exports);
|
|
24
24
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
25
|
var import_react = require("react");
|
|
26
|
+
var import_react2 = require("react");
|
|
26
27
|
var import_react_dom = require("react-dom");
|
|
27
28
|
var import_remote_component = require("#internal/shared/client/remote-component");
|
|
29
|
+
var import_polyfill = require("#internal/shared/client/polyfill");
|
|
30
|
+
var import_apply_origin = require("#internal/shared/client/apply-origin");
|
|
28
31
|
function getRemoteComponentHtml(html) {
|
|
29
32
|
if (typeof document === "undefined")
|
|
30
33
|
return html;
|
|
31
|
-
const
|
|
32
|
-
temp
|
|
34
|
+
const parser = new DOMParser();
|
|
35
|
+
const temp = parser.parseFromString(html, "text/html");
|
|
33
36
|
const ssrRemoteComponentContainer = temp.querySelector(
|
|
34
37
|
'div[id^="__REMOTE_COMPONENT"]'
|
|
35
38
|
);
|
|
@@ -44,15 +47,21 @@ function getRemoteComponentHtml(html) {
|
|
|
44
47
|
}
|
|
45
48
|
return "";
|
|
46
49
|
}
|
|
50
|
+
const attrToProp = {
|
|
51
|
+
fetchpriority: "fetchPriority",
|
|
52
|
+
crossorigin: "crossOrigin"
|
|
53
|
+
};
|
|
47
54
|
function RemoteComponent({
|
|
48
55
|
src,
|
|
49
56
|
isolate,
|
|
57
|
+
mode = "open",
|
|
58
|
+
reset,
|
|
50
59
|
credentials = "same-origin",
|
|
51
60
|
name: nameProp = "__vercel_remote_component",
|
|
52
61
|
shared = {},
|
|
53
62
|
children
|
|
54
63
|
}) {
|
|
55
|
-
const name = (0,
|
|
64
|
+
const name = (0, import_react2.useMemo)(() => {
|
|
56
65
|
if (typeof src === "string") {
|
|
57
66
|
const url2 = new URL(
|
|
58
67
|
src,
|
|
@@ -66,21 +75,25 @@ function RemoteComponent({
|
|
|
66
75
|
}
|
|
67
76
|
return nameProp;
|
|
68
77
|
}, [src, nameProp]);
|
|
69
|
-
const [data, setData] = (0,
|
|
70
|
-
const [remoteComponent, setRemoteComponent] = (0,
|
|
71
|
-
const shadowRootContainerRef = (0,
|
|
72
|
-
const [shadowRoot, setShadowRoot] = (0,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
const [data, setData] = (0, import_react2.useState)(null);
|
|
79
|
+
const [remoteComponent, setRemoteComponent] = (0, import_react2.useState)(null);
|
|
80
|
+
const shadowRootContainerRef = (0, import_react2.useRef)(null);
|
|
81
|
+
const [shadowRoot, setShadowRoot] = (0, import_react2.useState)(() => {
|
|
82
|
+
const self = globalThis;
|
|
83
|
+
const shadowRootKey = `__remote_components_shadowroot_${src ? new URL(src, typeof location !== "undefined" ? location.origin : "http://localhost").href.replace(/[^a-z0-9]/g, "_") : ""}_${(data?.name ?? name).replace(/[^a-z0-9]/g, "_")}`;
|
|
84
|
+
const ssrShadowRoot = typeof document !== "undefined" ? document.querySelector(
|
|
85
|
+
`[data-remote-component-id="shadowroot_${src ? new URL(src, typeof location !== "undefined" ? location.origin : "http://localhost").href.replace(/[^a-z0-9]/g, "_") : ""}_${(data?.name ?? name).replace(/[^a-z0-9]/g, "_")}"]`
|
|
86
|
+
)?.shadowRoot ?? self[shadowRootKey] ?? null : null;
|
|
87
|
+
self[shadowRootKey] = null;
|
|
88
|
+
return ssrShadowRoot;
|
|
89
|
+
});
|
|
90
|
+
const htmlRef = (0, import_react2.useRef)(
|
|
91
|
+
typeof document !== "undefined" ? document.querySelector(
|
|
92
|
+
`[data-remote-component-id="shadowroot_${src ? new URL(src, typeof location !== "undefined" ? location.origin : "http://localhost").href.replace(/[^a-z0-9]/g, "_") : ""}_${(data?.name ?? name).replace(/[^a-z0-9]/g, "_")}"]`
|
|
93
|
+
)?.shadowRoot?.innerHTML ?? document.getElementById(`__REMOTE_COMPONENT${name}`)?.innerHTML ?? document.querySelector(`div[data-bundle][data-route][id^="${name}"]`)?.innerHTML ?? document.querySelector("div[data-bundle][data-route]")?.innerHTML : null
|
|
81
94
|
);
|
|
82
|
-
const endTemplateRef = (0,
|
|
83
|
-
const childrenRef = (0,
|
|
95
|
+
const endTemplateRef = (0, import_react2.useRef)(null);
|
|
96
|
+
const childrenRef = (0, import_react2.useRef)(
|
|
84
97
|
typeof document !== "undefined" ? (() => {
|
|
85
98
|
let el = document.querySelector(`template[id="${name}_start"]`);
|
|
86
99
|
const elements = [];
|
|
@@ -93,7 +106,8 @@ function RemoteComponent({
|
|
|
93
106
|
return elements;
|
|
94
107
|
})() : []
|
|
95
108
|
);
|
|
96
|
-
(0,
|
|
109
|
+
const prevSrcRef = (0, import_react2.useRef)(null);
|
|
110
|
+
(0, import_react2.useLayoutEffect)(() => {
|
|
97
111
|
if (childrenRef.current.length > 0 && remoteComponent) {
|
|
98
112
|
childrenRef.current.forEach((el) => {
|
|
99
113
|
el.remove();
|
|
@@ -101,12 +115,19 @@ function RemoteComponent({
|
|
|
101
115
|
childrenRef.current = [];
|
|
102
116
|
}
|
|
103
117
|
if (isolate !== false && typeof document !== "undefined" && !shadowRoot) {
|
|
118
|
+
const self = globalThis;
|
|
119
|
+
const shadowRootKey = `__remote_components_shadowroot_${src ? new URL(src, typeof location !== "undefined" ? location.origin : "http://localhost").href.replace(/[^a-z0-9]/g, "_") : ""}_${(data?.name ?? name).replace(/[^a-z0-9]/g, "_")}`;
|
|
104
120
|
let shadowRootElement = null;
|
|
105
|
-
const element = document.
|
|
106
|
-
|
|
121
|
+
const element = document.querySelector(
|
|
122
|
+
`[data-remote-component-id="shadowroot_${src ? new URL(src, typeof location !== "undefined" ? location.origin : "http://localhost").href.replace(/[^a-z0-9]/g, "_") : ""}_${(data?.name ?? name).replace(/[^a-z0-9]/g, "_")}"]`
|
|
123
|
+
);
|
|
124
|
+
shadowRootElement = self[shadowRootKey] ?? element?.shadowRoot ?? null;
|
|
107
125
|
if (!shadowRootElement && element) {
|
|
108
|
-
|
|
109
|
-
|
|
126
|
+
try {
|
|
127
|
+
shadowRootElement = element.attachShadow({ mode });
|
|
128
|
+
self[shadowRootKey] = shadowRootElement;
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
110
131
|
}
|
|
111
132
|
if (shadowRootElement) {
|
|
112
133
|
shadowRootElement.querySelectorAll("*:not(link)").forEach((node) => {
|
|
@@ -115,8 +136,31 @@ function RemoteComponent({
|
|
|
115
136
|
setShadowRoot(shadowRootElement);
|
|
116
137
|
}
|
|
117
138
|
}
|
|
118
|
-
}, [name, isolate, shadowRoot, remoteComponent]);
|
|
119
|
-
|
|
139
|
+
}, [name, isolate, shadowRoot, remoteComponent, mode, src, data]);
|
|
140
|
+
(0, import_react2.useLayoutEffect)(() => {
|
|
141
|
+
if (shadowRoot && remoteComponent) {
|
|
142
|
+
const resetStyles = shadowRoot.querySelectorAll(
|
|
143
|
+
"style[data-remote-components-reset]"
|
|
144
|
+
);
|
|
145
|
+
if (resetStyles.length > 1) {
|
|
146
|
+
resetStyles.forEach((style, index) => {
|
|
147
|
+
if (index > 0) {
|
|
148
|
+
style.remove();
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
htmlRef.current = null;
|
|
153
|
+
let el = shadowRoot.childNodes[0] ?? null;
|
|
154
|
+
while (el && (!("id" in el) || el.id !== `${name}_start`)) {
|
|
155
|
+
const nextEl = el.nextSibling;
|
|
156
|
+
if (el.nodeName !== "LINK" && el.nodeName !== "STYLE") {
|
|
157
|
+
el.parentNode?.removeChild(el);
|
|
158
|
+
}
|
|
159
|
+
el = nextEl;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}, [shadowRoot, remoteComponent, name]);
|
|
163
|
+
const url = (0, import_react2.useMemo)(() => {
|
|
120
164
|
if (typeof src !== "string")
|
|
121
165
|
return new URL(
|
|
122
166
|
typeof document !== "undefined" ? location.href : "http://localhost"
|
|
@@ -127,116 +171,130 @@ function RemoteComponent({
|
|
|
127
171
|
return new URL(src, "http://localhost");
|
|
128
172
|
}
|
|
129
173
|
}, [src]);
|
|
130
|
-
(0,
|
|
174
|
+
(0, import_react2.useEffect)(() => {
|
|
131
175
|
let mounted = true;
|
|
132
|
-
(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
176
|
+
if (src && src !== prevSrcRef.current) {
|
|
177
|
+
prevSrcRef.current = src;
|
|
178
|
+
(0, import_react2.startTransition)(async () => {
|
|
179
|
+
try {
|
|
180
|
+
let html = getRemoteComponentHtml(
|
|
181
|
+
htmlRef.current ?? (endTemplateRef.current?.previousElementSibling?.tagName === "div" ? endTemplateRef.current.previousElementSibling.innerHTML : "")
|
|
182
|
+
);
|
|
183
|
+
if (!html && src) {
|
|
184
|
+
const fetchInit = {
|
|
185
|
+
method: "GET",
|
|
186
|
+
headers: {
|
|
187
|
+
Accept: "text/html"
|
|
188
|
+
},
|
|
189
|
+
credentials
|
|
190
|
+
};
|
|
191
|
+
const res = await fetch(url, fetchInit);
|
|
192
|
+
if (!res.ok) {
|
|
193
|
+
throw new Error(
|
|
194
|
+
`Failed to fetch remote component "${name}": ${res.status}`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
const remoteHtml = await res.text();
|
|
198
|
+
htmlRef.current = remoteHtml;
|
|
199
|
+
html = getRemoteComponentHtml(remoteHtml);
|
|
200
|
+
}
|
|
201
|
+
const parser = new DOMParser();
|
|
202
|
+
const doc = parser.parseFromString(html, "text/html");
|
|
203
|
+
const component = doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) ?? // fallback to the first element with the data-bundle and data-route attributes when not using a named remote component
|
|
204
|
+
doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
|
|
205
|
+
doc.querySelector("div#__next");
|
|
206
|
+
const nextData = JSON.parse(
|
|
207
|
+
(doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
|
|
208
|
+
);
|
|
209
|
+
const remoteName = component?.getAttribute("id")?.replace(/_ssr$/, "") || (nextData ? "__next" : name);
|
|
210
|
+
const rsc = doc.querySelector(`#${remoteName}_rsc`);
|
|
211
|
+
const bundle = component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default";
|
|
212
|
+
const metadata = {
|
|
213
|
+
name: remoteName,
|
|
214
|
+
bundle,
|
|
215
|
+
route: component?.getAttribute("data-route") ?? nextData?.page ?? import_remote_component.DEFAULT_ROUTE,
|
|
216
|
+
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || import_remote_component.RUNTIME_WEBPACK)
|
|
144
217
|
};
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
218
|
+
const remoteSharedEl = doc.querySelector(
|
|
219
|
+
`#${remoteName}_shared[data-remote-components-shared]`
|
|
220
|
+
);
|
|
221
|
+
const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
|
|
222
|
+
remoteSharedEl?.remove();
|
|
223
|
+
if (!component || !(rsc || nextData)) {
|
|
224
|
+
throw new Error(`Failed to find component with id "${remoteName}"`);
|
|
150
225
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
type: "application/javascript"
|
|
203
|
-
});
|
|
204
|
-
const blobUrl = URL.createObjectURL(blob);
|
|
205
|
-
newScript.onload = () => {
|
|
206
|
-
resolve(void 0);
|
|
207
|
-
URL.revokeObjectURL(blobUrl);
|
|
208
|
-
newScript.remove();
|
|
209
|
-
};
|
|
210
|
-
newScript.onerror = () => {
|
|
211
|
-
URL.revokeObjectURL(blobUrl);
|
|
212
|
-
newScript.remove();
|
|
226
|
+
(0, import_apply_origin.applyOriginToNodes)(doc, url);
|
|
227
|
+
const links = Array.from(
|
|
228
|
+
doc.querySelectorAll("link[href]")
|
|
229
|
+
).filter((link) => {
|
|
230
|
+
return !component.contains(link);
|
|
231
|
+
}).map((link) => ({
|
|
232
|
+
href: new URL(link.getAttribute("href") ?? link.href, url).href,
|
|
233
|
+
...link.getAttributeNames().reduce((acc, key) => {
|
|
234
|
+
if (key !== "href") {
|
|
235
|
+
acc[attrToProp[key] ?? key] = link.getAttribute(key) ?? "";
|
|
236
|
+
}
|
|
237
|
+
return acc;
|
|
238
|
+
}, {})
|
|
239
|
+
}));
|
|
240
|
+
const scripts = doc.querySelectorAll(
|
|
241
|
+
"script[src],script[data-src]"
|
|
242
|
+
);
|
|
243
|
+
const inlineScripts = doc.querySelectorAll(
|
|
244
|
+
"script:not([src]):not([data-src]):not([id*='_rsc']):not([id='__NEXT_DATA__']):not([id='__REMOTE_NEXT_DATA__'])"
|
|
245
|
+
);
|
|
246
|
+
const self = globalThis;
|
|
247
|
+
const prevNextScripts = self.__next_s;
|
|
248
|
+
const nextScripts = [];
|
|
249
|
+
self.__next_s = nextScripts;
|
|
250
|
+
await Promise.all(
|
|
251
|
+
Array.from(inlineScripts).filter(
|
|
252
|
+
(script) => !(script.id.endsWith("_shared") && script.getAttribute("type") === "application/json" && typeof script.getAttribute(
|
|
253
|
+
"data-remote-components-shared"
|
|
254
|
+
) === "string")
|
|
255
|
+
).map((script) => {
|
|
256
|
+
return new Promise((resolve) => {
|
|
257
|
+
if (script.textContent && !script.textContent.includes("self.__next_f=") && !script.textContent.includes("self.__next_f.push")) {
|
|
258
|
+
if (!script.getAttribute("type") || script.getAttribute("type") === "text/javascript" || script.getAttribute("type") === "application/javascript") {
|
|
259
|
+
const newScript = document.createElement("script");
|
|
260
|
+
const blob = new Blob([script.textContent], {
|
|
261
|
+
type: "application/javascript"
|
|
262
|
+
});
|
|
263
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
264
|
+
newScript.onload = () => {
|
|
265
|
+
resolve(void 0);
|
|
266
|
+
URL.revokeObjectURL(blobUrl);
|
|
267
|
+
newScript.remove();
|
|
268
|
+
};
|
|
269
|
+
newScript.onerror = () => {
|
|
270
|
+
URL.revokeObjectURL(blobUrl);
|
|
271
|
+
newScript.remove();
|
|
272
|
+
resolve(void 0);
|
|
273
|
+
};
|
|
274
|
+
newScript.src = blobUrl;
|
|
275
|
+
document.body.appendChild(newScript);
|
|
276
|
+
} else {
|
|
213
277
|
resolve(void 0);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
document.body.appendChild(newScript);
|
|
278
|
+
document.body.appendChild(script);
|
|
279
|
+
}
|
|
217
280
|
} else {
|
|
218
281
|
resolve(void 0);
|
|
219
|
-
document.body.appendChild(script);
|
|
220
282
|
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
document.head.appendChild(script);
|
|
237
|
-
});
|
|
238
|
-
self.__next_s = prevNextScripts;
|
|
239
|
-
if (mounted) {
|
|
283
|
+
});
|
|
284
|
+
})
|
|
285
|
+
);
|
|
286
|
+
nextScripts.forEach(([scriptSrc, props]) => {
|
|
287
|
+
const script = document.createElement("script");
|
|
288
|
+
if (scriptSrc) {
|
|
289
|
+
script.src = scriptSrc;
|
|
290
|
+
}
|
|
291
|
+
if (typeof props.children === "string") {
|
|
292
|
+
script.textContent = props.children;
|
|
293
|
+
}
|
|
294
|
+
(0, import_remote_component.setAttributesFromProps)(script, props);
|
|
295
|
+
document.head.appendChild(script);
|
|
296
|
+
});
|
|
297
|
+
self.__next_s = prevNextScripts;
|
|
240
298
|
if (rsc) {
|
|
241
299
|
document.body.appendChild(rsc);
|
|
242
300
|
}
|
|
@@ -247,6 +305,7 @@ function RemoteComponent({
|
|
|
247
305
|
url: url.href,
|
|
248
306
|
data: rsc ? (rsc.textContent || "").split("\n").filter(Boolean) : []
|
|
249
307
|
};
|
|
308
|
+
const userShared = await shared;
|
|
250
309
|
const result = await (0, import_remote_component.loadRemoteComponent)({
|
|
251
310
|
url: new URL(url, location.origin),
|
|
252
311
|
name: remoteName,
|
|
@@ -273,25 +332,29 @@ function RemoteComponent({
|
|
|
273
332
|
).href
|
|
274
333
|
};
|
|
275
334
|
}),
|
|
276
|
-
shared
|
|
335
|
+
shared: {
|
|
336
|
+
...(0, import_polyfill.sharedPolyfills)(userShared),
|
|
337
|
+
...userShared
|
|
338
|
+
},
|
|
277
339
|
remoteShared,
|
|
278
340
|
container: shadowRoot
|
|
279
341
|
});
|
|
342
|
+
if (rsc) {
|
|
343
|
+
rsc.remove();
|
|
344
|
+
}
|
|
345
|
+
setData(newData);
|
|
346
|
+
if (result.error) {
|
|
347
|
+
setRemoteComponent(result.error);
|
|
348
|
+
} else {
|
|
349
|
+
setRemoteComponent(result.component);
|
|
350
|
+
}
|
|
351
|
+
} catch (error) {
|
|
280
352
|
if (mounted) {
|
|
281
|
-
|
|
282
|
-
if (result.error) {
|
|
283
|
-
setRemoteComponent(result.error);
|
|
284
|
-
} else {
|
|
285
|
-
setRemoteComponent(result.component);
|
|
286
|
-
}
|
|
353
|
+
setRemoteComponent(error);
|
|
287
354
|
}
|
|
288
355
|
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
setRemoteComponent(error);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
});
|
|
356
|
+
});
|
|
357
|
+
}
|
|
295
358
|
return () => {
|
|
296
359
|
mounted = false;
|
|
297
360
|
};
|
|
@@ -305,50 +368,65 @@ function RemoteComponent({
|
|
|
305
368
|
route: data?.route || import_remote_component.DEFAULT_ROUTE,
|
|
306
369
|
runtime: data?.runtime || import_remote_component.RUNTIME_WEBPACK
|
|
307
370
|
}) });
|
|
308
|
-
const
|
|
371
|
+
const resetStyle = reset ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { "data-remote-components-reset": "", children: `:host { all: initial; }` }) : null;
|
|
372
|
+
const linksToRender = data?.links?.map((link) => /* @__PURE__ */ (0, import_react.createElement)(
|
|
309
373
|
"link",
|
|
310
374
|
{
|
|
311
|
-
|
|
375
|
+
...link,
|
|
312
376
|
href: new URL(link.href, url).href,
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
`${link.href}_${link.rel}`
|
|
377
|
+
key: JSON.stringify(link)
|
|
378
|
+
}
|
|
316
379
|
)) || null;
|
|
317
380
|
const componentToRender = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
381
|
+
resetStyle,
|
|
318
382
|
linksToRender,
|
|
319
383
|
remoteComponent ?? children
|
|
320
384
|
] });
|
|
321
385
|
if (isolate !== false) {
|
|
322
|
-
const shadowRemoteComponentHtml = shadowRoot?.querySelector(
|
|
323
|
-
`#__REMOTE_COMPONENT${name}`
|
|
324
|
-
);
|
|
386
|
+
const shadowRemoteComponentHtml = shadowRoot?.querySelector(`#__REMOTE_COMPONENT${name}`) ?? shadowRoot?.querySelector("div[data-bundle][data-route]");
|
|
325
387
|
if (shadowRemoteComponentHtml) {
|
|
326
388
|
shadowRemoteComponentHtml.remove();
|
|
327
389
|
}
|
|
328
|
-
if (shadowRoot && remoteComponent && htmlRef.current) {
|
|
329
|
-
const content = shadowRoot.querySelectorAll(":not(link,style)");
|
|
330
|
-
content.forEach((node) => node.remove());
|
|
331
|
-
htmlRef.current = null;
|
|
332
|
-
}
|
|
333
390
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
334
391
|
metadataJson,
|
|
335
392
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
336
393
|
"div",
|
|
337
394
|
{
|
|
338
|
-
id: `shadowroot_${src ? new URL(src, typeof location !== "undefined" ? location.origin : "http://localhost").href.replace(/[^a-z0-9]/g, "_") : ""}_${data?.name ?? name}`,
|
|
395
|
+
"data-remote-component-id": `shadowroot_${src ? new URL(src, typeof location !== "undefined" ? location.origin : "http://localhost").href.replace(/[^a-z0-9]/g, "_") : ""}_${(data?.name ?? name).replace(/[^a-z0-9]/g, "_")}`,
|
|
396
|
+
id: `shadowroot_${data?.name ?? name}`,
|
|
339
397
|
ref: shadowRootContainerRef,
|
|
340
398
|
children: [
|
|
341
399
|
typeof document === "undefined" ? (
|
|
342
400
|
// eslint-disable-next-line react/no-unknown-property
|
|
343
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("template", { shadowrootmode:
|
|
401
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("template", { shadowrootmode: mode, children: [
|
|
402
|
+
typeof document === "undefined" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
403
|
+
"div",
|
|
404
|
+
{
|
|
405
|
+
dangerouslySetInnerHTML: {
|
|
406
|
+
__html: `<img
|
|
407
|
+
alt="" decoding="async" style="display:none"
|
|
408
|
+
src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="
|
|
409
|
+
onload="(function(el){
|
|
410
|
+
const root = el.getRootNode();
|
|
411
|
+
globalThis.__remote_components_shadowroot_${src ? new URL(src, typeof location !== "undefined" ? location.origin : "http://localhost").href.replace(/[^a-z0-9]/g, "_") : ""}_${(data?.name ?? name).replace(/[^a-z0-9]/g, "_")} = root;
|
|
412
|
+
el.parentElement.remove();
|
|
413
|
+
})(this)"
|
|
414
|
+
/>`
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
) : null,
|
|
418
|
+
resetStyle,
|
|
344
419
|
linksToRender,
|
|
345
420
|
children
|
|
346
421
|
] })
|
|
347
422
|
) : null,
|
|
348
423
|
shadowRoot && remoteComponent ? (0, import_react_dom.createPortal)(
|
|
349
424
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
425
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { id: `${name}_start` }),
|
|
426
|
+
resetStyle,
|
|
350
427
|
linksToRender,
|
|
351
|
-
remoteComponent
|
|
428
|
+
remoteComponent,
|
|
429
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { id: `${name}_end`, ref: endTemplateRef })
|
|
352
430
|
] }),
|
|
353
431
|
shadowRoot
|
|
354
432
|
) : null
|
|
@@ -357,6 +435,7 @@ function RemoteComponent({
|
|
|
357
435
|
)
|
|
358
436
|
] });
|
|
359
437
|
}
|
|
438
|
+
htmlRef.current = null;
|
|
360
439
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
361
440
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { id: `${name}_start` }),
|
|
362
441
|
metadataJson,
|