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
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";
|
|
@@ -1913,11 +1914,12 @@ function bindResolveClientUrl(prop, remoteSrc) {
|
|
|
1913
1914
|
// src/host/react/hooks/use-resolve-client-url.ts
|
|
1914
1915
|
function useResolveClientUrl(prop, urlHref) {
|
|
1915
1916
|
const { resolveClientUrl: contextValue } = useRemoteComponentsContext();
|
|
1916
|
-
const
|
|
1917
|
-
|
|
1918
|
-
() => bindResolveClientUrl(
|
|
1919
|
-
[
|
|
1917
|
+
const raw = prop ?? contextValue;
|
|
1918
|
+
const bound = useMemo(
|
|
1919
|
+
() => bindResolveClientUrl(raw, urlHref),
|
|
1920
|
+
[raw, urlHref]
|
|
1920
1921
|
);
|
|
1922
|
+
return { bound, raw };
|
|
1921
1923
|
}
|
|
1922
1924
|
|
|
1923
1925
|
// src/host/react/hooks/use-shadow-root.ts
|
|
@@ -1999,9 +2001,9 @@ function ConsumeRemoteComponent({
|
|
|
1999
2001
|
isolate,
|
|
2000
2002
|
mode = "open",
|
|
2001
2003
|
reset,
|
|
2002
|
-
credentials
|
|
2004
|
+
credentials: credentialsProp,
|
|
2003
2005
|
name: nameProp = "__vercel_remote_component",
|
|
2004
|
-
shared
|
|
2006
|
+
shared: sharedProp,
|
|
2005
2007
|
children,
|
|
2006
2008
|
onBeforeLoad,
|
|
2007
2009
|
onLoad,
|
|
@@ -2009,9 +2011,12 @@ function ConsumeRemoteComponent({
|
|
|
2009
2011
|
onChange,
|
|
2010
2012
|
onRequest,
|
|
2011
2013
|
onResponse,
|
|
2012
|
-
resolveClientUrl:
|
|
2014
|
+
resolveClientUrl: resolveClientUrlProp
|
|
2013
2015
|
}) {
|
|
2014
2016
|
const instanceId = useId();
|
|
2017
|
+
const { credentials: contextCredentials, shared: contextShared } = useRemoteComponentsContext2();
|
|
2018
|
+
const credentials = credentialsProp ?? contextCredentials ?? "same-origin";
|
|
2019
|
+
const shared = sharedProp ?? contextShared ?? {};
|
|
2015
2020
|
const name = useMemo2(
|
|
2016
2021
|
() => resolveNameFromSrc(src, nameProp),
|
|
2017
2022
|
[src, nameProp]
|
|
@@ -2020,7 +2025,10 @@ function ConsumeRemoteComponent({
|
|
|
2020
2025
|
null
|
|
2021
2026
|
);
|
|
2022
2027
|
const url = useMemo2(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);
|
|
2023
|
-
const resolveClientUrl = useResolveClientUrl(
|
|
2028
|
+
const { bound: resolveClientUrl } = useResolveClientUrl(
|
|
2029
|
+
resolveClientUrlProp,
|
|
2030
|
+
url.href
|
|
2031
|
+
);
|
|
2024
2032
|
const id = url.origin === (typeof location !== "undefined" ? location.origin : DUMMY_FALLBACK) ? url.pathname : url.href;
|
|
2025
2033
|
const keySuffix = `${escapeString(id)}_${escapeString(
|
|
2026
2034
|
data?.name ?? name
|