remote-components 0.1.0 → 0.1.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/{component-loader-76eb1b8b.d.ts → component-loader-21865da3.d.ts} +140 -16
- package/dist/host-config-58cdccea.d.ts +87 -0
- package/dist/html/host.cjs +294 -162
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +294 -162
- package/dist/html/host.js.map +1 -1
- package/dist/internal/next/host/app-router-client.cjs +9 -7
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.d.ts +32 -19
- package/dist/internal/next/host/app-router-client.js +9 -7
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/next/remote/render-server.cjs.map +1 -1
- package/dist/internal/next/remote/render-server.d.ts +13 -14
- package/dist/internal/next/remote/render-server.js.map +1 -1
- package/dist/internal/shared/client/proxy-through-host.cjs +15 -1
- package/dist/internal/shared/client/proxy-through-host.cjs.map +1 -1
- package/dist/internal/shared/client/proxy-through-host.d.ts +5 -0
- package/dist/internal/shared/client/proxy-through-host.js +15 -1
- package/dist/internal/shared/client/proxy-through-host.js.map +1 -1
- 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.map +1 -1
- package/dist/internal/shared/contract/host-state.cjs +38 -0
- package/dist/internal/shared/contract/host-state.cjs.map +1 -0
- package/dist/internal/shared/contract/host-state.d.ts +53 -0
- package/dist/internal/shared/contract/host-state.js +14 -0
- package/dist/internal/shared/contract/host-state.js.map +1 -0
- package/dist/internal/shared/contract/resolve-name-from-src.cjs +40 -0
- package/dist/internal/shared/contract/resolve-name-from-src.cjs.map +1 -0
- package/dist/internal/shared/contract/resolve-name-from-src.d.ts +13 -0
- package/dist/internal/shared/contract/resolve-name-from-src.js +16 -0
- package/dist/internal/shared/contract/resolve-name-from-src.js.map +1 -0
- package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
- 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.map +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +1 -1
- package/dist/next/host/app-router-server.cjs.map +1 -1
- package/dist/next/host/app-router-server.d.ts +11 -41
- package/dist/next/host/app-router-server.js.map +1 -1
- package/dist/next/host/client/index.cjs +203 -95
- 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 +203 -95
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-client.cjs.map +1 -1
- package/dist/next/host/pages-router-client.d.ts +13 -36
- package/dist/next/host/pages-router-client.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.d.ts +17 -42
- 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 +13 -39
- package/dist/next/index.js.map +1 -1
- package/dist/next/remote/server.d.ts +4 -0
- package/dist/react/index.cjs +203 -95
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +12 -49
- package/dist/react/index.js +203 -95
- package/dist/react/index.js.map +1 -1
- package/dist/{types-cbe44b51.d.ts → types-2b26a246.d.ts} +23 -6
- package/package.json +1 -1
|
@@ -1,6 +1,26 @@
|
|
|
1
|
-
import { I as InternalResolveClientUrl } from './proxy-through-host-a676a522.js';
|
|
1
|
+
import { R as ResolveClientUrl, I as InternalResolveClientUrl } from './proxy-through-host-a676a522.js';
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Serialized descriptor for a `<script>` element extracted from a remote
|
|
6
|
+
* component response. Used in both SSR fetch results and client-side props.
|
|
7
|
+
*/
|
|
8
|
+
interface ScriptDescriptor {
|
|
9
|
+
/** The script `src` URL. Empty string for inline scripts. */
|
|
10
|
+
src: string;
|
|
11
|
+
/** Inline script content (only present for scripts without a `src`). */
|
|
12
|
+
textContent?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Serialized descriptor for a `<link>` element extracted from a remote
|
|
16
|
+
* component response. Captures all HTML attributes as key-value pairs.
|
|
17
|
+
*
|
|
18
|
+
* Note: the client-side parser works with live `HTMLLinkElement` objects.
|
|
19
|
+
* This descriptor represents the serialized form passed between SSR and
|
|
20
|
+
* client hydration.
|
|
21
|
+
*/
|
|
22
|
+
type LinkDescriptor = Record<string, string | boolean>;
|
|
23
|
+
|
|
4
24
|
interface RemoteComponentMetadata {
|
|
5
25
|
bundle: string;
|
|
6
26
|
route: string;
|
|
@@ -125,11 +145,98 @@ type OnRequestHook = (url: URL, init: RequestInit, options: HookOptions) => Prom
|
|
|
125
145
|
*/
|
|
126
146
|
type OnResponseHook = (url: URL, response: Response, options: HookOptions) => Promise<Response | undefined> | Response | undefined;
|
|
127
147
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Configuration for Shadow DOM isolation of a remote component.
|
|
150
|
+
*
|
|
151
|
+
* Used by both the public {@link HostConfig} (user-facing props) and
|
|
152
|
+
* {@link ResolvedRemoteComponentData} (internal runtime data) to control
|
|
153
|
+
* whether and how the remote component is wrapped in a shadow root.
|
|
154
|
+
*/
|
|
155
|
+
interface ShadowDomConfig {
|
|
156
|
+
/** Whether to isolate the remote component using a Shadow DOM wrapper. */
|
|
157
|
+
isolate?: boolean;
|
|
158
|
+
/** The Shadow DOM mode. Defaults to `'open'`. */
|
|
159
|
+
mode?: 'open' | 'closed';
|
|
160
|
+
/** Whether to include a CSS reset style in the Shadow DOM. Defaults to `false`. */
|
|
161
|
+
reset?: boolean;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Core configuration accepted by every host implementation.
|
|
165
|
+
*
|
|
166
|
+
* `src` is optional here because not every host has a source at construction
|
|
167
|
+
* time (e.g. the React host during SSR hydration, or a `<remote-component>`
|
|
168
|
+
* element before its `src` attribute is set). Frameworks that require `src`
|
|
169
|
+
* narrow it to required in their own props type.
|
|
170
|
+
*
|
|
171
|
+
* Client-only fields (`credentials`, `resolveClientUrl`) live in the separate
|
|
172
|
+
* {@link ClientHostConfig} interface so that server-only hosts (App Router)
|
|
173
|
+
* can extend `HostConfig` directly without omitting anything.
|
|
174
|
+
*/
|
|
175
|
+
interface HostConfig extends ShadowDomConfig {
|
|
176
|
+
/** The source URL of the remote component. Relative or absolute. */
|
|
177
|
+
src?: string | URL;
|
|
178
|
+
/** Selects a named remote component when multiple are exposed on a single page. */
|
|
179
|
+
name?: string;
|
|
180
|
+
/** Intercepts fetch requests before they are sent. */
|
|
181
|
+
onRequest?: OnRequestHook;
|
|
182
|
+
/** Inspects or transforms fetch responses after they arrive. */
|
|
183
|
+
onResponse?: OnResponseHook;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Client-side host configuration that extends {@link HostConfig}.
|
|
187
|
+
*
|
|
188
|
+
* These fields only apply to hosts that fetch and resolve assets on the client
|
|
189
|
+
* (React host, Pages Router host, HTML host). Server-only hosts like the
|
|
190
|
+
* App Router server component do not need these.
|
|
191
|
+
*/
|
|
192
|
+
interface ClientHostConfig {
|
|
193
|
+
/** The credentials mode for the fetch request. Defaults to `'same-origin'`. */
|
|
194
|
+
credentials?: RequestCredentials;
|
|
195
|
+
/**
|
|
196
|
+
* Rewrites client-side asset URLs (scripts, stylesheets, chunks, modules, images).
|
|
197
|
+
* Return a new URL string to redirect the request (e.g. through a proxy),
|
|
198
|
+
* or `undefined` to use the original URL.
|
|
199
|
+
*/
|
|
200
|
+
resolveClientUrl?: ResolveClientUrl;
|
|
201
|
+
}
|
|
202
|
+
/** Information provided to the `onChange` lifecycle callback. */
|
|
203
|
+
interface ChangeInfo {
|
|
204
|
+
previousSrc: string | URL | null;
|
|
205
|
+
nextSrc: string | URL | null;
|
|
206
|
+
previousName: string | undefined;
|
|
207
|
+
nextName: string | undefined;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Lifecycle callbacks shared by host and remote component implementations.
|
|
211
|
+
*
|
|
212
|
+
* On the host side, these fire during client-side loading (the React host
|
|
213
|
+
* exposes them as callback props; the HTML host dispatches DOM events).
|
|
214
|
+
* On the remote side (Next.js `<RemoteComponent>` wrapper), the callbacks
|
|
215
|
+
* are forwarded as `data-on-*` attributes so the host can wire them up.
|
|
216
|
+
*
|
|
217
|
+
* Server-only components (e.g. Next.js App Router server host) do not
|
|
218
|
+
* support these callbacks since they render once on the server.
|
|
219
|
+
*/
|
|
220
|
+
interface HostLifecycleCallbacks {
|
|
221
|
+
/** Called right before a new remote component load starts. */
|
|
222
|
+
onBeforeLoad?: (src: string | URL) => void;
|
|
223
|
+
/** Called when the remote component has been successfully loaded and mounted. */
|
|
224
|
+
onLoad?: (src: string | URL) => void;
|
|
225
|
+
/** Called when an error occurs while loading or mounting the remote component. */
|
|
226
|
+
onError?: (error: unknown) => void;
|
|
227
|
+
/** Called when a different remote component is loaded into the same wrapper. */
|
|
228
|
+
onChange?: (info: ChangeInfo) => void;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Payload fields extracted from an SSR fetch response that the client-side
|
|
233
|
+
* component loader needs to hydrate or mount a remote component.
|
|
234
|
+
*
|
|
235
|
+
* These mirror the relevant parts of `FetchRemoteComponentResponse` from the
|
|
236
|
+
* SSR layer. Both {@link ResolvedRemoteComponentData} and
|
|
237
|
+
* `LoadRemoteComponentProps` compose this interface.
|
|
238
|
+
*/
|
|
239
|
+
interface RemoteComponentPayload {
|
|
133
240
|
name: string;
|
|
134
241
|
bundle: string;
|
|
135
242
|
route?: string;
|
|
@@ -141,14 +248,23 @@ interface RemoteComponentProps {
|
|
|
141
248
|
};
|
|
142
249
|
buildId?: string;
|
|
143
250
|
} | null;
|
|
144
|
-
scripts?:
|
|
145
|
-
src: string;
|
|
146
|
-
}[];
|
|
147
|
-
links?: Record<string, string | boolean | undefined>[];
|
|
251
|
+
scripts?: ScriptDescriptor[];
|
|
148
252
|
remoteShared?: Record<string, string>;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Internal runtime data for a resolved remote component.
|
|
256
|
+
*
|
|
257
|
+
* This is **not** the public `RemoteComponentProps` that consumers pass to
|
|
258
|
+
* `<RemoteComponent>`. It represents the pre-resolved payload fields produced
|
|
259
|
+
* by SSR fetching, combined with presentation config from
|
|
260
|
+
* {@link ShadowDomConfig}, and consumed by the client-side renderer.
|
|
261
|
+
*/
|
|
262
|
+
interface ResolvedRemoteComponentData extends RemoteComponentPayload, ShadowDomConfig {
|
|
263
|
+
/** The src provided to the `<RemoteComponent>` component, resolved to a string. */
|
|
264
|
+
src: string;
|
|
265
|
+
/** The src converted to a URL string. For relative URLs, the VERCEL_URL is used as the origin. */
|
|
266
|
+
serverUrl: string;
|
|
267
|
+
links?: LinkDescriptor[];
|
|
152
268
|
type?: RemoteComponentMetadata['type'];
|
|
153
269
|
children: react.ReactNode;
|
|
154
270
|
}
|
|
@@ -184,17 +300,25 @@ interface LoaderResult {
|
|
|
184
300
|
}
|
|
185
301
|
type MountOrUnmountFunction = (el?: ShadowRoot | DocumentFragment | HTMLElement | HTMLCollection | null) => Promise<void> | void;
|
|
186
302
|
|
|
187
|
-
|
|
303
|
+
/**
|
|
304
|
+
* Props accepted by {@link loadRemoteComponent}.
|
|
305
|
+
*
|
|
306
|
+
* Extends {@link RemoteComponentPayload} (the SSR-resolved fields needed for
|
|
307
|
+
* hydration) with loader-specific fields (`url`, `shared`, `container`, etc.).
|
|
308
|
+
* `remoteShared` is narrowed from optional to required (defaults to `{}` at
|
|
309
|
+
* the call site).
|
|
310
|
+
*/
|
|
311
|
+
interface LoadRemoteComponentProps extends RemoteComponentPayload {
|
|
188
312
|
url: URL;
|
|
189
313
|
shared: Promise<Record<string, (bundle?: string) => Promise<unknown>>> | Record<string, (bundle?: string) => Promise<unknown>>;
|
|
190
314
|
remoteShared: Record<string, string>;
|
|
191
315
|
container?: HTMLHeadElement | ShadowRoot | null;
|
|
192
316
|
rscName?: string;
|
|
193
317
|
resolveClientUrl?: InternalResolveClientUrl;
|
|
194
|
-
}
|
|
318
|
+
}
|
|
195
319
|
/**
|
|
196
320
|
* Main loader function that orchestrates the component loading process
|
|
197
321
|
*/
|
|
198
322
|
declare function loadRemoteComponent({ url, name, rscName, bundle, route, runtime, data, nextData, scripts, shared, remoteShared, container, resolveClientUrl, }: LoadRemoteComponentProps): Promise<LoaderResult>;
|
|
199
323
|
|
|
200
|
-
export { GlobalScope as G,
|
|
324
|
+
export { ClientHostConfig as C, GlobalScope as G, HostConfig as H, LoadRemoteComponentProps as L, MountOrUnmountFunction as M, OnRequestHook as O, RemoteComponentPayload as R, HostLifecycleCallbacks as a, HookOptions as b, OnResponseHook as c, LoaderResult as d, ResolvedRemoteComponentData as e, loadRemoteComponent as l };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ResolveClientUrl } from './internal/shared/client/proxy-through-host.js';
|
|
2
|
+
import { O as OnRequestHook, a as OnResponseHook } from './types-2b26a246.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for Shadow DOM isolation of a remote component.
|
|
6
|
+
*
|
|
7
|
+
* Used by both the public {@link HostConfig} (user-facing props) and
|
|
8
|
+
* {@link ResolvedRemoteComponentData} (internal runtime data) to control
|
|
9
|
+
* whether and how the remote component is wrapped in a shadow root.
|
|
10
|
+
*/
|
|
11
|
+
interface ShadowDomConfig {
|
|
12
|
+
/** Whether to isolate the remote component using a Shadow DOM wrapper. */
|
|
13
|
+
isolate?: boolean;
|
|
14
|
+
/** The Shadow DOM mode. Defaults to `'open'`. */
|
|
15
|
+
mode?: 'open' | 'closed';
|
|
16
|
+
/** Whether to include a CSS reset style in the Shadow DOM. Defaults to `false`. */
|
|
17
|
+
reset?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Core configuration accepted by every host implementation.
|
|
21
|
+
*
|
|
22
|
+
* `src` is optional here because not every host has a source at construction
|
|
23
|
+
* time (e.g. the React host during SSR hydration, or a `<remote-component>`
|
|
24
|
+
* element before its `src` attribute is set). Frameworks that require `src`
|
|
25
|
+
* narrow it to required in their own props type.
|
|
26
|
+
*
|
|
27
|
+
* Client-only fields (`credentials`, `resolveClientUrl`) live in the separate
|
|
28
|
+
* {@link ClientHostConfig} interface so that server-only hosts (App Router)
|
|
29
|
+
* can extend `HostConfig` directly without omitting anything.
|
|
30
|
+
*/
|
|
31
|
+
interface HostConfig extends ShadowDomConfig {
|
|
32
|
+
/** The source URL of the remote component. Relative or absolute. */
|
|
33
|
+
src?: string | URL;
|
|
34
|
+
/** Selects a named remote component when multiple are exposed on a single page. */
|
|
35
|
+
name?: string;
|
|
36
|
+
/** Intercepts fetch requests before they are sent. */
|
|
37
|
+
onRequest?: OnRequestHook;
|
|
38
|
+
/** Inspects or transforms fetch responses after they arrive. */
|
|
39
|
+
onResponse?: OnResponseHook;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Client-side host configuration that extends {@link HostConfig}.
|
|
43
|
+
*
|
|
44
|
+
* These fields only apply to hosts that fetch and resolve assets on the client
|
|
45
|
+
* (React host, Pages Router host, HTML host). Server-only hosts like the
|
|
46
|
+
* App Router server component do not need these.
|
|
47
|
+
*/
|
|
48
|
+
interface ClientHostConfig {
|
|
49
|
+
/** The credentials mode for the fetch request. Defaults to `'same-origin'`. */
|
|
50
|
+
credentials?: RequestCredentials;
|
|
51
|
+
/**
|
|
52
|
+
* Rewrites client-side asset URLs (scripts, stylesheets, chunks, modules, images).
|
|
53
|
+
* Return a new URL string to redirect the request (e.g. through a proxy),
|
|
54
|
+
* or `undefined` to use the original URL.
|
|
55
|
+
*/
|
|
56
|
+
resolveClientUrl?: ResolveClientUrl;
|
|
57
|
+
}
|
|
58
|
+
/** Information provided to the `onChange` lifecycle callback. */
|
|
59
|
+
interface ChangeInfo {
|
|
60
|
+
previousSrc: string | URL | null;
|
|
61
|
+
nextSrc: string | URL | null;
|
|
62
|
+
previousName: string | undefined;
|
|
63
|
+
nextName: string | undefined;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Lifecycle callbacks shared by host and remote component implementations.
|
|
67
|
+
*
|
|
68
|
+
* On the host side, these fire during client-side loading (the React host
|
|
69
|
+
* exposes them as callback props; the HTML host dispatches DOM events).
|
|
70
|
+
* On the remote side (Next.js `<RemoteComponent>` wrapper), the callbacks
|
|
71
|
+
* are forwarded as `data-on-*` attributes so the host can wire them up.
|
|
72
|
+
*
|
|
73
|
+
* Server-only components (e.g. Next.js App Router server host) do not
|
|
74
|
+
* support these callbacks since they render once on the server.
|
|
75
|
+
*/
|
|
76
|
+
interface HostLifecycleCallbacks {
|
|
77
|
+
/** Called right before a new remote component load starts. */
|
|
78
|
+
onBeforeLoad?: (src: string | URL) => void;
|
|
79
|
+
/** Called when the remote component has been successfully loaded and mounted. */
|
|
80
|
+
onLoad?: (src: string | URL) => void;
|
|
81
|
+
/** Called when an error occurs while loading or mounting the remote component. */
|
|
82
|
+
onError?: (error: unknown) => void;
|
|
83
|
+
/** Called when a different remote component is loaded into the same wrapper. */
|
|
84
|
+
onChange?: (info: ChangeInfo) => void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { ClientHostConfig as C, HostConfig as H, ShadowDomConfig as S, HostLifecycleCallbacks as a };
|