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
|
@@ -23,10 +23,11 @@ __export(image_impl_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(image_impl_exports);
|
|
24
24
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
25
|
var import_polyfill = require("#internal/host/shared/polyfill");
|
|
26
|
+
const getBundleUrl = (bundle) => globalThis.__remote_bundle_url__?.[bundle];
|
|
26
27
|
function createRemoteLoader(bundle, resolveClientUrl) {
|
|
27
28
|
return ({ src, width, quality }) => {
|
|
28
|
-
const
|
|
29
|
-
const origin =
|
|
29
|
+
const bundleUrl = getBundleUrl(bundle);
|
|
30
|
+
const origin = bundleUrl?.origin ?? "";
|
|
30
31
|
let imageUrl = src;
|
|
31
32
|
try {
|
|
32
33
|
const parsed = new URL(src);
|
|
@@ -37,7 +38,8 @@ function createRemoteLoader(bundle, resolveClientUrl) {
|
|
|
37
38
|
}
|
|
38
39
|
const { assetPrefix } = /^(?<assetPrefix>.*?)\/_next\//.exec(imageUrl)?.groups ?? {};
|
|
39
40
|
const url = `${origin}${assetPrefix ?? ""}/_next/image?url=${encodeURIComponent(imageUrl)}&w=${width}&q=${quality ?? 75}`;
|
|
40
|
-
|
|
41
|
+
const remoteSrc = bundleUrl?.href ?? url;
|
|
42
|
+
return resolveClientUrl?.(remoteSrc, url) ?? url;
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
45
|
function imageImpl(ImageComponent, bundle, resolveClientUrl, useRemoteLoader) {
|
|
@@ -47,7 +49,9 @@ function imageImpl(ImageComponent, bundle, resolveClientUrl, useRemoteLoader) {
|
|
|
47
49
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ImageComponent, { loader: remoteLoader, ...props });
|
|
48
50
|
}
|
|
49
51
|
const rawSrc = (0, import_polyfill.applyBundleUrlToImagePropsSrc)(bundle, props.src);
|
|
50
|
-
const
|
|
52
|
+
const bundleUrl = getBundleUrl(bundle);
|
|
53
|
+
const remoteSrc = bundleUrl?.href ?? rawSrc;
|
|
54
|
+
const src = resolveClientUrl?.(remoteSrc, rawSrc) ?? rawSrc;
|
|
51
55
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ImageComponent, { ...props, src });
|
|
52
56
|
};
|
|
53
57
|
component.default = component;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/nextjs/image-impl.tsx"],"sourcesContent":["import type {\n default as ImageComponentType,\n ImageLoaderProps,\n ImageProps,\n} from 'next/image';\nimport { applyBundleUrlToImagePropsSrc } from '#internal/host/shared/polyfill';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/nextjs/image-impl.tsx"],"sourcesContent":["import type {\n default as ImageComponentType,\n ImageLoaderProps,\n ImageProps,\n} from 'next/image';\nimport { applyBundleUrlToImagePropsSrc } from '#internal/host/shared/polyfill';\nimport type { ResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\n\nconst getBundleUrl = (bundle: string) =>\n (\n globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n }\n ).__remote_bundle_url__?.[bundle];\n\nfunction createRemoteLoader(\n bundle: string,\n resolveClientUrl?: ResolveClientUrl,\n) {\n return ({ src, width, quality }: ImageLoaderProps) => {\n const bundleUrl = getBundleUrl(bundle);\n const origin = bundleUrl?.origin ?? '';\n\n // Use a relative path when src is on the remote origin so the remote's\n // /_next/image endpoint serves it locally — avoids requiring the remote's\n // own origin in remotePatterns and works consistently across local/deployed.\n // Relative paths (common from Next.js static imports) pass through as-is.\n let imageUrl = src;\n try {\n const parsed = new URL(src);\n if (origin && parsed.origin === origin) {\n imageUrl = parsed.pathname + parsed.search;\n }\n } catch {\n // src is already a relative path, use as-is\n }\n\n const { assetPrefix } =\n /^(?<assetPrefix>.*?)\\/_next\\//.exec(imageUrl)?.groups ?? {};\n const url = `${origin}${assetPrefix ?? ''}/_next/image?url=${encodeURIComponent(imageUrl)}&w=${width}&q=${\n quality ?? 75\n }`;\n const remoteSrc = bundleUrl?.href ?? url;\n return resolveClientUrl?.(remoteSrc, url) ?? url;\n };\n}\n\nexport function imageImpl(\n ImageComponent: typeof ImageComponentType,\n bundle: string,\n resolveClientUrl?: ResolveClientUrl,\n useRemoteLoader?: boolean,\n) {\n const remoteLoader = useRemoteLoader\n ? createRemoteLoader(bundle, resolveClientUrl)\n : undefined;\n\n const component = function RemoteImage(props: ImageProps) {\n // When using remoteLoader, pass props.src unchanged — the loader receives\n // the original value (relative path or StaticImageData string) and handles\n // URL construction and proxying itself. This matches the original working\n // pattern and avoids unnecessary absolute→relative round-trips.\n // Without remoteLoader, rewrite src to point at the remote origin and proxy.\n if (remoteLoader) {\n return <ImageComponent loader={remoteLoader} {...props} />;\n }\n const rawSrc = applyBundleUrlToImagePropsSrc(bundle, props.src);\n const bundleUrl = getBundleUrl(bundle);\n const remoteSrc = bundleUrl?.href ?? rawSrc;\n const src = resolveClientUrl?.(remoteSrc, rawSrc) ?? rawSrc;\n return <ImageComponent {...props} src={src} />;\n };\n component.default = component;\n return component;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgEa;AA3Db,sBAA8C;AAG9C,MAAM,eAAe,CAAC,WAElB,WAGA,wBAAwB,MAAM;AAElC,SAAS,mBACP,QACA,kBACA;AACA,SAAO,CAAC,EAAE,KAAK,OAAO,QAAQ,MAAwB;AACpD,UAAM,YAAY,aAAa,MAAM;AACrC,UAAM,SAAS,WAAW,UAAU;AAMpC,QAAI,WAAW;AACf,QAAI;AACF,YAAM,SAAS,IAAI,IAAI,GAAG;AAC1B,UAAI,UAAU,OAAO,WAAW,QAAQ;AACtC,mBAAW,OAAO,WAAW,OAAO;AAAA,MACtC;AAAA,IACF,QAAE;AAAA,IAEF;AAEA,UAAM,EAAE,YAAY,IAClB,gCAAgC,KAAK,QAAQ,GAAG,UAAU,CAAC;AAC7D,UAAM,MAAM,GAAG,SAAS,eAAe,sBAAsB,mBAAmB,QAAQ,OAAO,WAC7F,WAAW;AAEb,UAAM,YAAY,WAAW,QAAQ;AACrC,WAAO,mBAAmB,WAAW,GAAG,KAAK;AAAA,EAC/C;AACF;AAEO,SAAS,UACd,gBACA,QACA,kBACA,iBACA;AACA,QAAM,eAAe,kBACjB,mBAAmB,QAAQ,gBAAgB,IAC3C;AAEJ,QAAM,YAAY,SAAS,YAAY,OAAmB;AAMxD,QAAI,cAAc;AAChB,aAAO,4CAAC,kBAAe,QAAQ,cAAe,GAAG,OAAO;AAAA,IAC1D;AACA,UAAM,aAAS,+CAA8B,QAAQ,MAAM,GAAG;AAC9D,UAAM,YAAY,aAAa,MAAM;AACrC,UAAM,YAAY,WAAW,QAAQ;AACrC,UAAM,MAAM,mBAAmB,WAAW,MAAM,KAAK;AACrD,WAAO,4CAAC,kBAAgB,GAAG,OAAO,KAAU;AAAA,EAC9C;AACA,YAAU,UAAU;AACpB,SAAO;AACT;","names":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import ImageComponentType, { ImageProps } from 'next/image';
|
|
3
|
-
import {
|
|
3
|
+
import { ResolveClientUrl } from '../../runtime/url/resolve-client-url.js';
|
|
4
4
|
|
|
5
|
-
declare function imageImpl(ImageComponent: typeof ImageComponentType, bundle: string, resolveClientUrl?:
|
|
5
|
+
declare function imageImpl(ImageComponent: typeof ImageComponentType, bundle: string, resolveClientUrl?: ResolveClientUrl, useRemoteLoader?: boolean): {
|
|
6
6
|
(props: ImageProps): react_jsx_runtime.JSX.Element;
|
|
7
7
|
default: /*elided*/ any;
|
|
8
8
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { applyBundleUrlToImagePropsSrc } from "#internal/host/shared/polyfill";
|
|
3
|
+
const getBundleUrl = (bundle) => globalThis.__remote_bundle_url__?.[bundle];
|
|
3
4
|
function createRemoteLoader(bundle, resolveClientUrl) {
|
|
4
5
|
return ({ src, width, quality }) => {
|
|
5
|
-
const
|
|
6
|
-
const origin =
|
|
6
|
+
const bundleUrl = getBundleUrl(bundle);
|
|
7
|
+
const origin = bundleUrl?.origin ?? "";
|
|
7
8
|
let imageUrl = src;
|
|
8
9
|
try {
|
|
9
10
|
const parsed = new URL(src);
|
|
@@ -14,7 +15,8 @@ function createRemoteLoader(bundle, resolveClientUrl) {
|
|
|
14
15
|
}
|
|
15
16
|
const { assetPrefix } = /^(?<assetPrefix>.*?)\/_next\//.exec(imageUrl)?.groups ?? {};
|
|
16
17
|
const url = `${origin}${assetPrefix ?? ""}/_next/image?url=${encodeURIComponent(imageUrl)}&w=${width}&q=${quality ?? 75}`;
|
|
17
|
-
|
|
18
|
+
const remoteSrc = bundleUrl?.href ?? url;
|
|
19
|
+
return resolveClientUrl?.(remoteSrc, url) ?? url;
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
22
|
function imageImpl(ImageComponent, bundle, resolveClientUrl, useRemoteLoader) {
|
|
@@ -24,7 +26,9 @@ function imageImpl(ImageComponent, bundle, resolveClientUrl, useRemoteLoader) {
|
|
|
24
26
|
return /* @__PURE__ */ jsx(ImageComponent, { loader: remoteLoader, ...props });
|
|
25
27
|
}
|
|
26
28
|
const rawSrc = applyBundleUrlToImagePropsSrc(bundle, props.src);
|
|
27
|
-
const
|
|
29
|
+
const bundleUrl = getBundleUrl(bundle);
|
|
30
|
+
const remoteSrc = bundleUrl?.href ?? rawSrc;
|
|
31
|
+
const src = resolveClientUrl?.(remoteSrc, rawSrc) ?? rawSrc;
|
|
28
32
|
return /* @__PURE__ */ jsx(ImageComponent, { ...props, src });
|
|
29
33
|
};
|
|
30
34
|
component.default = component;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/nextjs/image-impl.tsx"],"sourcesContent":["import type {\n default as ImageComponentType,\n ImageLoaderProps,\n ImageProps,\n} from 'next/image';\nimport { applyBundleUrlToImagePropsSrc } from '#internal/host/shared/polyfill';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/nextjs/image-impl.tsx"],"sourcesContent":["import type {\n default as ImageComponentType,\n ImageLoaderProps,\n ImageProps,\n} from 'next/image';\nimport { applyBundleUrlToImagePropsSrc } from '#internal/host/shared/polyfill';\nimport type { ResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\n\nconst getBundleUrl = (bundle: string) =>\n (\n globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n }\n ).__remote_bundle_url__?.[bundle];\n\nfunction createRemoteLoader(\n bundle: string,\n resolveClientUrl?: ResolveClientUrl,\n) {\n return ({ src, width, quality }: ImageLoaderProps) => {\n const bundleUrl = getBundleUrl(bundle);\n const origin = bundleUrl?.origin ?? '';\n\n // Use a relative path when src is on the remote origin so the remote's\n // /_next/image endpoint serves it locally — avoids requiring the remote's\n // own origin in remotePatterns and works consistently across local/deployed.\n // Relative paths (common from Next.js static imports) pass through as-is.\n let imageUrl = src;\n try {\n const parsed = new URL(src);\n if (origin && parsed.origin === origin) {\n imageUrl = parsed.pathname + parsed.search;\n }\n } catch {\n // src is already a relative path, use as-is\n }\n\n const { assetPrefix } =\n /^(?<assetPrefix>.*?)\\/_next\\//.exec(imageUrl)?.groups ?? {};\n const url = `${origin}${assetPrefix ?? ''}/_next/image?url=${encodeURIComponent(imageUrl)}&w=${width}&q=${\n quality ?? 75\n }`;\n const remoteSrc = bundleUrl?.href ?? url;\n return resolveClientUrl?.(remoteSrc, url) ?? url;\n };\n}\n\nexport function imageImpl(\n ImageComponent: typeof ImageComponentType,\n bundle: string,\n resolveClientUrl?: ResolveClientUrl,\n useRemoteLoader?: boolean,\n) {\n const remoteLoader = useRemoteLoader\n ? createRemoteLoader(bundle, resolveClientUrl)\n : undefined;\n\n const component = function RemoteImage(props: ImageProps) {\n // When using remoteLoader, pass props.src unchanged — the loader receives\n // the original value (relative path or StaticImageData string) and handles\n // URL construction and proxying itself. This matches the original working\n // pattern and avoids unnecessary absolute→relative round-trips.\n // Without remoteLoader, rewrite src to point at the remote origin and proxy.\n if (remoteLoader) {\n return <ImageComponent loader={remoteLoader} {...props} />;\n }\n const rawSrc = applyBundleUrlToImagePropsSrc(bundle, props.src);\n const bundleUrl = getBundleUrl(bundle);\n const remoteSrc = bundleUrl?.href ?? rawSrc;\n const src = resolveClientUrl?.(remoteSrc, rawSrc) ?? rawSrc;\n return <ImageComponent {...props} src={src} />;\n };\n component.default = component;\n return component;\n}\n"],"mappings":"AAgEa;AA3Db,SAAS,qCAAqC;AAG9C,MAAM,eAAe,CAAC,WAElB,WAGA,wBAAwB,MAAM;AAElC,SAAS,mBACP,QACA,kBACA;AACA,SAAO,CAAC,EAAE,KAAK,OAAO,QAAQ,MAAwB;AACpD,UAAM,YAAY,aAAa,MAAM;AACrC,UAAM,SAAS,WAAW,UAAU;AAMpC,QAAI,WAAW;AACf,QAAI;AACF,YAAM,SAAS,IAAI,IAAI,GAAG;AAC1B,UAAI,UAAU,OAAO,WAAW,QAAQ;AACtC,mBAAW,OAAO,WAAW,OAAO;AAAA,MACtC;AAAA,IACF,QAAE;AAAA,IAEF;AAEA,UAAM,EAAE,YAAY,IAClB,gCAAgC,KAAK,QAAQ,GAAG,UAAU,CAAC;AAC7D,UAAM,MAAM,GAAG,SAAS,eAAe,sBAAsB,mBAAmB,QAAQ,OAAO,WAC7F,WAAW;AAEb,UAAM,YAAY,WAAW,QAAQ;AACrC,WAAO,mBAAmB,WAAW,GAAG,KAAK;AAAA,EAC/C;AACF;AAEO,SAAS,UACd,gBACA,QACA,kBACA,iBACA;AACA,QAAM,eAAe,kBACjB,mBAAmB,QAAQ,gBAAgB,IAC3C;AAEJ,QAAM,YAAY,SAAS,YAAY,OAAmB;AAMxD,QAAI,cAAc;AAChB,aAAO,oBAAC,kBAAe,QAAQ,cAAe,GAAG,OAAO;AAAA,IAC1D;AACA,UAAM,SAAS,8BAA8B,QAAQ,MAAM,GAAG;AAC9D,UAAM,YAAY,aAAa,MAAM;AACrC,UAAM,YAAY,WAAW,QAAQ;AACrC,UAAM,MAAM,mBAAmB,WAAW,MAAM,KAAK;AACrD,WAAO,oBAAC,kBAAgB,GAAG,OAAO,KAAU;AAAA,EAC9C;AACA,YAAU,UAAU;AACpB,SAAO;AACT;","names":[]}
|
|
@@ -19,25 +19,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var context_exports = {};
|
|
21
21
|
__export(context_exports, {
|
|
22
|
-
|
|
22
|
+
RemoteComponentsContext: () => RemoteComponentsContext,
|
|
23
23
|
useRemoteComponentsContext: () => useRemoteComponentsContext
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(context_exports);
|
|
26
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
26
|
var import_react = require("react");
|
|
28
|
-
const RemoteComponentsContext = (0, import_react.createContext)(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
children
|
|
32
|
-
}) {
|
|
33
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RemoteComponentsContext, { value: { resolveClientUrl }, children });
|
|
34
|
-
}
|
|
27
|
+
const RemoteComponentsContext = (0, import_react.createContext)(
|
|
28
|
+
{}
|
|
29
|
+
);
|
|
35
30
|
function useRemoteComponentsContext() {
|
|
36
31
|
return (0, import_react.useContext)(RemoteComponentsContext);
|
|
37
32
|
}
|
|
38
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
34
|
0 && (module.exports = {
|
|
40
|
-
|
|
35
|
+
RemoteComponentsContext,
|
|
41
36
|
useRemoteComponentsContext
|
|
42
37
|
});
|
|
43
38
|
//# sourceMappingURL=context.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/react/context.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, useContext } from 'react';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/react/context.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, useContext } from 'react';\nimport type { ConsumeClientOnlyConfig } from '#internal/host/shared/config';\n\nexport const RemoteComponentsContext = createContext<ConsumeClientOnlyConfig>(\n {},\n);\n\nexport function useRemoteComponentsContext(): ConsumeClientOnlyConfig {\n return useContext(RemoteComponentsContext);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0C;AAGnC,MAAM,8BAA0B;AAAA,EACrC,CAAC;AACH;AAEO,SAAS,6BAAsD;AACpE,aAAO,yBAAW,uBAAuB;AAC3C;","names":[]}
|
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import {
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ConsumeClientOnlyConfig } from '../shared/config.js';
|
|
3
|
+
import '../../runtime/url/resolve-client-url.js';
|
|
4
|
+
import '../shared/fetch-interceptors.js';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Client-side context provider for passing `resolveClientUrl` to all nested
|
|
9
|
-
* `<ConsumeRemoteComponent>` instances. Since `resolveClientUrl` is a function, it
|
|
10
|
-
* can't be passed as a prop through Server Components — this provider should
|
|
11
|
-
* wrap the tree in a Client Component boundary so the callback is available
|
|
12
|
-
* on the client where asset fetches happen.
|
|
13
|
-
*/
|
|
14
|
-
declare function RemoteComponentsClientProvider({ resolveClientUrl, children, }: {
|
|
15
|
-
resolveClientUrl?: ResolveClientUrl;
|
|
16
|
-
children: React.ReactNode;
|
|
17
|
-
}): react_jsx_runtime.JSX.Element;
|
|
18
|
-
declare function useRemoteComponentsContext(): RemoteComponentsContextValue;
|
|
6
|
+
declare const RemoteComponentsContext: react.Context<ConsumeClientOnlyConfig>;
|
|
7
|
+
declare function useRemoteComponentsContext(): ConsumeClientOnlyConfig;
|
|
19
8
|
|
|
20
|
-
export {
|
|
9
|
+
export { RemoteComponentsContext, useRemoteComponentsContext };
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
2
|
import { createContext, useContext } from "react";
|
|
4
|
-
const RemoteComponentsContext = createContext(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
children
|
|
8
|
-
}) {
|
|
9
|
-
return /* @__PURE__ */ jsx(RemoteComponentsContext, { value: { resolveClientUrl }, children });
|
|
10
|
-
}
|
|
3
|
+
const RemoteComponentsContext = createContext(
|
|
4
|
+
{}
|
|
5
|
+
);
|
|
11
6
|
function useRemoteComponentsContext() {
|
|
12
7
|
return useContext(RemoteComponentsContext);
|
|
13
8
|
}
|
|
14
9
|
export {
|
|
15
|
-
|
|
10
|
+
RemoteComponentsContext,
|
|
16
11
|
useRemoteComponentsContext
|
|
17
12
|
};
|
|
18
13
|
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/react/context.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, useContext } from 'react';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/react/context.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, useContext } from 'react';\nimport type { ConsumeClientOnlyConfig } from '#internal/host/shared/config';\n\nexport const RemoteComponentsContext = createContext<ConsumeClientOnlyConfig>(\n {},\n);\n\nexport function useRemoteComponentsContext(): ConsumeClientOnlyConfig {\n return useContext(RemoteComponentsContext);\n}\n"],"mappings":";AAEA,SAAS,eAAe,kBAAkB;AAGnC,MAAM,0BAA0B;AAAA,EACrC,CAAC;AACH;AAEO,SAAS,6BAAsD;AACpE,SAAO,WAAW,uBAAuB;AAC3C;","names":[]}
|
|
@@ -26,11 +26,12 @@ var import_context = require("#internal/host/react/context");
|
|
|
26
26
|
var import_default_resolve_client_url = require("#internal/runtime/url/default-resolve-client-url");
|
|
27
27
|
function useResolveClientUrl(prop, urlHref) {
|
|
28
28
|
const { resolveClientUrl: contextValue } = (0, import_context.useRemoteComponentsContext)();
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
() => (0, import_default_resolve_client_url.bindResolveClientUrl)(
|
|
32
|
-
[
|
|
29
|
+
const raw = prop ?? contextValue;
|
|
30
|
+
const bound = (0, import_react.useMemo)(
|
|
31
|
+
() => (0, import_default_resolve_client_url.bindResolveClientUrl)(raw, urlHref),
|
|
32
|
+
[raw, urlHref]
|
|
33
33
|
);
|
|
34
|
+
return { bound, raw };
|
|
34
35
|
}
|
|
35
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
37
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/host/react/hooks/use-resolve-client-url.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useRemoteComponentsContext } from '#internal/host/react/context';\nimport { bindResolveClientUrl } from '#internal/runtime/url/default-resolve-client-url';\nimport type { ResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\n\nexport function useResolveClientUrl(\n prop: ResolveClientUrl | undefined,\n urlHref: string,\n) {\n const { resolveClientUrl: contextValue } = useRemoteComponentsContext();\n const
|
|
1
|
+
{"version":3,"sources":["../../../../../src/host/react/hooks/use-resolve-client-url.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useRemoteComponentsContext } from '#internal/host/react/context';\nimport { bindResolveClientUrl } from '#internal/runtime/url/default-resolve-client-url';\nimport type { ResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\n\nexport function useResolveClientUrl(\n prop: ResolveClientUrl | undefined,\n urlHref: string,\n) {\n const { resolveClientUrl: contextValue } = useRemoteComponentsContext();\n const raw = prop ?? contextValue;\n const bound = useMemo(\n () => bindResolveClientUrl(raw, urlHref),\n [raw, urlHref],\n );\n return { bound, raw };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;AACxB,qBAA2C;AAC3C,wCAAqC;AAG9B,SAAS,oBACd,MACA,SACA;AACA,QAAM,EAAE,kBAAkB,aAAa,QAAI,2CAA2B;AACtE,QAAM,MAAM,QAAQ;AACpB,QAAM,YAAQ;AAAA,IACZ,UAAM,wDAAqB,KAAK,OAAO;AAAA,IACvC,CAAC,KAAK,OAAO;AAAA,EACf;AACA,SAAO,EAAE,OAAO,IAAI;AACtB;","names":[]}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ResolveClientUrl, InternalResolveClientUrl } from '../../../runtime/url/resolve-client-url.js';
|
|
2
2
|
|
|
3
|
-
declare function useResolveClientUrl(prop: ResolveClientUrl | undefined, urlHref: string):
|
|
3
|
+
declare function useResolveClientUrl(prop: ResolveClientUrl | undefined, urlHref: string): {
|
|
4
|
+
bound: InternalResolveClientUrl | undefined;
|
|
5
|
+
raw: ResolveClientUrl | undefined;
|
|
6
|
+
};
|
|
4
7
|
|
|
5
8
|
export { useResolveClientUrl };
|
|
@@ -3,11 +3,12 @@ import { useRemoteComponentsContext } from "#internal/host/react/context";
|
|
|
3
3
|
import { bindResolveClientUrl } from "#internal/runtime/url/default-resolve-client-url";
|
|
4
4
|
function useResolveClientUrl(prop, urlHref) {
|
|
5
5
|
const { resolveClientUrl: contextValue } = useRemoteComponentsContext();
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
() => bindResolveClientUrl(
|
|
9
|
-
[
|
|
6
|
+
const raw = prop ?? contextValue;
|
|
7
|
+
const bound = useMemo(
|
|
8
|
+
() => bindResolveClientUrl(raw, urlHref),
|
|
9
|
+
[raw, urlHref]
|
|
10
10
|
);
|
|
11
|
+
return { bound, raw };
|
|
11
12
|
}
|
|
12
13
|
export {
|
|
13
14
|
useResolveClientUrl
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/host/react/hooks/use-resolve-client-url.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useRemoteComponentsContext } from '#internal/host/react/context';\nimport { bindResolveClientUrl } from '#internal/runtime/url/default-resolve-client-url';\nimport type { ResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\n\nexport function useResolveClientUrl(\n prop: ResolveClientUrl | undefined,\n urlHref: string,\n) {\n const { resolveClientUrl: contextValue } = useRemoteComponentsContext();\n const
|
|
1
|
+
{"version":3,"sources":["../../../../../src/host/react/hooks/use-resolve-client-url.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useRemoteComponentsContext } from '#internal/host/react/context';\nimport { bindResolveClientUrl } from '#internal/runtime/url/default-resolve-client-url';\nimport type { ResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\n\nexport function useResolveClientUrl(\n prop: ResolveClientUrl | undefined,\n urlHref: string,\n) {\n const { resolveClientUrl: contextValue } = useRemoteComponentsContext();\n const raw = prop ?? contextValue;\n const bound = useMemo(\n () => bindResolveClientUrl(raw, urlHref),\n [raw, urlHref],\n );\n return { bound, raw };\n}\n"],"mappings":"AAAA,SAAS,eAAe;AACxB,SAAS,kCAAkC;AAC3C,SAAS,4BAA4B;AAG9B,SAAS,oBACd,MACA,SACA;AACA,QAAM,EAAE,kBAAkB,aAAa,IAAI,2BAA2B;AACtE,QAAM,MAAM,QAAQ;AACpB,QAAM,QAAQ;AAAA,IACZ,MAAM,qBAAqB,KAAK,OAAO;AAAA,IACvC,CAAC,KAAK,OAAO;AAAA,EACf;AACA,SAAO,EAAE,OAAO,IAAI;AACtB;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/shared/config.ts"],"sourcesContent":["import type { ResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\nimport type { OnRequestHook, OnResponseHook } from './fetch-interceptors';\n\n/**\n * Configuration for Shadow DOM isolation of a remote component.\n *\n * Used by both the public {@link ConsumeRemoteComponentConfig} (user-facing props) and\n * {@link ConsumeServerData} (internal runtime data) to control\n * whether and how the remote component is wrapped in a shadow root.\n */\nexport interface ShadowDomConfig {\n /** Whether to isolate the remote component using a Shadow DOM wrapper. */\n isolate?: boolean;\n /** The Shadow DOM mode. Defaults to `'open'`. */\n mode?: 'open' | 'closed';\n /** Whether to include a CSS reset style in the Shadow DOM. Defaults to `false`. */\n reset?: boolean;\n}\n\n/**\n * Configuration accepted by server-rendered embed hosts (e.g. the Next.js App Router\n * `<ConsumeRemoteComponent>`). This is the minimal, serializable subset — no client-side\n * asset fetching fields, no lifecycle callbacks.\n *\n * `src` is optional here because not every host has a source at construction\n * time (e.g. the React host during SSR hydration, or a `<remote-component>`\n * element before its `src` attribute is set). Frameworks that require `src`\n * narrow it to required in their own props type.\n */\nexport interface ConsumeServerConfig extends ShadowDomConfig {\n /** The source URL of the remote component. Relative or absolute. */\n src?: string | URL;\n /** Selects a named remote component when multiple are exposed on a single page. */\n name?: string;\n /** Intercepts fetch requests before they are sent. */\n onRequest?: OnRequestHook;\n /** Inspects or transforms fetch responses after they arrive. */\n onResponse?: OnResponseHook;\n}\n\n/**\n * Client-only configuration fields — the subset of {@link ConsumeClientConfig}\n * that applies only to client-side asset fetching. Used directly in contexts where\n * the full server config is already present (e.g. {@link ConsumeRemoteComponentClient}).\n */\nexport interface ConsumeClientOnlyConfig {\n /** The credentials mode for the fetch request. Defaults to `'same-origin'`. */\n credentials?: RequestCredentials;\n /**\n * Rewrites client-side asset URLs (scripts, stylesheets, chunks, modules, images).\n * Return a new URL string to redirect the request (e.g. through a proxy),\n * or `undefined` to use the original URL.\n */\n resolveClientUrl?: ResolveClientUrl;\n}\n\n/**\n * Configuration accepted by client-side embed hosts (React host, Pages Router host,\n * HTML host). Extends {@link ConsumeServerConfig} with fields for\n * client-side asset fetching (`credentials`, `resolveClientUrl`).\n */\nexport interface ConsumeClientConfig\n extends ConsumeServerConfig,\n ConsumeClientOnlyConfig {}\n\n/**\n * Complete configuration for client-side embed hosts (React host, Pages Router host).\n * Combines {@link ConsumeClientConfig} with {@link ConsumeLifecycleCallbacks}.\n *\n * This is the base type for public-facing props on hosts that fetch and mount\n * remote components on the client. The App Router server host uses only\n * {@link ConsumeServerConfig} since RSC cannot accept function callbacks.\n */\nexport interface ConsumeRemoteComponentConfig\n extends ConsumeClientConfig,\n ConsumeLifecycleCallbacks {}\n\n/** Information provided to the `onChange` lifecycle callback. */\nexport interface ChangeInfo {\n previousSrc: string | URL | null;\n nextSrc: string | URL | null;\n previousName: string | undefined;\n nextName: string | undefined;\n}\n\n/**\n * Lifecycle callbacks shared by host and remote component implementations.\n *\n * On the host side, these fire during client-side loading (the React host\n * exposes them as callback props; the HTML host dispatches DOM events).\n * On the remote side (Next.js `<ExposeRemoteComponent>` wrapper), the callbacks\n * are forwarded as `data-on-*` attributes so the host can wire them up.\n *\n * Server-only components (e.g. Next.js App Router server host) do not\n * support these callbacks since they render once on the server.\n */\nexport interface ConsumeLifecycleCallbacks {\n /** Called right before a new remote component load starts. */\n onBeforeLoad?: (src: string | URL) => void;\n /** Called when the remote component has been successfully loaded and mounted. */\n onLoad?: (src: string | URL) => void;\n /** Called when an error occurs while loading or mounting the remote component. */\n onError?: (error: unknown) => void;\n /** Called when a different remote component is loaded into the same wrapper. */\n onChange?: (info: ChangeInfo) => void;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/config.ts"],"sourcesContent":["import type { ResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\nimport type { OnRequestHook, OnResponseHook } from './fetch-interceptors';\n\n/**\n * Configuration for Shadow DOM isolation of a remote component.\n *\n * Used by both the public {@link ConsumeRemoteComponentConfig} (user-facing props) and\n * {@link ConsumeServerData} (internal runtime data) to control\n * whether and how the remote component is wrapped in a shadow root.\n */\nexport interface ShadowDomConfig {\n /** Whether to isolate the remote component using a Shadow DOM wrapper. */\n isolate?: boolean;\n /** The Shadow DOM mode. Defaults to `'open'`. */\n mode?: 'open' | 'closed';\n /** Whether to include a CSS reset style in the Shadow DOM. Defaults to `false`. */\n reset?: boolean;\n}\n\n/**\n * Configuration accepted by server-rendered embed hosts (e.g. the Next.js App Router\n * `<ConsumeRemoteComponent>`). This is the minimal, serializable subset — no client-side\n * asset fetching fields, no lifecycle callbacks.\n *\n * `src` is optional here because not every host has a source at construction\n * time (e.g. the React host during SSR hydration, or a `<remote-component>`\n * element before its `src` attribute is set). Frameworks that require `src`\n * narrow it to required in their own props type.\n */\nexport interface ConsumeServerConfig extends ShadowDomConfig {\n /** The source URL of the remote component. Relative or absolute. */\n src?: string | URL;\n /** Selects a named remote component when multiple are exposed on a single page. */\n name?: string;\n /** Intercepts fetch requests before they are sent. */\n onRequest?: OnRequestHook;\n /** Inspects or transforms fetch responses after they arrive. */\n onResponse?: OnResponseHook;\n}\n\n/**\n * Client-only configuration fields — the subset of {@link ConsumeClientConfig}\n * that applies only to client-side asset fetching. Used directly in contexts where\n * the full server config is already present (e.g. {@link ConsumeRemoteComponentClient}).\n */\nexport interface ConsumeClientOnlyConfig {\n /** The credentials mode for the fetch request. Defaults to `'same-origin'`. */\n credentials?: RequestCredentials;\n /**\n * Rewrites client-side asset URLs (scripts, stylesheets, chunks, modules, images).\n * Return a new URL string to redirect the request (e.g. through a proxy),\n * or `undefined` to use the original URL.\n */\n resolveClientUrl?: ResolveClientUrl;\n /**\n * Shared module factories provided to the remote component's module system.\n * Each key is a module specifier; the value is a factory function that returns\n * the module. Since factories are functions, this can only be supplied from\n * client-side code and cannot be passed through Server Component boundaries.\n */\n shared?:\n | Promise<Record<string, (bundle?: string) => Promise<unknown>>>\n | Record<string, (bundle?: string) => Promise<unknown>>;\n}\n\n/**\n * Configuration accepted by client-side embed hosts (React host, Pages Router host,\n * HTML host). Extends {@link ConsumeServerConfig} with fields for\n * client-side asset fetching (`credentials`, `resolveClientUrl`).\n */\nexport interface ConsumeClientConfig\n extends ConsumeServerConfig,\n ConsumeClientOnlyConfig {}\n\n/**\n * Complete configuration for client-side embed hosts (React host, Pages Router host).\n * Combines {@link ConsumeClientConfig} with {@link ConsumeLifecycleCallbacks}.\n *\n * This is the base type for public-facing props on hosts that fetch and mount\n * remote components on the client. The App Router server host uses only\n * {@link ConsumeServerConfig} since RSC cannot accept function callbacks.\n */\nexport interface ConsumeRemoteComponentConfig\n extends ConsumeClientConfig,\n ConsumeLifecycleCallbacks {}\n\n/** Information provided to the `onChange` lifecycle callback. */\nexport interface ChangeInfo {\n previousSrc: string | URL | null;\n nextSrc: string | URL | null;\n previousName: string | undefined;\n nextName: string | undefined;\n}\n\n/**\n * Lifecycle callbacks shared by host and remote component implementations.\n *\n * On the host side, these fire during client-side loading (the React host\n * exposes them as callback props; the HTML host dispatches DOM events).\n * On the remote side (Next.js `<ExposeRemoteComponent>` wrapper), the callbacks\n * are forwarded as `data-on-*` attributes so the host can wire them up.\n *\n * Server-only components (e.g. Next.js App Router server host) do not\n * support these callbacks since they render once on the server.\n */\nexport interface ConsumeLifecycleCallbacks {\n /** Called right before a new remote component load starts. */\n onBeforeLoad?: (src: string | URL) => void;\n /** Called when the remote component has been successfully loaded and mounted. */\n onLoad?: (src: string | URL) => void;\n /** Called when an error occurs while loading or mounting the remote component. */\n onError?: (error: unknown) => void;\n /** Called when a different remote component is loaded into the same wrapper. */\n onChange?: (info: ChangeInfo) => void;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -50,6 +50,13 @@ interface ConsumeClientOnlyConfig {
|
|
|
50
50
|
* or `undefined` to use the original URL.
|
|
51
51
|
*/
|
|
52
52
|
resolveClientUrl?: ResolveClientUrl;
|
|
53
|
+
/**
|
|
54
|
+
* Shared module factories provided to the remote component's module system.
|
|
55
|
+
* Each key is a module specifier; the value is a factory function that returns
|
|
56
|
+
* the module. Since factories are functions, this can only be supplied from
|
|
57
|
+
* client-side code and cannot be passed through Server Component boundaries.
|
|
58
|
+
*/
|
|
59
|
+
shared?: Promise<Record<string, (bundle?: string) => Promise<unknown>>> | Record<string, (bundle?: string) => Promise<unknown>>;
|
|
53
60
|
}
|
|
54
61
|
/**
|
|
55
62
|
* Configuration accepted by client-side embed hosts (React host, Pages Router host,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
import { ScriptDescriptor, LinkDescriptor } from './asset-descriptors.js';
|
|
3
3
|
import { ShadowDomConfig } from './config.js';
|
|
4
4
|
import { RemoteComponentMetadata } from '../../runtime/metadata.js';
|
|
@@ -42,7 +42,7 @@ interface ConsumeRemoteComponentServerData extends RemoteComponentLoaderPayload,
|
|
|
42
42
|
serverUrl: string;
|
|
43
43
|
links?: LinkDescriptor[];
|
|
44
44
|
type?: RemoteComponentMetadata['type'];
|
|
45
|
-
children:
|
|
45
|
+
children: react.ReactNode;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export { ConsumeRemoteComponentServerData, RemoteComponentLoaderPayload };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InternalResolveClientUrl } from '../url/resolve-client-url.js';
|
|
2
|
-
import { a as ConsumeLoaderPayload } from '../../../server-handoff-
|
|
2
|
+
import { a as ConsumeLoaderPayload } from '../../../server-handoff-ce13bebc.js';
|
|
3
3
|
import { LoaderResult } from '../types.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import '../../host/shared/asset-descriptors.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
import { ScriptDescriptor, LinkDescriptor } from './internal/host/shared/asset-descriptors.js';
|
|
3
3
|
import { ShadowDomConfig } from './internal/host/shared/config.js';
|
|
4
4
|
import { RemoteComponentMetadata } from './internal/runtime/metadata.js';
|
|
@@ -40,7 +40,7 @@ interface ConsumeServerData extends ConsumeLoaderPayload, ShadowDomConfig {
|
|
|
40
40
|
serverUrl: string;
|
|
41
41
|
links?: LinkDescriptor[];
|
|
42
42
|
type?: RemoteComponentMetadata['type'];
|
|
43
|
-
children:
|
|
43
|
+
children: react.ReactNode;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export { ConsumeServerData as C, ConsumeLoaderPayload as a };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remote-components",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Compose remote components at runtime between microfrontends applications.",
|
|
6
6
|
"keywords": [
|
|
@@ -94,11 +94,6 @@
|
|
|
94
94
|
"require": "./dist/host/proxy/client.cjs",
|
|
95
95
|
"default": "./dist/host/proxy/client.js"
|
|
96
96
|
},
|
|
97
|
-
"./host/react/context": {
|
|
98
|
-
"import": "./dist/internal/host/react/context.js",
|
|
99
|
-
"require": "./dist/internal/host/react/context.cjs",
|
|
100
|
-
"default": "./dist/internal/host/react/context.js"
|
|
101
|
-
},
|
|
102
97
|
"./remote/middleware": {
|
|
103
98
|
"import": "./dist/remote/middleware.js",
|
|
104
99
|
"require": "./dist/remote/middleware.cjs",
|
|
@@ -161,9 +156,6 @@
|
|
|
161
156
|
"host/proxy/client": [
|
|
162
157
|
"./dist/host/proxy/client.d.ts"
|
|
163
158
|
],
|
|
164
|
-
"host/react/context": [
|
|
165
|
-
"./dist/internal/host/react/context.d.ts"
|
|
166
|
-
],
|
|
167
159
|
"remote/middleware": [
|
|
168
160
|
"./dist/remote/middleware.d.ts"
|
|
169
161
|
],
|