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.
Files changed (65) hide show
  1. package/dist/config/nextjs.cjs +2 -4
  2. package/dist/config/nextjs.cjs.map +1 -1
  3. package/dist/config/nextjs.d.ts +1 -1
  4. package/dist/config/nextjs.js +2 -4
  5. package/dist/config/nextjs.js.map +1 -1
  6. package/dist/host/html.cjs +40 -59
  7. package/dist/host/html.cjs.map +1 -1
  8. package/dist/host/html.js +40 -62
  9. package/dist/host/html.js.map +1 -1
  10. package/dist/host/nextjs/app/client-only.cjs +199 -231
  11. package/dist/host/nextjs/app/client-only.cjs.map +1 -1
  12. package/dist/host/nextjs/app/client-only.d.ts +28 -9
  13. package/dist/host/nextjs/app/client-only.js +198 -231
  14. package/dist/host/nextjs/app/client-only.js.map +1 -1
  15. package/dist/host/nextjs/pages.cjs +5 -12
  16. package/dist/host/nextjs/pages.cjs.map +1 -1
  17. package/dist/host/nextjs/pages.js +6 -13
  18. package/dist/host/nextjs/pages.js.map +1 -1
  19. package/dist/host/react.cjs +45 -71
  20. package/dist/host/react.cjs.map +1 -1
  21. package/dist/host/react.d.ts +2 -366
  22. package/dist/host/react.js +45 -71
  23. package/dist/host/react.js.map +1 -1
  24. package/dist/index-4c65355c.d.ts +298 -0
  25. package/dist/internal/config/webpack/next-client-pages-loader.d.ts +3 -3
  26. package/dist/internal/host/nextjs/app-client.cjs +1 -5
  27. package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
  28. package/dist/internal/host/nextjs/app-client.d.ts +1 -1
  29. package/dist/internal/host/nextjs/app-client.js +2 -6
  30. package/dist/internal/host/nextjs/app-client.js.map +1 -1
  31. package/dist/internal/host/nextjs/image-shared.cjs +25 -15
  32. package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
  33. package/dist/internal/host/nextjs/image-shared.d.ts +19 -6
  34. package/dist/internal/host/nextjs/image-shared.js +24 -14
  35. package/dist/internal/host/nextjs/image-shared.js.map +1 -1
  36. package/dist/internal/host/react/context.cjs +5 -10
  37. package/dist/internal/host/react/context.cjs.map +1 -1
  38. package/dist/internal/host/react/context.d.ts +7 -18
  39. package/dist/internal/host/react/context.js +4 -9
  40. package/dist/internal/host/react/context.js.map +1 -1
  41. package/dist/internal/host/react/hooks/use-resolve-client-url.cjs +2 -5
  42. package/dist/internal/host/react/hooks/use-resolve-client-url.cjs.map +1 -1
  43. package/dist/internal/host/react/hooks/use-resolve-client-url.js +2 -5
  44. package/dist/internal/host/react/hooks/use-resolve-client-url.js.map +1 -1
  45. package/dist/internal/host/shared/config.cjs.map +1 -1
  46. package/dist/internal/host/shared/config.d.ts +7 -0
  47. package/dist/internal/host/shared/polyfill.cjs +10 -65
  48. package/dist/internal/host/shared/polyfill.cjs.map +1 -1
  49. package/dist/internal/host/shared/polyfill.d.ts +1 -3
  50. package/dist/internal/host/shared/polyfill.js +9 -63
  51. package/dist/internal/host/shared/polyfill.js.map +1 -1
  52. package/dist/internal/host/shared/remote-image-loader.cjs +53 -0
  53. package/dist/internal/host/shared/remote-image-loader.cjs.map +1 -0
  54. package/dist/internal/host/shared/remote-image-loader.d.ts +30 -0
  55. package/dist/internal/host/shared/remote-image-loader.js +29 -0
  56. package/dist/internal/host/shared/remote-image-loader.js.map +1 -0
  57. package/dist/internal/host/shared/resolved-data.d.ts +2 -2
  58. package/dist/internal/runtime/loaders/component-loader.d.ts +1 -1
  59. package/dist/{server-handoff-8c89b856.d.ts → server-handoff-ce13bebc.d.ts} +2 -2
  60. package/package.json +1 -9
  61. package/dist/internal/host/nextjs/image-impl.cjs +0 -60
  62. package/dist/internal/host/nextjs/image-impl.cjs.map +0 -1
  63. package/dist/internal/host/nextjs/image-impl.d.ts +0 -10
  64. package/dist/internal/host/nextjs/image-impl.js +0 -36
  65. 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/polyfill.tsx
406
- import { jsx } from "react/jsx-runtime";
407
- function applyBundleUrlToSrc(bundle, src) {
405
+ // src/host/shared/remote-image-loader.ts
406
+ function getRemoteBundleOrigin(bundle) {
408
407
  const self = globalThis;
409
- if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {
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 applyBundleUrlToImagePropsSrc(bundle, src) {
419
- if (typeof src === "string") {
420
- return applyBundleUrlToSrc(bundle, src);
421
- }
422
- const propSrc = src;
423
- return applyBundleUrlToSrc(bundle, propSrc.src);
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
- "next/dist/client/image-component": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
516
- Image: imageImpl(bundle, resolveClientUrl),
517
- __esModule: true
518
- })),
519
- "next/image": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
520
- default: imageImpl(bundle, resolveClientUrl),
521
- getImageProps: (_imgProps) => {
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/api/image"] = polyfill["next/dist/client/image-component"];
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