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.
Files changed (42) hide show
  1. package/dist/host/nextjs/app/client-only.cjs +76 -40
  2. package/dist/host/nextjs/app/client-only.cjs.map +1 -1
  3. package/dist/host/nextjs/app/client-only.d.ts +28 -9
  4. package/dist/host/nextjs/app/client-only.js +74 -39
  5. package/dist/host/nextjs/app/client-only.js.map +1 -1
  6. package/dist/host/nextjs/pages.cjs +4 -4
  7. package/dist/host/nextjs/pages.cjs.map +1 -1
  8. package/dist/host/nextjs/pages.js +4 -4
  9. package/dist/host/nextjs/pages.js.map +1 -1
  10. package/dist/host/react.cjs +16 -8
  11. package/dist/host/react.cjs.map +1 -1
  12. package/dist/host/react.d.ts +2 -366
  13. package/dist/host/react.js +16 -8
  14. package/dist/host/react.js.map +1 -1
  15. package/dist/index-4c65355c.d.ts +298 -0
  16. package/dist/internal/config/webpack/next-client-pages-loader.d.ts +3 -3
  17. package/dist/internal/host/nextjs/app-client.cjs +4 -3
  18. package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
  19. package/dist/internal/host/nextjs/app-client.d.ts +1 -1
  20. package/dist/internal/host/nextjs/app-client.js +4 -3
  21. package/dist/internal/host/nextjs/app-client.js.map +1 -1
  22. package/dist/internal/host/nextjs/image-impl.cjs +8 -4
  23. package/dist/internal/host/nextjs/image-impl.cjs.map +1 -1
  24. package/dist/internal/host/nextjs/image-impl.d.ts +2 -2
  25. package/dist/internal/host/nextjs/image-impl.js +8 -4
  26. package/dist/internal/host/nextjs/image-impl.js.map +1 -1
  27. package/dist/internal/host/react/context.cjs +5 -10
  28. package/dist/internal/host/react/context.cjs.map +1 -1
  29. package/dist/internal/host/react/context.d.ts +7 -18
  30. package/dist/internal/host/react/context.js +4 -9
  31. package/dist/internal/host/react/context.js.map +1 -1
  32. package/dist/internal/host/react/hooks/use-resolve-client-url.cjs +5 -4
  33. package/dist/internal/host/react/hooks/use-resolve-client-url.cjs.map +1 -1
  34. package/dist/internal/host/react/hooks/use-resolve-client-url.d.ts +4 -1
  35. package/dist/internal/host/react/hooks/use-resolve-client-url.js +5 -4
  36. package/dist/internal/host/react/hooks/use-resolve-client-url.js.map +1 -1
  37. package/dist/internal/host/shared/config.cjs.map +1 -1
  38. package/dist/internal/host/shared/config.d.ts +7 -0
  39. package/dist/internal/host/shared/resolved-data.d.ts +2 -2
  40. package/dist/internal/runtime/loaders/component-loader.d.ts +1 -1
  41. package/dist/{server-handoff-8c89b856.d.ts → server-handoff-ce13bebc.d.ts} +2 -2
  42. package/package.json +1 -9
@@ -61,10 +61,12 @@ 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
68
  var Image = __toESM(require("next/image"), 1);
69
+ var import_react5 = require("react");
68
70
 
69
71
  // src/utils/logger.ts
70
72
  init_constants();
@@ -411,10 +413,11 @@ function sharedPolyfills(shared2, resolveClientUrl) {
411
413
 
412
414
  // src/host/nextjs/image-impl.tsx
413
415
  var import_jsx_runtime2 = require("react/jsx-runtime");
416
+ var getBundleUrl = (bundle) => globalThis.__remote_bundle_url__?.[bundle];
414
417
  function createRemoteLoader(bundle, resolveClientUrl) {
415
418
  return ({ src, width, quality }) => {
416
- const self = globalThis;
417
- const origin = self.__remote_bundle_url__?.[bundle]?.origin ?? "";
419
+ const bundleUrl = getBundleUrl(bundle);
420
+ const origin = bundleUrl?.origin ?? "";
418
421
  let imageUrl = src;
419
422
  try {
420
423
  const parsed = new URL(src);
@@ -425,7 +428,8 @@ function createRemoteLoader(bundle, resolveClientUrl) {
425
428
  }
426
429
  const { assetPrefix } = /^(?<assetPrefix>.*?)\/_next\//.exec(imageUrl)?.groups ?? {};
427
430
  const url = `${origin}${assetPrefix ?? ""}/_next/image?url=${encodeURIComponent(imageUrl)}&w=${width}&q=${quality ?? 75}`;
428
- return resolveClientUrl?.(url) ?? url;
431
+ const remoteSrc = bundleUrl?.href ?? url;
432
+ return resolveClientUrl?.(remoteSrc, url) ?? url;
429
433
  };
430
434
  }
431
435
  function imageImpl2(ImageComponent, bundle, resolveClientUrl, useRemoteLoader) {
@@ -435,40 +439,22 @@ function imageImpl2(ImageComponent, bundle, resolveClientUrl, useRemoteLoader) {
435
439
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ImageComponent, { loader: remoteLoader, ...props });
436
440
  }
437
441
  const rawSrc = applyBundleUrlToImagePropsSrc(bundle, props.src);
438
- const src = resolveClientUrl?.(rawSrc) ?? rawSrc;
442
+ const bundleUrl = getBundleUrl(bundle);
443
+ const remoteSrc = bundleUrl?.href ?? rawSrc;
444
+ const src = resolveClientUrl?.(remoteSrc, rawSrc) ?? rawSrc;
439
445
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ImageComponent, { ...props, src });
440
446
  };
441
447
  component.default = component;
442
448
  return component;
443
449
  }
444
450
 
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
- }
451
+ // src/host/nextjs/app-client-only.tsx
452
+ var import_context3 = require("#internal/host/react/context");
468
453
 
469
454
  // src/host/react/index.tsx
470
455
  var import_react3 = require("react");
471
456
  var import_react_dom = require("react-dom");
457
+ var import_context2 = require("#internal/host/react/context");
472
458
 
473
459
  // src/host/server/fetch-headers.ts
474
460
  function remoteFetchHeaders() {
@@ -2003,13 +1989,40 @@ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
2003
1989
  // src/host/react/hooks/use-resolve-client-url.ts
2004
1990
  var import_react = require("react");
2005
1991
  var import_context = require("#internal/host/react/context");
1992
+
1993
+ // src/runtime/url/resolve-client-url.ts
1994
+ function withRemoteSrc(resolveClientUrl, remoteSrc) {
1995
+ const remoteOrigin = parseOrigin(remoteSrc);
1996
+ return (url) => {
1997
+ const urlOrigin = parseOrigin(url);
1998
+ if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
1999
+ return void 0;
2000
+ }
2001
+ return resolveClientUrl(remoteSrc, url);
2002
+ };
2003
+ }
2004
+ function parseOrigin(url) {
2005
+ try {
2006
+ return new URL(url).origin;
2007
+ } catch {
2008
+ return void 0;
2009
+ }
2010
+ }
2011
+
2012
+ // src/runtime/url/default-resolve-client-url.ts
2013
+ function bindResolveClientUrl(prop, remoteSrc) {
2014
+ return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
2015
+ }
2016
+
2017
+ // src/host/react/hooks/use-resolve-client-url.ts
2006
2018
  function useResolveClientUrl(prop, urlHref) {
2007
2019
  const { resolveClientUrl: contextValue } = (0, import_context.useRemoteComponentsContext)();
2008
- const resolveClientUrl = prop ?? contextValue;
2009
- return (0, import_react.useMemo)(
2010
- () => bindResolveClientUrl(resolveClientUrl, urlHref),
2011
- [resolveClientUrl, urlHref]
2020
+ const raw = prop ?? contextValue;
2021
+ const bound = (0, import_react.useMemo)(
2022
+ () => bindResolveClientUrl(raw, urlHref),
2023
+ [raw, urlHref]
2012
2024
  );
2025
+ return { bound, raw };
2013
2026
  }
2014
2027
 
2015
2028
  // src/host/react/hooks/use-shadow-root.ts
@@ -2094,9 +2107,9 @@ function ConsumeRemoteComponent({
2094
2107
  isolate,
2095
2108
  mode = "open",
2096
2109
  reset,
2097
- credentials = "same-origin",
2110
+ credentials: credentialsProp,
2098
2111
  name: nameProp = "__vercel_remote_component",
2099
- shared: shared2 = {},
2112
+ shared: sharedProp,
2100
2113
  children,
2101
2114
  onBeforeLoad,
2102
2115
  onLoad,
@@ -2104,9 +2117,12 @@ function ConsumeRemoteComponent({
2104
2117
  onChange,
2105
2118
  onRequest,
2106
2119
  onResponse,
2107
- resolveClientUrl: _resolveClientUrl
2120
+ resolveClientUrl: resolveClientUrlProp
2108
2121
  }) {
2109
2122
  const instanceId = (0, import_react3.useId)();
2123
+ const { credentials: contextCredentials, shared: contextShared } = (0, import_context2.useRemoteComponentsContext)();
2124
+ const credentials = credentialsProp ?? contextCredentials ?? "same-origin";
2125
+ const shared2 = sharedProp ?? contextShared ?? {};
2110
2126
  const name = (0, import_react3.useMemo)(
2111
2127
  () => resolveNameFromSrc(src, nameProp),
2112
2128
  [src, nameProp]
@@ -2115,7 +2131,10 @@ function ConsumeRemoteComponent({
2115
2131
  null
2116
2132
  );
2117
2133
  const url = (0, import_react3.useMemo)(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);
2118
- const resolveClientUrl = useResolveClientUrl(_resolveClientUrl, url.href);
2134
+ const { bound: resolveClientUrl } = useResolveClientUrl(
2135
+ resolveClientUrlProp,
2136
+ url.href
2137
+ );
2119
2138
  const id = url.origin === (typeof location !== "undefined" ? location.origin : DUMMY_FALLBACK) ? url.pathname : url.href;
2120
2139
  const keySuffix = `${escapeString(id)}_${escapeString(
2121
2140
  data?.name ?? name
@@ -2717,22 +2736,39 @@ var sharedModules = async (userShared, resolveClientUrl) => {
2717
2736
  ...resolvedUserShared
2718
2737
  };
2719
2738
  };
2739
+ function RemoteComponentsClientProvider({
2740
+ shared: shared2,
2741
+ resolveClientUrl,
2742
+ children,
2743
+ ...props
2744
+ }) {
2745
+ const mergedShared = (0, import_react5.useMemo)(
2746
+ () => sharedModules(shared2, resolveClientUrl),
2747
+ [shared2, resolveClientUrl]
2748
+ );
2749
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2750
+ import_context3.RemoteComponentsContext,
2751
+ {
2752
+ value: { shared: mergedShared, resolveClientUrl, ...props },
2753
+ children
2754
+ }
2755
+ );
2756
+ }
2720
2757
  function ConsumeRemoteComponent2(props) {
2721
2758
  if (typeof props.src !== "string" && !(props.src instanceof URL)) {
2722
2759
  return props.children ?? null;
2723
2760
  }
2724
- const src = typeof props.src === "string" ? props.src : props.src.href;
2725
- const resolveClientUrl = props.resolveClientUrl ? bindResolveClientUrl(props.resolveClientUrl, src) : void 0;
2726
2761
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2727
2762
  ConsumeRemoteComponent,
2728
2763
  {
2729
2764
  ...props,
2730
- shared: sharedModules(props.shared, resolveClientUrl)
2765
+ shared: sharedModules(props.shared, props.resolveClientUrl)
2731
2766
  }
2732
2767
  );
2733
2768
  }
2734
2769
  // Annotate the CommonJS export names for ESM import in node:
2735
2770
  0 && (module.exports = {
2736
- ConsumeRemoteComponent
2771
+ ConsumeRemoteComponent,
2772
+ RemoteComponentsClientProvider
2737
2773
  });
2738
2774
  //# sourceMappingURL=client-only.cjs.map