remote-components 0.2.1 → 0.2.2
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/host/nextjs/app/client-only.cjs +76 -40
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.d.ts +28 -9
- package/dist/host/nextjs/app/client-only.js +74 -39
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/nextjs/pages.cjs +4 -4
- package/dist/host/nextjs/pages.cjs.map +1 -1
- package/dist/host/nextjs/pages.js +4 -4
- package/dist/host/nextjs/pages.js.map +1 -1
- package/dist/host/react.cjs +16 -8
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.d.ts +2 -366
- package/dist/host/react.js +16 -8
- package/dist/host/react.js.map +1 -1
- package/dist/index-4c65355c.d.ts +298 -0
- package/dist/internal/config/webpack/next-client-pages-loader.d.ts +3 -3
- package/dist/internal/host/nextjs/app-client.cjs +4 -3
- package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
- package/dist/internal/host/nextjs/app-client.d.ts +1 -1
- package/dist/internal/host/nextjs/app-client.js +4 -3
- package/dist/internal/host/nextjs/app-client.js.map +1 -1
- package/dist/internal/host/nextjs/image-impl.cjs +8 -4
- package/dist/internal/host/nextjs/image-impl.cjs.map +1 -1
- package/dist/internal/host/nextjs/image-impl.d.ts +2 -2
- package/dist/internal/host/nextjs/image-impl.js +8 -4
- package/dist/internal/host/nextjs/image-impl.js.map +1 -1
- package/dist/internal/host/react/context.cjs +5 -10
- package/dist/internal/host/react/context.cjs.map +1 -1
- package/dist/internal/host/react/context.d.ts +7 -18
- package/dist/internal/host/react/context.js +4 -9
- package/dist/internal/host/react/context.js.map +1 -1
- package/dist/internal/host/react/hooks/use-resolve-client-url.cjs +5 -4
- package/dist/internal/host/react/hooks/use-resolve-client-url.cjs.map +1 -1
- package/dist/internal/host/react/hooks/use-resolve-client-url.d.ts +4 -1
- package/dist/internal/host/react/hooks/use-resolve-client-url.js +5 -4
- package/dist/internal/host/react/hooks/use-resolve-client-url.js.map +1 -1
- package/dist/internal/host/shared/config.cjs.map +1 -1
- package/dist/internal/host/shared/config.d.ts +7 -0
- package/dist/internal/host/shared/resolved-data.d.ts +2 -2
- package/dist/internal/runtime/loaders/component-loader.d.ts +1 -1
- package/dist/{server-handoff-8c89b856.d.ts → server-handoff-ce13bebc.d.ts} +2 -2
- package/package.json +1 -9
|
@@ -1,16 +1,35 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import
|
|
3
|
-
import { ConsumeRemoteComponentProps } from '
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { C as ConsumeClientOnlyConfig, a as ConsumeRemoteComponentProps } from '../../../index-4c65355c.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Provider for Next.js App Router hosts. Provides real Next.js implementations
|
|
7
|
+
* of `next/image`, `next/navigation`, `next/link`, etc. to all nested
|
|
8
|
+
* `<ConsumeRemoteComponent>` instances.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
+
* Works in both Server and Client Components — set it up once in your layout
|
|
11
|
+
* and use `<ConsumeRemoteComponent>` from `remote-components/react` everywhere:
|
|
10
12
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { RemoteComponentsClientProvider } from 'remote-components/host/nextjs/app/client-only';
|
|
15
|
+
*
|
|
16
|
+
* <RemoteComponentsClientProvider resolveClientUrl={proxyClientRequestsThroughHost}>
|
|
17
|
+
* {children}
|
|
18
|
+
* </RemoteComponentsClientProvider>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function RemoteComponentsClientProvider({ shared, resolveClientUrl, children, ...props }: ConsumeClientOnlyConfig & {
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
}): react_jsx_runtime.JSX.Element;
|
|
24
|
+
/**
|
|
25
|
+
* `ConsumeRemoteComponent` for Next.js App Router hosts. Provides real Next.js
|
|
26
|
+
* implementations of `next/image`, `next/navigation`, `next/link`, etc.
|
|
27
|
+
*
|
|
28
|
+
* The provider approach is recommended because it works in both Server and Client
|
|
29
|
+
* Components — set up `RemoteComponentsClientProvider` from this module once in
|
|
30
|
+
* your layout, and use `<ConsumeRemoteComponent>` from `remote-components/react`
|
|
31
|
+
* everywhere. Import this component only when adding a provider is not practical.
|
|
13
32
|
*/
|
|
14
|
-
declare function ConsumeRemoteComponent(props: ConsumeRemoteComponentProps): string | number | bigint | boolean | Iterable<
|
|
33
|
+
declare function ConsumeRemoteComponent(props: ConsumeRemoteComponentProps): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null;
|
|
15
34
|
|
|
16
|
-
export { ConsumeRemoteComponent };
|
|
35
|
+
export { ConsumeRemoteComponent, RemoteComponentsClientProvider };
|
|
@@ -38,6 +38,7 @@ var init_app = __esm({
|
|
|
38
38
|
|
|
39
39
|
// src/host/nextjs/app-client-only.tsx
|
|
40
40
|
import * as Image from "next/image";
|
|
41
|
+
import { useMemo as useMemo3 } from "react";
|
|
41
42
|
|
|
42
43
|
// src/utils/logger.ts
|
|
43
44
|
init_constants();
|
|
@@ -384,10 +385,11 @@ function sharedPolyfills(shared2, resolveClientUrl) {
|
|
|
384
385
|
|
|
385
386
|
// src/host/nextjs/image-impl.tsx
|
|
386
387
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
388
|
+
var getBundleUrl = (bundle) => globalThis.__remote_bundle_url__?.[bundle];
|
|
387
389
|
function createRemoteLoader(bundle, resolveClientUrl) {
|
|
388
390
|
return ({ src, width, quality }) => {
|
|
389
|
-
const
|
|
390
|
-
const origin =
|
|
391
|
+
const bundleUrl = getBundleUrl(bundle);
|
|
392
|
+
const origin = bundleUrl?.origin ?? "";
|
|
391
393
|
let imageUrl = src;
|
|
392
394
|
try {
|
|
393
395
|
const parsed = new URL(src);
|
|
@@ -398,7 +400,8 @@ function createRemoteLoader(bundle, resolveClientUrl) {
|
|
|
398
400
|
}
|
|
399
401
|
const { assetPrefix } = /^(?<assetPrefix>.*?)\/_next\//.exec(imageUrl)?.groups ?? {};
|
|
400
402
|
const url = `${origin}${assetPrefix ?? ""}/_next/image?url=${encodeURIComponent(imageUrl)}&w=${width}&q=${quality ?? 75}`;
|
|
401
|
-
|
|
403
|
+
const remoteSrc = bundleUrl?.href ?? url;
|
|
404
|
+
return resolveClientUrl?.(remoteSrc, url) ?? url;
|
|
402
405
|
};
|
|
403
406
|
}
|
|
404
407
|
function imageImpl2(ImageComponent, bundle, resolveClientUrl, useRemoteLoader) {
|
|
@@ -408,36 +411,17 @@ function imageImpl2(ImageComponent, bundle, resolveClientUrl, useRemoteLoader) {
|
|
|
408
411
|
return /* @__PURE__ */ jsx2(ImageComponent, { loader: remoteLoader, ...props });
|
|
409
412
|
}
|
|
410
413
|
const rawSrc = applyBundleUrlToImagePropsSrc(bundle, props.src);
|
|
411
|
-
const
|
|
414
|
+
const bundleUrl = getBundleUrl(bundle);
|
|
415
|
+
const remoteSrc = bundleUrl?.href ?? rawSrc;
|
|
416
|
+
const src = resolveClientUrl?.(remoteSrc, rawSrc) ?? rawSrc;
|
|
412
417
|
return /* @__PURE__ */ jsx2(ImageComponent, { ...props, src });
|
|
413
418
|
};
|
|
414
419
|
component.default = component;
|
|
415
420
|
return component;
|
|
416
421
|
}
|
|
417
422
|
|
|
418
|
-
// src/
|
|
419
|
-
|
|
420
|
-
const remoteOrigin = parseOrigin(remoteSrc);
|
|
421
|
-
return (url) => {
|
|
422
|
-
const urlOrigin = parseOrigin(url);
|
|
423
|
-
if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
|
|
424
|
-
return void 0;
|
|
425
|
-
}
|
|
426
|
-
return resolveClientUrl(remoteSrc, url);
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
function parseOrigin(url) {
|
|
430
|
-
try {
|
|
431
|
-
return new URL(url).origin;
|
|
432
|
-
} catch {
|
|
433
|
-
return void 0;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
// src/runtime/url/default-resolve-client-url.ts
|
|
438
|
-
function bindResolveClientUrl(prop, remoteSrc) {
|
|
439
|
-
return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
|
|
440
|
-
}
|
|
423
|
+
// src/host/nextjs/app-client-only.tsx
|
|
424
|
+
import { RemoteComponentsContext } from "#internal/host/react/context";
|
|
441
425
|
|
|
442
426
|
// src/host/react/index.tsx
|
|
443
427
|
import {
|
|
@@ -450,6 +434,7 @@ import {
|
|
|
450
434
|
useState as useState2
|
|
451
435
|
} from "react";
|
|
452
436
|
import { createPortal } from "react-dom";
|
|
437
|
+
import { useRemoteComponentsContext as useRemoteComponentsContext2 } from "#internal/host/react/context";
|
|
453
438
|
|
|
454
439
|
// src/host/server/fetch-headers.ts
|
|
455
440
|
function remoteFetchHeaders() {
|
|
@@ -1984,13 +1969,40 @@ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
|
|
|
1984
1969
|
// src/host/react/hooks/use-resolve-client-url.ts
|
|
1985
1970
|
import { useMemo } from "react";
|
|
1986
1971
|
import { useRemoteComponentsContext } from "#internal/host/react/context";
|
|
1972
|
+
|
|
1973
|
+
// src/runtime/url/resolve-client-url.ts
|
|
1974
|
+
function withRemoteSrc(resolveClientUrl, remoteSrc) {
|
|
1975
|
+
const remoteOrigin = parseOrigin(remoteSrc);
|
|
1976
|
+
return (url) => {
|
|
1977
|
+
const urlOrigin = parseOrigin(url);
|
|
1978
|
+
if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
|
|
1979
|
+
return void 0;
|
|
1980
|
+
}
|
|
1981
|
+
return resolveClientUrl(remoteSrc, url);
|
|
1982
|
+
};
|
|
1983
|
+
}
|
|
1984
|
+
function parseOrigin(url) {
|
|
1985
|
+
try {
|
|
1986
|
+
return new URL(url).origin;
|
|
1987
|
+
} catch {
|
|
1988
|
+
return void 0;
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
// src/runtime/url/default-resolve-client-url.ts
|
|
1993
|
+
function bindResolveClientUrl(prop, remoteSrc) {
|
|
1994
|
+
return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
// src/host/react/hooks/use-resolve-client-url.ts
|
|
1987
1998
|
function useResolveClientUrl(prop, urlHref) {
|
|
1988
1999
|
const { resolveClientUrl: contextValue } = useRemoteComponentsContext();
|
|
1989
|
-
const
|
|
1990
|
-
|
|
1991
|
-
() => bindResolveClientUrl(
|
|
1992
|
-
[
|
|
2000
|
+
const raw = prop ?? contextValue;
|
|
2001
|
+
const bound = useMemo(
|
|
2002
|
+
() => bindResolveClientUrl(raw, urlHref),
|
|
2003
|
+
[raw, urlHref]
|
|
1993
2004
|
);
|
|
2005
|
+
return { bound, raw };
|
|
1994
2006
|
}
|
|
1995
2007
|
|
|
1996
2008
|
// src/host/react/hooks/use-shadow-root.ts
|
|
@@ -2072,9 +2084,9 @@ function ConsumeRemoteComponent({
|
|
|
2072
2084
|
isolate,
|
|
2073
2085
|
mode = "open",
|
|
2074
2086
|
reset,
|
|
2075
|
-
credentials
|
|
2087
|
+
credentials: credentialsProp,
|
|
2076
2088
|
name: nameProp = "__vercel_remote_component",
|
|
2077
|
-
shared:
|
|
2089
|
+
shared: sharedProp,
|
|
2078
2090
|
children,
|
|
2079
2091
|
onBeforeLoad,
|
|
2080
2092
|
onLoad,
|
|
@@ -2082,9 +2094,12 @@ function ConsumeRemoteComponent({
|
|
|
2082
2094
|
onChange,
|
|
2083
2095
|
onRequest,
|
|
2084
2096
|
onResponse,
|
|
2085
|
-
resolveClientUrl:
|
|
2097
|
+
resolveClientUrl: resolveClientUrlProp
|
|
2086
2098
|
}) {
|
|
2087
2099
|
const instanceId = useId();
|
|
2100
|
+
const { credentials: contextCredentials, shared: contextShared } = useRemoteComponentsContext2();
|
|
2101
|
+
const credentials = credentialsProp ?? contextCredentials ?? "same-origin";
|
|
2102
|
+
const shared2 = sharedProp ?? contextShared ?? {};
|
|
2088
2103
|
const name = useMemo2(
|
|
2089
2104
|
() => resolveNameFromSrc(src, nameProp),
|
|
2090
2105
|
[src, nameProp]
|
|
@@ -2093,7 +2108,10 @@ function ConsumeRemoteComponent({
|
|
|
2093
2108
|
null
|
|
2094
2109
|
);
|
|
2095
2110
|
const url = useMemo2(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);
|
|
2096
|
-
const resolveClientUrl = useResolveClientUrl(
|
|
2111
|
+
const { bound: resolveClientUrl } = useResolveClientUrl(
|
|
2112
|
+
resolveClientUrlProp,
|
|
2113
|
+
url.href
|
|
2114
|
+
);
|
|
2097
2115
|
const id = url.origin === (typeof location !== "undefined" ? location.origin : DUMMY_FALLBACK) ? url.pathname : url.href;
|
|
2098
2116
|
const keySuffix = `${escapeString(id)}_${escapeString(
|
|
2099
2117
|
data?.name ?? name
|
|
@@ -2696,21 +2714,38 @@ var sharedModules = async (userShared, resolveClientUrl) => {
|
|
|
2696
2714
|
...resolvedUserShared
|
|
2697
2715
|
};
|
|
2698
2716
|
};
|
|
2717
|
+
function RemoteComponentsClientProvider({
|
|
2718
|
+
shared: shared2,
|
|
2719
|
+
resolveClientUrl,
|
|
2720
|
+
children,
|
|
2721
|
+
...props
|
|
2722
|
+
}) {
|
|
2723
|
+
const mergedShared = useMemo3(
|
|
2724
|
+
() => sharedModules(shared2, resolveClientUrl),
|
|
2725
|
+
[shared2, resolveClientUrl]
|
|
2726
|
+
);
|
|
2727
|
+
return /* @__PURE__ */ jsx4(
|
|
2728
|
+
RemoteComponentsContext,
|
|
2729
|
+
{
|
|
2730
|
+
value: { shared: mergedShared, resolveClientUrl, ...props },
|
|
2731
|
+
children
|
|
2732
|
+
}
|
|
2733
|
+
);
|
|
2734
|
+
}
|
|
2699
2735
|
function ConsumeRemoteComponent2(props) {
|
|
2700
2736
|
if (typeof props.src !== "string" && !(props.src instanceof URL)) {
|
|
2701
2737
|
return props.children ?? null;
|
|
2702
2738
|
}
|
|
2703
|
-
const src = typeof props.src === "string" ? props.src : props.src.href;
|
|
2704
|
-
const resolveClientUrl = props.resolveClientUrl ? bindResolveClientUrl(props.resolveClientUrl, src) : void 0;
|
|
2705
2739
|
return /* @__PURE__ */ jsx4(
|
|
2706
2740
|
ConsumeRemoteComponent,
|
|
2707
2741
|
{
|
|
2708
2742
|
...props,
|
|
2709
|
-
shared: sharedModules(props.shared, resolveClientUrl)
|
|
2743
|
+
shared: sharedModules(props.shared, props.resolveClientUrl)
|
|
2710
2744
|
}
|
|
2711
2745
|
);
|
|
2712
2746
|
}
|
|
2713
2747
|
export {
|
|
2714
|
-
ConsumeRemoteComponent2 as ConsumeRemoteComponent
|
|
2748
|
+
ConsumeRemoteComponent2 as ConsumeRemoteComponent,
|
|
2749
|
+
RemoteComponentsClientProvider
|
|
2715
2750
|
};
|
|
2716
2751
|
//# sourceMappingURL=client-only.js.map
|