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
package/dist/host/html.js
CHANGED
|
@@ -402,26 +402,40 @@ var init_next_client_pages_loader = __esm({
|
|
|
402
402
|
}
|
|
403
403
|
});
|
|
404
404
|
|
|
405
|
-
// src/host/shared/
|
|
406
|
-
|
|
407
|
-
function applyBundleUrlToSrc(bundle, src) {
|
|
405
|
+
// src/host/shared/remote-image-loader.ts
|
|
406
|
+
function getRemoteBundleOrigin(bundle) {
|
|
408
407
|
const self = globalThis;
|
|
409
|
-
|
|
410
|
-
return src;
|
|
411
|
-
}
|
|
412
|
-
const { assetPrefix, path } = /^(?<assetPrefix>.*?)\/_next\/(?<path>.*)/.exec(src)?.groups ?? {};
|
|
413
|
-
if (!path) {
|
|
414
|
-
return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;
|
|
415
|
-
}
|
|
416
|
-
return `${self.__remote_bundle_url__?.[bundle]?.origin ?? ""}${assetPrefix}/_next/${path}`;
|
|
408
|
+
return self.__remote_bundle_url__?.[bundle]?.origin ?? "";
|
|
417
409
|
}
|
|
418
|
-
function
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
410
|
+
function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
411
|
+
const loader = Object.assign(
|
|
412
|
+
({
|
|
413
|
+
config,
|
|
414
|
+
src,
|
|
415
|
+
width,
|
|
416
|
+
quality
|
|
417
|
+
}) => {
|
|
418
|
+
const q = quality ?? 75;
|
|
419
|
+
const remoteOrigin = getRemoteBundleOrigin(bundle);
|
|
420
|
+
const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;
|
|
421
|
+
const basePath = isCrossOrigin ? `${remoteOrigin}${config.path ?? "/_next/image"}` : config.path ?? `${remoteOrigin}/_next/image`;
|
|
422
|
+
const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;
|
|
423
|
+
return resolveClientUrl?.(url) ?? url;
|
|
424
|
+
},
|
|
425
|
+
// Signals to getImgProps that this is a default loader (not a user-defined
|
|
426
|
+
// one), enabling srcSet generation with device/image sizes from the config.
|
|
427
|
+
{ __next_img_default: true }
|
|
428
|
+
);
|
|
429
|
+
return loader;
|
|
424
430
|
}
|
|
431
|
+
var init_remote_image_loader = __esm({
|
|
432
|
+
"src/host/shared/remote-image-loader.ts"() {
|
|
433
|
+
"use strict";
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
// src/host/shared/polyfill.tsx
|
|
438
|
+
import { jsx } from "react/jsx-runtime";
|
|
425
439
|
function sharedPolyfills(shared, resolveClientUrl) {
|
|
426
440
|
const self = globalThis;
|
|
427
441
|
const polyfill = {
|
|
@@ -512,17 +526,13 @@ function sharedPolyfills(shared, resolveClientUrl) {
|
|
|
512
526
|
},
|
|
513
527
|
__esModule: true
|
|
514
528
|
})),
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
throw new Error(
|
|
523
|
-
"Next.js getImageProps() is not implemented in remote components"
|
|
524
|
-
);
|
|
525
|
-
},
|
|
529
|
+
// Instead of replacing next/image entirely, we let the real Next.js Image
|
|
530
|
+
// component load from the remote bundle and only replace its default loader.
|
|
531
|
+
// This gives us full next/image fidelity (fill, priority, srcSet, blur
|
|
532
|
+
// placeholders, error handling) while routing image optimization through the
|
|
533
|
+
// remote app's /_next/image endpoint.
|
|
534
|
+
"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({
|
|
535
|
+
default: createRemoteImageLoader(bundle, resolveClientUrl),
|
|
526
536
|
__esModule: true
|
|
527
537
|
})),
|
|
528
538
|
"next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
|
|
@@ -562,47 +572,15 @@ function sharedPolyfills(shared, resolveClientUrl) {
|
|
|
562
572
|
polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
|
|
563
573
|
polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
|
|
564
574
|
polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
|
|
565
|
-
polyfill["next/dist/
|
|
575
|
+
polyfill["next/dist/esm/shared/lib/image-loader"] = polyfill["next/dist/shared/lib/image-loader"];
|
|
566
576
|
polyfill["next/script"] = polyfill["next/dist/client/script"];
|
|
567
577
|
return polyfill;
|
|
568
578
|
}
|
|
569
|
-
var imageImpl;
|
|
570
579
|
var init_polyfill = __esm({
|
|
571
580
|
"src/host/shared/polyfill.tsx"() {
|
|
572
581
|
"use strict";
|
|
582
|
+
init_remote_image_loader();
|
|
573
583
|
init_logger();
|
|
574
|
-
imageImpl = (bundle, resolveClientUrl) => function RemoteImage({
|
|
575
|
-
fill: _fill,
|
|
576
|
-
loader: _loader,
|
|
577
|
-
quality: _quality,
|
|
578
|
-
priority: _priority,
|
|
579
|
-
loading: _loading,
|
|
580
|
-
placeholder: _placeholder,
|
|
581
|
-
blurDataURL: _blurDataURL,
|
|
582
|
-
unoptimized: _unoptimized,
|
|
583
|
-
overrideSrc: _overrideSrc,
|
|
584
|
-
src,
|
|
585
|
-
...props
|
|
586
|
-
}) {
|
|
587
|
-
const newSrc = applyBundleUrlToImagePropsSrc(
|
|
588
|
-
bundle,
|
|
589
|
-
typeof src === "string" ? src : src.src
|
|
590
|
-
);
|
|
591
|
-
const proxiedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
|
|
592
|
-
return (
|
|
593
|
-
// eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
|
|
594
|
-
/* @__PURE__ */ jsx(
|
|
595
|
-
"img",
|
|
596
|
-
{
|
|
597
|
-
decoding: "async",
|
|
598
|
-
style: { color: "transparent" },
|
|
599
|
-
...props,
|
|
600
|
-
src: proxiedSrc,
|
|
601
|
-
suppressHydrationWarning: true
|
|
602
|
-
}
|
|
603
|
-
)
|
|
604
|
-
);
|
|
605
|
-
};
|
|
606
584
|
}
|
|
607
585
|
});
|
|
608
586
|
|