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
|
@@ -61,10 +61,95 @@ var init_app = __esm({
|
|
|
61
61
|
// src/host/nextjs/app-client-only.tsx
|
|
62
62
|
var app_client_only_exports = {};
|
|
63
63
|
__export(app_client_only_exports, {
|
|
64
|
-
ConsumeRemoteComponent: () => ConsumeRemoteComponent2
|
|
64
|
+
ConsumeRemoteComponent: () => ConsumeRemoteComponent2,
|
|
65
|
+
RemoteComponentsClientProvider: () => RemoteComponentsClientProvider
|
|
65
66
|
});
|
|
66
67
|
module.exports = __toCommonJS(app_client_only_exports);
|
|
67
|
-
var
|
|
68
|
+
var import_react5 = require("react");
|
|
69
|
+
|
|
70
|
+
// src/host/shared/remote-image-loader.ts
|
|
71
|
+
function getRemoteBundleOrigin(bundle) {
|
|
72
|
+
const self = globalThis;
|
|
73
|
+
return self.__remote_bundle_url__?.[bundle]?.origin ?? "";
|
|
74
|
+
}
|
|
75
|
+
function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
76
|
+
const loader = Object.assign(
|
|
77
|
+
({
|
|
78
|
+
config,
|
|
79
|
+
src,
|
|
80
|
+
width,
|
|
81
|
+
quality
|
|
82
|
+
}) => {
|
|
83
|
+
const q = quality ?? 75;
|
|
84
|
+
const remoteOrigin = getRemoteBundleOrigin(bundle);
|
|
85
|
+
const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;
|
|
86
|
+
const basePath = isCrossOrigin ? `${remoteOrigin}${config.path ?? "/_next/image"}` : config.path ?? `${remoteOrigin}/_next/image`;
|
|
87
|
+
const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;
|
|
88
|
+
return resolveClientUrl?.(url) ?? url;
|
|
89
|
+
},
|
|
90
|
+
// Signals to getImgProps that this is a default loader (not a user-defined
|
|
91
|
+
// one), enabling srcSet generation with device/image sizes from the config.
|
|
92
|
+
{ __next_img_default: true }
|
|
93
|
+
);
|
|
94
|
+
return loader;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/runtime/url/resolve-client-url.ts
|
|
98
|
+
function withRemoteSrc(resolveClientUrl, remoteSrc) {
|
|
99
|
+
const remoteOrigin = parseOrigin(remoteSrc);
|
|
100
|
+
return (url) => {
|
|
101
|
+
const urlOrigin = parseOrigin(url);
|
|
102
|
+
if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
105
|
+
return resolveClientUrl(remoteSrc, url);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function parseOrigin(url) {
|
|
109
|
+
try {
|
|
110
|
+
return new URL(url).origin;
|
|
111
|
+
} catch {
|
|
112
|
+
return void 0;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/runtime/url/default-resolve-client-url.ts
|
|
117
|
+
function bindResolveClientUrl(prop, remoteSrc) {
|
|
118
|
+
return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/host/nextjs/image-shared.ts
|
|
122
|
+
function resolveForBundle(unbound, bundle) {
|
|
123
|
+
if (!unbound)
|
|
124
|
+
return void 0;
|
|
125
|
+
const self = globalThis;
|
|
126
|
+
const remoteSrc = self.__remote_bundle_url__?.[bundle]?.href ?? "";
|
|
127
|
+
return bindResolveClientUrl(unbound, remoteSrc);
|
|
128
|
+
}
|
|
129
|
+
function createImageLoaderSharedEntries({
|
|
130
|
+
bound,
|
|
131
|
+
unbound
|
|
132
|
+
} = {}) {
|
|
133
|
+
const entry = (bundle) => {
|
|
134
|
+
const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);
|
|
135
|
+
return Promise.resolve({
|
|
136
|
+
default: createRemoteImageLoader(bundle, resolveClientUrl),
|
|
137
|
+
__esModule: true
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
"next/dist/shared/lib/image-loader": entry,
|
|
142
|
+
"next/dist/esm/shared/lib/image-loader": entry
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/host/nextjs/app-client-only.tsx
|
|
147
|
+
var import_context3 = require("#internal/host/react/context");
|
|
148
|
+
|
|
149
|
+
// src/host/react/index.tsx
|
|
150
|
+
var import_react3 = require("react");
|
|
151
|
+
var import_react_dom = require("react-dom");
|
|
152
|
+
var import_context2 = require("#internal/host/react/context");
|
|
68
153
|
|
|
69
154
|
// src/utils/logger.ts
|
|
70
155
|
init_constants();
|
|
@@ -212,58 +297,63 @@ function warnCrossOriginFetchError(logLocation, url) {
|
|
|
212
297
|
}
|
|
213
298
|
}
|
|
214
299
|
|
|
300
|
+
// src/host/server/fetch-headers.ts
|
|
301
|
+
function remoteFetchHeaders() {
|
|
302
|
+
return {
|
|
303
|
+
/**
|
|
304
|
+
* Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
|
|
305
|
+
* If the remote component uses vercel deployment protection, ensure the host and remote vercel
|
|
306
|
+
* projects share a common automation bypass secret, and the shared secret is used as the
|
|
307
|
+
* VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
|
|
308
|
+
*/
|
|
309
|
+
...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
|
|
310
|
+
"x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
|
|
311
|
+
} : {},
|
|
312
|
+
Accept: "text/html"
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/host/server/fetch-with-hooks.ts
|
|
317
|
+
async function fetchWithWarning(url, init) {
|
|
318
|
+
try {
|
|
319
|
+
return await fetch(url, init);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
warnCrossOriginFetchError("FetchRemoteComponent", url);
|
|
322
|
+
throw error;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
async function fetchWithHooks(url, additionalInit, options = {}) {
|
|
326
|
+
const {
|
|
327
|
+
onRequest,
|
|
328
|
+
onResponse,
|
|
329
|
+
abortController = new AbortController()
|
|
330
|
+
} = options;
|
|
331
|
+
const signal = abortController.signal;
|
|
332
|
+
const hookOptions = {
|
|
333
|
+
signal,
|
|
334
|
+
abort: (reason) => abortController.abort(reason)
|
|
335
|
+
};
|
|
336
|
+
const init = {
|
|
337
|
+
method: "GET",
|
|
338
|
+
headers: remoteFetchHeaders(),
|
|
339
|
+
signal,
|
|
340
|
+
...additionalInit
|
|
341
|
+
};
|
|
342
|
+
const res = await onRequest?.(url, init, hookOptions) ?? await fetchWithWarning(url, init);
|
|
343
|
+
return await onResponse?.(url, res, hookOptions) ?? res;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// src/host/server/get-client-or-server-url.ts
|
|
347
|
+
function getClientOrServerUrl(src, serverFallback) {
|
|
348
|
+
const fallback = typeof location !== "undefined" ? location.href : serverFallback;
|
|
349
|
+
if (!src) {
|
|
350
|
+
return new URL(fallback);
|
|
351
|
+
}
|
|
352
|
+
return typeof src === "string" ? new URL(src, fallback) : src;
|
|
353
|
+
}
|
|
354
|
+
|
|
215
355
|
// src/host/shared/polyfill.tsx
|
|
216
|
-
var import_jsx_runtime = (
|
|
217
|
-
// eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
|
|
218
|
-
require("react/jsx-runtime")
|
|
219
|
-
);
|
|
220
|
-
function applyBundleUrlToSrc(bundle, src) {
|
|
221
|
-
const self = globalThis;
|
|
222
|
-
if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {
|
|
223
|
-
return src;
|
|
224
|
-
}
|
|
225
|
-
const { assetPrefix, path } = /^(?<assetPrefix>.*?)\/_next\/(?<path>.*)/.exec(src)?.groups ?? {};
|
|
226
|
-
if (!path) {
|
|
227
|
-
return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;
|
|
228
|
-
}
|
|
229
|
-
return `${self.__remote_bundle_url__?.[bundle]?.origin ?? ""}${assetPrefix}/_next/${path}`;
|
|
230
|
-
}
|
|
231
|
-
function applyBundleUrlToImagePropsSrc(bundle, src) {
|
|
232
|
-
if (typeof src === "string") {
|
|
233
|
-
return applyBundleUrlToSrc(bundle, src);
|
|
234
|
-
}
|
|
235
|
-
const propSrc = src;
|
|
236
|
-
return applyBundleUrlToSrc(bundle, propSrc.src);
|
|
237
|
-
}
|
|
238
|
-
var imageImpl = (bundle, resolveClientUrl) => function RemoteImage({
|
|
239
|
-
fill: _fill,
|
|
240
|
-
loader: _loader,
|
|
241
|
-
quality: _quality,
|
|
242
|
-
priority: _priority,
|
|
243
|
-
loading: _loading,
|
|
244
|
-
placeholder: _placeholder,
|
|
245
|
-
blurDataURL: _blurDataURL,
|
|
246
|
-
unoptimized: _unoptimized,
|
|
247
|
-
overrideSrc: _overrideSrc,
|
|
248
|
-
src,
|
|
249
|
-
...props
|
|
250
|
-
}) {
|
|
251
|
-
const newSrc = applyBundleUrlToImagePropsSrc(
|
|
252
|
-
bundle,
|
|
253
|
-
typeof src === "string" ? src : src.src
|
|
254
|
-
);
|
|
255
|
-
const proxiedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
|
|
256
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
257
|
-
"img",
|
|
258
|
-
{
|
|
259
|
-
decoding: "async",
|
|
260
|
-
style: { color: "transparent" },
|
|
261
|
-
...props,
|
|
262
|
-
src: proxiedSrc,
|
|
263
|
-
suppressHydrationWarning: true
|
|
264
|
-
}
|
|
265
|
-
);
|
|
266
|
-
};
|
|
356
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
267
357
|
function sharedPolyfills(shared2, resolveClientUrl) {
|
|
268
358
|
const self = globalThis;
|
|
269
359
|
const polyfill = {
|
|
@@ -354,17 +444,13 @@ function sharedPolyfills(shared2, resolveClientUrl) {
|
|
|
354
444
|
},
|
|
355
445
|
__esModule: true
|
|
356
446
|
})),
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
throw new Error(
|
|
365
|
-
"Next.js getImageProps() is not implemented in remote components"
|
|
366
|
-
);
|
|
367
|
-
},
|
|
447
|
+
// Instead of replacing next/image entirely, we let the real Next.js Image
|
|
448
|
+
// component load from the remote bundle and only replace its default loader.
|
|
449
|
+
// This gives us full next/image fidelity (fill, priority, srcSet, blur
|
|
450
|
+
// placeholders, error handling) while routing image optimization through the
|
|
451
|
+
// remote app's /_next/image endpoint.
|
|
452
|
+
"next/dist/shared/lib/image-loader": self.__remote_component_host_shared_modules__?.["next/dist/shared/lib/image-loader"] ?? shared2?.["next/dist/shared/lib/image-loader"] ?? ((bundle) => Promise.resolve({
|
|
453
|
+
default: createRemoteImageLoader(bundle, resolveClientUrl),
|
|
368
454
|
__esModule: true
|
|
369
455
|
})),
|
|
370
456
|
"next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared2?.["next/script"] ?? (() => Promise.resolve({
|
|
@@ -404,127 +490,11 @@ function sharedPolyfills(shared2, resolveClientUrl) {
|
|
|
404
490
|
polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
|
|
405
491
|
polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
|
|
406
492
|
polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
|
|
407
|
-
polyfill["next/dist/
|
|
493
|
+
polyfill["next/dist/esm/shared/lib/image-loader"] = polyfill["next/dist/shared/lib/image-loader"];
|
|
408
494
|
polyfill["next/script"] = polyfill["next/dist/client/script"];
|
|
409
495
|
return polyfill;
|
|
410
496
|
}
|
|
411
497
|
|
|
412
|
-
// src/host/nextjs/image-impl.tsx
|
|
413
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
414
|
-
function createRemoteLoader(bundle, resolveClientUrl) {
|
|
415
|
-
return ({ src, width, quality }) => {
|
|
416
|
-
const self = globalThis;
|
|
417
|
-
const origin = self.__remote_bundle_url__?.[bundle]?.origin ?? "";
|
|
418
|
-
let imageUrl = src;
|
|
419
|
-
try {
|
|
420
|
-
const parsed = new URL(src);
|
|
421
|
-
if (origin && parsed.origin === origin) {
|
|
422
|
-
imageUrl = parsed.pathname + parsed.search;
|
|
423
|
-
}
|
|
424
|
-
} catch {
|
|
425
|
-
}
|
|
426
|
-
const { assetPrefix } = /^(?<assetPrefix>.*?)\/_next\//.exec(imageUrl)?.groups ?? {};
|
|
427
|
-
const url = `${origin}${assetPrefix ?? ""}/_next/image?url=${encodeURIComponent(imageUrl)}&w=${width}&q=${quality ?? 75}`;
|
|
428
|
-
return resolveClientUrl?.(url) ?? url;
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
function imageImpl2(ImageComponent, bundle, resolveClientUrl, useRemoteLoader) {
|
|
432
|
-
const remoteLoader = useRemoteLoader ? createRemoteLoader(bundle, resolveClientUrl) : void 0;
|
|
433
|
-
const component = function RemoteImage(props) {
|
|
434
|
-
if (remoteLoader) {
|
|
435
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ImageComponent, { loader: remoteLoader, ...props });
|
|
436
|
-
}
|
|
437
|
-
const rawSrc = applyBundleUrlToImagePropsSrc(bundle, props.src);
|
|
438
|
-
const src = resolveClientUrl?.(rawSrc) ?? rawSrc;
|
|
439
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ImageComponent, { ...props, src });
|
|
440
|
-
};
|
|
441
|
-
component.default = component;
|
|
442
|
-
return component;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
// src/runtime/url/resolve-client-url.ts
|
|
446
|
-
function withRemoteSrc(resolveClientUrl, remoteSrc) {
|
|
447
|
-
const remoteOrigin = parseOrigin(remoteSrc);
|
|
448
|
-
return (url) => {
|
|
449
|
-
const urlOrigin = parseOrigin(url);
|
|
450
|
-
if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
|
|
451
|
-
return void 0;
|
|
452
|
-
}
|
|
453
|
-
return resolveClientUrl(remoteSrc, url);
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
function parseOrigin(url) {
|
|
457
|
-
try {
|
|
458
|
-
return new URL(url).origin;
|
|
459
|
-
} catch {
|
|
460
|
-
return void 0;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
// src/runtime/url/default-resolve-client-url.ts
|
|
465
|
-
function bindResolveClientUrl(prop, remoteSrc) {
|
|
466
|
-
return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// src/host/react/index.tsx
|
|
470
|
-
var import_react3 = require("react");
|
|
471
|
-
var import_react_dom = require("react-dom");
|
|
472
|
-
|
|
473
|
-
// src/host/server/fetch-headers.ts
|
|
474
|
-
function remoteFetchHeaders() {
|
|
475
|
-
return {
|
|
476
|
-
/**
|
|
477
|
-
* Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
|
|
478
|
-
* If the remote component uses vercel deployment protection, ensure the host and remote vercel
|
|
479
|
-
* projects share a common automation bypass secret, and the shared secret is used as the
|
|
480
|
-
* VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
|
|
481
|
-
*/
|
|
482
|
-
...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
|
|
483
|
-
"x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
|
|
484
|
-
} : {},
|
|
485
|
-
Accept: "text/html"
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
// src/host/server/fetch-with-hooks.ts
|
|
490
|
-
async function fetchWithWarning(url, init) {
|
|
491
|
-
try {
|
|
492
|
-
return await fetch(url, init);
|
|
493
|
-
} catch (error) {
|
|
494
|
-
warnCrossOriginFetchError("FetchRemoteComponent", url);
|
|
495
|
-
throw error;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
async function fetchWithHooks(url, additionalInit, options = {}) {
|
|
499
|
-
const {
|
|
500
|
-
onRequest,
|
|
501
|
-
onResponse,
|
|
502
|
-
abortController = new AbortController()
|
|
503
|
-
} = options;
|
|
504
|
-
const signal = abortController.signal;
|
|
505
|
-
const hookOptions = {
|
|
506
|
-
signal,
|
|
507
|
-
abort: (reason) => abortController.abort(reason)
|
|
508
|
-
};
|
|
509
|
-
const init = {
|
|
510
|
-
method: "GET",
|
|
511
|
-
headers: remoteFetchHeaders(),
|
|
512
|
-
signal,
|
|
513
|
-
...additionalInit
|
|
514
|
-
};
|
|
515
|
-
const res = await onRequest?.(url, init, hookOptions) ?? await fetchWithWarning(url, init);
|
|
516
|
-
return await onResponse?.(url, res, hookOptions) ?? res;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
// src/host/server/get-client-or-server-url.ts
|
|
520
|
-
function getClientOrServerUrl(src, serverFallback) {
|
|
521
|
-
const fallback = typeof location !== "undefined" ? location.href : serverFallback;
|
|
522
|
-
if (!src) {
|
|
523
|
-
return new URL(fallback);
|
|
524
|
-
}
|
|
525
|
-
return typeof src === "string" ? new URL(src, fallback) : src;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
498
|
// src/host/shared/state.ts
|
|
529
499
|
function createHostState() {
|
|
530
500
|
return {
|
|
@@ -2005,11 +1975,8 @@ var import_react = require("react");
|
|
|
2005
1975
|
var import_context = require("#internal/host/react/context");
|
|
2006
1976
|
function useResolveClientUrl(prop, urlHref) {
|
|
2007
1977
|
const { resolveClientUrl: contextValue } = (0, import_context.useRemoteComponentsContext)();
|
|
2008
|
-
const
|
|
2009
|
-
return (0, import_react.useMemo)(
|
|
2010
|
-
() => bindResolveClientUrl(resolveClientUrl, urlHref),
|
|
2011
|
-
[resolveClientUrl, urlHref]
|
|
2012
|
-
);
|
|
1978
|
+
const raw = prop ?? contextValue;
|
|
1979
|
+
return (0, import_react.useMemo)(() => bindResolveClientUrl(raw, urlHref), [raw, urlHref]);
|
|
2013
1980
|
}
|
|
2014
1981
|
|
|
2015
1982
|
// src/host/react/hooks/use-shadow-root.ts
|
|
@@ -2084,7 +2051,7 @@ function getRemoteComponentHtml(html) {
|
|
|
2084
2051
|
}
|
|
2085
2052
|
|
|
2086
2053
|
// src/host/react/index.tsx
|
|
2087
|
-
var
|
|
2054
|
+
var import_jsx_runtime2 = (
|
|
2088
2055
|
// TODO: remove wrapper div by converting HTML to RSC or React tree
|
|
2089
2056
|
require("react/jsx-runtime")
|
|
2090
2057
|
);
|
|
@@ -2094,9 +2061,9 @@ function ConsumeRemoteComponent({
|
|
|
2094
2061
|
isolate,
|
|
2095
2062
|
mode = "open",
|
|
2096
2063
|
reset,
|
|
2097
|
-
credentials
|
|
2064
|
+
credentials: credentialsProp,
|
|
2098
2065
|
name: nameProp = "__vercel_remote_component",
|
|
2099
|
-
shared:
|
|
2066
|
+
shared: sharedProp,
|
|
2100
2067
|
children,
|
|
2101
2068
|
onBeforeLoad,
|
|
2102
2069
|
onLoad,
|
|
@@ -2104,9 +2071,12 @@ function ConsumeRemoteComponent({
|
|
|
2104
2071
|
onChange,
|
|
2105
2072
|
onRequest,
|
|
2106
2073
|
onResponse,
|
|
2107
|
-
resolveClientUrl:
|
|
2074
|
+
resolveClientUrl: resolveClientUrlProp
|
|
2108
2075
|
}) {
|
|
2109
2076
|
const instanceId = (0, import_react3.useId)();
|
|
2077
|
+
const { credentials: contextCredentials, shared: contextShared } = (0, import_context2.useRemoteComponentsContext)();
|
|
2078
|
+
const credentials = credentialsProp ?? contextCredentials ?? "same-origin";
|
|
2079
|
+
const shared2 = sharedProp ?? contextShared ?? {};
|
|
2110
2080
|
const name = (0, import_react3.useMemo)(
|
|
2111
2081
|
() => resolveNameFromSrc(src, nameProp),
|
|
2112
2082
|
[src, nameProp]
|
|
@@ -2115,7 +2085,7 @@ function ConsumeRemoteComponent({
|
|
|
2115
2085
|
null
|
|
2116
2086
|
);
|
|
2117
2087
|
const url = (0, import_react3.useMemo)(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);
|
|
2118
|
-
const resolveClientUrl = useResolveClientUrl(
|
|
2088
|
+
const resolveClientUrl = useResolveClientUrl(resolveClientUrlProp, url.href);
|
|
2119
2089
|
const id = url.origin === (typeof location !== "undefined" ? location.origin : DUMMY_FALLBACK) ? url.pathname : url.href;
|
|
2120
2090
|
const keySuffix = `${escapeString(id)}_${escapeString(
|
|
2121
2091
|
data?.name ?? name
|
|
@@ -2388,7 +2358,7 @@ function ConsumeRemoteComponent({
|
|
|
2388
2358
|
onLoad?.(src);
|
|
2389
2359
|
} else if (isolate === false) {
|
|
2390
2360
|
setRemoteComponent(
|
|
2391
|
-
/* @__PURE__ */ (0,
|
|
2361
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2392
2362
|
"div",
|
|
2393
2363
|
{
|
|
2394
2364
|
dangerouslySetInnerHTML: { __html: component.innerHTML },
|
|
@@ -2501,13 +2471,13 @@ function ConsumeRemoteComponent({
|
|
|
2501
2471
|
if (remoteComponent instanceof Error) {
|
|
2502
2472
|
throw remoteComponent;
|
|
2503
2473
|
}
|
|
2504
|
-
const metadataJson = /* @__PURE__ */ (0,
|
|
2474
|
+
const metadataJson = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
|
|
2505
2475
|
name: data?.name || name,
|
|
2506
2476
|
bundle: data?.bundle || "default",
|
|
2507
2477
|
route: data?.route || DEFAULT_ROUTE,
|
|
2508
2478
|
runtime: hostStateRef.current.prevIsRemoteComponent ? RUNTIME_SCRIPT : data?.runtime || RUNTIME_WEBPACK
|
|
2509
2479
|
}) });
|
|
2510
|
-
const resetStyle = reset ? /* @__PURE__ */ (0,
|
|
2480
|
+
const resetStyle = reset ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { "data-remote-components-reset": "react", children: `:host { all: initial; }` }) : null;
|
|
2511
2481
|
const linksToRender = data?.links?.map((link) => /* @__PURE__ */ (0, import_react4.createElement)(
|
|
2512
2482
|
"link",
|
|
2513
2483
|
{
|
|
@@ -2516,7 +2486,7 @@ function ConsumeRemoteComponent({
|
|
|
2516
2486
|
key: JSON.stringify(link)
|
|
2517
2487
|
}
|
|
2518
2488
|
)) || null;
|
|
2519
|
-
const componentToRender = /* @__PURE__ */ (0,
|
|
2489
|
+
const componentToRender = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2520
2490
|
resetStyle,
|
|
2521
2491
|
linksToRender,
|
|
2522
2492
|
remoteComponent ?? children
|
|
@@ -2554,9 +2524,9 @@ function ConsumeRemoteComponent({
|
|
|
2554
2524
|
if (shadowRemoteComponentHtml) {
|
|
2555
2525
|
shadowRemoteComponentHtml.remove();
|
|
2556
2526
|
}
|
|
2557
|
-
return /* @__PURE__ */ (0,
|
|
2527
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2558
2528
|
metadataJson,
|
|
2559
|
-
/* @__PURE__ */ (0,
|
|
2529
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
2560
2530
|
"div",
|
|
2561
2531
|
{
|
|
2562
2532
|
"data-remote-component-id": `shadowroot_${keySuffix}`,
|
|
@@ -2565,8 +2535,8 @@ function ConsumeRemoteComponent({
|
|
|
2565
2535
|
children: [
|
|
2566
2536
|
typeof document === "undefined" ? (
|
|
2567
2537
|
// eslint-disable-next-line react/no-unknown-property
|
|
2568
|
-
/* @__PURE__ */ (0,
|
|
2569
|
-
typeof document === "undefined" ? /* @__PURE__ */ (0,
|
|
2538
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("template", { shadowrootmode: mode, children: [
|
|
2539
|
+
typeof document === "undefined" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2570
2540
|
"div",
|
|
2571
2541
|
{
|
|
2572
2542
|
dangerouslySetInnerHTML: {
|
|
@@ -2588,12 +2558,12 @@ function ConsumeRemoteComponent({
|
|
|
2588
2558
|
] })
|
|
2589
2559
|
) : null,
|
|
2590
2560
|
shadowRoot && remoteComponent ? (0, import_react_dom.createPortal)(
|
|
2591
|
-
/* @__PURE__ */ (0,
|
|
2592
|
-
/* @__PURE__ */ (0,
|
|
2561
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2562
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("template", { id: `${name}_start` }),
|
|
2593
2563
|
resetStyle,
|
|
2594
2564
|
linksToRender,
|
|
2595
2565
|
remoteComponent,
|
|
2596
|
-
/* @__PURE__ */ (0,
|
|
2566
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("template", { id: `${name}_end`, ref: endTemplateRef })
|
|
2597
2567
|
] }),
|
|
2598
2568
|
shadowRoot
|
|
2599
2569
|
) : null
|
|
@@ -2603,11 +2573,11 @@ function ConsumeRemoteComponent({
|
|
|
2603
2573
|
] });
|
|
2604
2574
|
}
|
|
2605
2575
|
htmlRef.current = null;
|
|
2606
|
-
return /* @__PURE__ */ (0,
|
|
2607
|
-
/* @__PURE__ */ (0,
|
|
2576
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2577
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("template", { id: `${name}_start` }),
|
|
2608
2578
|
metadataJson,
|
|
2609
2579
|
componentToRender,
|
|
2610
|
-
/* @__PURE__ */ (0,
|
|
2580
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("template", { id: `${name}_end`, ref: endTemplateRef })
|
|
2611
2581
|
] });
|
|
2612
2582
|
}
|
|
2613
2583
|
|
|
@@ -2676,25 +2646,8 @@ var routerImpl = async () => {
|
|
|
2676
2646
|
});
|
|
2677
2647
|
};
|
|
2678
2648
|
|
|
2679
|
-
// src/host/nextjs/image-shared.ts
|
|
2680
|
-
function createNextImageSharedEntries(getWrappedImage, options) {
|
|
2681
|
-
const entries = {
|
|
2682
|
-
"next/image": (bundle) => Promise.resolve(getWrappedImage(bundle)),
|
|
2683
|
-
"next/dist/client/image-component": (bundle) => Promise.resolve({
|
|
2684
|
-
Image: getWrappedImage(bundle)
|
|
2685
|
-
})
|
|
2686
|
-
};
|
|
2687
|
-
if (options?.getImageProps) {
|
|
2688
|
-
entries["next/dist/api/image"] = (bundle) => Promise.resolve({
|
|
2689
|
-
default: getWrappedImage(bundle),
|
|
2690
|
-
getImageProps: options.getImageProps
|
|
2691
|
-
});
|
|
2692
|
-
}
|
|
2693
|
-
return entries;
|
|
2694
|
-
}
|
|
2695
|
-
|
|
2696
2649
|
// src/host/nextjs/app-client-only.tsx
|
|
2697
|
-
var
|
|
2650
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
2698
2651
|
async function tryImportShared() {
|
|
2699
2652
|
try {
|
|
2700
2653
|
const { shared: shared2 } = await Promise.resolve().then(() => (init_app(), app_exports));
|
|
@@ -2711,28 +2664,43 @@ var sharedModules = async (userShared, resolveClientUrl) => {
|
|
|
2711
2664
|
return {
|
|
2712
2665
|
...resolvedShared,
|
|
2713
2666
|
"next/router": routerImpl,
|
|
2714
|
-
...
|
|
2715
|
-
(bundle) => imageImpl2(Image.default, bundle ?? "default", resolveClientUrl)
|
|
2716
|
-
),
|
|
2667
|
+
...createImageLoaderSharedEntries({ unbound: resolveClientUrl }),
|
|
2717
2668
|
...resolvedUserShared
|
|
2718
2669
|
};
|
|
2719
2670
|
};
|
|
2671
|
+
function RemoteComponentsClientProvider({
|
|
2672
|
+
shared: shared2,
|
|
2673
|
+
resolveClientUrl,
|
|
2674
|
+
children,
|
|
2675
|
+
...props
|
|
2676
|
+
}) {
|
|
2677
|
+
const mergedShared = (0, import_react5.useMemo)(
|
|
2678
|
+
() => sharedModules(shared2, resolveClientUrl),
|
|
2679
|
+
[shared2, resolveClientUrl]
|
|
2680
|
+
);
|
|
2681
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2682
|
+
import_context3.RemoteComponentsContext,
|
|
2683
|
+
{
|
|
2684
|
+
value: { shared: mergedShared, resolveClientUrl, ...props },
|
|
2685
|
+
children
|
|
2686
|
+
}
|
|
2687
|
+
);
|
|
2688
|
+
}
|
|
2720
2689
|
function ConsumeRemoteComponent2(props) {
|
|
2721
2690
|
if (typeof props.src !== "string" && !(props.src instanceof URL)) {
|
|
2722
2691
|
return props.children ?? null;
|
|
2723
2692
|
}
|
|
2724
|
-
|
|
2725
|
-
const resolveClientUrl = props.resolveClientUrl ? bindResolveClientUrl(props.resolveClientUrl, src) : void 0;
|
|
2726
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2693
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2727
2694
|
ConsumeRemoteComponent,
|
|
2728
2695
|
{
|
|
2729
2696
|
...props,
|
|
2730
|
-
shared: sharedModules(props.shared, resolveClientUrl)
|
|
2697
|
+
shared: sharedModules(props.shared, props.resolveClientUrl)
|
|
2731
2698
|
}
|
|
2732
2699
|
);
|
|
2733
2700
|
}
|
|
2734
2701
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2735
2702
|
0 && (module.exports = {
|
|
2736
|
-
ConsumeRemoteComponent
|
|
2703
|
+
ConsumeRemoteComponent,
|
|
2704
|
+
RemoteComponentsClientProvider
|
|
2737
2705
|
});
|
|
2738
2706
|
//# sourceMappingURL=client-only.cjs.map
|