remote-components 0.0.42 → 0.0.44
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-2ca91ad8.d.ts → component-loader-26b1f55e.d.ts} +63 -1
- package/dist/html/host.cjs +55 -19
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +55 -19
- package/dist/html/host.js.map +1 -1
- package/dist/internal/next/host/app-router-client.d.ts +30 -3
- package/dist/internal/next/remote/render-client.cjs +1 -1
- package/dist/internal/next/remote/render-client.cjs.map +1 -1
- package/dist/internal/next/remote/render-client.js +1 -1
- package/dist/internal/next/remote/render-client.js.map +1 -1
- package/dist/internal/shared/client/remote-component.cjs +29 -0
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +2 -2
- package/dist/internal/shared/client/remote-component.js +29 -0
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
- package/dist/internal/shared/ssr/fetch-headers.cjs +4 -6
- package/dist/internal/shared/ssr/fetch-headers.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-headers.d.ts +1 -1
- package/dist/internal/shared/ssr/fetch-headers.js +4 -6
- package/dist/internal/shared/ssr/fetch-headers.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.cjs +14 -23
- package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.d.ts +5 -9
- package/dist/internal/shared/ssr/fetch-remote-component.js +13 -21
- package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.cjs +40 -0
- package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -0
- package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +39 -0
- package/dist/internal/shared/ssr/fetch-with-hooks.js +16 -0
- package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -0
- package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.cjs.map +1 -1
- package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.js.map +1 -1
- package/dist/next/config.cjs +1 -9
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +1 -9
- package/dist/next/config.js.map +1 -1
- package/dist/next/host/app-router-server.cjs +7 -8
- package/dist/next/host/app-router-server.cjs.map +1 -1
- package/dist/next/host/app-router-server.d.ts +13 -4
- package/dist/next/host/app-router-server.js +7 -8
- package/dist/next/host/app-router-server.js.map +1 -1
- package/dist/next/host/client/index.cjs +149 -72
- package/dist/next/host/client/index.cjs.map +1 -1
- package/dist/next/host/client/index.d.ts +2 -49
- package/dist/next/host/client/index.js +144 -66
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-client.cjs +62 -2
- package/dist/next/host/pages-router-client.cjs.map +1 -1
- package/dist/next/host/pages-router-client.d.ts +26 -1
- package/dist/next/host/pages-router-client.js +63 -3
- package/dist/next/host/pages-router-client.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs +18 -22
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.d.ts +36 -3
- package/dist/next/host/pages-router-server.js +18 -22
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.ts +1 -1
- package/dist/next/index.js.map +1 -1
- package/dist/react/index.cjs +1581 -87
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +13 -14
- package/dist/react/index.js +1559 -87
- package/dist/react/index.js.map +1 -1
- package/dist/shared/host/app.cjs +1 -1
- package/dist/shared/host/app.cjs.map +1 -1
- package/dist/shared/host/app.js +1 -1
- package/dist/shared/host/app.js.map +1 -1
- package/dist/shared/host/pages.cjs +1 -1
- package/dist/shared/host/pages.cjs.map +1 -1
- package/dist/shared/host/pages.js +1 -1
- package/dist/shared/host/pages.js.map +1 -1
- package/dist/shared/remote/app.cjs +1 -1
- package/dist/shared/remote/app.cjs.map +1 -1
- package/dist/shared/remote/app.js +1 -1
- package/dist/shared/remote/app.js.map +1 -1
- package/dist/shared/remote/pages.cjs +1 -1
- package/dist/shared/remote/pages.cjs.map +1 -1
- package/dist/shared/remote/pages.js +1 -1
- package/dist/shared/remote/pages.js.map +1 -1
- package/dist/types-2ab78f67.d.ts +71 -0
- package/package.json +54 -32
- package/dist/types-235b68a5.d.ts +0 -32
- package/dist/types-cbf6c34f.d.ts +0 -9
|
@@ -1,54 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
declare module 'react/jsx-runtime' {
|
|
6
|
-
namespace JSX {
|
|
7
|
-
interface IntrinsicElements {
|
|
8
|
-
template: {
|
|
9
|
-
shadowrootmode?: 'open' | 'closed';
|
|
10
|
-
id?: string;
|
|
11
|
-
ref?: React.Ref<HTMLTemplateElement>;
|
|
12
|
-
dangerouslySetInnerHTML?: {
|
|
13
|
-
__html: string;
|
|
14
|
-
};
|
|
15
|
-
children?: React.ReactNode;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
interface RemoteComponentProps {
|
|
21
|
-
/** The source URL of the remote component. */
|
|
22
|
-
src?: string | URL;
|
|
23
|
-
/** Whether to isolate the remote component using a Shadow DOM wrapper. */
|
|
24
|
-
isolate?: boolean;
|
|
25
|
-
/** The shadow DOM mode to use when isolating the remote component. */
|
|
26
|
-
mode?: 'open' | 'closed';
|
|
27
|
-
/** Whether to include a CSS reset style in the shadow DOM. Defaults to `false`. */
|
|
28
|
-
reset?: boolean;
|
|
29
|
-
/** The credentials to use for the fetch request. Defaults to `same-origin`. */
|
|
30
|
-
credentials?: RequestCredentials;
|
|
31
|
-
name?: string;
|
|
32
|
-
/** Shared modules to include in the remote component's context. */
|
|
33
|
-
shared?: LoadRemoteComponentProps['shared'];
|
|
34
|
-
/** Additional headers to use when fetching the remote component. */
|
|
35
|
-
additionalHeaders?: Headers | Record<string, string>;
|
|
36
|
-
/** The children to use as a loading fallback until the remote component is loaded. */
|
|
37
|
-
children?: React.ReactNode;
|
|
38
|
-
/** Called right before a new remote component load starts. */
|
|
39
|
-
onBeforeLoad?: (src: string | URL) => void;
|
|
40
|
-
/** Called when the remote component has been successfully loaded and mounted. */
|
|
41
|
-
onLoad?: (src: string | URL) => void;
|
|
42
|
-
/** Called when an error occurs while loading or mounting the remote component. */
|
|
43
|
-
onError?: (error: unknown) => void;
|
|
44
|
-
/** Called when a different remote component is loaded into the same wrapper. */
|
|
45
|
-
onChange?: (info: {
|
|
46
|
-
previousSrc: string | URL | null;
|
|
47
|
-
nextSrc: string | URL | null;
|
|
48
|
-
previousName: string | undefined;
|
|
49
|
-
nextName: string | undefined;
|
|
50
|
-
}) => void;
|
|
51
|
-
}
|
|
3
|
+
import { RemoteComponentProps } from '../../../react/index.js';
|
|
4
|
+
import '../../../component-loader-26b1f55e.js';
|
|
52
5
|
|
|
53
6
|
/**
|
|
54
7
|
* RemoteComponent - Client-side component for rendering remote components
|
|
@@ -7,10 +7,11 @@ import * as Image from "next/image";
|
|
|
7
7
|
import {
|
|
8
8
|
startTransition,
|
|
9
9
|
useEffect,
|
|
10
|
-
|
|
10
|
+
useId,
|
|
11
|
+
useLayoutEffect as useLayoutEffect2,
|
|
11
12
|
useMemo,
|
|
12
|
-
useRef,
|
|
13
|
-
useState
|
|
13
|
+
useRef as useRef2,
|
|
14
|
+
useState as useState2
|
|
14
15
|
} from "react";
|
|
15
16
|
import { createPortal } from "react-dom";
|
|
16
17
|
|
|
@@ -598,6 +599,7 @@ function getBundleKey(bundle) {
|
|
|
598
599
|
// src/shared/client/chunk-loader.ts
|
|
599
600
|
function createChunkLoader(runtime) {
|
|
600
601
|
return function __turbopack_chunk_load__(chunkId, scriptBundle) {
|
|
602
|
+
logDebug("ChunkLoader", `Loading chunk: "${chunkId}"`);
|
|
601
603
|
const self = globalThis;
|
|
602
604
|
const {
|
|
603
605
|
bundle,
|
|
@@ -607,8 +609,14 @@ function createChunkLoader(runtime) {
|
|
|
607
609
|
bundle: scriptBundle ?? "",
|
|
608
610
|
id: chunkId
|
|
609
611
|
};
|
|
612
|
+
logDebug(
|
|
613
|
+
"ChunkLoader",
|
|
614
|
+
`Parsed chunk - bundle: "${bundle}", path: "${path}", prefix: "${prefix}"`
|
|
615
|
+
);
|
|
610
616
|
const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
|
|
617
|
+
logDebug("ChunkLoader", `Remote runtime: "${remoteRuntime}"`);
|
|
611
618
|
if (remoteRuntime === RUNTIME_WEBPACK) {
|
|
619
|
+
logDebug("ChunkLoader", "Skipping chunk load - webpack runtime detected");
|
|
612
620
|
return Promise.resolve(void 0);
|
|
613
621
|
}
|
|
614
622
|
const url = new URL(
|
|
@@ -619,14 +627,17 @@ function createChunkLoader(runtime) {
|
|
|
619
627
|
self.__remote_bundle_url__?.[bundle ?? "default"] ?? new URL(location.origin)
|
|
620
628
|
).href;
|
|
621
629
|
if (url.endsWith(".css")) {
|
|
630
|
+
logDebug("ChunkLoader", `Skipping CSS file: "${url}"`);
|
|
622
631
|
return;
|
|
623
632
|
}
|
|
624
633
|
if (!self.__remote_components_turbopack_chunk_loader_promise__) {
|
|
625
634
|
self.__remote_components_turbopack_chunk_loader_promise__ = {};
|
|
626
635
|
}
|
|
627
636
|
if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {
|
|
637
|
+
logDebug("ChunkLoader", `Returning cached promise for: "${url}"`);
|
|
628
638
|
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
629
639
|
}
|
|
640
|
+
logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
|
|
630
641
|
self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
|
|
631
642
|
fetch(url).then((res) => res.text()).then((code) => {
|
|
632
643
|
if (code.includes("globalThis.TURBOPACK")) {
|
|
@@ -638,7 +649,12 @@ function createChunkLoader(runtime) {
|
|
|
638
649
|
};
|
|
639
650
|
}
|
|
640
651
|
async function handleTurbopackChunk(code, bundle, url) {
|
|
652
|
+
logDebug(
|
|
653
|
+
"ChunkLoader",
|
|
654
|
+
`Handling Turbopack chunk - bundle: "${bundle}", url: "${url}"`
|
|
655
|
+
);
|
|
641
656
|
if (/importScripts\(\.\.\.self.TURBOPACK_NEXT_CHUNK_URLS/.test(code)) {
|
|
657
|
+
logDebug("ChunkLoader", `Skipping worker chunk: "${url}"`);
|
|
642
658
|
const preloadLinks = document.querySelectorAll(
|
|
643
659
|
`link[rel="preload"][href="${new URL(url).pathname}"]`
|
|
644
660
|
);
|
|
@@ -647,6 +663,7 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
647
663
|
}
|
|
648
664
|
const self = globalThis;
|
|
649
665
|
const bundleKey = getBundleKey(bundle);
|
|
666
|
+
logDebug("ChunkLoader", `Bundle key: "${bundleKey}"`);
|
|
650
667
|
const transformedCode = code.replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(
|
|
651
668
|
/TURBOPACK_WORKER_LOCATION/g,
|
|
652
669
|
`TURBOPACK_WORKER_LOCATION_${bundleKey}`
|
|
@@ -666,6 +683,7 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
666
683
|
)
|
|
667
684
|
).href}$1$2.js.map`
|
|
668
685
|
);
|
|
686
|
+
logDebug("ChunkLoader", `Creating blob script for: "${url}"`);
|
|
669
687
|
await new Promise((scriptResolve, scriptReject) => {
|
|
670
688
|
const blob = new Blob([transformedCode], {
|
|
671
689
|
type: "application/javascript; charset=UTF-8"
|
|
@@ -692,10 +710,18 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
692
710
|
document.head.appendChild(script);
|
|
693
711
|
});
|
|
694
712
|
const chunkLists = self[`TURBOPACK_${bundleKey}_CHUNK_LISTS`];
|
|
713
|
+
logDebug(
|
|
714
|
+
"ChunkLoader",
|
|
715
|
+
`Processing chunk lists for bundle "${bundle}": ${chunkLists?.length ?? 0} lists`
|
|
716
|
+
);
|
|
695
717
|
const loadChunkLists = [];
|
|
696
718
|
while (chunkLists?.length) {
|
|
697
719
|
const { chunks } = chunkLists.shift() ?? { chunks: [] };
|
|
698
720
|
if (chunks.length > 0) {
|
|
721
|
+
logDebug(
|
|
722
|
+
"ChunkLoader",
|
|
723
|
+
`Loading ${chunks.length} additional chunks for bundle "${bundle}": [${chunks.join(", ")}]`
|
|
724
|
+
);
|
|
699
725
|
chunks.forEach((id) => {
|
|
700
726
|
const chunkLoadResult = self.__webpack_chunk_load__?.(
|
|
701
727
|
`[${bundle}] ${url.slice(0, url.indexOf("/_next"))}/_next/${id}`
|
|
@@ -707,6 +733,10 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
707
733
|
}
|
|
708
734
|
}
|
|
709
735
|
if (loadChunkLists.length > 0) {
|
|
736
|
+
logDebug(
|
|
737
|
+
"ChunkLoader",
|
|
738
|
+
`Waiting for ${loadChunkLists.length} additional chunks to load`
|
|
739
|
+
);
|
|
710
740
|
await Promise.all(loadChunkLists);
|
|
711
741
|
}
|
|
712
742
|
}
|
|
@@ -1398,23 +1428,35 @@ async function loadStaticRemoteComponent(scripts, url) {
|
|
|
1398
1428
|
}
|
|
1399
1429
|
|
|
1400
1430
|
// src/shared/ssr/fetch-headers.ts
|
|
1401
|
-
function remoteFetchHeaders(
|
|
1431
|
+
function remoteFetchHeaders() {
|
|
1402
1432
|
return {
|
|
1403
1433
|
/**
|
|
1404
1434
|
* Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
|
|
1405
|
-
*
|
|
1406
|
-
*
|
|
1435
|
+
* If the remote component uses vercel deployment protection, ensure the host and remote vercel
|
|
1436
|
+
* projects share a common automation bypass secret, and the shared secret is used as the
|
|
1437
|
+
* VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
|
|
1407
1438
|
*/
|
|
1408
1439
|
...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
|
|
1409
1440
|
"x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
|
|
1410
1441
|
} : {},
|
|
1411
|
-
...Object.fromEntries(
|
|
1412
|
-
additionalHeaders instanceof Headers ? additionalHeaders.entries() : Object.entries(additionalHeaders ?? {})
|
|
1413
|
-
),
|
|
1414
1442
|
Accept: "text/html"
|
|
1415
1443
|
};
|
|
1416
1444
|
}
|
|
1417
1445
|
|
|
1446
|
+
// src/shared/ssr/fetch-with-hooks.ts
|
|
1447
|
+
async function fetchWithHooks(url, init, options = {}) {
|
|
1448
|
+
const { onRequest, onResponse } = options;
|
|
1449
|
+
let res = await onRequest?.(url, init);
|
|
1450
|
+
if (!res) {
|
|
1451
|
+
res = await fetch(url, init);
|
|
1452
|
+
}
|
|
1453
|
+
const transformedRes = await onResponse?.(url, res);
|
|
1454
|
+
if (transformedRes) {
|
|
1455
|
+
res = transformedRes;
|
|
1456
|
+
}
|
|
1457
|
+
return res;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1418
1460
|
// src/shared/ssr/get-client-or-server-url.ts
|
|
1419
1461
|
function getClientOrServerUrl(src, serverFallback) {
|
|
1420
1462
|
const fallback = typeof location !== "undefined" ? location.href : serverFallback;
|
|
@@ -1424,9 +1466,57 @@ function getClientOrServerUrl(src, serverFallback) {
|
|
|
1424
1466
|
return typeof src === "string" ? new URL(src, fallback) : src;
|
|
1425
1467
|
}
|
|
1426
1468
|
|
|
1427
|
-
// src/react/
|
|
1428
|
-
import {
|
|
1429
|
-
|
|
1469
|
+
// src/react/hooks/use-shadow-root.ts
|
|
1470
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
1471
|
+
function useShadowRoot({
|
|
1472
|
+
isolate,
|
|
1473
|
+
mode,
|
|
1474
|
+
keySuffix
|
|
1475
|
+
}) {
|
|
1476
|
+
const shadowRootContainerRef = useRef(null);
|
|
1477
|
+
const [shadowRoot, setShadowRoot] = useState(() => {
|
|
1478
|
+
const self = globalThis;
|
|
1479
|
+
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
1480
|
+
const ssrShadowRoot = typeof document !== "undefined" ? document.querySelector(
|
|
1481
|
+
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
1482
|
+
)?.shadowRoot ?? self[shadowRootKey] ?? null : null;
|
|
1483
|
+
self[shadowRootKey] = null;
|
|
1484
|
+
return ssrShadowRoot;
|
|
1485
|
+
});
|
|
1486
|
+
useLayoutEffect(() => {
|
|
1487
|
+
if (isolate !== false && typeof document !== "undefined" && (!shadowRoot || !shadowRoot.isConnected)) {
|
|
1488
|
+
const self = globalThis;
|
|
1489
|
+
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
1490
|
+
let shadowRootElement = null;
|
|
1491
|
+
const element = document.querySelector(
|
|
1492
|
+
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
1493
|
+
);
|
|
1494
|
+
shadowRootElement = self[shadowRootKey] ?? element?.shadowRoot ?? null;
|
|
1495
|
+
if (!shadowRootElement && element) {
|
|
1496
|
+
try {
|
|
1497
|
+
shadowRootElement = element.attachShadow({ mode });
|
|
1498
|
+
self[shadowRootKey] = shadowRootElement;
|
|
1499
|
+
} catch {
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
if (shadowRootElement) {
|
|
1503
|
+
shadowRootElement.querySelectorAll("*:not(link)").forEach((node) => {
|
|
1504
|
+
node.remove();
|
|
1505
|
+
});
|
|
1506
|
+
setShadowRoot(shadowRootElement);
|
|
1507
|
+
}
|
|
1508
|
+
} else if (isolate === false && shadowRoot) {
|
|
1509
|
+
const self = globalThis;
|
|
1510
|
+
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
1511
|
+
self[shadowRootKey] = null;
|
|
1512
|
+
setShadowRoot(null);
|
|
1513
|
+
}
|
|
1514
|
+
}, [isolate, shadowRoot, mode, keySuffix]);
|
|
1515
|
+
return { shadowRoot, shadowRootContainerRef };
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
// src/react/utils/parse-remote-html.ts
|
|
1519
|
+
var DUMMY_FALLBACK = "http://remote-components-dummy-fallback";
|
|
1430
1520
|
function getRemoteComponentHtml(html) {
|
|
1431
1521
|
if (typeof document === "undefined")
|
|
1432
1522
|
return html;
|
|
@@ -1446,7 +1536,10 @@ function getRemoteComponentHtml(html) {
|
|
|
1446
1536
|
}
|
|
1447
1537
|
return "";
|
|
1448
1538
|
}
|
|
1449
|
-
|
|
1539
|
+
|
|
1540
|
+
// src/react/index.tsx
|
|
1541
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
1542
|
+
import { createElement as createElement2 } from "react";
|
|
1450
1543
|
function RemoteComponent({
|
|
1451
1544
|
src,
|
|
1452
1545
|
isolate,
|
|
@@ -1455,13 +1548,15 @@ function RemoteComponent({
|
|
|
1455
1548
|
credentials = "same-origin",
|
|
1456
1549
|
name: nameProp = "__vercel_remote_component",
|
|
1457
1550
|
shared = {},
|
|
1458
|
-
additionalHeaders,
|
|
1459
1551
|
children,
|
|
1460
1552
|
onBeforeLoad,
|
|
1461
1553
|
onLoad,
|
|
1462
1554
|
onError,
|
|
1463
|
-
onChange
|
|
1555
|
+
onChange,
|
|
1556
|
+
onRequest,
|
|
1557
|
+
onResponse
|
|
1464
1558
|
}) {
|
|
1559
|
+
const instanceId = useId();
|
|
1465
1560
|
const name = useMemo(() => {
|
|
1466
1561
|
if (typeof src === "string") {
|
|
1467
1562
|
const url2 = new URL(
|
|
@@ -1476,28 +1571,23 @@ function RemoteComponent({
|
|
|
1476
1571
|
}
|
|
1477
1572
|
return nameProp;
|
|
1478
1573
|
}, [src, nameProp]);
|
|
1479
|
-
const [data, setData] =
|
|
1574
|
+
const [data, setData] = useState2(null);
|
|
1480
1575
|
const url = useMemo(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);
|
|
1481
1576
|
const id = url.origin === (typeof location !== "undefined" ? location.origin : DUMMY_FALLBACK) ? url.pathname : url.href;
|
|
1482
|
-
const keySuffix = `${escapeString(id)}_${escapeString(data?.name ?? name)}`;
|
|
1483
|
-
const [remoteComponent, setRemoteComponent] =
|
|
1484
|
-
const shadowRootContainerRef =
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
const ssrShadowRoot = typeof document !== "undefined" ? document.querySelector(
|
|
1489
|
-
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
1490
|
-
)?.shadowRoot ?? self[shadowRootKey] ?? null : null;
|
|
1491
|
-
self[shadowRootKey] = null;
|
|
1492
|
-
return ssrShadowRoot;
|
|
1577
|
+
const keySuffix = `${escapeString(id)}_${escapeString(data?.name ?? name)}_${escapeString(instanceId)}`;
|
|
1578
|
+
const [remoteComponent, setRemoteComponent] = useState2(null);
|
|
1579
|
+
const { shadowRoot, shadowRootContainerRef } = useShadowRoot({
|
|
1580
|
+
isolate,
|
|
1581
|
+
mode,
|
|
1582
|
+
keySuffix
|
|
1493
1583
|
});
|
|
1494
|
-
const htmlRef =
|
|
1584
|
+
const htmlRef = useRef2(
|
|
1495
1585
|
typeof document !== "undefined" ? document.querySelector(
|
|
1496
1586
|
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
1497
1587
|
)?.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
|
|
1498
1588
|
);
|
|
1499
|
-
const endTemplateRef =
|
|
1500
|
-
const childrenRef =
|
|
1589
|
+
const endTemplateRef = useRef2(null);
|
|
1590
|
+
const childrenRef = useRef2(
|
|
1501
1591
|
typeof document !== "undefined" ? (() => {
|
|
1502
1592
|
let el = document.querySelector(`template[id="${name}_start"]`);
|
|
1503
1593
|
const elements = [];
|
|
@@ -1510,44 +1600,28 @@ function RemoteComponent({
|
|
|
1510
1600
|
return elements;
|
|
1511
1601
|
})() : []
|
|
1512
1602
|
);
|
|
1513
|
-
const prevSrcRef =
|
|
1514
|
-
const componentHydrationHtml =
|
|
1515
|
-
const prevIsRemoteComponentRef =
|
|
1516
|
-
const prevUrlRef =
|
|
1517
|
-
const prevRemoteComponentContainerRef =
|
|
1518
|
-
const unmountRef =
|
|
1519
|
-
const prevNameRef =
|
|
1520
|
-
|
|
1603
|
+
const prevSrcRef = useRef2(null);
|
|
1604
|
+
const componentHydrationHtml = useRef2(null);
|
|
1605
|
+
const prevIsRemoteComponentRef = useRef2(false);
|
|
1606
|
+
const prevUrlRef = useRef2(null);
|
|
1607
|
+
const prevRemoteComponentContainerRef = useRef2(null);
|
|
1608
|
+
const unmountRef = useRef2(null);
|
|
1609
|
+
const prevNameRef = useRef2(void 0);
|
|
1610
|
+
useLayoutEffect2(() => {
|
|
1611
|
+
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
1612
|
+
return () => {
|
|
1613
|
+
delete globalThis[shadowRootKey];
|
|
1614
|
+
};
|
|
1615
|
+
}, [keySuffix]);
|
|
1616
|
+
useLayoutEffect2(() => {
|
|
1521
1617
|
if (childrenRef.current.length > 0 && remoteComponent) {
|
|
1522
1618
|
childrenRef.current.forEach((el) => {
|
|
1523
1619
|
el.remove();
|
|
1524
1620
|
});
|
|
1525
1621
|
childrenRef.current = [];
|
|
1526
1622
|
}
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
|
|
1530
|
-
let shadowRootElement = null;
|
|
1531
|
-
const element = document.querySelector(
|
|
1532
|
-
`[data-remote-component-id="shadowroot_${keySuffix}"]`
|
|
1533
|
-
);
|
|
1534
|
-
shadowRootElement = self[shadowRootKey] ?? element?.shadowRoot ?? null;
|
|
1535
|
-
if (!shadowRootElement && element) {
|
|
1536
|
-
try {
|
|
1537
|
-
shadowRootElement = element.attachShadow({ mode });
|
|
1538
|
-
self[shadowRootKey] = shadowRootElement;
|
|
1539
|
-
} catch {
|
|
1540
|
-
}
|
|
1541
|
-
}
|
|
1542
|
-
if (shadowRootElement) {
|
|
1543
|
-
shadowRootElement.querySelectorAll("*:not(link)").forEach((node) => {
|
|
1544
|
-
node.remove();
|
|
1545
|
-
});
|
|
1546
|
-
setShadowRoot(shadowRootElement);
|
|
1547
|
-
}
|
|
1548
|
-
}
|
|
1549
|
-
}, [isolate, shadowRoot, remoteComponent, mode, keySuffix]);
|
|
1550
|
-
useLayoutEffect(() => {
|
|
1623
|
+
}, [remoteComponent]);
|
|
1624
|
+
useLayoutEffect2(() => {
|
|
1551
1625
|
if (shadowRoot && remoteComponent) {
|
|
1552
1626
|
const resetStyles = shadowRoot.querySelectorAll(
|
|
1553
1627
|
"style[data-remote-components-reset]"
|
|
@@ -1584,10 +1658,13 @@ function RemoteComponent({
|
|
|
1584
1658
|
if (!html && src) {
|
|
1585
1659
|
const fetchInit = {
|
|
1586
1660
|
method: "GET",
|
|
1587
|
-
headers: remoteFetchHeaders(
|
|
1661
|
+
headers: remoteFetchHeaders(),
|
|
1588
1662
|
credentials
|
|
1589
1663
|
};
|
|
1590
|
-
const res = await
|
|
1664
|
+
const res = await fetchWithHooks(url, fetchInit, {
|
|
1665
|
+
onRequest,
|
|
1666
|
+
onResponse
|
|
1667
|
+
});
|
|
1591
1668
|
if (!res.ok) {
|
|
1592
1669
|
let error = failedToFetchRemoteComponentError(
|
|
1593
1670
|
url.href,
|
|
@@ -1897,13 +1974,14 @@ function RemoteComponent({
|
|
|
1897
1974
|
name,
|
|
1898
1975
|
shared,
|
|
1899
1976
|
shadowRoot,
|
|
1900
|
-
additionalHeaders,
|
|
1901
1977
|
reset,
|
|
1902
1978
|
id,
|
|
1903
1979
|
onBeforeLoad,
|
|
1904
1980
|
onLoad,
|
|
1905
1981
|
onError,
|
|
1906
|
-
onChange
|
|
1982
|
+
onChange,
|
|
1983
|
+
onRequest,
|
|
1984
|
+
onResponse
|
|
1907
1985
|
]);
|
|
1908
1986
|
if (remoteComponent instanceof Error) {
|
|
1909
1987
|
throw remoteComponent;
|