@tanstack/react-router 1.147.1 → 1.147.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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const React = require("react");
5
5
  const routerCore = require("@tanstack/router-core");
6
+ const utils = require("./utils.cjs");
6
7
  function _interopNamespaceDefault(e) {
7
8
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
8
9
  if (e) {
@@ -21,8 +22,8 @@ function _interopNamespaceDefault(e) {
21
22
  }
22
23
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
23
24
  function useAwaited({ promise: _promise }) {
24
- if (React__namespace.use) {
25
- const data = React__namespace.use(_promise);
25
+ if (utils.reactUse) {
26
+ const data = utils.reactUse(_promise);
26
27
  return data;
27
28
  }
28
29
  const promise = routerCore.defer(_promise);
@@ -1 +1 @@
1
- {"version":3,"file":"awaited.cjs","sources":["../../src/awaited.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { TSR_DEFERRED_PROMISE, defer } from '@tanstack/router-core'\n\nexport type AwaitOptions<T> = {\n promise: Promise<T>\n}\n\n/** Suspend until a deferred promise resolves or rejects and return its data. */\nexport function useAwaited<T>({ promise: _promise }: AwaitOptions<T>): T {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (React.use) {\n const data = React.use(_promise)\n return data\n }\n const promise = defer(_promise)\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'pending') {\n throw promise\n }\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'error') {\n throw promise[TSR_DEFERRED_PROMISE].error\n }\n\n return promise[TSR_DEFERRED_PROMISE].data\n}\n\n/**\n * Component that suspends on a deferred promise and renders its child with\n * the resolved value. Optionally provides a Suspense fallback.\n */\nexport function Await<T>(\n props: AwaitOptions<T> & {\n fallback?: React.ReactNode\n children: (result: T) => React.ReactNode\n },\n) {\n const inner = <AwaitInner {...props} />\n if (props.fallback) {\n return <React.Suspense fallback={props.fallback}>{inner}</React.Suspense>\n }\n return inner\n}\n\nfunction AwaitInner<T>(\n props: AwaitOptions<T> & {\n fallback?: React.ReactNode\n children: (result: T) => React.ReactNode\n },\n): React.JSX.Element {\n const data = useAwaited(props)\n\n return props.children(data) as React.JSX.Element\n}\n"],"names":["React","defer","TSR_DEFERRED_PROMISE","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AASO,SAAS,WAAc,EAAE,SAAS,YAAgC;AAEvE,MAAIA,iBAAM,KAAK;AACb,UAAM,OAAOA,iBAAM,IAAI,QAAQ;AAC/B,WAAO;AAAA,EACT;AACA,QAAM,UAAUC,WAAAA,MAAM,QAAQ;AAE9B,MAAI,QAAQC,WAAAA,oBAAoB,EAAE,WAAW,WAAW;AACtD,UAAM;AAAA,EACR;AAEA,MAAI,QAAQA,WAAAA,oBAAoB,EAAE,WAAW,SAAS;AACpD,UAAM,QAAQA,WAAAA,oBAAoB,EAAE;AAAA,EACtC;AAEA,SAAO,QAAQA,WAAAA,oBAAoB,EAAE;AACvC;AAMO,SAAS,MACd,OAIA;AACA,QAAM,QAAQC,2BAAAA,IAAC,YAAA,EAAY,GAAG,MAAA,CAAO;AACrC,MAAI,MAAM,UAAU;AAClB,0CAAQH,iBAAM,UAAN,EAAe,UAAU,MAAM,UAAW,UAAA,OAAM;AAAA,EAC1D;AACA,SAAO;AACT;AAEA,SAAS,WACP,OAImB;AACnB,QAAM,OAAO,WAAW,KAAK;AAE7B,SAAO,MAAM,SAAS,IAAI;AAC5B;;;"}
1
+ {"version":3,"file":"awaited.cjs","sources":["../../src/awaited.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { TSR_DEFERRED_PROMISE, defer } from '@tanstack/router-core'\nimport { reactUse } from './utils'\n\nexport type AwaitOptions<T> = {\n promise: Promise<T>\n}\n\n/** Suspend until a deferred promise resolves or rejects and return its data. */\nexport function useAwaited<T>({ promise: _promise }: AwaitOptions<T>): T {\n if (reactUse) {\n const data = reactUse(_promise)\n return data\n }\n const promise = defer(_promise)\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'pending') {\n throw promise\n }\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'error') {\n throw promise[TSR_DEFERRED_PROMISE].error\n }\n\n return promise[TSR_DEFERRED_PROMISE].data\n}\n\n/**\n * Component that suspends on a deferred promise and renders its child with\n * the resolved value. Optionally provides a Suspense fallback.\n */\nexport function Await<T>(\n props: AwaitOptions<T> & {\n fallback?: React.ReactNode\n children: (result: T) => React.ReactNode\n },\n) {\n const inner = <AwaitInner {...props} />\n if (props.fallback) {\n return <React.Suspense fallback={props.fallback}>{inner}</React.Suspense>\n }\n return inner\n}\n\nfunction AwaitInner<T>(\n props: AwaitOptions<T> & {\n fallback?: React.ReactNode\n children: (result: T) => React.ReactNode\n },\n): React.JSX.Element {\n const data = useAwaited(props)\n\n return props.children(data) as React.JSX.Element\n}\n"],"names":["reactUse","defer","TSR_DEFERRED_PROMISE","jsx","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAUO,SAAS,WAAc,EAAE,SAAS,YAAgC;AACvE,MAAIA,gBAAU;AACZ,UAAM,OAAOA,MAAAA,SAAS,QAAQ;AAC9B,WAAO;AAAA,EACT;AACA,QAAM,UAAUC,WAAAA,MAAM,QAAQ;AAE9B,MAAI,QAAQC,WAAAA,oBAAoB,EAAE,WAAW,WAAW;AACtD,UAAM;AAAA,EACR;AAEA,MAAI,QAAQA,WAAAA,oBAAoB,EAAE,WAAW,SAAS;AACpD,UAAM,QAAQA,WAAAA,oBAAoB,EAAE;AAAA,EACtC;AAEA,SAAO,QAAQA,WAAAA,oBAAoB,EAAE;AACvC;AAMO,SAAS,MACd,OAIA;AACA,QAAM,QAAQC,2BAAAA,IAAC,YAAA,EAAY,GAAG,MAAA,CAAO;AACrC,MAAI,MAAM,UAAU;AAClB,0CAAQC,iBAAM,UAAN,EAAe,UAAU,MAAM,UAAW,UAAA,OAAM;AAAA,EAC1D;AACA,SAAO;AACT;AAEA,SAAS,WACP,OAImB;AACnB,QAAM,OAAO,WAAW,KAAK;AAE7B,SAAO,MAAM,SAAS,IAAI;AAC5B;;;"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const React = require("react");
4
4
  const routerCore = require("@tanstack/router-core");
5
+ const utils = require("./utils.cjs");
5
6
  function _interopNamespaceDefault(e) {
6
7
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
7
8
  if (e) {
@@ -54,8 +55,8 @@ function lazyRouteComponent(importer, exportName) {
54
55
  throw error;
55
56
  }
56
57
  if (!comp) {
57
- if (React__namespace.use) {
58
- React__namespace.use(load());
58
+ if (utils.reactUse) {
59
+ utils.reactUse(load());
59
60
  } else {
60
61
  throw load();
61
62
  }
@@ -1 +1 @@
1
- {"version":3,"file":"lazyRouteComponent.cjs","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { isModuleNotFoundError } from '@tanstack/router-core'\nimport type { AsyncRouteComponent } from './route'\n\n/**\n * Wrap a dynamic import to create a route component that supports\n * `.preload()` and friendly reload-on-module-missing behavior.\n *\n * @param importer Function returning a module promise\n * @param exportName Named export to use (default: `default`)\n * @returns A lazy route component compatible with TanStack Router\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/lazyRouteComponentFunction\n */\nexport function lazyRouteComponent<\n T extends Record<string, any>,\n TKey extends keyof T = 'default',\n>(\n importer: () => Promise<T>,\n exportName?: TKey,\n): T[TKey] extends (props: infer TProps) => any\n ? AsyncRouteComponent<TProps>\n : never {\n let loadPromise: Promise<any> | undefined\n let comp: T[TKey] | T['default']\n let error: any\n let reload: boolean\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer()\n .then((res) => {\n loadPromise = undefined\n comp = res[exportName ?? 'default']\n })\n .catch((err) => {\n // We don't want an error thrown from preload in this case, because\n // there's nothing we want to do about module not found during preload.\n // Record the error, the rest is handled during the render path.\n error = err\n // If the load fails due to module not found, it may mean a new version of\n // the build was deployed and the user's browser is still using an old version.\n // If this happens, the old version in the user's browser would have an outdated\n // URL to the lazy module.\n // In that case, we want to attempt one window refresh to get the latest.\n if (isModuleNotFoundError(error)) {\n if (\n error instanceof Error &&\n typeof window !== 'undefined' &&\n typeof sessionStorage !== 'undefined'\n ) {\n // Again, we want to reload one time on module not found error and not enter\n // a reload loop if there is some other issue besides an old deploy.\n // That's why we store our reload attempt in sessionStorage.\n // Use error.message as key because it contains the module path that failed.\n const storageKey = `tanstack_router_reload:${error.message}`\n if (!sessionStorage.getItem(storageKey)) {\n sessionStorage.setItem(storageKey, '1')\n reload = true\n }\n }\n }\n })\n }\n\n return loadPromise\n }\n\n const lazyComp = function Lazy(props: any) {\n // Now that we're out of preload and into actual render path,\n if (reload) {\n // If it was a module loading error,\n // throw eternal suspense while we wait for window to reload\n window.location.reload()\n throw new Promise(() => {})\n }\n if (error) {\n // Otherwise, just throw the error\n throw error\n }\n\n if (!comp) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (React.use) {\n React.use(load())\n } else {\n throw load()\n }\n }\n\n return React.createElement(comp, props)\n }\n\n ;(lazyComp as any).preload = load\n\n return lazyComp as any\n}\n"],"names":["isModuleNotFoundError","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAaO,SAAS,mBAId,UACA,YAGQ;AACR,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AAEJ,QAAM,OAAO,MAAM;AACjB,QAAI,CAAC,aAAa;AAChB,oBAAc,SAAA,EACX,KAAK,CAAC,QAAQ;AACb,sBAAc;AACd,eAAO,IAAI,cAAc,SAAS;AAAA,MACpC,CAAC,EACA,MAAM,CAAC,QAAQ;AAId,gBAAQ;AAMR,YAAIA,WAAAA,sBAAsB,KAAK,GAAG;AAChC,cACE,iBAAiB,SACjB,OAAO,WAAW,eAClB,OAAO,mBAAmB,aAC1B;AAKA,kBAAM,aAAa,0BAA0B,MAAM,OAAO;AAC1D,gBAAI,CAAC,eAAe,QAAQ,UAAU,GAAG;AACvC,6BAAe,QAAQ,YAAY,GAAG;AACtC,uBAAS;AAAA,YACX;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACL;AAEA,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,SAAS,KAAK,OAAY;AAEzC,QAAI,QAAQ;AAGV,aAAO,SAAS,OAAA;AAChB,YAAM,IAAI,QAAQ,MAAM;AAAA,MAAC,CAAC;AAAA,IAC5B;AACA,QAAI,OAAO;AAET,YAAM;AAAA,IACR;AAEA,QAAI,CAAC,MAAM;AAET,UAAIC,iBAAM,KAAK;AACbA,yBAAM,IAAI,MAAM;AAAA,MAClB,OAAO;AACL,cAAM,KAAA;AAAA,MACR;AAAA,IACF;AAEA,WAAOA,iBAAM,cAAc,MAAM,KAAK;AAAA,EACxC;AAEE,WAAiB,UAAU;AAE7B,SAAO;AACT;;"}
1
+ {"version":3,"file":"lazyRouteComponent.cjs","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { isModuleNotFoundError } from '@tanstack/router-core'\nimport { reactUse } from './utils'\nimport type { AsyncRouteComponent } from './route'\n\n/**\n * Wrap a dynamic import to create a route component that supports\n * `.preload()` and friendly reload-on-module-missing behavior.\n *\n * @param importer Function returning a module promise\n * @param exportName Named export to use (default: `default`)\n * @returns A lazy route component compatible with TanStack Router\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/lazyRouteComponentFunction\n */\nexport function lazyRouteComponent<\n T extends Record<string, any>,\n TKey extends keyof T = 'default',\n>(\n importer: () => Promise<T>,\n exportName?: TKey,\n): T[TKey] extends (props: infer TProps) => any\n ? AsyncRouteComponent<TProps>\n : never {\n let loadPromise: Promise<any> | undefined\n let comp: T[TKey] | T['default']\n let error: any\n let reload: boolean\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer()\n .then((res) => {\n loadPromise = undefined\n comp = res[exportName ?? 'default']\n })\n .catch((err) => {\n // We don't want an error thrown from preload in this case, because\n // there's nothing we want to do about module not found during preload.\n // Record the error, the rest is handled during the render path.\n error = err\n // If the load fails due to module not found, it may mean a new version of\n // the build was deployed and the user's browser is still using an old version.\n // If this happens, the old version in the user's browser would have an outdated\n // URL to the lazy module.\n // In that case, we want to attempt one window refresh to get the latest.\n if (isModuleNotFoundError(error)) {\n if (\n error instanceof Error &&\n typeof window !== 'undefined' &&\n typeof sessionStorage !== 'undefined'\n ) {\n // Again, we want to reload one time on module not found error and not enter\n // a reload loop if there is some other issue besides an old deploy.\n // That's why we store our reload attempt in sessionStorage.\n // Use error.message as key because it contains the module path that failed.\n const storageKey = `tanstack_router_reload:${error.message}`\n if (!sessionStorage.getItem(storageKey)) {\n sessionStorage.setItem(storageKey, '1')\n reload = true\n }\n }\n }\n })\n }\n\n return loadPromise\n }\n\n const lazyComp = function Lazy(props: any) {\n // Now that we're out of preload and into actual render path,\n if (reload) {\n // If it was a module loading error,\n // throw eternal suspense while we wait for window to reload\n window.location.reload()\n throw new Promise(() => {})\n }\n if (error) {\n // Otherwise, just throw the error\n throw error\n }\n\n if (!comp) {\n if (reactUse) {\n reactUse(load())\n } else {\n throw load()\n }\n }\n\n return React.createElement(comp, props)\n }\n\n ;(lazyComp as any).preload = load\n\n return lazyComp as any\n}\n"],"names":["isModuleNotFoundError","reactUse","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAcO,SAAS,mBAId,UACA,YAGQ;AACR,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AAEJ,QAAM,OAAO,MAAM;AACjB,QAAI,CAAC,aAAa;AAChB,oBAAc,SAAA,EACX,KAAK,CAAC,QAAQ;AACb,sBAAc;AACd,eAAO,IAAI,cAAc,SAAS;AAAA,MACpC,CAAC,EACA,MAAM,CAAC,QAAQ;AAId,gBAAQ;AAMR,YAAIA,WAAAA,sBAAsB,KAAK,GAAG;AAChC,cACE,iBAAiB,SACjB,OAAO,WAAW,eAClB,OAAO,mBAAmB,aAC1B;AAKA,kBAAM,aAAa,0BAA0B,MAAM,OAAO;AAC1D,gBAAI,CAAC,eAAe,QAAQ,UAAU,GAAG;AACvC,6BAAe,QAAQ,YAAY,GAAG;AACtC,uBAAS;AAAA,YACX;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACL;AAEA,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,SAAS,KAAK,OAAY;AAEzC,QAAI,QAAQ;AAGV,aAAO,SAAS,OAAA;AAChB,YAAM,IAAI,QAAQ,MAAM;AAAA,MAAC,CAAC;AAAA,IAC5B;AACA,QAAI,OAAO;AAET,YAAM;AAAA,IACR;AAEA,QAAI,CAAC,MAAM;AACT,UAAIC,gBAAU;AACZA,cAAAA,SAAS,MAAM;AAAA,MACjB,OAAO;AACL,cAAM,KAAA;AAAA,MACR;AAAA,IACF;AAEA,WAAOC,iBAAM,cAAc,MAAM,KAAK;AAAA,EACxC;AAEE,WAAiB,UAAU;AAE7B,SAAO;AACT;;"}
@@ -18,6 +18,8 @@ function _interopNamespaceDefault(e) {
18
18
  return Object.freeze(n);
19
19
  }
20
20
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
21
+ const REACT_USE = "use";
22
+ const reactUse = React__namespace[REACT_USE];
21
23
  function useStableCallback(fn) {
22
24
  const fnRef = React__namespace.useRef(fn);
23
25
  fnRef.current = fn;
@@ -58,6 +60,7 @@ function useForwardedRef(ref) {
58
60
  React__namespace.useImperativeHandle(ref, () => innerRef.current, []);
59
61
  return innerRef;
60
62
  }
63
+ exports.reactUse = reactUse;
61
64
  exports.useForwardedRef = useForwardedRef;
62
65
  exports.useIntersectionObserver = useIntersectionObserver;
63
66
  exports.useLayoutEffect = useLayoutEffect;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\n\nexport function useStableCallback<T extends (...args: Array<any>) => any>(\n fn: T,\n): T {\n const fnRef = React.useRef(fn)\n fnRef.current = fn\n\n const ref = React.useRef((...args: Array<any>) => fnRef.current(...args))\n return ref.current as T\n}\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\n/**\n * Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3\n */\nexport function usePrevious<T>(value: T): T | null {\n // initialise the ref with previous and current values\n const ref = React.useRef<{ value: T; prev: T | null }>({\n value: value,\n prev: null,\n })\n\n const current = ref.current.value\n\n // if the value passed into hook doesn't match what we store as \"current\"\n // move the \"current\" to the \"previous\"\n // and store the passed value as \"current\"\n if (value !== current) {\n ref.current = {\n value: value,\n prev: current,\n }\n }\n\n // return the previous value only\n return ref.current.prev\n}\n\n/**\n * React hook to wrap `IntersectionObserver`.\n *\n * This hook will create an `IntersectionObserver` and observe the ref passed to it.\n *\n * When the intersection changes, the callback will be called with the `IntersectionObserverEntry`.\n *\n * @param ref - The ref to observe\n * @param intersectionObserverOptions - The options to pass to the IntersectionObserver\n * @param options - The options to pass to the hook\n * @param callback - The callback to call when the intersection changes\n * @returns The IntersectionObserver instance\n * @example\n * ```tsx\n * const MyComponent = () => {\n * const ref = React.useRef<HTMLDivElement>(null)\n * useIntersectionObserver(\n * ref,\n * (entry) => { doSomething(entry) },\n * { rootMargin: '10px' },\n * { disabled: false }\n * )\n * return <div ref={ref} />\n * ```\n */\nexport function useIntersectionObserver<T extends Element>(\n ref: React.RefObject<T | null>,\n callback: (entry: IntersectionObserverEntry | undefined) => void,\n intersectionObserverOptions: IntersectionObserverInit = {},\n options: { disabled?: boolean } = {},\n) {\n React.useEffect(() => {\n if (\n !ref.current ||\n options.disabled ||\n typeof IntersectionObserver !== 'function'\n ) {\n return\n }\n\n const observer = new IntersectionObserver(([entry]) => {\n callback(entry)\n }, intersectionObserverOptions)\n\n observer.observe(ref.current)\n\n return () => {\n observer.disconnect()\n }\n }, [callback, intersectionObserverOptions, options.disabled, ref])\n}\n\n/**\n * React hook to take a `React.ForwardedRef` and returns a `ref` that can be used on a DOM element.\n *\n * @param ref - The forwarded ref\n * @returns The inner ref returned by `useRef`\n * @example\n * ```tsx\n * const MyComponent = React.forwardRef((props, ref) => {\n * const innerRef = useForwardedRef(ref)\n * return <div ref={innerRef} />\n * })\n * ```\n */\nexport function useForwardedRef<T>(ref?: React.ForwardedRef<T>) {\n const innerRef = React.useRef<T>(null)\n React.useImperativeHandle(ref, () => innerRef.current!, [])\n return innerRef\n}\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEO,SAAS,kBACd,IACG;AACH,QAAM,QAAQA,iBAAM,OAAO,EAAE;AAC7B,QAAM,UAAU;AAEhB,QAAM,MAAMA,iBAAM,OAAO,IAAI,SAAqB,MAAM,QAAQ,GAAG,IAAI,CAAC;AACxE,SAAO,IAAI;AACb;AAEO,MAAM,kBACX,OAAO,WAAW,cAAcA,iBAAM,kBAAkBA,iBAAM;AAKzD,SAAS,YAAe,OAAoB;AAEjD,QAAM,MAAMA,iBAAM,OAAqC;AAAA,IACrD;AAAA,IACA,MAAM;AAAA,EAAA,CACP;AAED,QAAM,UAAU,IAAI,QAAQ;AAK5B,MAAI,UAAU,SAAS;AACrB,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,MAAM;AAAA,IAAA;AAAA,EAEV;AAGA,SAAO,IAAI,QAAQ;AACrB;AA2BO,SAAS,wBACd,KACA,UACA,8BAAwD,CAAA,GACxD,UAAkC,IAClC;AACAA,mBAAM,UAAU,MAAM;AACpB,QACE,CAAC,IAAI,WACL,QAAQ,YACR,OAAO,yBAAyB,YAChC;AACA;AAAA,IACF;AAEA,UAAM,WAAW,IAAI,qBAAqB,CAAC,CAAC,KAAK,MAAM;AACrD,eAAS,KAAK;AAAA,IAChB,GAAG,2BAA2B;AAE9B,aAAS,QAAQ,IAAI,OAAO;AAE5B,WAAO,MAAM;AACX,eAAS,WAAA;AAAA,IACX;AAAA,EACF,GAAG,CAAC,UAAU,6BAA6B,QAAQ,UAAU,GAAG,CAAC;AACnE;AAeO,SAAS,gBAAmB,KAA6B;AAC9D,QAAM,WAAWA,iBAAM,OAAU,IAAI;AACrCA,mBAAM,oBAAoB,KAAK,MAAM,SAAS,SAAU,CAAA,CAAE;AAC1D,SAAO;AACT;;;;;;"}
1
+ {"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\n\n// Safe version of React.use() that will not cause compilation errors against\n// React 18 with Webpack, which statically analyzes imports and fails when it\n// sees React.use referenced (since 'use' is not exported from React 18).\n// This uses a dynamic string lookup to avoid the static analysis.\nconst REACT_USE = 'use'\n\n/**\n * React.use if available (React 19+), undefined otherwise.\n * Use dynamic lookup to avoid Webpack compilation errors with React 18.\n */\nexport const reactUse:\n | (<T>(usable: Promise<T> | React.Context<T>) => T)\n | undefined = (React as any)[REACT_USE]\n\nexport function useStableCallback<T extends (...args: Array<any>) => any>(\n fn: T,\n): T {\n const fnRef = React.useRef(fn)\n fnRef.current = fn\n\n const ref = React.useRef((...args: Array<any>) => fnRef.current(...args))\n return ref.current as T\n}\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\n/**\n * Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3\n */\nexport function usePrevious<T>(value: T): T | null {\n // initialise the ref with previous and current values\n const ref = React.useRef<{ value: T; prev: T | null }>({\n value: value,\n prev: null,\n })\n\n const current = ref.current.value\n\n // if the value passed into hook doesn't match what we store as \"current\"\n // move the \"current\" to the \"previous\"\n // and store the passed value as \"current\"\n if (value !== current) {\n ref.current = {\n value: value,\n prev: current,\n }\n }\n\n // return the previous value only\n return ref.current.prev\n}\n\n/**\n * React hook to wrap `IntersectionObserver`.\n *\n * This hook will create an `IntersectionObserver` and observe the ref passed to it.\n *\n * When the intersection changes, the callback will be called with the `IntersectionObserverEntry`.\n *\n * @param ref - The ref to observe\n * @param intersectionObserverOptions - The options to pass to the IntersectionObserver\n * @param options - The options to pass to the hook\n * @param callback - The callback to call when the intersection changes\n * @returns The IntersectionObserver instance\n * @example\n * ```tsx\n * const MyComponent = () => {\n * const ref = React.useRef<HTMLDivElement>(null)\n * useIntersectionObserver(\n * ref,\n * (entry) => { doSomething(entry) },\n * { rootMargin: '10px' },\n * { disabled: false }\n * )\n * return <div ref={ref} />\n * ```\n */\nexport function useIntersectionObserver<T extends Element>(\n ref: React.RefObject<T | null>,\n callback: (entry: IntersectionObserverEntry | undefined) => void,\n intersectionObserverOptions: IntersectionObserverInit = {},\n options: { disabled?: boolean } = {},\n) {\n React.useEffect(() => {\n if (\n !ref.current ||\n options.disabled ||\n typeof IntersectionObserver !== 'function'\n ) {\n return\n }\n\n const observer = new IntersectionObserver(([entry]) => {\n callback(entry)\n }, intersectionObserverOptions)\n\n observer.observe(ref.current)\n\n return () => {\n observer.disconnect()\n }\n }, [callback, intersectionObserverOptions, options.disabled, ref])\n}\n\n/**\n * React hook to take a `React.ForwardedRef` and returns a `ref` that can be used on a DOM element.\n *\n * @param ref - The forwarded ref\n * @returns The inner ref returned by `useRef`\n * @example\n * ```tsx\n * const MyComponent = React.forwardRef((props, ref) => {\n * const innerRef = useForwardedRef(ref)\n * return <div ref={innerRef} />\n * })\n * ```\n */\nexport function useForwardedRef<T>(ref?: React.ForwardedRef<T>) {\n const innerRef = React.useRef<T>(null)\n React.useImperativeHandle(ref, () => innerRef.current!, [])\n return innerRef\n}\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;AAMA,MAAM,YAAY;AAMX,MAAM,WAEIA,iBAAc,SAAS;AAEjC,SAAS,kBACd,IACG;AACH,QAAM,QAAQA,iBAAM,OAAO,EAAE;AAC7B,QAAM,UAAU;AAEhB,QAAM,MAAMA,iBAAM,OAAO,IAAI,SAAqB,MAAM,QAAQ,GAAG,IAAI,CAAC;AACxE,SAAO,IAAI;AACb;AAEO,MAAM,kBACX,OAAO,WAAW,cAAcA,iBAAM,kBAAkBA,iBAAM;AAKzD,SAAS,YAAe,OAAoB;AAEjD,QAAM,MAAMA,iBAAM,OAAqC;AAAA,IACrD;AAAA,IACA,MAAM;AAAA,EAAA,CACP;AAED,QAAM,UAAU,IAAI,QAAQ;AAK5B,MAAI,UAAU,SAAS;AACrB,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,MAAM;AAAA,IAAA;AAAA,EAEV;AAGA,SAAO,IAAI,QAAQ;AACrB;AA2BO,SAAS,wBACd,KACA,UACA,8BAAwD,CAAA,GACxD,UAAkC,IAClC;AACAA,mBAAM,UAAU,MAAM;AACpB,QACE,CAAC,IAAI,WACL,QAAQ,YACR,OAAO,yBAAyB,YAChC;AACA;AAAA,IACF;AAEA,UAAM,WAAW,IAAI,qBAAqB,CAAC,CAAC,KAAK,MAAM;AACrD,eAAS,KAAK;AAAA,IAChB,GAAG,2BAA2B;AAE9B,aAAS,QAAQ,IAAI,OAAO;AAE5B,WAAO,MAAM;AACX,eAAS,WAAA;AAAA,IACX;AAAA,EACF,GAAG,CAAC,UAAU,6BAA6B,QAAQ,UAAU,GAAG,CAAC;AACnE;AAeO,SAAS,gBAAmB,KAA6B;AAC9D,QAAM,WAAWA,iBAAM,OAAU,IAAI;AACrCA,mBAAM,oBAAoB,KAAK,MAAM,SAAS,SAAU,CAAA,CAAE;AAC1D,SAAO;AACT;;;;;;;"}
@@ -1,4 +1,9 @@
1
1
  import * as React from 'react';
2
+ /**
3
+ * React.use if available (React 19+), undefined otherwise.
4
+ * Use dynamic lookup to avoid Webpack compilation errors with React 18.
5
+ */
6
+ export declare const reactUse: (<T>(usable: Promise<T> | React.Context<T>) => T) | undefined;
2
7
  export declare function useStableCallback<T extends (...args: Array<any>) => any>(fn: T): T;
3
8
  export declare const useLayoutEffect: typeof React.useLayoutEffect;
4
9
  /**
@@ -1,9 +1,10 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
3
  import { defer, TSR_DEFERRED_PROMISE } from "@tanstack/router-core";
4
+ import { reactUse } from "./utils.js";
4
5
  function useAwaited({ promise: _promise }) {
5
- if (React.use) {
6
- const data = React.use(_promise);
6
+ if (reactUse) {
7
+ const data = reactUse(_promise);
7
8
  return data;
8
9
  }
9
10
  const promise = defer(_promise);
@@ -1 +1 @@
1
- {"version":3,"file":"awaited.js","sources":["../../src/awaited.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { TSR_DEFERRED_PROMISE, defer } from '@tanstack/router-core'\n\nexport type AwaitOptions<T> = {\n promise: Promise<T>\n}\n\n/** Suspend until a deferred promise resolves or rejects and return its data. */\nexport function useAwaited<T>({ promise: _promise }: AwaitOptions<T>): T {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (React.use) {\n const data = React.use(_promise)\n return data\n }\n const promise = defer(_promise)\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'pending') {\n throw promise\n }\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'error') {\n throw promise[TSR_DEFERRED_PROMISE].error\n }\n\n return promise[TSR_DEFERRED_PROMISE].data\n}\n\n/**\n * Component that suspends on a deferred promise and renders its child with\n * the resolved value. Optionally provides a Suspense fallback.\n */\nexport function Await<T>(\n props: AwaitOptions<T> & {\n fallback?: React.ReactNode\n children: (result: T) => React.ReactNode\n },\n) {\n const inner = <AwaitInner {...props} />\n if (props.fallback) {\n return <React.Suspense fallback={props.fallback}>{inner}</React.Suspense>\n }\n return inner\n}\n\nfunction AwaitInner<T>(\n props: AwaitOptions<T> & {\n fallback?: React.ReactNode\n children: (result: T) => React.ReactNode\n },\n): React.JSX.Element {\n const data = useAwaited(props)\n\n return props.children(data) as React.JSX.Element\n}\n"],"names":[],"mappings":";;;AASO,SAAS,WAAc,EAAE,SAAS,YAAgC;AAEvE,MAAI,MAAM,KAAK;AACb,UAAM,OAAO,MAAM,IAAI,QAAQ;AAC/B,WAAO;AAAA,EACT;AACA,QAAM,UAAU,MAAM,QAAQ;AAE9B,MAAI,QAAQ,oBAAoB,EAAE,WAAW,WAAW;AACtD,UAAM;AAAA,EACR;AAEA,MAAI,QAAQ,oBAAoB,EAAE,WAAW,SAAS;AACpD,UAAM,QAAQ,oBAAoB,EAAE;AAAA,EACtC;AAEA,SAAO,QAAQ,oBAAoB,EAAE;AACvC;AAMO,SAAS,MACd,OAIA;AACA,QAAM,QAAQ,oBAAC,YAAA,EAAY,GAAG,MAAA,CAAO;AACrC,MAAI,MAAM,UAAU;AAClB,+BAAQ,MAAM,UAAN,EAAe,UAAU,MAAM,UAAW,UAAA,OAAM;AAAA,EAC1D;AACA,SAAO;AACT;AAEA,SAAS,WACP,OAImB;AACnB,QAAM,OAAO,WAAW,KAAK;AAE7B,SAAO,MAAM,SAAS,IAAI;AAC5B;"}
1
+ {"version":3,"file":"awaited.js","sources":["../../src/awaited.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { TSR_DEFERRED_PROMISE, defer } from '@tanstack/router-core'\nimport { reactUse } from './utils'\n\nexport type AwaitOptions<T> = {\n promise: Promise<T>\n}\n\n/** Suspend until a deferred promise resolves or rejects and return its data. */\nexport function useAwaited<T>({ promise: _promise }: AwaitOptions<T>): T {\n if (reactUse) {\n const data = reactUse(_promise)\n return data\n }\n const promise = defer(_promise)\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'pending') {\n throw promise\n }\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'error') {\n throw promise[TSR_DEFERRED_PROMISE].error\n }\n\n return promise[TSR_DEFERRED_PROMISE].data\n}\n\n/**\n * Component that suspends on a deferred promise and renders its child with\n * the resolved value. Optionally provides a Suspense fallback.\n */\nexport function Await<T>(\n props: AwaitOptions<T> & {\n fallback?: React.ReactNode\n children: (result: T) => React.ReactNode\n },\n) {\n const inner = <AwaitInner {...props} />\n if (props.fallback) {\n return <React.Suspense fallback={props.fallback}>{inner}</React.Suspense>\n }\n return inner\n}\n\nfunction AwaitInner<T>(\n props: AwaitOptions<T> & {\n fallback?: React.ReactNode\n children: (result: T) => React.ReactNode\n },\n): React.JSX.Element {\n const data = useAwaited(props)\n\n return props.children(data) as React.JSX.Element\n}\n"],"names":[],"mappings":";;;;AAUO,SAAS,WAAc,EAAE,SAAS,YAAgC;AACvE,MAAI,UAAU;AACZ,UAAM,OAAO,SAAS,QAAQ;AAC9B,WAAO;AAAA,EACT;AACA,QAAM,UAAU,MAAM,QAAQ;AAE9B,MAAI,QAAQ,oBAAoB,EAAE,WAAW,WAAW;AACtD,UAAM;AAAA,EACR;AAEA,MAAI,QAAQ,oBAAoB,EAAE,WAAW,SAAS;AACpD,UAAM,QAAQ,oBAAoB,EAAE;AAAA,EACtC;AAEA,SAAO,QAAQ,oBAAoB,EAAE;AACvC;AAMO,SAAS,MACd,OAIA;AACA,QAAM,QAAQ,oBAAC,YAAA,EAAY,GAAG,MAAA,CAAO;AACrC,MAAI,MAAM,UAAU;AAClB,+BAAQ,MAAM,UAAN,EAAe,UAAU,MAAM,UAAW,UAAA,OAAM;AAAA,EAC1D;AACA,SAAO;AACT;AAEA,SAAS,WACP,OAImB;AACnB,QAAM,OAAO,WAAW,KAAK;AAE7B,SAAO,MAAM,SAAS,IAAI;AAC5B;"}
@@ -1,5 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { isModuleNotFoundError } from "@tanstack/router-core";
3
+ import { reactUse } from "./utils.js";
3
4
  function lazyRouteComponent(importer, exportName) {
4
5
  let loadPromise;
5
6
  let comp;
@@ -35,8 +36,8 @@ function lazyRouteComponent(importer, exportName) {
35
36
  throw error;
36
37
  }
37
38
  if (!comp) {
38
- if (React.use) {
39
- React.use(load());
39
+ if (reactUse) {
40
+ reactUse(load());
40
41
  } else {
41
42
  throw load();
42
43
  }
@@ -1 +1 @@
1
- {"version":3,"file":"lazyRouteComponent.js","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { isModuleNotFoundError } from '@tanstack/router-core'\nimport type { AsyncRouteComponent } from './route'\n\n/**\n * Wrap a dynamic import to create a route component that supports\n * `.preload()` and friendly reload-on-module-missing behavior.\n *\n * @param importer Function returning a module promise\n * @param exportName Named export to use (default: `default`)\n * @returns A lazy route component compatible with TanStack Router\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/lazyRouteComponentFunction\n */\nexport function lazyRouteComponent<\n T extends Record<string, any>,\n TKey extends keyof T = 'default',\n>(\n importer: () => Promise<T>,\n exportName?: TKey,\n): T[TKey] extends (props: infer TProps) => any\n ? AsyncRouteComponent<TProps>\n : never {\n let loadPromise: Promise<any> | undefined\n let comp: T[TKey] | T['default']\n let error: any\n let reload: boolean\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer()\n .then((res) => {\n loadPromise = undefined\n comp = res[exportName ?? 'default']\n })\n .catch((err) => {\n // We don't want an error thrown from preload in this case, because\n // there's nothing we want to do about module not found during preload.\n // Record the error, the rest is handled during the render path.\n error = err\n // If the load fails due to module not found, it may mean a new version of\n // the build was deployed and the user's browser is still using an old version.\n // If this happens, the old version in the user's browser would have an outdated\n // URL to the lazy module.\n // In that case, we want to attempt one window refresh to get the latest.\n if (isModuleNotFoundError(error)) {\n if (\n error instanceof Error &&\n typeof window !== 'undefined' &&\n typeof sessionStorage !== 'undefined'\n ) {\n // Again, we want to reload one time on module not found error and not enter\n // a reload loop if there is some other issue besides an old deploy.\n // That's why we store our reload attempt in sessionStorage.\n // Use error.message as key because it contains the module path that failed.\n const storageKey = `tanstack_router_reload:${error.message}`\n if (!sessionStorage.getItem(storageKey)) {\n sessionStorage.setItem(storageKey, '1')\n reload = true\n }\n }\n }\n })\n }\n\n return loadPromise\n }\n\n const lazyComp = function Lazy(props: any) {\n // Now that we're out of preload and into actual render path,\n if (reload) {\n // If it was a module loading error,\n // throw eternal suspense while we wait for window to reload\n window.location.reload()\n throw new Promise(() => {})\n }\n if (error) {\n // Otherwise, just throw the error\n throw error\n }\n\n if (!comp) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (React.use) {\n React.use(load())\n } else {\n throw load()\n }\n }\n\n return React.createElement(comp, props)\n }\n\n ;(lazyComp as any).preload = load\n\n return lazyComp as any\n}\n"],"names":[],"mappings":";;AAaO,SAAS,mBAId,UACA,YAGQ;AACR,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AAEJ,QAAM,OAAO,MAAM;AACjB,QAAI,CAAC,aAAa;AAChB,oBAAc,SAAA,EACX,KAAK,CAAC,QAAQ;AACb,sBAAc;AACd,eAAO,IAAI,cAAc,SAAS;AAAA,MACpC,CAAC,EACA,MAAM,CAAC,QAAQ;AAId,gBAAQ;AAMR,YAAI,sBAAsB,KAAK,GAAG;AAChC,cACE,iBAAiB,SACjB,OAAO,WAAW,eAClB,OAAO,mBAAmB,aAC1B;AAKA,kBAAM,aAAa,0BAA0B,MAAM,OAAO;AAC1D,gBAAI,CAAC,eAAe,QAAQ,UAAU,GAAG;AACvC,6BAAe,QAAQ,YAAY,GAAG;AACtC,uBAAS;AAAA,YACX;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACL;AAEA,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,SAAS,KAAK,OAAY;AAEzC,QAAI,QAAQ;AAGV,aAAO,SAAS,OAAA;AAChB,YAAM,IAAI,QAAQ,MAAM;AAAA,MAAC,CAAC;AAAA,IAC5B;AACA,QAAI,OAAO;AAET,YAAM;AAAA,IACR;AAEA,QAAI,CAAC,MAAM;AAET,UAAI,MAAM,KAAK;AACb,cAAM,IAAI,MAAM;AAAA,MAClB,OAAO;AACL,cAAM,KAAA;AAAA,MACR;AAAA,IACF;AAEA,WAAO,MAAM,cAAc,MAAM,KAAK;AAAA,EACxC;AAEE,WAAiB,UAAU;AAE7B,SAAO;AACT;"}
1
+ {"version":3,"file":"lazyRouteComponent.js","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { isModuleNotFoundError } from '@tanstack/router-core'\nimport { reactUse } from './utils'\nimport type { AsyncRouteComponent } from './route'\n\n/**\n * Wrap a dynamic import to create a route component that supports\n * `.preload()` and friendly reload-on-module-missing behavior.\n *\n * @param importer Function returning a module promise\n * @param exportName Named export to use (default: `default`)\n * @returns A lazy route component compatible with TanStack Router\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/lazyRouteComponentFunction\n */\nexport function lazyRouteComponent<\n T extends Record<string, any>,\n TKey extends keyof T = 'default',\n>(\n importer: () => Promise<T>,\n exportName?: TKey,\n): T[TKey] extends (props: infer TProps) => any\n ? AsyncRouteComponent<TProps>\n : never {\n let loadPromise: Promise<any> | undefined\n let comp: T[TKey] | T['default']\n let error: any\n let reload: boolean\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer()\n .then((res) => {\n loadPromise = undefined\n comp = res[exportName ?? 'default']\n })\n .catch((err) => {\n // We don't want an error thrown from preload in this case, because\n // there's nothing we want to do about module not found during preload.\n // Record the error, the rest is handled during the render path.\n error = err\n // If the load fails due to module not found, it may mean a new version of\n // the build was deployed and the user's browser is still using an old version.\n // If this happens, the old version in the user's browser would have an outdated\n // URL to the lazy module.\n // In that case, we want to attempt one window refresh to get the latest.\n if (isModuleNotFoundError(error)) {\n if (\n error instanceof Error &&\n typeof window !== 'undefined' &&\n typeof sessionStorage !== 'undefined'\n ) {\n // Again, we want to reload one time on module not found error and not enter\n // a reload loop if there is some other issue besides an old deploy.\n // That's why we store our reload attempt in sessionStorage.\n // Use error.message as key because it contains the module path that failed.\n const storageKey = `tanstack_router_reload:${error.message}`\n if (!sessionStorage.getItem(storageKey)) {\n sessionStorage.setItem(storageKey, '1')\n reload = true\n }\n }\n }\n })\n }\n\n return loadPromise\n }\n\n const lazyComp = function Lazy(props: any) {\n // Now that we're out of preload and into actual render path,\n if (reload) {\n // If it was a module loading error,\n // throw eternal suspense while we wait for window to reload\n window.location.reload()\n throw new Promise(() => {})\n }\n if (error) {\n // Otherwise, just throw the error\n throw error\n }\n\n if (!comp) {\n if (reactUse) {\n reactUse(load())\n } else {\n throw load()\n }\n }\n\n return React.createElement(comp, props)\n }\n\n ;(lazyComp as any).preload = load\n\n return lazyComp as any\n}\n"],"names":[],"mappings":";;;AAcO,SAAS,mBAId,UACA,YAGQ;AACR,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AAEJ,QAAM,OAAO,MAAM;AACjB,QAAI,CAAC,aAAa;AAChB,oBAAc,SAAA,EACX,KAAK,CAAC,QAAQ;AACb,sBAAc;AACd,eAAO,IAAI,cAAc,SAAS;AAAA,MACpC,CAAC,EACA,MAAM,CAAC,QAAQ;AAId,gBAAQ;AAMR,YAAI,sBAAsB,KAAK,GAAG;AAChC,cACE,iBAAiB,SACjB,OAAO,WAAW,eAClB,OAAO,mBAAmB,aAC1B;AAKA,kBAAM,aAAa,0BAA0B,MAAM,OAAO;AAC1D,gBAAI,CAAC,eAAe,QAAQ,UAAU,GAAG;AACvC,6BAAe,QAAQ,YAAY,GAAG;AACtC,uBAAS;AAAA,YACX;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACL;AAEA,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,SAAS,KAAK,OAAY;AAEzC,QAAI,QAAQ;AAGV,aAAO,SAAS,OAAA;AAChB,YAAM,IAAI,QAAQ,MAAM;AAAA,MAAC,CAAC;AAAA,IAC5B;AACA,QAAI,OAAO;AAET,YAAM;AAAA,IACR;AAEA,QAAI,CAAC,MAAM;AACT,UAAI,UAAU;AACZ,iBAAS,MAAM;AAAA,MACjB,OAAO;AACL,cAAM,KAAA;AAAA,MACR;AAAA,IACF;AAEA,WAAO,MAAM,cAAc,MAAM,KAAK;AAAA,EACxC;AAEE,WAAiB,UAAU;AAE7B,SAAO;AACT;"}
@@ -1,4 +1,9 @@
1
1
  import * as React from 'react';
2
+ /**
3
+ * React.use if available (React 19+), undefined otherwise.
4
+ * Use dynamic lookup to avoid Webpack compilation errors with React 18.
5
+ */
6
+ export declare const reactUse: (<T>(usable: Promise<T> | React.Context<T>) => T) | undefined;
2
7
  export declare function useStableCallback<T extends (...args: Array<any>) => any>(fn: T): T;
3
8
  export declare const useLayoutEffect: typeof React.useLayoutEffect;
4
9
  /**
package/dist/esm/utils.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import * as React from "react";
2
+ const REACT_USE = "use";
3
+ const reactUse = React[REACT_USE];
2
4
  function useStableCallback(fn) {
3
5
  const fnRef = React.useRef(fn);
4
6
  fnRef.current = fn;
@@ -40,6 +42,7 @@ function useForwardedRef(ref) {
40
42
  return innerRef;
41
43
  }
42
44
  export {
45
+ reactUse,
43
46
  useForwardedRef,
44
47
  useIntersectionObserver,
45
48
  useLayoutEffect,
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\n\nexport function useStableCallback<T extends (...args: Array<any>) => any>(\n fn: T,\n): T {\n const fnRef = React.useRef(fn)\n fnRef.current = fn\n\n const ref = React.useRef((...args: Array<any>) => fnRef.current(...args))\n return ref.current as T\n}\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\n/**\n * Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3\n */\nexport function usePrevious<T>(value: T): T | null {\n // initialise the ref with previous and current values\n const ref = React.useRef<{ value: T; prev: T | null }>({\n value: value,\n prev: null,\n })\n\n const current = ref.current.value\n\n // if the value passed into hook doesn't match what we store as \"current\"\n // move the \"current\" to the \"previous\"\n // and store the passed value as \"current\"\n if (value !== current) {\n ref.current = {\n value: value,\n prev: current,\n }\n }\n\n // return the previous value only\n return ref.current.prev\n}\n\n/**\n * React hook to wrap `IntersectionObserver`.\n *\n * This hook will create an `IntersectionObserver` and observe the ref passed to it.\n *\n * When the intersection changes, the callback will be called with the `IntersectionObserverEntry`.\n *\n * @param ref - The ref to observe\n * @param intersectionObserverOptions - The options to pass to the IntersectionObserver\n * @param options - The options to pass to the hook\n * @param callback - The callback to call when the intersection changes\n * @returns The IntersectionObserver instance\n * @example\n * ```tsx\n * const MyComponent = () => {\n * const ref = React.useRef<HTMLDivElement>(null)\n * useIntersectionObserver(\n * ref,\n * (entry) => { doSomething(entry) },\n * { rootMargin: '10px' },\n * { disabled: false }\n * )\n * return <div ref={ref} />\n * ```\n */\nexport function useIntersectionObserver<T extends Element>(\n ref: React.RefObject<T | null>,\n callback: (entry: IntersectionObserverEntry | undefined) => void,\n intersectionObserverOptions: IntersectionObserverInit = {},\n options: { disabled?: boolean } = {},\n) {\n React.useEffect(() => {\n if (\n !ref.current ||\n options.disabled ||\n typeof IntersectionObserver !== 'function'\n ) {\n return\n }\n\n const observer = new IntersectionObserver(([entry]) => {\n callback(entry)\n }, intersectionObserverOptions)\n\n observer.observe(ref.current)\n\n return () => {\n observer.disconnect()\n }\n }, [callback, intersectionObserverOptions, options.disabled, ref])\n}\n\n/**\n * React hook to take a `React.ForwardedRef` and returns a `ref` that can be used on a DOM element.\n *\n * @param ref - The forwarded ref\n * @returns The inner ref returned by `useRef`\n * @example\n * ```tsx\n * const MyComponent = React.forwardRef((props, ref) => {\n * const innerRef = useForwardedRef(ref)\n * return <div ref={innerRef} />\n * })\n * ```\n */\nexport function useForwardedRef<T>(ref?: React.ForwardedRef<T>) {\n const innerRef = React.useRef<T>(null)\n React.useImperativeHandle(ref, () => innerRef.current!, [])\n return innerRef\n}\n"],"names":[],"mappings":";AAEO,SAAS,kBACd,IACG;AACH,QAAM,QAAQ,MAAM,OAAO,EAAE;AAC7B,QAAM,UAAU;AAEhB,QAAM,MAAM,MAAM,OAAO,IAAI,SAAqB,MAAM,QAAQ,GAAG,IAAI,CAAC;AACxE,SAAO,IAAI;AACb;AAEO,MAAM,kBACX,OAAO,WAAW,cAAc,MAAM,kBAAkB,MAAM;AAKzD,SAAS,YAAe,OAAoB;AAEjD,QAAM,MAAM,MAAM,OAAqC;AAAA,IACrD;AAAA,IACA,MAAM;AAAA,EAAA,CACP;AAED,QAAM,UAAU,IAAI,QAAQ;AAK5B,MAAI,UAAU,SAAS;AACrB,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,MAAM;AAAA,IAAA;AAAA,EAEV;AAGA,SAAO,IAAI,QAAQ;AACrB;AA2BO,SAAS,wBACd,KACA,UACA,8BAAwD,CAAA,GACxD,UAAkC,IAClC;AACA,QAAM,UAAU,MAAM;AACpB,QACE,CAAC,IAAI,WACL,QAAQ,YACR,OAAO,yBAAyB,YAChC;AACA;AAAA,IACF;AAEA,UAAM,WAAW,IAAI,qBAAqB,CAAC,CAAC,KAAK,MAAM;AACrD,eAAS,KAAK;AAAA,IAChB,GAAG,2BAA2B;AAE9B,aAAS,QAAQ,IAAI,OAAO;AAE5B,WAAO,MAAM;AACX,eAAS,WAAA;AAAA,IACX;AAAA,EACF,GAAG,CAAC,UAAU,6BAA6B,QAAQ,UAAU,GAAG,CAAC;AACnE;AAeO,SAAS,gBAAmB,KAA6B;AAC9D,QAAM,WAAW,MAAM,OAAU,IAAI;AACrC,QAAM,oBAAoB,KAAK,MAAM,SAAS,SAAU,CAAA,CAAE;AAC1D,SAAO;AACT;"}
1
+ {"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\n\n// Safe version of React.use() that will not cause compilation errors against\n// React 18 with Webpack, which statically analyzes imports and fails when it\n// sees React.use referenced (since 'use' is not exported from React 18).\n// This uses a dynamic string lookup to avoid the static analysis.\nconst REACT_USE = 'use'\n\n/**\n * React.use if available (React 19+), undefined otherwise.\n * Use dynamic lookup to avoid Webpack compilation errors with React 18.\n */\nexport const reactUse:\n | (<T>(usable: Promise<T> | React.Context<T>) => T)\n | undefined = (React as any)[REACT_USE]\n\nexport function useStableCallback<T extends (...args: Array<any>) => any>(\n fn: T,\n): T {\n const fnRef = React.useRef(fn)\n fnRef.current = fn\n\n const ref = React.useRef((...args: Array<any>) => fnRef.current(...args))\n return ref.current as T\n}\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\n/**\n * Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3\n */\nexport function usePrevious<T>(value: T): T | null {\n // initialise the ref with previous and current values\n const ref = React.useRef<{ value: T; prev: T | null }>({\n value: value,\n prev: null,\n })\n\n const current = ref.current.value\n\n // if the value passed into hook doesn't match what we store as \"current\"\n // move the \"current\" to the \"previous\"\n // and store the passed value as \"current\"\n if (value !== current) {\n ref.current = {\n value: value,\n prev: current,\n }\n }\n\n // return the previous value only\n return ref.current.prev\n}\n\n/**\n * React hook to wrap `IntersectionObserver`.\n *\n * This hook will create an `IntersectionObserver` and observe the ref passed to it.\n *\n * When the intersection changes, the callback will be called with the `IntersectionObserverEntry`.\n *\n * @param ref - The ref to observe\n * @param intersectionObserverOptions - The options to pass to the IntersectionObserver\n * @param options - The options to pass to the hook\n * @param callback - The callback to call when the intersection changes\n * @returns The IntersectionObserver instance\n * @example\n * ```tsx\n * const MyComponent = () => {\n * const ref = React.useRef<HTMLDivElement>(null)\n * useIntersectionObserver(\n * ref,\n * (entry) => { doSomething(entry) },\n * { rootMargin: '10px' },\n * { disabled: false }\n * )\n * return <div ref={ref} />\n * ```\n */\nexport function useIntersectionObserver<T extends Element>(\n ref: React.RefObject<T | null>,\n callback: (entry: IntersectionObserverEntry | undefined) => void,\n intersectionObserverOptions: IntersectionObserverInit = {},\n options: { disabled?: boolean } = {},\n) {\n React.useEffect(() => {\n if (\n !ref.current ||\n options.disabled ||\n typeof IntersectionObserver !== 'function'\n ) {\n return\n }\n\n const observer = new IntersectionObserver(([entry]) => {\n callback(entry)\n }, intersectionObserverOptions)\n\n observer.observe(ref.current)\n\n return () => {\n observer.disconnect()\n }\n }, [callback, intersectionObserverOptions, options.disabled, ref])\n}\n\n/**\n * React hook to take a `React.ForwardedRef` and returns a `ref` that can be used on a DOM element.\n *\n * @param ref - The forwarded ref\n * @returns The inner ref returned by `useRef`\n * @example\n * ```tsx\n * const MyComponent = React.forwardRef((props, ref) => {\n * const innerRef = useForwardedRef(ref)\n * return <div ref={innerRef} />\n * })\n * ```\n */\nexport function useForwardedRef<T>(ref?: React.ForwardedRef<T>) {\n const innerRef = React.useRef<T>(null)\n React.useImperativeHandle(ref, () => innerRef.current!, [])\n return innerRef\n}\n"],"names":[],"mappings":";AAMA,MAAM,YAAY;AAMX,MAAM,WAEI,MAAc,SAAS;AAEjC,SAAS,kBACd,IACG;AACH,QAAM,QAAQ,MAAM,OAAO,EAAE;AAC7B,QAAM,UAAU;AAEhB,QAAM,MAAM,MAAM,OAAO,IAAI,SAAqB,MAAM,QAAQ,GAAG,IAAI,CAAC;AACxE,SAAO,IAAI;AACb;AAEO,MAAM,kBACX,OAAO,WAAW,cAAc,MAAM,kBAAkB,MAAM;AAKzD,SAAS,YAAe,OAAoB;AAEjD,QAAM,MAAM,MAAM,OAAqC;AAAA,IACrD;AAAA,IACA,MAAM;AAAA,EAAA,CACP;AAED,QAAM,UAAU,IAAI,QAAQ;AAK5B,MAAI,UAAU,SAAS;AACrB,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,MAAM;AAAA,IAAA;AAAA,EAEV;AAGA,SAAO,IAAI,QAAQ;AACrB;AA2BO,SAAS,wBACd,KACA,UACA,8BAAwD,CAAA,GACxD,UAAkC,IAClC;AACA,QAAM,UAAU,MAAM;AACpB,QACE,CAAC,IAAI,WACL,QAAQ,YACR,OAAO,yBAAyB,YAChC;AACA;AAAA,IACF;AAEA,UAAM,WAAW,IAAI,qBAAqB,CAAC,CAAC,KAAK,MAAM;AACrD,eAAS,KAAK;AAAA,IAChB,GAAG,2BAA2B;AAE9B,aAAS,QAAQ,IAAI,OAAO;AAE5B,WAAO,MAAM;AACX,eAAS,WAAA;AAAA,IACX;AAAA,EACF,GAAG,CAAC,UAAU,6BAA6B,QAAQ,UAAU,GAAG,CAAC;AACnE;AAeO,SAAS,gBAAmB,KAA6B;AAC9D,QAAM,WAAW,MAAM,OAAU,IAAI;AACrC,QAAM,oBAAoB,KAAK,MAAM,SAAS,SAAU,CAAA,CAAE;AAC1D,SAAO;AACT;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.147.1",
3
+ "version": "1.147.2",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -79,8 +79,8 @@
79
79
  "isbot": "^5.1.22",
80
80
  "tiny-invariant": "^1.3.3",
81
81
  "tiny-warning": "^1.0.3",
82
- "@tanstack/history": "1.145.7",
83
- "@tanstack/router-core": "1.147.1"
82
+ "@tanstack/router-core": "1.147.1",
83
+ "@tanstack/history": "1.145.7"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@testing-library/jest-dom": "^6.6.3",
package/src/awaited.tsx CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react'
2
2
 
3
3
  import { TSR_DEFERRED_PROMISE, defer } from '@tanstack/router-core'
4
+ import { reactUse } from './utils'
4
5
 
5
6
  export type AwaitOptions<T> = {
6
7
  promise: Promise<T>
@@ -8,9 +9,8 @@ export type AwaitOptions<T> = {
8
9
 
9
10
  /** Suspend until a deferred promise resolves or rejects and return its data. */
10
11
  export function useAwaited<T>({ promise: _promise }: AwaitOptions<T>): T {
11
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
12
- if (React.use) {
13
- const data = React.use(_promise)
12
+ if (reactUse) {
13
+ const data = reactUse(_promise)
14
14
  return data
15
15
  }
16
16
  const promise = defer(_promise)
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react'
2
2
  import { isModuleNotFoundError } from '@tanstack/router-core'
3
+ import { reactUse } from './utils'
3
4
  import type { AsyncRouteComponent } from './route'
4
5
 
5
6
  /**
@@ -79,9 +80,8 @@ export function lazyRouteComponent<
79
80
  }
80
81
 
81
82
  if (!comp) {
82
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
83
- if (React.use) {
84
- React.use(load())
83
+ if (reactUse) {
84
+ reactUse(load())
85
85
  } else {
86
86
  throw load()
87
87
  }
package/src/utils.ts CHANGED
@@ -1,5 +1,19 @@
1
1
  import * as React from 'react'
2
2
 
3
+ // Safe version of React.use() that will not cause compilation errors against
4
+ // React 18 with Webpack, which statically analyzes imports and fails when it
5
+ // sees React.use referenced (since 'use' is not exported from React 18).
6
+ // This uses a dynamic string lookup to avoid the static analysis.
7
+ const REACT_USE = 'use'
8
+
9
+ /**
10
+ * React.use if available (React 19+), undefined otherwise.
11
+ * Use dynamic lookup to avoid Webpack compilation errors with React 18.
12
+ */
13
+ export const reactUse:
14
+ | (<T>(usable: Promise<T> | React.Context<T>) => T)
15
+ | undefined = (React as any)[REACT_USE]
16
+
3
17
  export function useStableCallback<T extends (...args: Array<any>) => any>(
4
18
  fn: T,
5
19
  ): T {