remote-components 0.0.43 → 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 +25 -19
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +25 -19
- package/dist/html/host.js.map +1 -1
- package/dist/internal/next/host/app-router-client.d.ts +1 -1
- 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.d.ts +2 -2
- 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 +29 -12
- 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 +29 -12
- 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 +29 -12
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +13 -5
- package/dist/react/index.js +29 -12
- 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-cbf6c34f.d.ts +0 -9
package/dist/react/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { L as LoadRemoteComponentProps } from '../component-loader-
|
|
2
|
+
import { L as LoadRemoteComponentProps, O as OnRequestHook, a as OnResponseHook } from '../component-loader-26b1f55e.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
5
5
|
declare module 'react/jsx-runtime' {
|
|
@@ -31,8 +31,6 @@ interface RemoteComponentProps {
|
|
|
31
31
|
name?: string;
|
|
32
32
|
/** Shared modules to include in the remote component's context. */
|
|
33
33
|
shared?: LoadRemoteComponentProps['shared'];
|
|
34
|
-
/** Additional headers to use when fetching the remote component. */
|
|
35
|
-
additionalHeaders?: Headers | Record<string, string>;
|
|
36
34
|
/** The children to use as a loading fallback until the remote component is loaded. */
|
|
37
35
|
children?: React.ReactNode;
|
|
38
36
|
/** Called right before a new remote component load starts. */
|
|
@@ -48,6 +46,16 @@ interface RemoteComponentProps {
|
|
|
48
46
|
previousName: string | undefined;
|
|
49
47
|
nextName: string | undefined;
|
|
50
48
|
}) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Called when a fetch request is made to retrieve the remote component payload.
|
|
51
|
+
* Can be used to intercept requests, modify headers, or provide a custom response.
|
|
52
|
+
*/
|
|
53
|
+
onRequest?: OnRequestHook;
|
|
54
|
+
/**
|
|
55
|
+
* Called after a fetch completes to retrieve the remote component payload.
|
|
56
|
+
* Can be used to inspect the response (e.g., check for redirects) or transform it.
|
|
57
|
+
*/
|
|
58
|
+
onResponse?: OnResponseHook;
|
|
51
59
|
}
|
|
52
60
|
/**
|
|
53
61
|
* RemoteComponent is a React component that fetches and renders a remote component.
|
|
@@ -85,6 +93,6 @@ interface RemoteComponentProps {
|
|
|
85
93
|
* />
|
|
86
94
|
* ```
|
|
87
95
|
*/
|
|
88
|
-
declare function RemoteComponent({ src, isolate, mode, reset, credentials, name: nameProp, shared,
|
|
96
|
+
declare function RemoteComponent({ src, isolate, mode, reset, credentials, name: nameProp, shared, children, onBeforeLoad, onLoad, onError, onChange, onRequest, onResponse, }: RemoteComponentProps): react_jsx_runtime.JSX.Element;
|
|
89
97
|
|
|
90
|
-
export { RemoteComponent, RemoteComponentProps };
|
|
98
|
+
export { OnRequestHook, OnResponseHook, RemoteComponent, RemoteComponentProps };
|
package/dist/react/index.js
CHANGED
|
@@ -1423,23 +1423,35 @@ async function loadStaticRemoteComponent(scripts, url) {
|
|
|
1423
1423
|
}
|
|
1424
1424
|
|
|
1425
1425
|
// src/shared/ssr/fetch-headers.ts
|
|
1426
|
-
function remoteFetchHeaders(
|
|
1426
|
+
function remoteFetchHeaders() {
|
|
1427
1427
|
return {
|
|
1428
1428
|
/**
|
|
1429
1429
|
* Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
|
|
1430
|
-
*
|
|
1431
|
-
*
|
|
1430
|
+
* If the remote component uses vercel deployment protection, ensure the host and remote vercel
|
|
1431
|
+
* projects share a common automation bypass secret, and the shared secret is used as the
|
|
1432
|
+
* VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
|
|
1432
1433
|
*/
|
|
1433
1434
|
...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
|
|
1434
1435
|
"x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
|
|
1435
1436
|
} : {},
|
|
1436
|
-
...Object.fromEntries(
|
|
1437
|
-
additionalHeaders instanceof Headers ? additionalHeaders.entries() : Object.entries(additionalHeaders ?? {})
|
|
1438
|
-
),
|
|
1439
1437
|
Accept: "text/html"
|
|
1440
1438
|
};
|
|
1441
1439
|
}
|
|
1442
1440
|
|
|
1441
|
+
// src/shared/ssr/fetch-with-hooks.ts
|
|
1442
|
+
async function fetchWithHooks(url, init, options = {}) {
|
|
1443
|
+
const { onRequest, onResponse } = options;
|
|
1444
|
+
let res = await onRequest?.(url, init);
|
|
1445
|
+
if (!res) {
|
|
1446
|
+
res = await fetch(url, init);
|
|
1447
|
+
}
|
|
1448
|
+
const transformedRes = await onResponse?.(url, res);
|
|
1449
|
+
if (transformedRes) {
|
|
1450
|
+
res = transformedRes;
|
|
1451
|
+
}
|
|
1452
|
+
return res;
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1443
1455
|
// src/shared/ssr/get-client-or-server-url.ts
|
|
1444
1456
|
function getClientOrServerUrl(src, serverFallback) {
|
|
1445
1457
|
const fallback = typeof location !== "undefined" ? location.href : serverFallback;
|
|
@@ -1531,12 +1543,13 @@ function RemoteComponent({
|
|
|
1531
1543
|
credentials = "same-origin",
|
|
1532
1544
|
name: nameProp = "__vercel_remote_component",
|
|
1533
1545
|
shared = {},
|
|
1534
|
-
additionalHeaders,
|
|
1535
1546
|
children,
|
|
1536
1547
|
onBeforeLoad,
|
|
1537
1548
|
onLoad,
|
|
1538
1549
|
onError,
|
|
1539
|
-
onChange
|
|
1550
|
+
onChange,
|
|
1551
|
+
onRequest,
|
|
1552
|
+
onResponse
|
|
1540
1553
|
}) {
|
|
1541
1554
|
const instanceId = useId();
|
|
1542
1555
|
const name = useMemo(() => {
|
|
@@ -1640,10 +1653,13 @@ function RemoteComponent({
|
|
|
1640
1653
|
if (!html && src) {
|
|
1641
1654
|
const fetchInit = {
|
|
1642
1655
|
method: "GET",
|
|
1643
|
-
headers: remoteFetchHeaders(
|
|
1656
|
+
headers: remoteFetchHeaders(),
|
|
1644
1657
|
credentials
|
|
1645
1658
|
};
|
|
1646
|
-
const res = await
|
|
1659
|
+
const res = await fetchWithHooks(url, fetchInit, {
|
|
1660
|
+
onRequest,
|
|
1661
|
+
onResponse
|
|
1662
|
+
});
|
|
1647
1663
|
if (!res.ok) {
|
|
1648
1664
|
let error = failedToFetchRemoteComponentError(
|
|
1649
1665
|
url.href,
|
|
@@ -1953,13 +1969,14 @@ function RemoteComponent({
|
|
|
1953
1969
|
name,
|
|
1954
1970
|
shared,
|
|
1955
1971
|
shadowRoot,
|
|
1956
|
-
additionalHeaders,
|
|
1957
1972
|
reset,
|
|
1958
1973
|
id,
|
|
1959
1974
|
onBeforeLoad,
|
|
1960
1975
|
onLoad,
|
|
1961
1976
|
onError,
|
|
1962
|
-
onChange
|
|
1977
|
+
onChange,
|
|
1978
|
+
onRequest,
|
|
1979
|
+
onResponse
|
|
1963
1980
|
]);
|
|
1964
1981
|
if (remoteComponent instanceof Error) {
|
|
1965
1982
|
throw remoteComponent;
|