@rpcbase/client 0.387.0 → 0.389.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.
@@ -1,7 +1,9 @@
1
1
  import { ReactNode } from 'react';
2
+ import { RoutePrefetchProviderProps } from '@rpcbase/router';
2
3
  type RootProviderProps = {
3
4
  children: ReactNode;
5
+ routePrefetch?: Omit<RoutePrefetchProviderProps, "children">;
4
6
  };
5
- export declare const RootProvider: ({ children }: RootProviderProps) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const RootProvider: ({ children, routePrefetch }: RootProviderProps) => import("react/jsx-runtime").JSX.Element;
6
8
  export {};
7
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/RootProvider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKjC,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,SAAS,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,cAAY,iBAAiB,4CAIzD,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/RootProvider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAyB,KAAK,0BAA0B,EAAE,MAAM,iBAAiB,CAAA;AAKxF,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,SAAS,CAAA;IACnB,aAAa,CAAC,EAAE,IAAI,CAAC,0BAA0B,EAAE,UAAU,CAAC,CAAA;CAC7D,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,6BAA2B,iBAAiB,4CAWxE,CAAA"}
package/dist/index.js CHANGED
@@ -2,12 +2,12 @@ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import { c } from "react/compiler-runtime";
3
3
  import { useSyncExternalStore, lazy, useEffect, Suspense, StrictMode, useState, useRef, useLayoutEffect, createContext, useContext } from "react";
4
4
  import env from "@rpcbase/env";
5
- import { getNavigationGuards, createRoutesFromElements, createBrowserRouter, RouterProvider, useLocation, useRouteError, isRouteErrorResponse } from "@rpcbase/router";
5
+ import { getNavigationGuards, createRoutesFromElements, createBrowserRouter, RouterProvider, matchRoutes, useLocation, RoutePrefetchProvider, useRouteError, isRouteErrorResponse } from "@rpcbase/router";
6
6
  import { hydrateRoot } from "react-dom/client";
7
7
  import { r as reportClientException } from "./errorReporting-CVoUUKxW.js";
8
8
  import { s } from "./errorReporting-CVoUUKxW.js";
9
- import { n as hydrateRtsFromWindow, v as useQuery } from "./useQuery-0Z8QorHN.js";
10
- import { R, S, p, q, t } from "./useQuery-0Z8QorHN.js";
9
+ import { n as hydrateRtsFromWindow, v as useQuery } from "./useQuery-ClKeTB8S.js";
10
+ import { R, S, p, q, t } from "./useQuery-ClKeTB8S.js";
11
11
  const emptyUnsubscribe = () => {
12
12
  };
13
13
  const useMediaQuery = (query) => {
@@ -752,6 +752,8 @@ const SsrErrorFallback = (t0) => {
752
752
  };
753
753
  const isProduction = env.MODE === "production";
754
754
  const LOADER_TIMEOUT_MS = 8e3;
755
+ const HYDRATION_IDENTIFIER_PREFIX = "rb-";
756
+ const IMMUTABLE_LAZY_ROUTE_KEYS = /* @__PURE__ */ new Set(["lazy", "caseSensitive", "path", "id", "index", "children"]);
755
757
  const showErrorOverlay = (err) => {
756
758
  const ErrorOverlay = customElements.get("vite-error-overlay");
757
759
  if (!ErrorOverlay) {
@@ -818,6 +820,31 @@ const applyLoaderTimeouts = (routes) => {
818
820
  }
819
821
  });
820
822
  };
823
+ const resolveLazyRoute = async (route) => {
824
+ const lazy2 = route.lazy;
825
+ if (typeof lazy2 !== "function") return;
826
+ const lazyModule = await lazy2();
827
+ if (!lazyModule || typeof lazyModule !== "object") {
828
+ route.lazy = void 0;
829
+ return;
830
+ }
831
+ const mutableRoute = route;
832
+ for (const [key, value] of Object.entries(lazyModule)) {
833
+ if (IMMUTABLE_LAZY_ROUTE_KEYS.has(key)) continue;
834
+ if (mutableRoute[key] !== void 0) continue;
835
+ mutableRoute[key] = value;
836
+ }
837
+ route.lazy = void 0;
838
+ };
839
+ const preloadMatchedLazyRoutes = async (routes) => {
840
+ const matches = matchRoutes(routes, {
841
+ pathname: window.location.pathname,
842
+ search: window.location.search,
843
+ hash: window.location.hash
844
+ });
845
+ if (!matches?.length) return;
846
+ await Promise.all(matches.map((match) => resolveLazyRoute(match.route)));
847
+ };
821
848
  const getRootElement = () => {
822
849
  const el = document.getElementById("root");
823
850
  if (!el) {
@@ -878,6 +905,7 @@ const initWithRoutes = async (routesElement, opts) => {
878
905
  hydrateRtsFromWindow();
879
906
  const routes = createRoutesFromElements(routesElement);
880
907
  applyLoaderTimeouts(routes);
908
+ await preloadMatchedLazyRoutes(routes);
881
909
  const router = createBrowserRouter(routes, {});
882
910
  clearStaticRouterHydrationData();
883
911
  installGlobalNavigationGuard(router);
@@ -906,11 +934,16 @@ const initWithRoutes = async (routesElement, opts) => {
906
934
  console.warn("Uncaught error", err, errorInfo?.componentStack);
907
935
  }
908
936
  };
937
+ const baseHydrationOptions = {
938
+ identifierPrefix: HYDRATION_IDENTIFIER_PREFIX
939
+ };
909
940
  const hydrationOptions = isProduction ? {
941
+ ...baseHydrationOptions,
910
942
  onUncaughtError: reactErrorHandler("uncaught"),
911
943
  onCaughtError: reactErrorHandler("caught"),
912
944
  onRecoverableError: reactErrorHandler("recoverable")
913
945
  } : opts?.devThrowsOnHydrationErrors ? {
946
+ ...baseHydrationOptions,
914
947
  onRecoverableError(error, errorInfo) {
915
948
  const err = toError(error);
916
949
  if (mentionsHydration(err) || mentionsHydration(errorInfo?.componentStack)) {
@@ -918,7 +951,7 @@ const initWithRoutes = async (routesElement, opts) => {
918
951
  }
919
952
  console.error(err, errorInfo?.componentStack);
920
953
  }
921
- } : void 0;
954
+ } : baseHydrationOptions;
922
955
  hydrateRoot(rootElement, /* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsxs(Fragment, { children: [
923
956
  /* @__PURE__ */ jsx(RouterProvider, { router }),
924
957
  /* @__PURE__ */ jsx(ClientOnly, { children: /* @__PURE__ */ jsx(Toaster, {}) })
@@ -1724,20 +1757,24 @@ function useApplyScroll() {
1724
1757
  useEffect(t10, t11);
1725
1758
  }
1726
1759
  const RootProvider = (t0) => {
1727
- const $ = c(2);
1760
+ const $ = c(4);
1728
1761
  const {
1729
- children
1762
+ children,
1763
+ routePrefetch
1730
1764
  } = t0;
1731
1765
  useApplyScroll();
1732
- let t1;
1733
- if ($[0] !== children) {
1734
- t1 = /* @__PURE__ */ jsx(Fragment, { children });
1766
+ const t1 = routePrefetch?.defaultPrefetch ?? "intent";
1767
+ let t2;
1768
+ if ($[0] !== children || $[1] !== routePrefetch || $[2] !== t1) {
1769
+ t2 = /* @__PURE__ */ jsx(RoutePrefetchProvider, { ...routePrefetch, defaultPrefetch: t1, children });
1735
1770
  $[0] = children;
1736
- $[1] = t1;
1771
+ $[1] = routePrefetch;
1772
+ $[2] = t1;
1773
+ $[3] = t2;
1737
1774
  } else {
1738
- t1 = $[1];
1775
+ t2 = $[3];
1739
1776
  }
1740
- return t1;
1777
+ return t2;
1741
1778
  };
1742
1779
  var isObject_1;
1743
1780
  var hasRequiredIsObject;