remote-components 0.0.36 → 0.0.37
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-8951c052.d.ts → component-loader-2ca91ad8.d.ts} +4 -1
- package/dist/internal/next/host/app-router-client.cjs +51 -38
- 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 +51 -38
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +2 -2
- package/dist/internal/shared/ssr/fetch-remote-component.cjs +14 -14
- package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.d.ts +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.js +14 -14
- package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
- package/dist/internal/shared/ssr/get-client-or-server-url.cjs +35 -0
- package/dist/internal/shared/ssr/get-client-or-server-url.cjs.map +1 -0
- package/dist/internal/shared/ssr/get-client-or-server-url.d.ts +3 -0
- package/dist/internal/shared/ssr/get-client-or-server-url.js +11 -0
- package/dist/internal/shared/ssr/get-client-or-server-url.js.map +1 -0
- package/dist/next/host/app-router-server.cjs +3 -2
- package/dist/next/host/app-router-server.cjs.map +1 -1
- package/dist/next/host/app-router-server.js +3 -2
- package/dist/next/host/app-router-server.js.map +1 -1
- package/dist/next/host/client/index.cjs +31 -27
- 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 +31 -27
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs +4 -8
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.d.ts +0 -1
- package/dist/next/host/pages-router-server.js +4 -8
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/react/index.cjs +23 -27
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +23 -27
- package/dist/react/index.js.map +1 -1
- package/dist/{types-4e7dea94.d.ts → types-235b68a5.d.ts} +4 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
-
import { L as LoadRemoteComponentProps } from '../../../component-loader-
|
|
3
|
+
import { L as LoadRemoteComponentProps } from '../../../component-loader-2ca91ad8.js';
|
|
4
4
|
|
|
5
5
|
declare module 'react/jsx-runtime' {
|
|
6
6
|
namespace JSX {
|
|
@@ -1315,6 +1315,15 @@ function remoteFetchHeaders(additionalHeaders) {
|
|
|
1315
1315
|
};
|
|
1316
1316
|
}
|
|
1317
1317
|
|
|
1318
|
+
// src/shared/ssr/get-client-or-server-url.ts
|
|
1319
|
+
function getClientOrServerUrl(src, serverFallback) {
|
|
1320
|
+
const fallback = typeof location !== "undefined" ? location.href : serverFallback;
|
|
1321
|
+
if (!src) {
|
|
1322
|
+
return new URL(fallback);
|
|
1323
|
+
}
|
|
1324
|
+
return typeof src === "string" ? new URL(src, fallback) : src;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1318
1327
|
// src/react/index.tsx
|
|
1319
1328
|
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
1320
1329
|
import { createElement as createElement2 } from "react";
|
|
@@ -1337,6 +1346,7 @@ function getRemoteComponentHtml(html) {
|
|
|
1337
1346
|
}
|
|
1338
1347
|
return "";
|
|
1339
1348
|
}
|
|
1349
|
+
var DUMMY_FALLBACK = "http://remote-components-dummy-fallback";
|
|
1340
1350
|
function RemoteComponent({
|
|
1341
1351
|
src,
|
|
1342
1352
|
isolate,
|
|
@@ -1352,7 +1362,7 @@ function RemoteComponent({
|
|
|
1352
1362
|
if (typeof src === "string") {
|
|
1353
1363
|
const url2 = new URL(
|
|
1354
1364
|
src,
|
|
1355
|
-
typeof document !== "undefined" ? location.href :
|
|
1365
|
+
typeof document !== "undefined" ? location.href : DUMMY_FALLBACK
|
|
1356
1366
|
);
|
|
1357
1367
|
if (url2.hash) {
|
|
1358
1368
|
return url2.hash.slice(1);
|
|
@@ -1363,20 +1373,23 @@ function RemoteComponent({
|
|
|
1363
1373
|
return nameProp;
|
|
1364
1374
|
}, [src, nameProp]);
|
|
1365
1375
|
const [data, setData] = useState(null);
|
|
1376
|
+
const url = useMemo(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);
|
|
1377
|
+
const id = url.origin === (typeof location !== "undefined" ? location.origin : DUMMY_FALLBACK) ? url.pathname : url.href;
|
|
1378
|
+
const keySuffix = `${escapeString(id)}_${escapeString(data?.name ?? name)}`;
|
|
1366
1379
|
const [remoteComponent, setRemoteComponent] = useState(null);
|
|
1367
1380
|
const shadowRootContainerRef = useRef(null);
|
|
1368
1381
|
const [shadowRoot, setShadowRoot] = useState(() => {
|
|
1369
1382
|
const self = globalThis;
|
|
1370
|
-
const shadowRootKey = `__remote_components_shadowroot_${
|
|
1383
|
+
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
1371
1384
|
const ssrShadowRoot = typeof document !== "undefined" ? document.querySelector(
|
|
1372
|
-
`[data-remote-component-id="shadowroot_${
|
|
1385
|
+
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
1373
1386
|
)?.shadowRoot ?? self[shadowRootKey] ?? null : null;
|
|
1374
1387
|
self[shadowRootKey] = null;
|
|
1375
1388
|
return ssrShadowRoot;
|
|
1376
1389
|
});
|
|
1377
1390
|
const htmlRef = useRef(
|
|
1378
1391
|
typeof document !== "undefined" ? document.querySelector(
|
|
1379
|
-
`[data-remote-component-id="shadowroot_${
|
|
1392
|
+
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
1380
1393
|
)?.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
|
|
1381
1394
|
);
|
|
1382
1395
|
const endTemplateRef = useRef(null);
|
|
@@ -1408,10 +1421,10 @@ function RemoteComponent({
|
|
|
1408
1421
|
}
|
|
1409
1422
|
if (isolate !== false && typeof document !== "undefined" && !shadowRoot) {
|
|
1410
1423
|
const self = globalThis;
|
|
1411
|
-
const shadowRootKey = `__remote_components_shadowroot_${
|
|
1424
|
+
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
1412
1425
|
let shadowRootElement = null;
|
|
1413
1426
|
const element = document.querySelector(
|
|
1414
|
-
`[data-remote-component-id="shadowroot_${
|
|
1427
|
+
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
1415
1428
|
);
|
|
1416
1429
|
shadowRootElement = self[shadowRootKey] ?? element?.shadowRoot ?? null;
|
|
1417
1430
|
if (!shadowRootElement && element) {
|
|
@@ -1428,7 +1441,7 @@ function RemoteComponent({
|
|
|
1428
1441
|
setShadowRoot(shadowRootElement);
|
|
1429
1442
|
}
|
|
1430
1443
|
}
|
|
1431
|
-
}, [
|
|
1444
|
+
}, [isolate, shadowRoot, remoteComponent, mode, keySuffix]);
|
|
1432
1445
|
useLayoutEffect(() => {
|
|
1433
1446
|
if (shadowRoot && remoteComponent) {
|
|
1434
1447
|
const resetStyles = shadowRoot.querySelectorAll(
|
|
@@ -1452,17 +1465,6 @@ function RemoteComponent({
|
|
|
1452
1465
|
}
|
|
1453
1466
|
}
|
|
1454
1467
|
}, [shadowRoot, remoteComponent, name]);
|
|
1455
|
-
const url = useMemo(() => {
|
|
1456
|
-
if (typeof src !== "string")
|
|
1457
|
-
return new URL(
|
|
1458
|
-
typeof document !== "undefined" ? location.href : "http://localhost"
|
|
1459
|
-
);
|
|
1460
|
-
try {
|
|
1461
|
-
return typeof document !== "undefined" ? new URL(src, location.href) : new URL(src);
|
|
1462
|
-
} catch {
|
|
1463
|
-
return new URL(src, "http://localhost");
|
|
1464
|
-
}
|
|
1465
|
-
}, [src]);
|
|
1466
1468
|
useEffect(() => {
|
|
1467
1469
|
if (src && src !== prevSrcRef.current) {
|
|
1468
1470
|
prevSrcRef.current = src;
|
|
@@ -1637,7 +1639,9 @@ function RemoteComponent({
|
|
|
1637
1639
|
}
|
|
1638
1640
|
let rscName;
|
|
1639
1641
|
if (rsc) {
|
|
1640
|
-
rscName = `__remote_component_rsc_${escapeString(
|
|
1642
|
+
rscName = `__remote_component_rsc_${escapeString(
|
|
1643
|
+
id
|
|
1644
|
+
)}_${escapeString(remoteName)}`;
|
|
1641
1645
|
rsc.textContent = rsc.textContent?.replace(
|
|
1642
1646
|
new RegExp(`self\\["${remoteName}"\\]`, "g"),
|
|
1643
1647
|
`self["${rscName}"]`
|
|
@@ -1648,14 +1652,13 @@ function RemoteComponent({
|
|
|
1648
1652
|
...metadata,
|
|
1649
1653
|
links,
|
|
1650
1654
|
remoteShared,
|
|
1651
|
-
|
|
1655
|
+
src: typeof src === "string" ? src : src.href,
|
|
1656
|
+
serverUrl: url.href,
|
|
1652
1657
|
data: rsc ? (rsc.textContent || "").split("\n").filter(Boolean) : []
|
|
1653
1658
|
};
|
|
1654
1659
|
componentHydrationHtml.current = `${Array.from(
|
|
1655
1660
|
doc.querySelectorAll("link,style")
|
|
1656
|
-
).map((link) => link.outerHTML).join(
|
|
1657
|
-
""
|
|
1658
|
-
)}${reset ? `<style data-remote-components-reset="">:host { all: initial; }</style>` : ""}${component.innerHTML}`;
|
|
1661
|
+
).map((link) => link.outerHTML).join("")}${reset ? `<style data-remote-components-reset="">:host { all: initial; }</style>` : ""}${component.innerHTML}`;
|
|
1659
1662
|
const userShared = await shared;
|
|
1660
1663
|
if ("__remote_components_missing_shared__" in userShared) {
|
|
1661
1664
|
userShared.__remote_components_missing_shared__().catch((e) => {
|
|
@@ -1707,7 +1710,7 @@ function RemoteComponent({
|
|
|
1707
1710
|
}
|
|
1708
1711
|
} else {
|
|
1709
1712
|
const result = await loadRemoteComponent({
|
|
1710
|
-
url
|
|
1713
|
+
url,
|
|
1711
1714
|
name: remoteName,
|
|
1712
1715
|
rscName,
|
|
1713
1716
|
bundle,
|
|
@@ -1764,7 +1767,8 @@ function RemoteComponent({
|
|
|
1764
1767
|
shared,
|
|
1765
1768
|
shadowRoot,
|
|
1766
1769
|
additionalHeaders,
|
|
1767
|
-
reset
|
|
1770
|
+
reset,
|
|
1771
|
+
id
|
|
1768
1772
|
]);
|
|
1769
1773
|
if (remoteComponent instanceof Error) {
|
|
1770
1774
|
throw remoteComponent;
|
|
@@ -1821,7 +1825,7 @@ function RemoteComponent({
|
|
|
1821
1825
|
/* @__PURE__ */ jsxs(
|
|
1822
1826
|
"div",
|
|
1823
1827
|
{
|
|
1824
|
-
"data-remote-component-id": `shadowroot_${
|
|
1828
|
+
"data-remote-component-id": `shadowroot_${keySuffix}`,
|
|
1825
1829
|
id: `shadowroot_${data?.name ?? name}`,
|
|
1826
1830
|
ref: shadowRootContainerRef,
|
|
1827
1831
|
children: [
|
|
@@ -1837,7 +1841,7 @@ function RemoteComponent({
|
|
|
1837
1841
|
src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="
|
|
1838
1842
|
onload="(function(el){
|
|
1839
1843
|
const root = el.getRootNode();
|
|
1840
|
-
globalThis.__remote_components_shadowroot_${
|
|
1844
|
+
globalThis.__remote_components_shadowroot_${keySuffix} = root;
|
|
1841
1845
|
el.parentElement.remove();
|
|
1842
1846
|
})(this)"
|
|
1843
1847
|
/>`
|