remote-components 0.0.33 → 0.0.34
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 +227 -13
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +227 -13
- package/dist/html/host.js.map +1 -1
- package/dist/html/remote.cjs +198 -0
- package/dist/html/remote.cjs.map +1 -0
- package/dist/html/remote.d.ts +2 -0
- package/dist/html/remote.js +197 -0
- package/dist/html/remote.js.map +1 -0
- package/dist/internal/next/host/app-router-client.cjs +56 -4
- 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 +58 -5
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/shared/client/remote-component.cjs +99 -0
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +11 -4
- package/dist/internal/shared/client/remote-component.js +97 -0
- package/dist/internal/shared/client/remote-component.js.map +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.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.cjs +17 -5
- 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 +17 -5
- package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.cjs +7 -3
- 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 +7 -3
- package/dist/internal/shared/ssr/fetch-remote-component.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 +1 -0
- package/dist/next/host/app-router-server.js.map +1 -1
- package/dist/next/host/client/index.cjs +292 -103
- 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 +289 -102
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/react/index.cjs +197 -103
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +196 -102
- 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 +8 -1
|
@@ -222,6 +222,7 @@ var attrToProp = {
|
|
|
222
222
|
var DEFAULT_ROUTE = "/";
|
|
223
223
|
var RUNTIME_WEBPACK = "webpack";
|
|
224
224
|
var RUNTIME_TURBOPACK = "turbopack";
|
|
225
|
+
var RUNTIME_SCRIPT = "script";
|
|
225
226
|
var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
226
227
|
function getBundleKey(bundle) {
|
|
227
228
|
return escapeString(bundle);
|
|
@@ -929,6 +930,100 @@ function loadNextPagesComponent(bundle, route, nextData, name, container) {
|
|
|
929
930
|
return { component };
|
|
930
931
|
}
|
|
931
932
|
|
|
933
|
+
// src/shared/client/static-loader.ts
|
|
934
|
+
async function loadStaticRemoteComponent(scripts, url) {
|
|
935
|
+
const self = globalThis;
|
|
936
|
+
if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
937
|
+
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
938
|
+
}
|
|
939
|
+
if (self.__remote_script_entrypoint_unmount__?.[url.href]) {
|
|
940
|
+
self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
|
|
941
|
+
}
|
|
942
|
+
const mountUnmountSets = await Promise.all(
|
|
943
|
+
scripts.map(async (script) => {
|
|
944
|
+
try {
|
|
945
|
+
let src = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
|
|
946
|
+
if (!src && script.textContent) {
|
|
947
|
+
const blob = new Blob(
|
|
948
|
+
[
|
|
949
|
+
script.textContent.replace(
|
|
950
|
+
/import\.meta\.url/g,
|
|
951
|
+
JSON.stringify(url)
|
|
952
|
+
)
|
|
953
|
+
],
|
|
954
|
+
{
|
|
955
|
+
type: "text/javascript"
|
|
956
|
+
}
|
|
957
|
+
);
|
|
958
|
+
src = URL.createObjectURL(blob);
|
|
959
|
+
}
|
|
960
|
+
const mod = await import(
|
|
961
|
+
/* @vite-ignore */
|
|
962
|
+
/* webpackIgnore: true */
|
|
963
|
+
new URL(src, url).href
|
|
964
|
+
);
|
|
965
|
+
if (src.startsWith("blob:")) {
|
|
966
|
+
URL.revokeObjectURL(src);
|
|
967
|
+
}
|
|
968
|
+
if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
|
|
969
|
+
if (!self.__remote_script_entrypoint_mount__) {
|
|
970
|
+
self.__remote_script_entrypoint_mount__ = {};
|
|
971
|
+
}
|
|
972
|
+
if (!self.__remote_script_entrypoint_mount__[url.href]) {
|
|
973
|
+
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
974
|
+
}
|
|
975
|
+
self.__remote_script_entrypoint_mount__[url.href]?.add(
|
|
976
|
+
mod.mount || mod.default?.mount || (() => {
|
|
977
|
+
})
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
|
|
981
|
+
if (!self.__remote_script_entrypoint_unmount__) {
|
|
982
|
+
self.__remote_script_entrypoint_unmount__ = {};
|
|
983
|
+
}
|
|
984
|
+
if (!self.__remote_script_entrypoint_unmount__[url.href]) {
|
|
985
|
+
self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
|
|
986
|
+
}
|
|
987
|
+
self.__remote_script_entrypoint_unmount__[url.href]?.add(
|
|
988
|
+
mod.unmount || mod.default?.unmount || (() => {
|
|
989
|
+
})
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
return {
|
|
993
|
+
mount: mod.mount || mod.default?.mount,
|
|
994
|
+
unmount: mod.unmount || mod.default?.unmount
|
|
995
|
+
};
|
|
996
|
+
} catch (e) {
|
|
997
|
+
console.error(
|
|
998
|
+
new RemoteComponentsError(
|
|
999
|
+
`Error loading remote component script from "${script.src || url.href}".`,
|
|
1000
|
+
{ cause: e }
|
|
1001
|
+
)
|
|
1002
|
+
);
|
|
1003
|
+
return {
|
|
1004
|
+
mount: void 0,
|
|
1005
|
+
unmount: void 0
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
})
|
|
1009
|
+
);
|
|
1010
|
+
return mountUnmountSets.reduce(
|
|
1011
|
+
(acc, { mount, unmount }) => {
|
|
1012
|
+
if (typeof mount === "function") {
|
|
1013
|
+
acc.mount.add(mount);
|
|
1014
|
+
}
|
|
1015
|
+
if (typeof unmount === "function") {
|
|
1016
|
+
acc.unmount.add(unmount);
|
|
1017
|
+
}
|
|
1018
|
+
return acc;
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
mount: /* @__PURE__ */ new Set(),
|
|
1022
|
+
unmount: /* @__PURE__ */ new Set()
|
|
1023
|
+
}
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
|
|
932
1027
|
// src/shared/client/set-attributes-from-props.ts
|
|
933
1028
|
var DOMAttributeNames = {
|
|
934
1029
|
acceptCharset: "accept-charset",
|
|
@@ -1242,7 +1337,10 @@ function remoteFetchHeaders(additionalHeaders) {
|
|
|
1242
1337
|
}
|
|
1243
1338
|
|
|
1244
1339
|
// src/react/index.tsx
|
|
1245
|
-
var import_jsx_runtime2 =
|
|
1340
|
+
var import_jsx_runtime2 = (
|
|
1341
|
+
// TODO: remove wrapper div by converting HTML to RSC or React tree
|
|
1342
|
+
require("react/jsx-runtime")
|
|
1343
|
+
);
|
|
1246
1344
|
var import_react2 = require("react");
|
|
1247
1345
|
function getRemoteComponentHtml(html) {
|
|
1248
1346
|
if (typeof document === "undefined")
|
|
@@ -1256,7 +1354,7 @@ function getRemoteComponentHtml(html) {
|
|
|
1256
1354
|
return ssrRemoteComponentContainer.innerHTML;
|
|
1257
1355
|
}
|
|
1258
1356
|
const remoteComponentContainer = temp.querySelectorAll(
|
|
1259
|
-
`div[data-bundle][data-route][data-runtime][id^="__vercel_remote_component"],div[data-bundle][data-route],div#__next`
|
|
1357
|
+
`div[data-bundle][data-route][data-runtime][id^="__vercel_remote_component"],div[data-bundle][data-route],div#__next,remote-component:not([src])`
|
|
1260
1358
|
);
|
|
1261
1359
|
if (remoteComponentContainer.length > 0) {
|
|
1262
1360
|
return `${Array.from(temp.querySelectorAll("link,script")).map((link) => link.outerHTML).join("")}${Array.from(remoteComponentContainer).map((container) => container.outerHTML).join("")}`;
|
|
@@ -1321,6 +1419,10 @@ function RemoteComponent({
|
|
|
1321
1419
|
);
|
|
1322
1420
|
const prevSrcRef = (0, import_react.useRef)(null);
|
|
1323
1421
|
const componentHydrationHtml = (0, import_react.useRef)(null);
|
|
1422
|
+
const prevIsRemoteComponentRef = (0, import_react.useRef)(false);
|
|
1423
|
+
const prevUrlRef = (0, import_react.useRef)(null);
|
|
1424
|
+
const prevRemoteComponentContainerRef = (0, import_react.useRef)(null);
|
|
1425
|
+
const unmountRef = (0, import_react.useRef)(null);
|
|
1324
1426
|
(0, import_react.useLayoutEffect)(() => {
|
|
1325
1427
|
if (childrenRef.current.length > 0 && remoteComponent) {
|
|
1326
1428
|
childrenRef.current.forEach((el) => {
|
|
@@ -1433,34 +1535,58 @@ function RemoteComponent({
|
|
|
1433
1535
|
}
|
|
1434
1536
|
const parser = new DOMParser();
|
|
1435
1537
|
const doc = parser.parseFromString(html, "text/html");
|
|
1436
|
-
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(
|
|
1538
|
+
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(
|
|
1539
|
+
`div[data-bundle][data-route][id^="${name}"]`
|
|
1540
|
+
) || doc.querySelectorAll("remote-component:not([src])").length > 1 && !doc.querySelector(`remote-component[name="${name}"]`)) {
|
|
1437
1541
|
throw multipleRemoteComponentsError(url.href);
|
|
1438
1542
|
}
|
|
1439
1543
|
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
|
|
1440
1544
|
doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
|
|
1441
|
-
doc.querySelector("div#__next")
|
|
1545
|
+
doc.querySelector("div#__next") ?? // fallback to the remote-component web component
|
|
1546
|
+
doc.querySelector(`remote-component[name="${name}"]:not([src])`) ?? doc.querySelector("remote-component:not([src])");
|
|
1442
1547
|
const nextData = JSON.parse(
|
|
1443
1548
|
(doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
|
|
1444
1549
|
);
|
|
1445
1550
|
const remoteName = component?.getAttribute("id")?.replace(/_ssr$/, "") || (nextData ? "__next" : name);
|
|
1446
1551
|
const rsc = doc.querySelector(`#${remoteName}_rsc`);
|
|
1447
1552
|
const bundle = component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default";
|
|
1553
|
+
const isRemoteComponent = component?.tagName.toLowerCase() === "remote-component";
|
|
1448
1554
|
const metadata = {
|
|
1449
1555
|
name: remoteName,
|
|
1450
1556
|
bundle,
|
|
1451
|
-
route: component?.getAttribute("data-route") ?? nextData?.page ?? DEFAULT_ROUTE,
|
|
1452
|
-
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime ||
|
|
1557
|
+
route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
|
|
1558
|
+
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
|
|
1453
1559
|
};
|
|
1454
1560
|
const remoteSharedEl = doc.querySelector(
|
|
1455
1561
|
`#${remoteName}_shared[data-remote-components-shared]`
|
|
1456
1562
|
);
|
|
1457
1563
|
const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
|
|
1458
1564
|
remoteSharedEl?.remove();
|
|
1459
|
-
if (!component || !(rsc || nextData)) {
|
|
1565
|
+
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
1460
1566
|
throw new RemoteComponentsError(
|
|
1461
1567
|
`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>?`
|
|
1462
1568
|
);
|
|
1463
1569
|
}
|
|
1570
|
+
if (prevIsRemoteComponentRef.current) {
|
|
1571
|
+
if (shadowRoot) {
|
|
1572
|
+
shadowRoot.innerHTML = "";
|
|
1573
|
+
}
|
|
1574
|
+
const self = globalThis;
|
|
1575
|
+
const prevUrl = prevUrlRef.current;
|
|
1576
|
+
if (prevUrl && self.__remote_script_entrypoint_unmount__?.[prevUrl.href]) {
|
|
1577
|
+
const unmountPromises = Promise.all(
|
|
1578
|
+
Array.from(unmountRef.current ?? []).map(
|
|
1579
|
+
async (unmount) => unmount(
|
|
1580
|
+
shadowRoot ?? prevRemoteComponentContainerRef.current
|
|
1581
|
+
)
|
|
1582
|
+
)
|
|
1583
|
+
);
|
|
1584
|
+
unmountRef.current = null;
|
|
1585
|
+
await unmountPromises;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
prevIsRemoteComponentRef.current = isRemoteComponent;
|
|
1589
|
+
prevUrlRef.current = url;
|
|
1464
1590
|
applyOriginToNodes(doc, url);
|
|
1465
1591
|
const links = Array.from(
|
|
1466
1592
|
doc.querySelectorAll("link[href]")
|
|
@@ -1475,64 +1601,64 @@ function RemoteComponent({
|
|
|
1475
1601
|
return acc;
|
|
1476
1602
|
}, {})
|
|
1477
1603
|
}));
|
|
1478
|
-
const scripts = doc.querySelectorAll(
|
|
1479
|
-
|
|
1480
|
-
);
|
|
1481
|
-
const inlineScripts = doc.querySelectorAll(
|
|
1604
|
+
const scripts = (isRemoteComponent ? component : doc).querySelectorAll("script[src],script[data-src]");
|
|
1605
|
+
const inlineScripts = (isRemoteComponent ? component : doc).querySelectorAll(
|
|
1482
1606
|
"script:not([src]):not([data-src]):not([id*='_rsc']):not([id='__NEXT_DATA__']):not([id='__REMOTE_NEXT_DATA__'])"
|
|
1483
1607
|
);
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
"
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
if (
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1608
|
+
if (!isRemoteComponent) {
|
|
1609
|
+
const self = globalThis;
|
|
1610
|
+
const prevNextScripts = self.__next_s;
|
|
1611
|
+
const nextScripts = [];
|
|
1612
|
+
self.__next_s = nextScripts;
|
|
1613
|
+
await Promise.all(
|
|
1614
|
+
Array.from(inlineScripts).filter(
|
|
1615
|
+
(script) => !(script.id.endsWith("_shared") && script.getAttribute("type") === "application/json" && typeof script.getAttribute(
|
|
1616
|
+
"data-remote-components-shared"
|
|
1617
|
+
) === "string")
|
|
1618
|
+
).map((script) => {
|
|
1619
|
+
return new Promise((resolve) => {
|
|
1620
|
+
if (script.textContent && !script.textContent.includes("self.__next_f=") && !script.textContent.includes("self.__next_f.push")) {
|
|
1621
|
+
if (!script.getAttribute("type") || script.getAttribute("type") === "text/javascript" || script.getAttribute("type") === "application/javascript") {
|
|
1622
|
+
const newScript = document.createElement("script");
|
|
1623
|
+
const blob = new Blob([script.textContent], {
|
|
1624
|
+
type: "application/javascript"
|
|
1625
|
+
});
|
|
1626
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
1627
|
+
newScript.onload = () => {
|
|
1628
|
+
resolve(void 0);
|
|
1629
|
+
URL.revokeObjectURL(blobUrl);
|
|
1630
|
+
newScript.remove();
|
|
1631
|
+
};
|
|
1632
|
+
newScript.onerror = () => {
|
|
1633
|
+
URL.revokeObjectURL(blobUrl);
|
|
1634
|
+
newScript.remove();
|
|
1635
|
+
resolve(void 0);
|
|
1636
|
+
};
|
|
1637
|
+
newScript.src = blobUrl;
|
|
1638
|
+
document.body.appendChild(newScript);
|
|
1639
|
+
} else {
|
|
1503
1640
|
resolve(void 0);
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
};
|
|
1507
|
-
newScript.onerror = () => {
|
|
1508
|
-
URL.revokeObjectURL(blobUrl);
|
|
1509
|
-
newScript.remove();
|
|
1510
|
-
resolve(void 0);
|
|
1511
|
-
};
|
|
1512
|
-
newScript.src = blobUrl;
|
|
1513
|
-
document.body.appendChild(newScript);
|
|
1641
|
+
document.body.appendChild(script);
|
|
1642
|
+
}
|
|
1514
1643
|
} else {
|
|
1515
1644
|
resolve(void 0);
|
|
1516
|
-
document.body.appendChild(script);
|
|
1517
1645
|
}
|
|
1518
|
-
}
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
});
|
|
1535
|
-
self.__next_s = prevNextScripts;
|
|
1646
|
+
});
|
|
1647
|
+
})
|
|
1648
|
+
);
|
|
1649
|
+
nextScripts.forEach(([scriptSrc, props]) => {
|
|
1650
|
+
const script = document.createElement("script");
|
|
1651
|
+
if (scriptSrc) {
|
|
1652
|
+
script.src = scriptSrc;
|
|
1653
|
+
}
|
|
1654
|
+
if (typeof props.children === "string") {
|
|
1655
|
+
script.textContent = props.children;
|
|
1656
|
+
}
|
|
1657
|
+
setAttributesFromProps(script, props);
|
|
1658
|
+
document.head.appendChild(script);
|
|
1659
|
+
});
|
|
1660
|
+
self.__next_s = prevNextScripts;
|
|
1661
|
+
}
|
|
1536
1662
|
let rscName;
|
|
1537
1663
|
if (rsc) {
|
|
1538
1664
|
rscName = `__remote_component_rsc_${escapeString(url.href)}_${escapeString(remoteName)}`;
|
|
@@ -1549,7 +1675,11 @@ function RemoteComponent({
|
|
|
1549
1675
|
url: url.href,
|
|
1550
1676
|
data: rsc ? (rsc.textContent || "").split("\n").filter(Boolean) : []
|
|
1551
1677
|
};
|
|
1552
|
-
componentHydrationHtml.current = Array.from(
|
|
1678
|
+
componentHydrationHtml.current = `${Array.from(
|
|
1679
|
+
doc.querySelectorAll("link,style")
|
|
1680
|
+
).map((link) => link.outerHTML).join(
|
|
1681
|
+
""
|
|
1682
|
+
)}${reset ? `<style data-remote-components-reset="">:host { all: initial; }</style>` : ""}${component.innerHTML}`;
|
|
1553
1683
|
const userShared = await shared;
|
|
1554
1684
|
if ("__remote_components_missing_shared__" in userShared) {
|
|
1555
1685
|
userShared.__remote_components_missing_shared__().catch((e) => {
|
|
@@ -1560,48 +1690,88 @@ function RemoteComponent({
|
|
|
1560
1690
|
remoteShared.__remote_components_missing_shared__
|
|
1561
1691
|
);
|
|
1562
1692
|
}
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
if (result.error) {
|
|
1602
|
-
setRemoteComponent(result.error);
|
|
1693
|
+
if (isRemoteComponent) {
|
|
1694
|
+
setData(newData);
|
|
1695
|
+
if (shadowRoot) {
|
|
1696
|
+
let shadowRootHtml = component.innerHTML;
|
|
1697
|
+
if (reset) {
|
|
1698
|
+
shadowRootHtml = `<style data-remote-components-reset="">:host { all: initial; }</style>${shadowRootHtml}`;
|
|
1699
|
+
}
|
|
1700
|
+
shadowRoot.innerHTML = shadowRootHtml;
|
|
1701
|
+
setRemoteComponent(null);
|
|
1702
|
+
const { mount, unmount } = await loadStaticRemoteComponent(
|
|
1703
|
+
Array.from(shadowRoot.querySelectorAll("script")),
|
|
1704
|
+
url
|
|
1705
|
+
);
|
|
1706
|
+
unmountRef.current = unmount;
|
|
1707
|
+
await Promise.all(
|
|
1708
|
+
Array.from(mount).map((mountFn) => mountFn(shadowRoot))
|
|
1709
|
+
);
|
|
1710
|
+
} else if (isolate === false) {
|
|
1711
|
+
setRemoteComponent(
|
|
1712
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1713
|
+
"div",
|
|
1714
|
+
{
|
|
1715
|
+
dangerouslySetInnerHTML: { __html: component.innerHTML },
|
|
1716
|
+
ref: prevRemoteComponentContainerRef
|
|
1717
|
+
}
|
|
1718
|
+
)
|
|
1719
|
+
);
|
|
1720
|
+
const { mount, unmount } = await loadStaticRemoteComponent(
|
|
1721
|
+
Array.from(component.querySelectorAll("script")),
|
|
1722
|
+
url
|
|
1723
|
+
);
|
|
1724
|
+
unmountRef.current = unmount;
|
|
1725
|
+
await Promise.all(
|
|
1726
|
+
Array.from(mount).map(
|
|
1727
|
+
(mountFn) => mountFn(prevRemoteComponentContainerRef.current)
|
|
1728
|
+
)
|
|
1729
|
+
);
|
|
1730
|
+
}
|
|
1603
1731
|
} else {
|
|
1604
|
-
|
|
1732
|
+
const result = await loadRemoteComponent({
|
|
1733
|
+
url: new URL(url, location.origin),
|
|
1734
|
+
name: remoteName,
|
|
1735
|
+
rscName,
|
|
1736
|
+
bundle,
|
|
1737
|
+
route: metadata.route,
|
|
1738
|
+
runtime: metadata.runtime,
|
|
1739
|
+
data: newData.data,
|
|
1740
|
+
nextData,
|
|
1741
|
+
scripts: Array.from(scripts).map((script) => {
|
|
1742
|
+
const scriptSrc = script.getAttribute("data-src") || script.getAttribute("src") || script.src;
|
|
1743
|
+
const { prefix, id: path } = REMOTE_COMPONENT_REGEX.exec(
|
|
1744
|
+
scriptSrc
|
|
1745
|
+
)?.groups ?? {
|
|
1746
|
+
prefix: void 0,
|
|
1747
|
+
id: scriptSrc
|
|
1748
|
+
};
|
|
1749
|
+
return {
|
|
1750
|
+
src: new URL(
|
|
1751
|
+
`${prefix ?? ""}${path}`.replace(
|
|
1752
|
+
/(?<char>[^:])(?<double>\/\/)/g,
|
|
1753
|
+
"$1/"
|
|
1754
|
+
),
|
|
1755
|
+
url
|
|
1756
|
+
).href
|
|
1757
|
+
};
|
|
1758
|
+
}),
|
|
1759
|
+
shared: {
|
|
1760
|
+
...sharedPolyfills(userShared),
|
|
1761
|
+
...userShared
|
|
1762
|
+
},
|
|
1763
|
+
remoteShared,
|
|
1764
|
+
container: shadowRoot
|
|
1765
|
+
});
|
|
1766
|
+
if (rsc) {
|
|
1767
|
+
rsc.remove();
|
|
1768
|
+
}
|
|
1769
|
+
setData(newData);
|
|
1770
|
+
if (result.error) {
|
|
1771
|
+
setRemoteComponent(result.error);
|
|
1772
|
+
} else {
|
|
1773
|
+
setRemoteComponent(result.component);
|
|
1774
|
+
}
|
|
1605
1775
|
}
|
|
1606
1776
|
} catch (error) {
|
|
1607
1777
|
setRemoteComponent(error);
|
|
@@ -1616,7 +1786,8 @@ function RemoteComponent({
|
|
|
1616
1786
|
name,
|
|
1617
1787
|
shared,
|
|
1618
1788
|
shadowRoot,
|
|
1619
|
-
additionalHeaders
|
|
1789
|
+
additionalHeaders,
|
|
1790
|
+
reset
|
|
1620
1791
|
]);
|
|
1621
1792
|
if (remoteComponent instanceof Error) {
|
|
1622
1793
|
throw remoteComponent;
|
|
@@ -1625,7 +1796,7 @@ function RemoteComponent({
|
|
|
1625
1796
|
name: data?.name || name,
|
|
1626
1797
|
bundle: data?.bundle || "default",
|
|
1627
1798
|
route: data?.route || DEFAULT_ROUTE,
|
|
1628
|
-
runtime: data?.runtime || RUNTIME_WEBPACK
|
|
1799
|
+
runtime: prevIsRemoteComponentRef.current ? RUNTIME_SCRIPT : data?.runtime || RUNTIME_WEBPACK
|
|
1629
1800
|
}) });
|
|
1630
1801
|
const resetStyle = reset ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { "data-remote-components-reset": "", children: `:host { all: initial; }` }) : null;
|
|
1631
1802
|
const linksToRender = data?.links?.map((link) => /* @__PURE__ */ (0, import_react2.createElement)(
|
|
@@ -1644,6 +1815,24 @@ function RemoteComponent({
|
|
|
1644
1815
|
if (componentHydrationHtml.current && shadowRoot && !shadowRoot.innerHTML) {
|
|
1645
1816
|
shadowRoot.innerHTML = componentHydrationHtml.current;
|
|
1646
1817
|
componentHydrationHtml.current = null;
|
|
1818
|
+
if (prevIsRemoteComponentRef.current) {
|
|
1819
|
+
loadStaticRemoteComponent(
|
|
1820
|
+
Array.from(shadowRoot.querySelectorAll("script")),
|
|
1821
|
+
url
|
|
1822
|
+
).then(({ mount }) => {
|
|
1823
|
+
return Promise.all(
|
|
1824
|
+
Array.from(mount).map((mountFn) => mountFn(shadowRoot))
|
|
1825
|
+
);
|
|
1826
|
+
}).catch((e) => {
|
|
1827
|
+
const error = new RemoteComponentsError(
|
|
1828
|
+
`Error mounting remote component from "${url.href}"`,
|
|
1829
|
+
{
|
|
1830
|
+
cause: e
|
|
1831
|
+
}
|
|
1832
|
+
);
|
|
1833
|
+
setRemoteComponent(error);
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1647
1836
|
}
|
|
1648
1837
|
if (isolate !== false) {
|
|
1649
1838
|
const shadowRemoteComponentHtml = shadowRoot?.querySelector(`#__REMOTE_COMPONENT${name}`) ?? shadowRoot?.querySelector("div[data-bundle][data-route]");
|