remote-components 0.2.2 → 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 +169 -237
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +170 -238
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/nextjs/pages.cjs +1 -8
- package/dist/host/nextjs/pages.cjs.map +1 -1
- package/dist/host/nextjs/pages.js +2 -9
- package/dist/host/nextjs/pages.js.map +1 -1
- package/dist/host/react.cjs +37 -71
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +37 -71
- package/dist/host/react.js.map +1 -1
- package/dist/internal/host/nextjs/app-client.cjs +3 -8
- package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
- package/dist/internal/host/nextjs/app-client.js +4 -9
- 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/hooks/use-resolve-client-url.cjs +1 -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.d.ts +1 -4
- package/dist/internal/host/react/hooks/use-resolve-client-url.js +1 -5
- package/dist/internal/host/react/hooks/use-resolve-client-url.js.map +1 -1
- 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/package.json +1 -1
- package/dist/internal/host/nextjs/image-impl.cjs +0 -64
- 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 -40
- package/dist/internal/host/nextjs/image-impl.js.map +0 -1
|
@@ -37,9 +37,100 @@ var init_app = __esm({
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
// src/host/nextjs/app-client-only.tsx
|
|
40
|
-
import * as Image from "next/image";
|
|
41
40
|
import { useMemo as useMemo3 } from "react";
|
|
42
41
|
|
|
42
|
+
// src/host/shared/remote-image-loader.ts
|
|
43
|
+
function getRemoteBundleOrigin(bundle) {
|
|
44
|
+
const self = globalThis;
|
|
45
|
+
return self.__remote_bundle_url__?.[bundle]?.origin ?? "";
|
|
46
|
+
}
|
|
47
|
+
function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
48
|
+
const loader = Object.assign(
|
|
49
|
+
({
|
|
50
|
+
config,
|
|
51
|
+
src,
|
|
52
|
+
width,
|
|
53
|
+
quality
|
|
54
|
+
}) => {
|
|
55
|
+
const q = quality ?? 75;
|
|
56
|
+
const remoteOrigin = getRemoteBundleOrigin(bundle);
|
|
57
|
+
const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;
|
|
58
|
+
const basePath = isCrossOrigin ? `${remoteOrigin}${config.path ?? "/_next/image"}` : config.path ?? `${remoteOrigin}/_next/image`;
|
|
59
|
+
const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;
|
|
60
|
+
return resolveClientUrl?.(url) ?? url;
|
|
61
|
+
},
|
|
62
|
+
// Signals to getImgProps that this is a default loader (not a user-defined
|
|
63
|
+
// one), enabling srcSet generation with device/image sizes from the config.
|
|
64
|
+
{ __next_img_default: true }
|
|
65
|
+
);
|
|
66
|
+
return loader;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/runtime/url/resolve-client-url.ts
|
|
70
|
+
function withRemoteSrc(resolveClientUrl, remoteSrc) {
|
|
71
|
+
const remoteOrigin = parseOrigin(remoteSrc);
|
|
72
|
+
return (url) => {
|
|
73
|
+
const urlOrigin = parseOrigin(url);
|
|
74
|
+
if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
|
|
75
|
+
return void 0;
|
|
76
|
+
}
|
|
77
|
+
return resolveClientUrl(remoteSrc, url);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function parseOrigin(url) {
|
|
81
|
+
try {
|
|
82
|
+
return new URL(url).origin;
|
|
83
|
+
} catch {
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// src/runtime/url/default-resolve-client-url.ts
|
|
89
|
+
function bindResolveClientUrl(prop, remoteSrc) {
|
|
90
|
+
return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/host/nextjs/image-shared.ts
|
|
94
|
+
function resolveForBundle(unbound, bundle) {
|
|
95
|
+
if (!unbound)
|
|
96
|
+
return void 0;
|
|
97
|
+
const self = globalThis;
|
|
98
|
+
const remoteSrc = self.__remote_bundle_url__?.[bundle]?.href ?? "";
|
|
99
|
+
return bindResolveClientUrl(unbound, remoteSrc);
|
|
100
|
+
}
|
|
101
|
+
function createImageLoaderSharedEntries({
|
|
102
|
+
bound,
|
|
103
|
+
unbound
|
|
104
|
+
} = {}) {
|
|
105
|
+
const entry = (bundle) => {
|
|
106
|
+
const resolveClientUrl = bound ?? resolveForBundle(unbound, bundle);
|
|
107
|
+
return Promise.resolve({
|
|
108
|
+
default: createRemoteImageLoader(bundle, resolveClientUrl),
|
|
109
|
+
__esModule: true
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
"next/dist/shared/lib/image-loader": entry,
|
|
114
|
+
"next/dist/esm/shared/lib/image-loader": entry
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/host/nextjs/app-client-only.tsx
|
|
119
|
+
import { RemoteComponentsContext } from "#internal/host/react/context";
|
|
120
|
+
|
|
121
|
+
// src/host/react/index.tsx
|
|
122
|
+
import {
|
|
123
|
+
startTransition,
|
|
124
|
+
useEffect,
|
|
125
|
+
useId,
|
|
126
|
+
useLayoutEffect as useLayoutEffect2,
|
|
127
|
+
useMemo as useMemo2,
|
|
128
|
+
useRef as useRef2,
|
|
129
|
+
useState as useState2
|
|
130
|
+
} from "react";
|
|
131
|
+
import { createPortal } from "react-dom";
|
|
132
|
+
import { useRemoteComponentsContext as useRemoteComponentsContext2 } from "#internal/host/react/context";
|
|
133
|
+
|
|
43
134
|
// src/utils/logger.ts
|
|
44
135
|
init_constants();
|
|
45
136
|
|
|
@@ -186,58 +277,63 @@ function warnCrossOriginFetchError(logLocation, url) {
|
|
|
186
277
|
}
|
|
187
278
|
}
|
|
188
279
|
|
|
280
|
+
// src/host/server/fetch-headers.ts
|
|
281
|
+
function remoteFetchHeaders() {
|
|
282
|
+
return {
|
|
283
|
+
/**
|
|
284
|
+
* Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
|
|
285
|
+
* If the remote component uses vercel deployment protection, ensure the host and remote vercel
|
|
286
|
+
* projects share a common automation bypass secret, and the shared secret is used as the
|
|
287
|
+
* VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
|
|
288
|
+
*/
|
|
289
|
+
...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
|
|
290
|
+
"x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
|
|
291
|
+
} : {},
|
|
292
|
+
Accept: "text/html"
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/host/server/fetch-with-hooks.ts
|
|
297
|
+
async function fetchWithWarning(url, init) {
|
|
298
|
+
try {
|
|
299
|
+
return await fetch(url, init);
|
|
300
|
+
} catch (error) {
|
|
301
|
+
warnCrossOriginFetchError("FetchRemoteComponent", url);
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
async function fetchWithHooks(url, additionalInit, options = {}) {
|
|
306
|
+
const {
|
|
307
|
+
onRequest,
|
|
308
|
+
onResponse,
|
|
309
|
+
abortController = new AbortController()
|
|
310
|
+
} = options;
|
|
311
|
+
const signal = abortController.signal;
|
|
312
|
+
const hookOptions = {
|
|
313
|
+
signal,
|
|
314
|
+
abort: (reason) => abortController.abort(reason)
|
|
315
|
+
};
|
|
316
|
+
const init = {
|
|
317
|
+
method: "GET",
|
|
318
|
+
headers: remoteFetchHeaders(),
|
|
319
|
+
signal,
|
|
320
|
+
...additionalInit
|
|
321
|
+
};
|
|
322
|
+
const res = await onRequest?.(url, init, hookOptions) ?? await fetchWithWarning(url, init);
|
|
323
|
+
return await onResponse?.(url, res, hookOptions) ?? res;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// src/host/server/get-client-or-server-url.ts
|
|
327
|
+
function getClientOrServerUrl(src, serverFallback) {
|
|
328
|
+
const fallback = typeof location !== "undefined" ? location.href : serverFallback;
|
|
329
|
+
if (!src) {
|
|
330
|
+
return new URL(fallback);
|
|
331
|
+
}
|
|
332
|
+
return typeof src === "string" ? new URL(src, fallback) : src;
|
|
333
|
+
}
|
|
334
|
+
|
|
189
335
|
// src/host/shared/polyfill.tsx
|
|
190
336
|
import { jsx } from "react/jsx-runtime";
|
|
191
|
-
function applyBundleUrlToSrc(bundle, src) {
|
|
192
|
-
const self = globalThis;
|
|
193
|
-
if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {
|
|
194
|
-
return src;
|
|
195
|
-
}
|
|
196
|
-
const { assetPrefix, path } = /^(?<assetPrefix>.*?)\/_next\/(?<path>.*)/.exec(src)?.groups ?? {};
|
|
197
|
-
if (!path) {
|
|
198
|
-
return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;
|
|
199
|
-
}
|
|
200
|
-
return `${self.__remote_bundle_url__?.[bundle]?.origin ?? ""}${assetPrefix}/_next/${path}`;
|
|
201
|
-
}
|
|
202
|
-
function applyBundleUrlToImagePropsSrc(bundle, src) {
|
|
203
|
-
if (typeof src === "string") {
|
|
204
|
-
return applyBundleUrlToSrc(bundle, src);
|
|
205
|
-
}
|
|
206
|
-
const propSrc = src;
|
|
207
|
-
return applyBundleUrlToSrc(bundle, propSrc.src);
|
|
208
|
-
}
|
|
209
|
-
var imageImpl = (bundle, resolveClientUrl) => function RemoteImage({
|
|
210
|
-
fill: _fill,
|
|
211
|
-
loader: _loader,
|
|
212
|
-
quality: _quality,
|
|
213
|
-
priority: _priority,
|
|
214
|
-
loading: _loading,
|
|
215
|
-
placeholder: _placeholder,
|
|
216
|
-
blurDataURL: _blurDataURL,
|
|
217
|
-
unoptimized: _unoptimized,
|
|
218
|
-
overrideSrc: _overrideSrc,
|
|
219
|
-
src,
|
|
220
|
-
...props
|
|
221
|
-
}) {
|
|
222
|
-
const newSrc = applyBundleUrlToImagePropsSrc(
|
|
223
|
-
bundle,
|
|
224
|
-
typeof src === "string" ? src : src.src
|
|
225
|
-
);
|
|
226
|
-
const proxiedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
|
|
227
|
-
return (
|
|
228
|
-
// eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
|
|
229
|
-
/* @__PURE__ */ jsx(
|
|
230
|
-
"img",
|
|
231
|
-
{
|
|
232
|
-
decoding: "async",
|
|
233
|
-
style: { color: "transparent" },
|
|
234
|
-
...props,
|
|
235
|
-
src: proxiedSrc,
|
|
236
|
-
suppressHydrationWarning: true
|
|
237
|
-
}
|
|
238
|
-
)
|
|
239
|
-
);
|
|
240
|
-
};
|
|
241
337
|
function sharedPolyfills(shared2, resolveClientUrl) {
|
|
242
338
|
const self = globalThis;
|
|
243
339
|
const polyfill = {
|
|
@@ -328,17 +424,13 @@ function sharedPolyfills(shared2, resolveClientUrl) {
|
|
|
328
424
|
},
|
|
329
425
|
__esModule: true
|
|
330
426
|
})),
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
throw new Error(
|
|
339
|
-
"Next.js getImageProps() is not implemented in remote components"
|
|
340
|
-
);
|
|
341
|
-
},
|
|
427
|
+
// Instead of replacing next/image entirely, we let the real Next.js Image
|
|
428
|
+
// component load from the remote bundle and only replace its default loader.
|
|
429
|
+
// This gives us full next/image fidelity (fill, priority, srcSet, blur
|
|
430
|
+
// placeholders, error handling) while routing image optimization through the
|
|
431
|
+
// remote app's /_next/image endpoint.
|
|
432
|
+
"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({
|
|
433
|
+
default: createRemoteImageLoader(bundle, resolveClientUrl),
|
|
342
434
|
__esModule: true
|
|
343
435
|
})),
|
|
344
436
|
"next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared2?.["next/script"] ?? (() => Promise.resolve({
|
|
@@ -378,119 +470,11 @@ function sharedPolyfills(shared2, resolveClientUrl) {
|
|
|
378
470
|
polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
|
|
379
471
|
polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
|
|
380
472
|
polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
|
|
381
|
-
polyfill["next/dist/
|
|
473
|
+
polyfill["next/dist/esm/shared/lib/image-loader"] = polyfill["next/dist/shared/lib/image-loader"];
|
|
382
474
|
polyfill["next/script"] = polyfill["next/dist/client/script"];
|
|
383
475
|
return polyfill;
|
|
384
476
|
}
|
|
385
477
|
|
|
386
|
-
// src/host/nextjs/image-impl.tsx
|
|
387
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
388
|
-
var getBundleUrl = (bundle) => globalThis.__remote_bundle_url__?.[bundle];
|
|
389
|
-
function createRemoteLoader(bundle, resolveClientUrl) {
|
|
390
|
-
return ({ src, width, quality }) => {
|
|
391
|
-
const bundleUrl = getBundleUrl(bundle);
|
|
392
|
-
const origin = bundleUrl?.origin ?? "";
|
|
393
|
-
let imageUrl = src;
|
|
394
|
-
try {
|
|
395
|
-
const parsed = new URL(src);
|
|
396
|
-
if (origin && parsed.origin === origin) {
|
|
397
|
-
imageUrl = parsed.pathname + parsed.search;
|
|
398
|
-
}
|
|
399
|
-
} catch {
|
|
400
|
-
}
|
|
401
|
-
const { assetPrefix } = /^(?<assetPrefix>.*?)\/_next\//.exec(imageUrl)?.groups ?? {};
|
|
402
|
-
const url = `${origin}${assetPrefix ?? ""}/_next/image?url=${encodeURIComponent(imageUrl)}&w=${width}&q=${quality ?? 75}`;
|
|
403
|
-
const remoteSrc = bundleUrl?.href ?? url;
|
|
404
|
-
return resolveClientUrl?.(remoteSrc, url) ?? url;
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
function imageImpl2(ImageComponent, bundle, resolveClientUrl, useRemoteLoader) {
|
|
408
|
-
const remoteLoader = useRemoteLoader ? createRemoteLoader(bundle, resolveClientUrl) : void 0;
|
|
409
|
-
const component = function RemoteImage(props) {
|
|
410
|
-
if (remoteLoader) {
|
|
411
|
-
return /* @__PURE__ */ jsx2(ImageComponent, { loader: remoteLoader, ...props });
|
|
412
|
-
}
|
|
413
|
-
const rawSrc = applyBundleUrlToImagePropsSrc(bundle, props.src);
|
|
414
|
-
const bundleUrl = getBundleUrl(bundle);
|
|
415
|
-
const remoteSrc = bundleUrl?.href ?? rawSrc;
|
|
416
|
-
const src = resolveClientUrl?.(remoteSrc, rawSrc) ?? rawSrc;
|
|
417
|
-
return /* @__PURE__ */ jsx2(ImageComponent, { ...props, src });
|
|
418
|
-
};
|
|
419
|
-
component.default = component;
|
|
420
|
-
return component;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// src/host/nextjs/app-client-only.tsx
|
|
424
|
-
import { RemoteComponentsContext } from "#internal/host/react/context";
|
|
425
|
-
|
|
426
|
-
// src/host/react/index.tsx
|
|
427
|
-
import {
|
|
428
|
-
startTransition,
|
|
429
|
-
useEffect,
|
|
430
|
-
useId,
|
|
431
|
-
useLayoutEffect as useLayoutEffect2,
|
|
432
|
-
useMemo as useMemo2,
|
|
433
|
-
useRef as useRef2,
|
|
434
|
-
useState as useState2
|
|
435
|
-
} from "react";
|
|
436
|
-
import { createPortal } from "react-dom";
|
|
437
|
-
import { useRemoteComponentsContext as useRemoteComponentsContext2 } from "#internal/host/react/context";
|
|
438
|
-
|
|
439
|
-
// src/host/server/fetch-headers.ts
|
|
440
|
-
function remoteFetchHeaders() {
|
|
441
|
-
return {
|
|
442
|
-
/**
|
|
443
|
-
* Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
|
|
444
|
-
* If the remote component uses vercel deployment protection, ensure the host and remote vercel
|
|
445
|
-
* projects share a common automation bypass secret, and the shared secret is used as the
|
|
446
|
-
* VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
|
|
447
|
-
*/
|
|
448
|
-
...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
|
|
449
|
-
"x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
|
|
450
|
-
} : {},
|
|
451
|
-
Accept: "text/html"
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// src/host/server/fetch-with-hooks.ts
|
|
456
|
-
async function fetchWithWarning(url, init) {
|
|
457
|
-
try {
|
|
458
|
-
return await fetch(url, init);
|
|
459
|
-
} catch (error) {
|
|
460
|
-
warnCrossOriginFetchError("FetchRemoteComponent", url);
|
|
461
|
-
throw error;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
async function fetchWithHooks(url, additionalInit, options = {}) {
|
|
465
|
-
const {
|
|
466
|
-
onRequest,
|
|
467
|
-
onResponse,
|
|
468
|
-
abortController = new AbortController()
|
|
469
|
-
} = options;
|
|
470
|
-
const signal = abortController.signal;
|
|
471
|
-
const hookOptions = {
|
|
472
|
-
signal,
|
|
473
|
-
abort: (reason) => abortController.abort(reason)
|
|
474
|
-
};
|
|
475
|
-
const init = {
|
|
476
|
-
method: "GET",
|
|
477
|
-
headers: remoteFetchHeaders(),
|
|
478
|
-
signal,
|
|
479
|
-
...additionalInit
|
|
480
|
-
};
|
|
481
|
-
const res = await onRequest?.(url, init, hookOptions) ?? await fetchWithWarning(url, init);
|
|
482
|
-
return await onResponse?.(url, res, hookOptions) ?? res;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
// src/host/server/get-client-or-server-url.ts
|
|
486
|
-
function getClientOrServerUrl(src, serverFallback) {
|
|
487
|
-
const fallback = typeof location !== "undefined" ? location.href : serverFallback;
|
|
488
|
-
if (!src) {
|
|
489
|
-
return new URL(fallback);
|
|
490
|
-
}
|
|
491
|
-
return typeof src === "string" ? new URL(src, fallback) : src;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
478
|
// src/host/shared/state.ts
|
|
495
479
|
function createHostState() {
|
|
496
480
|
return {
|
|
@@ -1969,40 +1953,10 @@ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
|
|
|
1969
1953
|
// src/host/react/hooks/use-resolve-client-url.ts
|
|
1970
1954
|
import { useMemo } from "react";
|
|
1971
1955
|
import { useRemoteComponentsContext } from "#internal/host/react/context";
|
|
1972
|
-
|
|
1973
|
-
// src/runtime/url/resolve-client-url.ts
|
|
1974
|
-
function withRemoteSrc(resolveClientUrl, remoteSrc) {
|
|
1975
|
-
const remoteOrigin = parseOrigin(remoteSrc);
|
|
1976
|
-
return (url) => {
|
|
1977
|
-
const urlOrigin = parseOrigin(url);
|
|
1978
|
-
if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
|
|
1979
|
-
return void 0;
|
|
1980
|
-
}
|
|
1981
|
-
return resolveClientUrl(remoteSrc, url);
|
|
1982
|
-
};
|
|
1983
|
-
}
|
|
1984
|
-
function parseOrigin(url) {
|
|
1985
|
-
try {
|
|
1986
|
-
return new URL(url).origin;
|
|
1987
|
-
} catch {
|
|
1988
|
-
return void 0;
|
|
1989
|
-
}
|
|
1990
|
-
}
|
|
1991
|
-
|
|
1992
|
-
// src/runtime/url/default-resolve-client-url.ts
|
|
1993
|
-
function bindResolveClientUrl(prop, remoteSrc) {
|
|
1994
|
-
return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
|
|
1995
|
-
}
|
|
1996
|
-
|
|
1997
|
-
// src/host/react/hooks/use-resolve-client-url.ts
|
|
1998
1956
|
function useResolveClientUrl(prop, urlHref) {
|
|
1999
1957
|
const { resolveClientUrl: contextValue } = useRemoteComponentsContext();
|
|
2000
1958
|
const raw = prop ?? contextValue;
|
|
2001
|
-
|
|
2002
|
-
() => bindResolveClientUrl(raw, urlHref),
|
|
2003
|
-
[raw, urlHref]
|
|
2004
|
-
);
|
|
2005
|
-
return { bound, raw };
|
|
1959
|
+
return useMemo(() => bindResolveClientUrl(raw, urlHref), [raw, urlHref]);
|
|
2006
1960
|
}
|
|
2007
1961
|
|
|
2008
1962
|
// src/host/react/hooks/use-shadow-root.ts
|
|
@@ -2077,7 +2031,7 @@ function getRemoteComponentHtml(html) {
|
|
|
2077
2031
|
}
|
|
2078
2032
|
|
|
2079
2033
|
// src/host/react/index.tsx
|
|
2080
|
-
import { Fragment, jsx as
|
|
2034
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
2081
2035
|
import { createElement as createElement2 } from "react";
|
|
2082
2036
|
function ConsumeRemoteComponent({
|
|
2083
2037
|
src,
|
|
@@ -2108,10 +2062,7 @@ function ConsumeRemoteComponent({
|
|
|
2108
2062
|
null
|
|
2109
2063
|
);
|
|
2110
2064
|
const url = useMemo2(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);
|
|
2111
|
-
const
|
|
2112
|
-
resolveClientUrlProp,
|
|
2113
|
-
url.href
|
|
2114
|
-
);
|
|
2065
|
+
const resolveClientUrl = useResolveClientUrl(resolveClientUrlProp, url.href);
|
|
2115
2066
|
const id = url.origin === (typeof location !== "undefined" ? location.origin : DUMMY_FALLBACK) ? url.pathname : url.href;
|
|
2116
2067
|
const keySuffix = `${escapeString(id)}_${escapeString(
|
|
2117
2068
|
data?.name ?? name
|
|
@@ -2385,7 +2336,7 @@ function ConsumeRemoteComponent({
|
|
|
2385
2336
|
} else if (isolate === false) {
|
|
2386
2337
|
setRemoteComponent(
|
|
2387
2338
|
// TODO: remove wrapper div by converting HTML to RSC or React tree
|
|
2388
|
-
/* @__PURE__ */
|
|
2339
|
+
/* @__PURE__ */ jsx2(
|
|
2389
2340
|
"div",
|
|
2390
2341
|
{
|
|
2391
2342
|
dangerouslySetInnerHTML: { __html: component.innerHTML },
|
|
@@ -2498,13 +2449,13 @@ function ConsumeRemoteComponent({
|
|
|
2498
2449
|
if (remoteComponent instanceof Error) {
|
|
2499
2450
|
throw remoteComponent;
|
|
2500
2451
|
}
|
|
2501
|
-
const metadataJson = /* @__PURE__ */
|
|
2452
|
+
const metadataJson = /* @__PURE__ */ jsx2("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
|
|
2502
2453
|
name: data?.name || name,
|
|
2503
2454
|
bundle: data?.bundle || "default",
|
|
2504
2455
|
route: data?.route || DEFAULT_ROUTE,
|
|
2505
2456
|
runtime: hostStateRef.current.prevIsRemoteComponent ? RUNTIME_SCRIPT : data?.runtime || RUNTIME_WEBPACK
|
|
2506
2457
|
}) });
|
|
2507
|
-
const resetStyle = reset ? /* @__PURE__ */
|
|
2458
|
+
const resetStyle = reset ? /* @__PURE__ */ jsx2("style", { "data-remote-components-reset": "react", children: `:host { all: initial; }` }) : null;
|
|
2508
2459
|
const linksToRender = data?.links?.map((link) => /* @__PURE__ */ createElement2(
|
|
2509
2460
|
"link",
|
|
2510
2461
|
{
|
|
@@ -2563,7 +2514,7 @@ function ConsumeRemoteComponent({
|
|
|
2563
2514
|
typeof document === "undefined" ? (
|
|
2564
2515
|
// eslint-disable-next-line react/no-unknown-property
|
|
2565
2516
|
/* @__PURE__ */ jsxs("template", { shadowrootmode: mode, children: [
|
|
2566
|
-
typeof document === "undefined" ? /* @__PURE__ */
|
|
2517
|
+
typeof document === "undefined" ? /* @__PURE__ */ jsx2(
|
|
2567
2518
|
"div",
|
|
2568
2519
|
{
|
|
2569
2520
|
dangerouslySetInnerHTML: {
|
|
@@ -2586,11 +2537,11 @@ function ConsumeRemoteComponent({
|
|
|
2586
2537
|
) : null,
|
|
2587
2538
|
shadowRoot && remoteComponent ? createPortal(
|
|
2588
2539
|
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2589
|
-
/* @__PURE__ */
|
|
2540
|
+
/* @__PURE__ */ jsx2("template", { id: `${name}_start` }),
|
|
2590
2541
|
resetStyle,
|
|
2591
2542
|
linksToRender,
|
|
2592
2543
|
remoteComponent,
|
|
2593
|
-
/* @__PURE__ */
|
|
2544
|
+
/* @__PURE__ */ jsx2("template", { id: `${name}_end`, ref: endTemplateRef })
|
|
2594
2545
|
] }),
|
|
2595
2546
|
shadowRoot
|
|
2596
2547
|
) : null
|
|
@@ -2601,10 +2552,10 @@ function ConsumeRemoteComponent({
|
|
|
2601
2552
|
}
|
|
2602
2553
|
htmlRef.current = null;
|
|
2603
2554
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2604
|
-
/* @__PURE__ */
|
|
2555
|
+
/* @__PURE__ */ jsx2("template", { id: `${name}_start` }),
|
|
2605
2556
|
metadataJson,
|
|
2606
2557
|
componentToRender,
|
|
2607
|
-
/* @__PURE__ */
|
|
2558
|
+
/* @__PURE__ */ jsx2("template", { id: `${name}_end`, ref: endTemplateRef })
|
|
2608
2559
|
] });
|
|
2609
2560
|
}
|
|
2610
2561
|
|
|
@@ -2673,25 +2624,8 @@ var routerImpl = async () => {
|
|
|
2673
2624
|
});
|
|
2674
2625
|
};
|
|
2675
2626
|
|
|
2676
|
-
// src/host/nextjs/image-shared.ts
|
|
2677
|
-
function createNextImageSharedEntries(getWrappedImage, options) {
|
|
2678
|
-
const entries = {
|
|
2679
|
-
"next/image": (bundle) => Promise.resolve(getWrappedImage(bundle)),
|
|
2680
|
-
"next/dist/client/image-component": (bundle) => Promise.resolve({
|
|
2681
|
-
Image: getWrappedImage(bundle)
|
|
2682
|
-
})
|
|
2683
|
-
};
|
|
2684
|
-
if (options?.getImageProps) {
|
|
2685
|
-
entries["next/dist/api/image"] = (bundle) => Promise.resolve({
|
|
2686
|
-
default: getWrappedImage(bundle),
|
|
2687
|
-
getImageProps: options.getImageProps
|
|
2688
|
-
});
|
|
2689
|
-
}
|
|
2690
|
-
return entries;
|
|
2691
|
-
}
|
|
2692
|
-
|
|
2693
2627
|
// src/host/nextjs/app-client-only.tsx
|
|
2694
|
-
import { jsx as
|
|
2628
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
2695
2629
|
async function tryImportShared() {
|
|
2696
2630
|
try {
|
|
2697
2631
|
const { shared: shared2 } = await Promise.resolve().then(() => (init_app(), app_exports));
|
|
@@ -2708,9 +2642,7 @@ var sharedModules = async (userShared, resolveClientUrl) => {
|
|
|
2708
2642
|
return {
|
|
2709
2643
|
...resolvedShared,
|
|
2710
2644
|
"next/router": routerImpl,
|
|
2711
|
-
...
|
|
2712
|
-
(bundle) => imageImpl2(Image.default, bundle ?? "default", resolveClientUrl)
|
|
2713
|
-
),
|
|
2645
|
+
...createImageLoaderSharedEntries({ unbound: resolveClientUrl }),
|
|
2714
2646
|
...resolvedUserShared
|
|
2715
2647
|
};
|
|
2716
2648
|
};
|
|
@@ -2724,7 +2656,7 @@ function RemoteComponentsClientProvider({
|
|
|
2724
2656
|
() => sharedModules(shared2, resolveClientUrl),
|
|
2725
2657
|
[shared2, resolveClientUrl]
|
|
2726
2658
|
);
|
|
2727
|
-
return /* @__PURE__ */
|
|
2659
|
+
return /* @__PURE__ */ jsx3(
|
|
2728
2660
|
RemoteComponentsContext,
|
|
2729
2661
|
{
|
|
2730
2662
|
value: { shared: mergedShared, resolveClientUrl, ...props },
|
|
@@ -2736,7 +2668,7 @@ function ConsumeRemoteComponent2(props) {
|
|
|
2736
2668
|
if (typeof props.src !== "string" && !(props.src instanceof URL)) {
|
|
2737
2669
|
return props.children ?? null;
|
|
2738
2670
|
}
|
|
2739
|
-
return /* @__PURE__ */
|
|
2671
|
+
return /* @__PURE__ */ jsx3(
|
|
2740
2672
|
ConsumeRemoteComponent,
|
|
2741
2673
|
{
|
|
2742
2674
|
...props,
|