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
package/dist/react/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { R as RemoteComponentProps$1 } from '../types-
|
|
2
|
+
import { R as RemoteComponentProps$1 } from '../types-4e7dea94.js';
|
|
3
3
|
import 'react';
|
|
4
|
-
import '../types-
|
|
4
|
+
import '../types-cbf6c34f.js';
|
|
5
5
|
|
|
6
6
|
type LoadRemoteComponentProps = Pick<RemoteComponentProps$1, 'name' | 'bundle' | 'route' | 'runtime' | 'data' | 'nextData' | 'scripts'> & {
|
|
7
7
|
url: URL;
|
package/dist/react/index.js
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { createElement } from "react";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
startTransition,
|
|
5
5
|
useEffect,
|
|
6
6
|
useLayoutEffect,
|
|
7
|
-
useRef,
|
|
8
7
|
useMemo,
|
|
9
|
-
|
|
8
|
+
useRef,
|
|
9
|
+
useState
|
|
10
10
|
} from "react";
|
|
11
11
|
import { createPortal } from "react-dom";
|
|
12
|
+
import { applyOriginToNodes } from "#internal/shared/client/apply-origin";
|
|
13
|
+
import { sharedPolyfills } from "#internal/shared/client/polyfill";
|
|
12
14
|
import {
|
|
15
|
+
DEFAULT_ROUTE,
|
|
13
16
|
loadRemoteComponent,
|
|
17
|
+
loadStaticRemoteComponent,
|
|
18
|
+
REMOTE_COMPONENT_REGEX,
|
|
14
19
|
RemoteComponentsError,
|
|
15
|
-
|
|
16
|
-
DEFAULT_ROUTE,
|
|
20
|
+
RUNTIME_SCRIPT,
|
|
17
21
|
RUNTIME_WEBPACK,
|
|
18
|
-
|
|
22
|
+
setAttributesFromProps
|
|
19
23
|
} from "#internal/shared/client/remote-component";
|
|
20
|
-
import { sharedPolyfills } from "#internal/shared/client/polyfill";
|
|
21
|
-
import { applyOriginToNodes } from "#internal/shared/client/apply-origin";
|
|
22
|
-
import { escapeString, attrToProp } from "#internal/shared/utils";
|
|
23
|
-
import { remoteFetchHeaders } from "#internal/shared/ssr/fetch-headers";
|
|
24
24
|
import {
|
|
25
25
|
failedToFetchRemoteComponentError,
|
|
26
26
|
multipleRemoteComponentsError
|
|
27
27
|
} from "#internal/shared/error";
|
|
28
|
+
import { remoteFetchHeaders } from "#internal/shared/ssr/fetch-headers";
|
|
29
|
+
import { attrToProp, escapeString } from "#internal/shared/utils";
|
|
28
30
|
function getRemoteComponentHtml(html) {
|
|
29
31
|
if (typeof document === "undefined")
|
|
30
32
|
return html;
|
|
@@ -37,7 +39,7 @@ function getRemoteComponentHtml(html) {
|
|
|
37
39
|
return ssrRemoteComponentContainer.innerHTML;
|
|
38
40
|
}
|
|
39
41
|
const remoteComponentContainer = temp.querySelectorAll(
|
|
40
|
-
`div[data-bundle][data-route][data-runtime][id^="__vercel_remote_component"],div[data-bundle][data-route],div#__next`
|
|
42
|
+
`div[data-bundle][data-route][data-runtime][id^="__vercel_remote_component"],div[data-bundle][data-route],div#__next,remote-component:not([src])`
|
|
41
43
|
);
|
|
42
44
|
if (remoteComponentContainer.length > 0) {
|
|
43
45
|
return `${Array.from(temp.querySelectorAll("link,script")).map((link) => link.outerHTML).join("")}${Array.from(remoteComponentContainer).map((container) => container.outerHTML).join("")}`;
|
|
@@ -102,6 +104,10 @@ function RemoteComponent({
|
|
|
102
104
|
);
|
|
103
105
|
const prevSrcRef = useRef(null);
|
|
104
106
|
const componentHydrationHtml = useRef(null);
|
|
107
|
+
const prevIsRemoteComponentRef = useRef(false);
|
|
108
|
+
const prevUrlRef = useRef(null);
|
|
109
|
+
const prevRemoteComponentContainerRef = useRef(null);
|
|
110
|
+
const unmountRef = useRef(null);
|
|
105
111
|
useLayoutEffect(() => {
|
|
106
112
|
if (childrenRef.current.length > 0 && remoteComponent) {
|
|
107
113
|
childrenRef.current.forEach((el) => {
|
|
@@ -214,34 +220,58 @@ function RemoteComponent({
|
|
|
214
220
|
}
|
|
215
221
|
const parser = new DOMParser();
|
|
216
222
|
const doc = parser.parseFromString(html, "text/html");
|
|
217
|
-
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(
|
|
223
|
+
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(
|
|
224
|
+
`div[data-bundle][data-route][id^="${name}"]`
|
|
225
|
+
) || doc.querySelectorAll("remote-component:not([src])").length > 1 && !doc.querySelector(`remote-component[name="${name}"]`)) {
|
|
218
226
|
throw multipleRemoteComponentsError(url.href);
|
|
219
227
|
}
|
|
220
228
|
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
|
|
221
229
|
doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
|
|
222
|
-
doc.querySelector("div#__next")
|
|
230
|
+
doc.querySelector("div#__next") ?? // fallback to the remote-component web component
|
|
231
|
+
doc.querySelector(`remote-component[name="${name}"]:not([src])`) ?? doc.querySelector("remote-component:not([src])");
|
|
223
232
|
const nextData = JSON.parse(
|
|
224
233
|
(doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
|
|
225
234
|
);
|
|
226
235
|
const remoteName = component?.getAttribute("id")?.replace(/_ssr$/, "") || (nextData ? "__next" : name);
|
|
227
236
|
const rsc = doc.querySelector(`#${remoteName}_rsc`);
|
|
228
237
|
const bundle = component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default";
|
|
238
|
+
const isRemoteComponent = component?.tagName.toLowerCase() === "remote-component";
|
|
229
239
|
const metadata = {
|
|
230
240
|
name: remoteName,
|
|
231
241
|
bundle,
|
|
232
|
-
route: component?.getAttribute("data-route") ?? nextData?.page ?? DEFAULT_ROUTE,
|
|
233
|
-
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime ||
|
|
242
|
+
route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
|
|
243
|
+
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
|
|
234
244
|
};
|
|
235
245
|
const remoteSharedEl = doc.querySelector(
|
|
236
246
|
`#${remoteName}_shared[data-remote-components-shared]`
|
|
237
247
|
);
|
|
238
248
|
const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
|
|
239
249
|
remoteSharedEl?.remove();
|
|
240
|
-
if (!component || !(rsc || nextData)) {
|
|
250
|
+
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
241
251
|
throw new RemoteComponentsError(
|
|
242
252
|
`Remote Component not found on ${url.href}.${remoteName !== "__vercel_remote_component" ? `The name for the <RemoteComponent> is "${remoteName}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
|
|
243
253
|
);
|
|
244
254
|
}
|
|
255
|
+
if (prevIsRemoteComponentRef.current) {
|
|
256
|
+
if (shadowRoot) {
|
|
257
|
+
shadowRoot.innerHTML = "";
|
|
258
|
+
}
|
|
259
|
+
const self = globalThis;
|
|
260
|
+
const prevUrl = prevUrlRef.current;
|
|
261
|
+
if (prevUrl && self.__remote_script_entrypoint_unmount__?.[prevUrl.href]) {
|
|
262
|
+
const unmountPromises = Promise.all(
|
|
263
|
+
Array.from(unmountRef.current ?? []).map(
|
|
264
|
+
async (unmount) => unmount(
|
|
265
|
+
shadowRoot ?? prevRemoteComponentContainerRef.current
|
|
266
|
+
)
|
|
267
|
+
)
|
|
268
|
+
);
|
|
269
|
+
unmountRef.current = null;
|
|
270
|
+
await unmountPromises;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
prevIsRemoteComponentRef.current = isRemoteComponent;
|
|
274
|
+
prevUrlRef.current = url;
|
|
245
275
|
applyOriginToNodes(doc, url);
|
|
246
276
|
const links = Array.from(
|
|
247
277
|
doc.querySelectorAll("link[href]")
|
|
@@ -256,64 +286,64 @@ function RemoteComponent({
|
|
|
256
286
|
return acc;
|
|
257
287
|
}, {})
|
|
258
288
|
}));
|
|
259
|
-
const scripts = doc.querySelectorAll(
|
|
260
|
-
|
|
261
|
-
);
|
|
262
|
-
const inlineScripts = doc.querySelectorAll(
|
|
289
|
+
const scripts = (isRemoteComponent ? component : doc).querySelectorAll("script[src],script[data-src]");
|
|
290
|
+
const inlineScripts = (isRemoteComponent ? component : doc).querySelectorAll(
|
|
263
291
|
"script:not([src]):not([data-src]):not([id*='_rsc']):not([id='__NEXT_DATA__']):not([id='__REMOTE_NEXT_DATA__'])"
|
|
264
292
|
);
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
"
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
293
|
+
if (!isRemoteComponent) {
|
|
294
|
+
const self = globalThis;
|
|
295
|
+
const prevNextScripts = self.__next_s;
|
|
296
|
+
const nextScripts = [];
|
|
297
|
+
self.__next_s = nextScripts;
|
|
298
|
+
await Promise.all(
|
|
299
|
+
Array.from(inlineScripts).filter(
|
|
300
|
+
(script) => !(script.id.endsWith("_shared") && script.getAttribute("type") === "application/json" && typeof script.getAttribute(
|
|
301
|
+
"data-remote-components-shared"
|
|
302
|
+
) === "string")
|
|
303
|
+
).map((script) => {
|
|
304
|
+
return new Promise((resolve) => {
|
|
305
|
+
if (script.textContent && !script.textContent.includes("self.__next_f=") && !script.textContent.includes("self.__next_f.push")) {
|
|
306
|
+
if (!script.getAttribute("type") || script.getAttribute("type") === "text/javascript" || script.getAttribute("type") === "application/javascript") {
|
|
307
|
+
const newScript = document.createElement("script");
|
|
308
|
+
const blob = new Blob([script.textContent], {
|
|
309
|
+
type: "application/javascript"
|
|
310
|
+
});
|
|
311
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
312
|
+
newScript.onload = () => {
|
|
313
|
+
resolve(void 0);
|
|
314
|
+
URL.revokeObjectURL(blobUrl);
|
|
315
|
+
newScript.remove();
|
|
316
|
+
};
|
|
317
|
+
newScript.onerror = () => {
|
|
318
|
+
URL.revokeObjectURL(blobUrl);
|
|
319
|
+
newScript.remove();
|
|
320
|
+
resolve(void 0);
|
|
321
|
+
};
|
|
322
|
+
newScript.src = blobUrl;
|
|
323
|
+
document.body.appendChild(newScript);
|
|
324
|
+
} else {
|
|
284
325
|
resolve(void 0);
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
};
|
|
288
|
-
newScript.onerror = () => {
|
|
289
|
-
URL.revokeObjectURL(blobUrl);
|
|
290
|
-
newScript.remove();
|
|
291
|
-
resolve(void 0);
|
|
292
|
-
};
|
|
293
|
-
newScript.src = blobUrl;
|
|
294
|
-
document.body.appendChild(newScript);
|
|
326
|
+
document.body.appendChild(script);
|
|
327
|
+
}
|
|
295
328
|
} else {
|
|
296
329
|
resolve(void 0);
|
|
297
|
-
document.body.appendChild(script);
|
|
298
330
|
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
});
|
|
316
|
-
self.__next_s = prevNextScripts;
|
|
331
|
+
});
|
|
332
|
+
})
|
|
333
|
+
);
|
|
334
|
+
nextScripts.forEach(([scriptSrc, props]) => {
|
|
335
|
+
const script = document.createElement("script");
|
|
336
|
+
if (scriptSrc) {
|
|
337
|
+
script.src = scriptSrc;
|
|
338
|
+
}
|
|
339
|
+
if (typeof props.children === "string") {
|
|
340
|
+
script.textContent = props.children;
|
|
341
|
+
}
|
|
342
|
+
setAttributesFromProps(script, props);
|
|
343
|
+
document.head.appendChild(script);
|
|
344
|
+
});
|
|
345
|
+
self.__next_s = prevNextScripts;
|
|
346
|
+
}
|
|
317
347
|
let rscName;
|
|
318
348
|
if (rsc) {
|
|
319
349
|
rscName = `__remote_component_rsc_${escapeString(url.href)}_${escapeString(remoteName)}`;
|
|
@@ -330,7 +360,11 @@ function RemoteComponent({
|
|
|
330
360
|
url: url.href,
|
|
331
361
|
data: rsc ? (rsc.textContent || "").split("\n").filter(Boolean) : []
|
|
332
362
|
};
|
|
333
|
-
componentHydrationHtml.current = Array.from(
|
|
363
|
+
componentHydrationHtml.current = `${Array.from(
|
|
364
|
+
doc.querySelectorAll("link,style")
|
|
365
|
+
).map((link) => link.outerHTML).join(
|
|
366
|
+
""
|
|
367
|
+
)}${reset ? `<style data-remote-components-reset="">:host { all: initial; }</style>` : ""}${component.innerHTML}`;
|
|
334
368
|
const userShared = await shared;
|
|
335
369
|
if ("__remote_components_missing_shared__" in userShared) {
|
|
336
370
|
userShared.__remote_components_missing_shared__().catch((e) => {
|
|
@@ -341,48 +375,89 @@ function RemoteComponent({
|
|
|
341
375
|
remoteShared.__remote_components_missing_shared__
|
|
342
376
|
);
|
|
343
377
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
setRemoteComponent(result.error);
|
|
378
|
+
if (isRemoteComponent) {
|
|
379
|
+
setData(newData);
|
|
380
|
+
if (shadowRoot) {
|
|
381
|
+
let shadowRootHtml = component.innerHTML;
|
|
382
|
+
if (reset) {
|
|
383
|
+
shadowRootHtml = `<style data-remote-components-reset="">:host { all: initial; }</style>${shadowRootHtml}`;
|
|
384
|
+
}
|
|
385
|
+
shadowRoot.innerHTML = shadowRootHtml;
|
|
386
|
+
setRemoteComponent(null);
|
|
387
|
+
const { mount, unmount } = await loadStaticRemoteComponent(
|
|
388
|
+
Array.from(shadowRoot.querySelectorAll("script")),
|
|
389
|
+
url
|
|
390
|
+
);
|
|
391
|
+
unmountRef.current = unmount;
|
|
392
|
+
await Promise.all(
|
|
393
|
+
Array.from(mount).map((mountFn) => mountFn(shadowRoot))
|
|
394
|
+
);
|
|
395
|
+
} else if (isolate === false) {
|
|
396
|
+
setRemoteComponent(
|
|
397
|
+
// TODO: remove wrapper div by converting HTML to RSC or React tree
|
|
398
|
+
/* @__PURE__ */ jsx(
|
|
399
|
+
"div",
|
|
400
|
+
{
|
|
401
|
+
dangerouslySetInnerHTML: { __html: component.innerHTML },
|
|
402
|
+
ref: prevRemoteComponentContainerRef
|
|
403
|
+
}
|
|
404
|
+
)
|
|
405
|
+
);
|
|
406
|
+
const { mount, unmount } = await loadStaticRemoteComponent(
|
|
407
|
+
Array.from(component.querySelectorAll("script")),
|
|
408
|
+
url
|
|
409
|
+
);
|
|
410
|
+
unmountRef.current = unmount;
|
|
411
|
+
await Promise.all(
|
|
412
|
+
Array.from(mount).map(
|
|
413
|
+
(mountFn) => mountFn(prevRemoteComponentContainerRef.current)
|
|
414
|
+
)
|
|
415
|
+
);
|
|
416
|
+
}
|
|
384
417
|
} else {
|
|
385
|
-
|
|
418
|
+
const result = await loadRemoteComponent({
|
|
419
|
+
url: new URL(url, location.origin),
|
|
420
|
+
name: remoteName,
|
|
421
|
+
rscName,
|
|
422
|
+
bundle,
|
|
423
|
+
route: metadata.route,
|
|
424
|
+
runtime: metadata.runtime,
|
|
425
|
+
data: newData.data,
|
|
426
|
+
nextData,
|
|
427
|
+
scripts: Array.from(scripts).map((script) => {
|
|
428
|
+
const scriptSrc = script.getAttribute("data-src") || script.getAttribute("src") || script.src;
|
|
429
|
+
const { prefix, id: path } = REMOTE_COMPONENT_REGEX.exec(
|
|
430
|
+
scriptSrc
|
|
431
|
+
)?.groups ?? {
|
|
432
|
+
prefix: void 0,
|
|
433
|
+
id: scriptSrc
|
|
434
|
+
};
|
|
435
|
+
return {
|
|
436
|
+
src: new URL(
|
|
437
|
+
`${prefix ?? ""}${path}`.replace(
|
|
438
|
+
/(?<char>[^:])(?<double>\/\/)/g,
|
|
439
|
+
"$1/"
|
|
440
|
+
),
|
|
441
|
+
url
|
|
442
|
+
).href
|
|
443
|
+
};
|
|
444
|
+
}),
|
|
445
|
+
shared: {
|
|
446
|
+
...sharedPolyfills(userShared),
|
|
447
|
+
...userShared
|
|
448
|
+
},
|
|
449
|
+
remoteShared,
|
|
450
|
+
container: shadowRoot
|
|
451
|
+
});
|
|
452
|
+
if (rsc) {
|
|
453
|
+
rsc.remove();
|
|
454
|
+
}
|
|
455
|
+
setData(newData);
|
|
456
|
+
if (result.error) {
|
|
457
|
+
setRemoteComponent(result.error);
|
|
458
|
+
} else {
|
|
459
|
+
setRemoteComponent(result.component);
|
|
460
|
+
}
|
|
386
461
|
}
|
|
387
462
|
} catch (error) {
|
|
388
463
|
setRemoteComponent(error);
|
|
@@ -397,7 +472,8 @@ function RemoteComponent({
|
|
|
397
472
|
name,
|
|
398
473
|
shared,
|
|
399
474
|
shadowRoot,
|
|
400
|
-
additionalHeaders
|
|
475
|
+
additionalHeaders,
|
|
476
|
+
reset
|
|
401
477
|
]);
|
|
402
478
|
if (remoteComponent instanceof Error) {
|
|
403
479
|
throw remoteComponent;
|
|
@@ -406,7 +482,7 @@ function RemoteComponent({
|
|
|
406
482
|
name: data?.name || name,
|
|
407
483
|
bundle: data?.bundle || "default",
|
|
408
484
|
route: data?.route || DEFAULT_ROUTE,
|
|
409
|
-
runtime: data?.runtime || RUNTIME_WEBPACK
|
|
485
|
+
runtime: prevIsRemoteComponentRef.current ? RUNTIME_SCRIPT : data?.runtime || RUNTIME_WEBPACK
|
|
410
486
|
}) });
|
|
411
487
|
const resetStyle = reset ? /* @__PURE__ */ jsx("style", { "data-remote-components-reset": "", children: `:host { all: initial; }` }) : null;
|
|
412
488
|
const linksToRender = data?.links?.map((link) => /* @__PURE__ */ createElement(
|
|
@@ -425,6 +501,24 @@ function RemoteComponent({
|
|
|
425
501
|
if (componentHydrationHtml.current && shadowRoot && !shadowRoot.innerHTML) {
|
|
426
502
|
shadowRoot.innerHTML = componentHydrationHtml.current;
|
|
427
503
|
componentHydrationHtml.current = null;
|
|
504
|
+
if (prevIsRemoteComponentRef.current) {
|
|
505
|
+
loadStaticRemoteComponent(
|
|
506
|
+
Array.from(shadowRoot.querySelectorAll("script")),
|
|
507
|
+
url
|
|
508
|
+
).then(({ mount }) => {
|
|
509
|
+
return Promise.all(
|
|
510
|
+
Array.from(mount).map((mountFn) => mountFn(shadowRoot))
|
|
511
|
+
);
|
|
512
|
+
}).catch((e) => {
|
|
513
|
+
const error = new RemoteComponentsError(
|
|
514
|
+
`Error mounting remote component from "${url.href}"`,
|
|
515
|
+
{
|
|
516
|
+
cause: e
|
|
517
|
+
}
|
|
518
|
+
);
|
|
519
|
+
setRemoteComponent(error);
|
|
520
|
+
});
|
|
521
|
+
}
|
|
428
522
|
}
|
|
429
523
|
if (isolate !== false) {
|
|
430
524
|
const shadowRemoteComponentHtml = shadowRoot?.querySelector(`#__REMOTE_COMPONENT${name}`) ?? shadowRoot?.querySelector("div[data-bundle][data-route]");
|