remote-components 0.2.1 → 0.3.0
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/config/nextjs.cjs +2 -4
- package/dist/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.d.ts +1 -1
- package/dist/config/nextjs.js +2 -4
- package/dist/config/nextjs.js.map +1 -1
- package/dist/host/html.cjs +40 -59
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +40 -62
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +199 -231
- 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 +198 -231
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/nextjs/pages.cjs +5 -12
- package/dist/host/nextjs/pages.cjs.map +1 -1
- package/dist/host/nextjs/pages.js +6 -13
- package/dist/host/nextjs/pages.js.map +1 -1
- package/dist/host/react.cjs +45 -71
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.d.ts +2 -366
- package/dist/host/react.js +45 -71
- 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 +1 -5
- 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 +2 -6
- package/dist/internal/host/nextjs/app-client.js.map +1 -1
- package/dist/internal/host/nextjs/image-shared.cjs +25 -15
- package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
- package/dist/internal/host/nextjs/image-shared.d.ts +19 -6
- package/dist/internal/host/nextjs/image-shared.js +24 -14
- package/dist/internal/host/nextjs/image-shared.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 +2 -5
- package/dist/internal/host/react/hooks/use-resolve-client-url.cjs.map +1 -1
- package/dist/internal/host/react/hooks/use-resolve-client-url.js +2 -5
- 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/polyfill.cjs +10 -65
- package/dist/internal/host/shared/polyfill.cjs.map +1 -1
- package/dist/internal/host/shared/polyfill.d.ts +1 -3
- package/dist/internal/host/shared/polyfill.js +9 -63
- package/dist/internal/host/shared/polyfill.js.map +1 -1
- package/dist/internal/host/shared/remote-image-loader.cjs +53 -0
- package/dist/internal/host/shared/remote-image-loader.cjs.map +1 -0
- package/dist/internal/host/shared/remote-image-loader.d.ts +30 -0
- package/dist/internal/host/shared/remote-image-loader.js +29 -0
- package/dist/internal/host/shared/remote-image-loader.js.map +1 -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
- package/dist/internal/host/nextjs/image-impl.cjs +0 -60
- package/dist/internal/host/nextjs/image-impl.cjs.map +0 -1
- package/dist/internal/host/nextjs/image-impl.d.ts +0 -10
- package/dist/internal/host/nextjs/image-impl.js +0 -36
- package/dist/internal/host/nextjs/image-impl.js.map +0 -1
package/dist/host/react.d.ts
CHANGED
|
@@ -1,366 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Intercepts client-side URL resolution for remote component resources.
|
|
5
|
-
* Called before each asset (script, stylesheet, chunk, module, image) is fetched.
|
|
6
|
-
*
|
|
7
|
-
* Return a new URL string to redirect the fetch (e.g., through a proxy),
|
|
8
|
-
* or undefined to use the original URL.
|
|
9
|
-
*
|
|
10
|
-
* @param remoteSrc - The `src` of the remote component being loaded
|
|
11
|
-
* @param url - The asset URL about to be fetched
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* // Proxy all assets from the remote's origin through the host
|
|
15
|
-
* const resolveClientUrl = (remoteSrc, url) => {
|
|
16
|
-
* const remoteOrigin = new URL(remoteSrc).origin;
|
|
17
|
-
* const parsed = new URL(url);
|
|
18
|
-
* if (parsed.origin !== location.origin && parsed.origin === remoteOrigin) {
|
|
19
|
-
* return `/rc-fetch-protected-remote?url=${encodeURIComponent(url)}`;
|
|
20
|
-
* }
|
|
21
|
-
* };
|
|
22
|
-
*/
|
|
23
|
-
type ResolveClientUrl = (remoteSrc: string, url: string) => string | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* Internal bound resolver — `ResolveClientUrl` with `remoteSrc` already applied.
|
|
26
|
-
* Used by internal loaders that don't need to know the remote src.
|
|
27
|
-
*/
|
|
28
|
-
type InternalResolveClientUrl = (url: string) => string | undefined;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Hook types for intercepting remote component fetch requests and responses.
|
|
32
|
-
*
|
|
33
|
-
* These are part of the public host configuration surface ({@link ConsumeServerConfig})
|
|
34
|
-
* and are used by both SSR and client-side host implementations.
|
|
35
|
-
*/
|
|
36
|
-
/**
|
|
37
|
-
* Options object passed to hook functions containing abort capabilities.
|
|
38
|
-
* Uses standard AbortController/AbortSignal for compatibility with Web APIs.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* // Abort on redirect
|
|
42
|
-
* component.onResponse = (url, response, { signal, abort }) => {
|
|
43
|
-
* if (response.redirected) {
|
|
44
|
-
* abort();
|
|
45
|
-
* }
|
|
46
|
-
* };
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* // Check if already aborted
|
|
50
|
-
* component.onRequest = (url, init, { signal }) => {
|
|
51
|
-
* if (signal.aborted) return;
|
|
52
|
-
* // ...
|
|
53
|
-
* };
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* // Pass signal to fetch or other APIs
|
|
57
|
-
* component.onRequest = async (url, init, { signal }) => {
|
|
58
|
-
* const data = await fetch('/api/check', { signal });
|
|
59
|
-
* // ...
|
|
60
|
-
* };
|
|
61
|
-
*/
|
|
62
|
-
interface HookOptions {
|
|
63
|
-
/** Standard AbortSignal - can be passed to fetch and other Web APIs */
|
|
64
|
-
signal: AbortSignal;
|
|
65
|
-
/** Abort loading - prevents further processing and DOM attachment */
|
|
66
|
-
abort(reason?: unknown): void;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Hook function that intercepts remote component fetch requests.
|
|
70
|
-
* Can be used to modify request options, provide a custom response, inspect the request,
|
|
71
|
-
* or abort loading.
|
|
72
|
-
*
|
|
73
|
-
* @param url - The URL being fetched
|
|
74
|
-
* @param init - The fetch init options being used
|
|
75
|
-
* @param options - Options object containing the abort signal
|
|
76
|
-
* @returns Optional Response to use instead of fetching, or void/undefined to proceed with normal fetch
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* // Log all remote component requests
|
|
80
|
-
* const onRequest = async (url, init, { abort }) => {
|
|
81
|
-
* console.log('Fetching remote component from:', url.href);
|
|
82
|
-
* };
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* // Add custom headers
|
|
86
|
-
* const onRequest = async (url, init) => {
|
|
87
|
-
* (init.headers as Headers).set('X-Custom-Header', 'value');
|
|
88
|
-
* };
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* // Provide a cached response
|
|
92
|
-
* const onRequest = async (url) => {
|
|
93
|
-
* const cached = cache.get(url.href);
|
|
94
|
-
* if (cached) {
|
|
95
|
-
* return new Response(cached);
|
|
96
|
-
* }
|
|
97
|
-
* };
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* // Block certain domains
|
|
101
|
-
* const onRequest = async (url, init, { abort }) => {
|
|
102
|
-
* if (isBlockedDomain(url)) {
|
|
103
|
-
* abort('Domain is blocked');
|
|
104
|
-
* }
|
|
105
|
-
* };
|
|
106
|
-
*/
|
|
107
|
-
type OnRequestHook = (url: URL, init: RequestInit, options: HookOptions) => Promise<Response | undefined> | Response | undefined;
|
|
108
|
-
/**
|
|
109
|
-
* Hook function that is called after a remote component fetch completes.
|
|
110
|
-
* Can be used to inspect the response, check for redirects, transform the response,
|
|
111
|
-
* or abort loading.
|
|
112
|
-
*
|
|
113
|
-
* @param url - The original URL that was requested
|
|
114
|
-
* @param response - The Response object from the fetch
|
|
115
|
-
* @param options - Options object containing the abort signal
|
|
116
|
-
* @returns Optional Response to use instead of the original, or void/undefined to use the original response
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* // Check for redirects and abort
|
|
120
|
-
* const onResponse = async (url, response, { abort }) => {
|
|
121
|
-
* if (response.redirected) {
|
|
122
|
-
* console.log(`Redirected from ${url.href} to ${response.url}`);
|
|
123
|
-
* abort();
|
|
124
|
-
* }
|
|
125
|
-
* };
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* // Cache the response
|
|
129
|
-
* const onResponse = async (url, response) => {
|
|
130
|
-
* const cloned = response.clone();
|
|
131
|
-
* cache.set(url.href, await cloned.text());
|
|
132
|
-
* };
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* // Transform the response
|
|
136
|
-
* const onResponse = async (url, response) => {
|
|
137
|
-
* const text = await response.text();
|
|
138
|
-
* const modified = text.replace(/foo/g, 'bar');
|
|
139
|
-
* return new Response(modified, response);
|
|
140
|
-
* };
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* // Abort on redirect to legacy routes
|
|
144
|
-
* const onResponse = async (url, response, { abort }) => {
|
|
145
|
-
* if (response.redirected && isLegacyRoute(response.url)) {
|
|
146
|
-
* window.location.href = toLegacyUrl(response.url);
|
|
147
|
-
* abort(); // Abort rendering - no flash!
|
|
148
|
-
* }
|
|
149
|
-
* };
|
|
150
|
-
*/
|
|
151
|
-
type OnResponseHook = (url: URL, response: Response, options: HookOptions) => Promise<Response | undefined> | Response | undefined;
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Configuration for Shadow DOM isolation of a remote component.
|
|
155
|
-
*
|
|
156
|
-
* Used by both the public {@link ConsumeRemoteComponentConfig} (user-facing props) and
|
|
157
|
-
* {@link ConsumeServerData} (internal runtime data) to control
|
|
158
|
-
* whether and how the remote component is wrapped in a shadow root.
|
|
159
|
-
*/
|
|
160
|
-
interface ShadowDomConfig {
|
|
161
|
-
/** Whether to isolate the remote component using a Shadow DOM wrapper. */
|
|
162
|
-
isolate?: boolean;
|
|
163
|
-
/** The Shadow DOM mode. Defaults to `'open'`. */
|
|
164
|
-
mode?: 'open' | 'closed';
|
|
165
|
-
/** Whether to include a CSS reset style in the Shadow DOM. Defaults to `false`. */
|
|
166
|
-
reset?: boolean;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Configuration accepted by server-rendered embed hosts (e.g. the Next.js App Router
|
|
170
|
-
* `<ConsumeRemoteComponent>`). This is the minimal, serializable subset — no client-side
|
|
171
|
-
* asset fetching fields, no lifecycle callbacks.
|
|
172
|
-
*
|
|
173
|
-
* `src` is optional here because not every host has a source at construction
|
|
174
|
-
* time (e.g. the React host during SSR hydration, or a `<remote-component>`
|
|
175
|
-
* element before its `src` attribute is set). Frameworks that require `src`
|
|
176
|
-
* narrow it to required in their own props type.
|
|
177
|
-
*/
|
|
178
|
-
interface ConsumeServerConfig extends ShadowDomConfig {
|
|
179
|
-
/** The source URL of the remote component. Relative or absolute. */
|
|
180
|
-
src?: string | URL;
|
|
181
|
-
/** Selects a named remote component when multiple are exposed on a single page. */
|
|
182
|
-
name?: string;
|
|
183
|
-
/** Intercepts fetch requests before they are sent. */
|
|
184
|
-
onRequest?: OnRequestHook;
|
|
185
|
-
/** Inspects or transforms fetch responses after they arrive. */
|
|
186
|
-
onResponse?: OnResponseHook;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Client-only configuration fields — the subset of {@link ConsumeClientConfig}
|
|
190
|
-
* that applies only to client-side asset fetching. Used directly in contexts where
|
|
191
|
-
* the full server config is already present (e.g. {@link ConsumeRemoteComponentClient}).
|
|
192
|
-
*/
|
|
193
|
-
interface ConsumeClientOnlyConfig {
|
|
194
|
-
/** The credentials mode for the fetch request. Defaults to `'same-origin'`. */
|
|
195
|
-
credentials?: RequestCredentials;
|
|
196
|
-
/**
|
|
197
|
-
* Rewrites client-side asset URLs (scripts, stylesheets, chunks, modules, images).
|
|
198
|
-
* Return a new URL string to redirect the request (e.g. through a proxy),
|
|
199
|
-
* or `undefined` to use the original URL.
|
|
200
|
-
*/
|
|
201
|
-
resolveClientUrl?: ResolveClientUrl;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Configuration accepted by client-side embed hosts (React host, Pages Router host,
|
|
205
|
-
* HTML host). Extends {@link ConsumeServerConfig} with fields for
|
|
206
|
-
* client-side asset fetching (`credentials`, `resolveClientUrl`).
|
|
207
|
-
*/
|
|
208
|
-
interface ConsumeClientConfig extends ConsumeServerConfig, ConsumeClientOnlyConfig {
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Complete configuration for client-side embed hosts (React host, Pages Router host).
|
|
212
|
-
* Combines {@link ConsumeClientConfig} with {@link ConsumeLifecycleCallbacks}.
|
|
213
|
-
*
|
|
214
|
-
* This is the base type for public-facing props on hosts that fetch and mount
|
|
215
|
-
* remote components on the client. The App Router server host uses only
|
|
216
|
-
* {@link ConsumeServerConfig} since RSC cannot accept function callbacks.
|
|
217
|
-
*/
|
|
218
|
-
interface ConsumeRemoteComponentConfig extends ConsumeClientConfig, ConsumeLifecycleCallbacks {
|
|
219
|
-
}
|
|
220
|
-
/** Information provided to the `onChange` lifecycle callback. */
|
|
221
|
-
interface ChangeInfo {
|
|
222
|
-
previousSrc: string | URL | null;
|
|
223
|
-
nextSrc: string | URL | null;
|
|
224
|
-
previousName: string | undefined;
|
|
225
|
-
nextName: string | undefined;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Lifecycle callbacks shared by host and remote component implementations.
|
|
229
|
-
*
|
|
230
|
-
* On the host side, these fire during client-side loading (the React host
|
|
231
|
-
* exposes them as callback props; the HTML host dispatches DOM events).
|
|
232
|
-
* On the remote side (Next.js `<ExposeRemoteComponent>` wrapper), the callbacks
|
|
233
|
-
* are forwarded as `data-on-*` attributes so the host can wire them up.
|
|
234
|
-
*
|
|
235
|
-
* Server-only components (e.g. Next.js App Router server host) do not
|
|
236
|
-
* support these callbacks since they render once on the server.
|
|
237
|
-
*/
|
|
238
|
-
interface ConsumeLifecycleCallbacks {
|
|
239
|
-
/** Called right before a new remote component load starts. */
|
|
240
|
-
onBeforeLoad?: (src: string | URL) => void;
|
|
241
|
-
/** Called when the remote component has been successfully loaded and mounted. */
|
|
242
|
-
onLoad?: (src: string | URL) => void;
|
|
243
|
-
/** Called when an error occurs while loading or mounting the remote component. */
|
|
244
|
-
onError?: (error: unknown) => void;
|
|
245
|
-
/** Called when a different remote component is loaded into the same wrapper. */
|
|
246
|
-
onChange?: (info: ChangeInfo) => void;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Metadata embedded in the HTML response by a remote application.
|
|
251
|
-
*
|
|
252
|
-
* Extracted from a `<script type="application/json" data-remote-component>`
|
|
253
|
-
* element during both SSR parsing ({@link fetchRemoteComponent}) and
|
|
254
|
-
* client-side parsing ({@link parseRemoteComponentDocument}).
|
|
255
|
-
*/
|
|
256
|
-
interface RemoteComponentMetadata {
|
|
257
|
-
bundle: string;
|
|
258
|
-
route: string;
|
|
259
|
-
runtime: 'webpack' | 'turbopack' | 'script';
|
|
260
|
-
id: string;
|
|
261
|
-
type: 'nextjs' | 'remote-component' | 'unknown';
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Serialized descriptor for a `<script>` element extracted from a remote
|
|
266
|
-
* component response. Used in both SSR fetch results and client-side props.
|
|
267
|
-
*/
|
|
268
|
-
interface ScriptDescriptor {
|
|
269
|
-
/** The script `src` URL. Empty string for inline scripts. */
|
|
270
|
-
src: string;
|
|
271
|
-
/** Inline script content (only present for scripts without a `src`). */
|
|
272
|
-
textContent?: string;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* The subset of the remote component fetch response that the client-side
|
|
277
|
-
* loader needs to hydrate or mount a remote component.
|
|
278
|
-
*
|
|
279
|
-
* Both {@link ConsumeServerData} and {@link ConsumeLoaderProps}
|
|
280
|
-
* compose this interface — it is the shared base for the RSC→client handoff
|
|
281
|
-
* and the loader function arguments.
|
|
282
|
-
*/
|
|
283
|
-
interface ConsumeLoaderPayload {
|
|
284
|
-
name: string;
|
|
285
|
-
bundle: string;
|
|
286
|
-
route?: string;
|
|
287
|
-
runtime?: RemoteComponentMetadata['runtime'];
|
|
288
|
-
data: string[];
|
|
289
|
-
nextData?: {
|
|
290
|
-
props: {
|
|
291
|
-
pageProps: Record<string, unknown>;
|
|
292
|
-
};
|
|
293
|
-
buildId?: string;
|
|
294
|
-
} | null;
|
|
295
|
-
scripts?: ScriptDescriptor[];
|
|
296
|
-
remoteShared?: Record<string, string>;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Props accepted by {@link loadRemoteComponent}.
|
|
301
|
-
*
|
|
302
|
-
* Extends {@link ConsumeLoaderPayload} (the SSR-resolved fields needed for
|
|
303
|
-
* hydration) with loader-specific fields (`url`, `shared`, `container`, etc.).
|
|
304
|
-
* `remoteShared` is narrowed from optional to required (defaults to `{}` at
|
|
305
|
-
* the call site).
|
|
306
|
-
*/
|
|
307
|
-
interface ConsumeLoaderProps extends ConsumeLoaderPayload {
|
|
308
|
-
url: URL;
|
|
309
|
-
shared: Promise<Record<string, (bundle?: string) => Promise<unknown>>> | Record<string, (bundle?: string) => Promise<unknown>>;
|
|
310
|
-
remoteShared: Record<string, string>;
|
|
311
|
-
container?: HTMLHeadElement | ShadowRoot | null;
|
|
312
|
-
rscName?: string;
|
|
313
|
-
resolveClientUrl?: InternalResolveClientUrl;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Props for the React remote component host.
|
|
318
|
-
*
|
|
319
|
-
* Extends {@link ConsumeRemoteComponentConfig} with `shared` for module sharing and
|
|
320
|
-
* `children` for loading fallback content.
|
|
321
|
-
*/
|
|
322
|
-
interface ConsumeRemoteComponentProps extends ConsumeRemoteComponentConfig {
|
|
323
|
-
/** Shared modules to include in the remote component's context. */
|
|
324
|
-
shared?: ConsumeLoaderProps['shared'];
|
|
325
|
-
/** Loading fallback content displayed while the remote component is being fetched. */
|
|
326
|
-
children?: React.ReactNode;
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* ConsumeRemoteComponent is a React component that fetches and renders a remote component.
|
|
330
|
-
* It supports SSR and can isolate the remote component in a shadow DOM.
|
|
331
|
-
*
|
|
332
|
-
* @param props - The properties for the remote component.
|
|
333
|
-
* @returns A React component that renders the remote component.
|
|
334
|
-
*
|
|
335
|
-
* @example
|
|
336
|
-
*
|
|
337
|
-
* Use the `<ConsumeRemoteComponent>` in your React application to consume a remote component from a remote application:
|
|
338
|
-
*
|
|
339
|
-
* ```tsx
|
|
340
|
-
* import { ConsumeRemoteComponent } from 'remote-components/host/react';
|
|
341
|
-
*
|
|
342
|
-
* export default function App() {
|
|
343
|
-
* return (
|
|
344
|
-
* <>
|
|
345
|
-
* <h1>Welcome to My App</h1>
|
|
346
|
-
* <p>This page consumes a remote component from another application.</p>
|
|
347
|
-
* <ConsumeRemoteComponent src="/nextjs-app-remote/components/header" />
|
|
348
|
-
* </>
|
|
349
|
-
* );
|
|
350
|
-
* }
|
|
351
|
-
* ```
|
|
352
|
-
*
|
|
353
|
-
* To share modules, you can provide a shared module map with references to the shared modules:
|
|
354
|
-
*
|
|
355
|
-
* ```tsx
|
|
356
|
-
* <ConsumeRemoteComponent
|
|
357
|
-
* src="/nextjs-app-remote/components/header"
|
|
358
|
-
* shared={{
|
|
359
|
-
* '@/components/provider': () => import('@/components/host-provider')
|
|
360
|
-
* }}
|
|
361
|
-
* />
|
|
362
|
-
* ```
|
|
363
|
-
*/
|
|
364
|
-
declare function ConsumeRemoteComponent({ src, isolate, mode, reset, credentials, name: nameProp, shared, children, onBeforeLoad, onLoad, onError, onChange, onRequest, onResponse, resolveClientUrl: _resolveClientUrl, }: ConsumeRemoteComponentProps): react_jsx_runtime.JSX.Element;
|
|
365
|
-
|
|
366
|
-
export { ConsumeRemoteComponent, ConsumeRemoteComponentProps, HookOptions, OnRequestHook, OnResponseHook };
|
|
1
|
+
import 'react/jsx-runtime';
|
|
2
|
+
export { b as ConsumeRemoteComponent, a as ConsumeRemoteComponentProps, H as HookOptions, O as OnRequestHook, c as OnResponseHook } from '../index-4c65355c.js';
|
package/dist/host/react.js
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
useState as useState2
|
|
10
10
|
} from "react";
|
|
11
11
|
import { createPortal } from "react-dom";
|
|
12
|
+
import { useRemoteComponentsContext as useRemoteComponentsContext2 } from "#internal/host/react/context";
|
|
12
13
|
|
|
13
14
|
// src/utils/constants.ts
|
|
14
15
|
var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
@@ -210,58 +211,35 @@ function getClientOrServerUrl(src, serverFallback) {
|
|
|
210
211
|
return typeof src === "string" ? new URL(src, fallback) : src;
|
|
211
212
|
}
|
|
212
213
|
|
|
213
|
-
// src/host/shared/
|
|
214
|
-
|
|
215
|
-
function applyBundleUrlToSrc(bundle, src) {
|
|
214
|
+
// src/host/shared/remote-image-loader.ts
|
|
215
|
+
function getRemoteBundleOrigin(bundle) {
|
|
216
216
|
const self = globalThis;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
priority: _priority,
|
|
238
|
-
loading: _loading,
|
|
239
|
-
placeholder: _placeholder,
|
|
240
|
-
blurDataURL: _blurDataURL,
|
|
241
|
-
unoptimized: _unoptimized,
|
|
242
|
-
overrideSrc: _overrideSrc,
|
|
243
|
-
src,
|
|
244
|
-
...props
|
|
245
|
-
}) {
|
|
246
|
-
const newSrc = applyBundleUrlToImagePropsSrc(
|
|
247
|
-
bundle,
|
|
248
|
-
typeof src === "string" ? src : src.src
|
|
249
|
-
);
|
|
250
|
-
const proxiedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
|
|
251
|
-
return (
|
|
252
|
-
// eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
|
|
253
|
-
/* @__PURE__ */ jsx(
|
|
254
|
-
"img",
|
|
255
|
-
{
|
|
256
|
-
decoding: "async",
|
|
257
|
-
style: { color: "transparent" },
|
|
258
|
-
...props,
|
|
259
|
-
src: proxiedSrc,
|
|
260
|
-
suppressHydrationWarning: true
|
|
261
|
-
}
|
|
262
|
-
)
|
|
217
|
+
return self.__remote_bundle_url__?.[bundle]?.origin ?? "";
|
|
218
|
+
}
|
|
219
|
+
function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
220
|
+
const loader = Object.assign(
|
|
221
|
+
({
|
|
222
|
+
config,
|
|
223
|
+
src,
|
|
224
|
+
width,
|
|
225
|
+
quality
|
|
226
|
+
}) => {
|
|
227
|
+
const q = quality ?? 75;
|
|
228
|
+
const remoteOrigin = getRemoteBundleOrigin(bundle);
|
|
229
|
+
const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;
|
|
230
|
+
const basePath = isCrossOrigin ? `${remoteOrigin}${config.path ?? "/_next/image"}` : config.path ?? `${remoteOrigin}/_next/image`;
|
|
231
|
+
const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;
|
|
232
|
+
return resolveClientUrl?.(url) ?? url;
|
|
233
|
+
},
|
|
234
|
+
// Signals to getImgProps that this is a default loader (not a user-defined
|
|
235
|
+
// one), enabling srcSet generation with device/image sizes from the config.
|
|
236
|
+
{ __next_img_default: true }
|
|
263
237
|
);
|
|
264
|
-
|
|
238
|
+
return loader;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/host/shared/polyfill.tsx
|
|
242
|
+
import { jsx } from "react/jsx-runtime";
|
|
265
243
|
function sharedPolyfills(shared, resolveClientUrl) {
|
|
266
244
|
const self = globalThis;
|
|
267
245
|
const polyfill = {
|
|
@@ -352,17 +330,13 @@ function sharedPolyfills(shared, resolveClientUrl) {
|
|
|
352
330
|
},
|
|
353
331
|
__esModule: true
|
|
354
332
|
})),
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
throw new Error(
|
|
363
|
-
"Next.js getImageProps() is not implemented in remote components"
|
|
364
|
-
);
|
|
365
|
-
},
|
|
333
|
+
// Instead of replacing next/image entirely, we let the real Next.js Image
|
|
334
|
+
// component load from the remote bundle and only replace its default loader.
|
|
335
|
+
// This gives us full next/image fidelity (fill, priority, srcSet, blur
|
|
336
|
+
// placeholders, error handling) while routing image optimization through the
|
|
337
|
+
// remote app's /_next/image endpoint.
|
|
338
|
+
"next/dist/shared/lib/image-loader": self.__remote_component_host_shared_modules__?.["next/dist/shared/lib/image-loader"] ?? shared?.["next/dist/shared/lib/image-loader"] ?? ((bundle) => Promise.resolve({
|
|
339
|
+
default: createRemoteImageLoader(bundle, resolveClientUrl),
|
|
366
340
|
__esModule: true
|
|
367
341
|
})),
|
|
368
342
|
"next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
|
|
@@ -402,7 +376,7 @@ function sharedPolyfills(shared, resolveClientUrl) {
|
|
|
402
376
|
polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
|
|
403
377
|
polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
|
|
404
378
|
polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
|
|
405
|
-
polyfill["next/dist/
|
|
379
|
+
polyfill["next/dist/esm/shared/lib/image-loader"] = polyfill["next/dist/shared/lib/image-loader"];
|
|
406
380
|
polyfill["next/script"] = polyfill["next/dist/client/script"];
|
|
407
381
|
return polyfill;
|
|
408
382
|
}
|
|
@@ -1913,11 +1887,8 @@ function bindResolveClientUrl(prop, remoteSrc) {
|
|
|
1913
1887
|
// src/host/react/hooks/use-resolve-client-url.ts
|
|
1914
1888
|
function useResolveClientUrl(prop, urlHref) {
|
|
1915
1889
|
const { resolveClientUrl: contextValue } = useRemoteComponentsContext();
|
|
1916
|
-
const
|
|
1917
|
-
return useMemo(
|
|
1918
|
-
() => bindResolveClientUrl(resolveClientUrl, urlHref),
|
|
1919
|
-
[resolveClientUrl, urlHref]
|
|
1920
|
-
);
|
|
1890
|
+
const raw = prop ?? contextValue;
|
|
1891
|
+
return useMemo(() => bindResolveClientUrl(raw, urlHref), [raw, urlHref]);
|
|
1921
1892
|
}
|
|
1922
1893
|
|
|
1923
1894
|
// src/host/react/hooks/use-shadow-root.ts
|
|
@@ -1999,9 +1970,9 @@ function ConsumeRemoteComponent({
|
|
|
1999
1970
|
isolate,
|
|
2000
1971
|
mode = "open",
|
|
2001
1972
|
reset,
|
|
2002
|
-
credentials
|
|
1973
|
+
credentials: credentialsProp,
|
|
2003
1974
|
name: nameProp = "__vercel_remote_component",
|
|
2004
|
-
shared
|
|
1975
|
+
shared: sharedProp,
|
|
2005
1976
|
children,
|
|
2006
1977
|
onBeforeLoad,
|
|
2007
1978
|
onLoad,
|
|
@@ -2009,9 +1980,12 @@ function ConsumeRemoteComponent({
|
|
|
2009
1980
|
onChange,
|
|
2010
1981
|
onRequest,
|
|
2011
1982
|
onResponse,
|
|
2012
|
-
resolveClientUrl:
|
|
1983
|
+
resolveClientUrl: resolveClientUrlProp
|
|
2013
1984
|
}) {
|
|
2014
1985
|
const instanceId = useId();
|
|
1986
|
+
const { credentials: contextCredentials, shared: contextShared } = useRemoteComponentsContext2();
|
|
1987
|
+
const credentials = credentialsProp ?? contextCredentials ?? "same-origin";
|
|
1988
|
+
const shared = sharedProp ?? contextShared ?? {};
|
|
2015
1989
|
const name = useMemo2(
|
|
2016
1990
|
() => resolveNameFromSrc(src, nameProp),
|
|
2017
1991
|
[src, nameProp]
|
|
@@ -2020,7 +1994,7 @@ function ConsumeRemoteComponent({
|
|
|
2020
1994
|
null
|
|
2021
1995
|
);
|
|
2022
1996
|
const url = useMemo2(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);
|
|
2023
|
-
const resolveClientUrl = useResolveClientUrl(
|
|
1997
|
+
const resolveClientUrl = useResolveClientUrl(resolveClientUrlProp, url.href);
|
|
2024
1998
|
const id = url.origin === (typeof location !== "undefined" ? location.origin : DUMMY_FALLBACK) ? url.pathname : url.href;
|
|
2025
1999
|
const keySuffix = `${escapeString(id)}_${escapeString(
|
|
2026
2000
|
data?.name ?? name
|