@tanstack/react-router 1.168.13 → 1.168.14

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 (144) hide show
  1. package/dist/cjs/Asset.cjs +1 -0
  2. package/dist/cjs/Asset.cjs.map +1 -1
  3. package/dist/cjs/CatchBoundary.cjs +1 -0
  4. package/dist/cjs/CatchBoundary.cjs.map +1 -1
  5. package/dist/cjs/ClientOnly.cjs +1 -0
  6. package/dist/cjs/ClientOnly.cjs.map +1 -1
  7. package/dist/cjs/HeadContent.cjs +1 -0
  8. package/dist/cjs/HeadContent.cjs.map +1 -1
  9. package/dist/cjs/HeadContent.dev.cjs +1 -0
  10. package/dist/cjs/HeadContent.dev.cjs.map +1 -1
  11. package/dist/cjs/Match.cjs +6 -5
  12. package/dist/cjs/Match.cjs.map +1 -1
  13. package/dist/cjs/Matches.cjs +4 -3
  14. package/dist/cjs/Matches.cjs.map +1 -1
  15. package/dist/cjs/RouterProvider.cjs +1 -0
  16. package/dist/cjs/RouterProvider.cjs.map +1 -1
  17. package/dist/cjs/Scripts.cjs +3 -2
  18. package/dist/cjs/Scripts.cjs.map +1 -1
  19. package/dist/cjs/Transitioner.cjs +6 -5
  20. package/dist/cjs/Transitioner.cjs.map +1 -1
  21. package/dist/cjs/headContentUtils.cjs +1 -1
  22. package/dist/cjs/headContentUtils.cjs.map +1 -1
  23. package/dist/cjs/index.cjs +1 -0
  24. package/dist/cjs/index.d.cts +1 -1
  25. package/dist/cjs/index.dev.cjs +1 -0
  26. package/dist/cjs/link.cjs +2 -1
  27. package/dist/cjs/link.cjs.map +1 -1
  28. package/dist/cjs/matchContext.cjs +1 -0
  29. package/dist/cjs/matchContext.cjs.map +1 -1
  30. package/dist/cjs/not-found.cjs +1 -1
  31. package/dist/cjs/not-found.cjs.map +1 -1
  32. package/dist/cjs/routerContext.cjs +1 -0
  33. package/dist/cjs/routerContext.cjs.map +1 -1
  34. package/dist/cjs/routerStores.cjs +2 -2
  35. package/dist/cjs/routerStores.cjs.map +1 -1
  36. package/dist/cjs/ssr/RouterClient.cjs +1 -1
  37. package/dist/cjs/ssr/RouterClient.cjs.map +1 -1
  38. package/dist/cjs/ssr/renderRouterToStream.cjs +2 -2
  39. package/dist/cjs/ssr/renderRouterToStream.cjs.map +1 -1
  40. package/dist/cjs/ssr/renderRouterToString.cjs +1 -1
  41. package/dist/cjs/ssr/renderRouterToString.cjs.map +1 -1
  42. package/dist/cjs/useBlocker.cjs +1 -0
  43. package/dist/cjs/useBlocker.cjs.map +1 -1
  44. package/dist/cjs/useCanGoBack.cjs +1 -1
  45. package/dist/cjs/useCanGoBack.cjs.map +1 -1
  46. package/dist/cjs/useLocation.cjs +1 -1
  47. package/dist/cjs/useLocation.cjs.map +1 -1
  48. package/dist/cjs/useMatch.cjs +3 -3
  49. package/dist/cjs/useMatch.cjs.map +1 -1
  50. package/dist/cjs/useNavigate.cjs +1 -0
  51. package/dist/cjs/useNavigate.cjs.map +1 -1
  52. package/dist/cjs/useRouter.cjs +1 -0
  53. package/dist/cjs/useRouter.cjs.map +1 -1
  54. package/dist/cjs/useRouterState.cjs +2 -1
  55. package/dist/cjs/useRouterState.cjs.map +1 -1
  56. package/dist/cjs/utils.cjs +1 -0
  57. package/dist/cjs/utils.cjs.map +1 -1
  58. package/dist/esm/Asset.js +1 -0
  59. package/dist/esm/Asset.js.map +1 -1
  60. package/dist/esm/CatchBoundary.js +1 -0
  61. package/dist/esm/CatchBoundary.js.map +1 -1
  62. package/dist/esm/ClientOnly.js +1 -0
  63. package/dist/esm/ClientOnly.js.map +1 -1
  64. package/dist/esm/HeadContent.dev.js +1 -0
  65. package/dist/esm/HeadContent.dev.js.map +1 -1
  66. package/dist/esm/HeadContent.js +1 -0
  67. package/dist/esm/HeadContent.js.map +1 -1
  68. package/dist/esm/Match.js +6 -5
  69. package/dist/esm/Match.js.map +1 -1
  70. package/dist/esm/Matches.js +4 -3
  71. package/dist/esm/Matches.js.map +1 -1
  72. package/dist/esm/RouterProvider.js +1 -0
  73. package/dist/esm/RouterProvider.js.map +1 -1
  74. package/dist/esm/Scripts.js +3 -2
  75. package/dist/esm/Scripts.js.map +1 -1
  76. package/dist/esm/Transitioner.js +6 -5
  77. package/dist/esm/Transitioner.js.map +1 -1
  78. package/dist/esm/headContentUtils.js +1 -1
  79. package/dist/esm/headContentUtils.js.map +1 -1
  80. package/dist/esm/index.d.ts +1 -1
  81. package/dist/esm/index.dev.js +1 -0
  82. package/dist/esm/index.js +1 -0
  83. package/dist/esm/link.js +2 -1
  84. package/dist/esm/link.js.map +1 -1
  85. package/dist/esm/matchContext.js +1 -0
  86. package/dist/esm/matchContext.js.map +1 -1
  87. package/dist/esm/not-found.js +1 -1
  88. package/dist/esm/not-found.js.map +1 -1
  89. package/dist/esm/routerContext.js +1 -0
  90. package/dist/esm/routerContext.js.map +1 -1
  91. package/dist/esm/routerStores.js +3 -3
  92. package/dist/esm/routerStores.js.map +1 -1
  93. package/dist/esm/ssr/RouterClient.js +1 -1
  94. package/dist/esm/ssr/RouterClient.js.map +1 -1
  95. package/dist/esm/ssr/renderRouterToStream.js +2 -2
  96. package/dist/esm/ssr/renderRouterToStream.js.map +1 -1
  97. package/dist/esm/ssr/renderRouterToString.js +1 -1
  98. package/dist/esm/ssr/renderRouterToString.js.map +1 -1
  99. package/dist/esm/useBlocker.js +1 -0
  100. package/dist/esm/useBlocker.js.map +1 -1
  101. package/dist/esm/useCanGoBack.js +1 -1
  102. package/dist/esm/useCanGoBack.js.map +1 -1
  103. package/dist/esm/useLocation.js +1 -1
  104. package/dist/esm/useLocation.js.map +1 -1
  105. package/dist/esm/useMatch.js +3 -3
  106. package/dist/esm/useMatch.js.map +1 -1
  107. package/dist/esm/useNavigate.js +1 -0
  108. package/dist/esm/useNavigate.js.map +1 -1
  109. package/dist/esm/useRouter.js +1 -0
  110. package/dist/esm/useRouter.js.map +1 -1
  111. package/dist/esm/useRouterState.js +2 -1
  112. package/dist/esm/useRouterState.js.map +1 -1
  113. package/dist/esm/utils.js +1 -0
  114. package/dist/esm/utils.js.map +1 -1
  115. package/package.json +2 -2
  116. package/src/Asset.tsx +2 -0
  117. package/src/CatchBoundary.tsx +2 -0
  118. package/src/ClientOnly.tsx +2 -0
  119. package/src/HeadContent.dev.tsx +2 -0
  120. package/src/HeadContent.tsx +2 -0
  121. package/src/Match.tsx +8 -6
  122. package/src/Matches.tsx +5 -3
  123. package/src/RouterProvider.tsx +2 -0
  124. package/src/Scripts.tsx +3 -4
  125. package/src/Transitioner.tsx +10 -10
  126. package/src/headContentUtils.tsx +1 -1
  127. package/src/index.dev.tsx +2 -0
  128. package/src/index.tsx +5 -0
  129. package/src/link.tsx +3 -1
  130. package/src/matchContext.tsx +2 -0
  131. package/src/not-found.tsx +2 -2
  132. package/src/routerContext.tsx +2 -0
  133. package/src/routerStores.ts +3 -3
  134. package/src/ssr/RouterClient.tsx +1 -1
  135. package/src/ssr/renderRouterToStream.tsx +2 -2
  136. package/src/ssr/renderRouterToString.tsx +1 -1
  137. package/src/useBlocker.tsx +2 -0
  138. package/src/useCanGoBack.ts +1 -1
  139. package/src/useLocation.tsx +1 -1
  140. package/src/useMatch.tsx +4 -3
  141. package/src/useNavigate.tsx +2 -0
  142. package/src/useRouter.tsx +2 -0
  143. package/src/useRouterState.tsx +3 -1
  144. package/src/utils.ts +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"routerContext.js","names":[],"sources":["../../src/routerContext.tsx"],"sourcesContent":["import * as React from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport const routerContext = React.createContext<AnyRouter>(null!)\n"],"mappings":";;AAGA,IAAa,gBAAgB,QAAM,cAAyB,KAAM"}
1
+ {"version":3,"file":"routerContext.js","names":[],"sources":["../../src/routerContext.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport const routerContext = React.createContext<AnyRouter>(null!)\n"],"mappings":";;;AAKA,IAAa,gBAAgB,QAAM,cAAyB,KAAM"}
@@ -1,5 +1,5 @@
1
1
  import { createNonReactiveMutableStore, createNonReactiveReadonlyStore } from "@tanstack/router-core";
2
- import { batch, createStore } from "@tanstack/react-store";
2
+ import { batch, createAtom } from "@tanstack/react-store";
3
3
  import { isServer } from "@tanstack/router-core/isServer";
4
4
  //#region src/routerStores.ts
5
5
  var getStoreFactory = (opts) => {
@@ -9,8 +9,8 @@ var getStoreFactory = (opts) => {
9
9
  batch: (fn) => fn()
10
10
  };
11
11
  return {
12
- createMutableStore: createStore,
13
- createReadonlyStore: createStore,
12
+ createMutableStore: createAtom,
13
+ createReadonlyStore: createAtom,
14
14
  batch
15
15
  };
16
16
  };
@@ -1 +1 @@
1
- {"version":3,"file":"routerStores.js","names":[],"sources":["../../src/routerStores.ts"],"sourcesContent":["import { batch, createStore } from '@tanstack/react-store'\nimport {\n createNonReactiveMutableStore,\n createNonReactiveReadonlyStore,\n} from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport type { Readable } from '@tanstack/react-store'\nimport type { GetStoreConfig } from '@tanstack/router-core'\n\ndeclare module '@tanstack/router-core' {\n export interface RouterReadableStore<TValue> extends Readable<TValue> {}\n}\nexport const getStoreFactory: GetStoreConfig = (opts) => {\n if (isServer ?? opts.isServer) {\n return {\n createMutableStore: createNonReactiveMutableStore,\n createReadonlyStore: createNonReactiveReadonlyStore,\n batch: (fn) => fn(),\n }\n }\n return {\n createMutableStore: createStore,\n createReadonlyStore: createStore,\n batch: batch,\n }\n}\n"],"mappings":";;;;AAYA,IAAa,mBAAmC,SAAS;AACvD,KAAI,YAAY,KAAK,SACnB,QAAO;EACL,oBAAoB;EACpB,qBAAqB;EACrB,QAAQ,OAAO,IAAI;EACpB;AAEH,QAAO;EACL,oBAAoB;EACpB,qBAAqB;EACd;EACR"}
1
+ {"version":3,"file":"routerStores.js","names":[],"sources":["../../src/routerStores.ts"],"sourcesContent":["import { batch, createAtom } from '@tanstack/react-store'\nimport {\n createNonReactiveMutableStore,\n createNonReactiveReadonlyStore,\n} from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport type { Readable } from '@tanstack/react-store'\nimport type { GetStoreConfig } from '@tanstack/router-core'\n\ndeclare module '@tanstack/router-core' {\n export interface RouterReadableStore<TValue> extends Readable<TValue> {}\n}\nexport const getStoreFactory: GetStoreConfig = (opts) => {\n if (isServer ?? opts.isServer) {\n return {\n createMutableStore: createNonReactiveMutableStore,\n createReadonlyStore: createNonReactiveReadonlyStore,\n batch: (fn) => fn(),\n }\n }\n return {\n createMutableStore: createAtom,\n createReadonlyStore: createAtom,\n batch: batch,\n }\n}\n"],"mappings":";;;;AAYA,IAAa,mBAAmC,SAAS;AACvD,KAAI,YAAY,KAAK,SACnB,QAAO;EACL,oBAAoB;EACpB,qBAAqB;EACrB,QAAQ,OAAO,IAAI;EACpB;AAEH,QAAO;EACL,oBAAoB;EACpB,qBAAqB;EACd;EACR"}
@@ -5,7 +5,7 @@ import { hydrate } from "@tanstack/router-core/ssr/client";
5
5
  //#region src/ssr/RouterClient.tsx
6
6
  var hydrationPromise;
7
7
  function RouterClient(props) {
8
- if (!hydrationPromise) if (!props.router.stores.matchesId.state.length) hydrationPromise = hydrate(props.router);
8
+ if (!hydrationPromise) if (!props.router.stores.matchesId.get().length) hydrationPromise = hydrate(props.router);
9
9
  else hydrationPromise = Promise.resolve();
10
10
  return /* @__PURE__ */ jsx(Await, {
11
11
  promise: hydrationPromise,
@@ -1 +1 @@
1
- {"version":3,"file":"RouterClient.js","names":[],"sources":["../../../src/ssr/RouterClient.tsx"],"sourcesContent":["import { hydrate } from '@tanstack/router-core/ssr/client'\nimport { Await } from '../awaited'\nimport { RouterProvider } from '../RouterProvider'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nlet hydrationPromise: Promise<void | Array<Array<void>>> | undefined\n\nexport function RouterClient(props: { router: AnyRouter }) {\n if (!hydrationPromise) {\n if (!props.router.stores.matchesId.state.length) {\n hydrationPromise = hydrate(props.router)\n } else {\n hydrationPromise = Promise.resolve()\n }\n }\n return (\n <Await\n promise={hydrationPromise}\n children={() => <RouterProvider router={props.router} />}\n />\n )\n}\n"],"mappings":";;;;;AAKA,IAAI;AAEJ,SAAgB,aAAa,OAA8B;AACzD,KAAI,CAAC,iBACH,KAAI,CAAC,MAAM,OAAO,OAAO,UAAU,MAAM,OACvC,oBAAmB,QAAQ,MAAM,OAAO;KAExC,oBAAmB,QAAQ,SAAS;AAGxC,QACE,oBAAC,OAAD;EACE,SAAS;EACT,gBAAgB,oBAAC,gBAAD,EAAgB,QAAQ,MAAM,QAAU,CAAA;EACxD,CAAA"}
1
+ {"version":3,"file":"RouterClient.js","names":[],"sources":["../../../src/ssr/RouterClient.tsx"],"sourcesContent":["import { hydrate } from '@tanstack/router-core/ssr/client'\nimport { Await } from '../awaited'\nimport { RouterProvider } from '../RouterProvider'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nlet hydrationPromise: Promise<void | Array<Array<void>>> | undefined\n\nexport function RouterClient(props: { router: AnyRouter }) {\n if (!hydrationPromise) {\n if (!props.router.stores.matchesId.get().length) {\n hydrationPromise = hydrate(props.router)\n } else {\n hydrationPromise = Promise.resolve()\n }\n }\n return (\n <Await\n promise={hydrationPromise}\n children={() => <RouterProvider router={props.router} />}\n />\n )\n}\n"],"mappings":";;;;;AAKA,IAAI;AAEJ,SAAgB,aAAa,OAA8B;AACzD,KAAI,CAAC,iBACH,KAAI,CAAC,MAAM,OAAO,OAAO,UAAU,KAAK,CAAC,OACvC,oBAAmB,QAAQ,MAAM,OAAO;KAExC,oBAAmB,QAAQ,SAAS;AAGxC,QACE,oBAAC,OAAD;EACE,SAAS;EACT,gBAAgB,oBAAC,gBAAD,EAAgB,QAAQ,MAAM,QAAU,CAAA;EACxD,CAAA"}
@@ -13,7 +13,7 @@ var renderRouterToStream = async ({ request, router, responseHeaders, children }
13
13
  if (isbot(request.headers.get("User-Agent"))) await stream.allReady;
14
14
  const responseStream = transformReadableStreamWithRouter(router, stream);
15
15
  return new Response(responseStream, {
16
- status: router.stores.statusCode.state,
16
+ status: router.stores.statusCode.get(),
17
17
  headers: responseHeaders
18
18
  });
19
19
  }
@@ -39,7 +39,7 @@ var renderRouterToStream = async ({ request, router, responseHeaders, children }
39
39
  }
40
40
  const responseStream = transformPipeableStreamWithRouter(router, reactAppPassthrough);
41
41
  return new Response(responseStream, {
42
- status: router.stores.statusCode.state,
42
+ status: router.stores.statusCode.get(),
43
43
  headers: responseHeaders
44
44
  });
45
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"renderRouterToStream.js","names":[],"sources":["../../../src/ssr/renderRouterToStream.tsx"],"sourcesContent":["import { PassThrough } from 'node:stream'\nimport ReactDOMServer from 'react-dom/server'\nimport { isbot } from 'isbot'\nimport {\n transformPipeableStreamWithRouter,\n transformReadableStreamWithRouter,\n} from '@tanstack/router-core/ssr/server'\nimport type { AnyRouter } from '@tanstack/router-core'\nimport type { ReadableStream } from 'node:stream/web'\nimport type { ReactNode } from 'react'\n\nexport const renderRouterToStream = async ({\n request,\n router,\n responseHeaders,\n children,\n}: {\n request: Request\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n if (typeof ReactDOMServer.renderToReadableStream === 'function') {\n const stream = await ReactDOMServer.renderToReadableStream(children, {\n signal: request.signal,\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n })\n\n if (isbot(request.headers.get('User-Agent'))) {\n await stream.allReady\n }\n\n const responseStream = transformReadableStreamWithRouter(\n router,\n stream as unknown as ReadableStream,\n )\n return new Response(responseStream as any, {\n status: router.stores.statusCode.state,\n headers: responseHeaders,\n })\n }\n\n if (typeof ReactDOMServer.renderToPipeableStream === 'function') {\n const reactAppPassthrough = new PassThrough()\n\n try {\n const pipeable = ReactDOMServer.renderToPipeableStream(children, {\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n ...(isbot(request.headers.get('User-Agent'))\n ? {\n onAllReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }\n : {\n onShellReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }),\n onError: (error, info) => {\n console.error('Error in renderToPipeableStream:', error, info)\n // Destroy the passthrough stream on error\n if (!reactAppPassthrough.destroyed) {\n reactAppPassthrough.destroy(\n error instanceof Error ? error : new Error(String(error)),\n )\n }\n },\n })\n } catch (e) {\n console.error('Error in renderToPipeableStream:', e)\n reactAppPassthrough.destroy(e instanceof Error ? e : new Error(String(e)))\n }\n\n const responseStream = transformPipeableStreamWithRouter(\n router,\n reactAppPassthrough,\n )\n return new Response(responseStream as any, {\n status: router.stores.statusCode.state,\n headers: responseHeaders,\n })\n }\n\n throw new Error(\n 'No renderToReadableStream or renderToPipeableStream found in react-dom/server. Ensure you are using a version of react-dom that supports streaming.',\n )\n}\n"],"mappings":";;;;;AAWA,IAAa,uBAAuB,OAAO,EACzC,SACA,QACA,iBACA,eAMI;AACJ,KAAI,OAAO,eAAe,2BAA2B,YAAY;EAC/D,MAAM,SAAS,MAAM,eAAe,uBAAuB,UAAU;GACnE,QAAQ,QAAQ;GAChB,OAAO,OAAO,QAAQ,KAAK;GAC3B,sBAAsB,OAAO;GAC9B,CAAC;AAEF,MAAI,MAAM,QAAQ,QAAQ,IAAI,aAAa,CAAC,CAC1C,OAAM,OAAO;EAGf,MAAM,iBAAiB,kCACrB,QACA,OACD;AACD,SAAO,IAAI,SAAS,gBAAuB;GACzC,QAAQ,OAAO,OAAO,WAAW;GACjC,SAAS;GACV,CAAC;;AAGJ,KAAI,OAAO,eAAe,2BAA2B,YAAY;EAC/D,MAAM,sBAAsB,IAAI,aAAa;AAE7C,MAAI;GACF,MAAM,WAAW,eAAe,uBAAuB,UAAU;IAC/D,OAAO,OAAO,QAAQ,KAAK;IAC3B,sBAAsB,OAAO;IAC7B,GAAI,MAAM,QAAQ,QAAQ,IAAI,aAAa,CAAC,GACxC,EACE,aAAa;AACX,cAAS,KAAK,oBAAoB;OAErC,GACD,EACE,eAAe;AACb,cAAS,KAAK,oBAAoB;OAErC;IACL,UAAU,OAAO,SAAS;AACxB,aAAQ,MAAM,oCAAoC,OAAO,KAAK;AAE9D,SAAI,CAAC,oBAAoB,UACvB,qBAAoB,QAClB,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC,CAC1D;;IAGN,CAAC;WACK,GAAG;AACV,WAAQ,MAAM,oCAAoC,EAAE;AACpD,uBAAoB,QAAQ,aAAa,QAAQ,IAAI,IAAI,MAAM,OAAO,EAAE,CAAC,CAAC;;EAG5E,MAAM,iBAAiB,kCACrB,QACA,oBACD;AACD,SAAO,IAAI,SAAS,gBAAuB;GACzC,QAAQ,OAAO,OAAO,WAAW;GACjC,SAAS;GACV,CAAC;;AAGJ,OAAM,IAAI,MACR,sJACD"}
1
+ {"version":3,"file":"renderRouterToStream.js","names":[],"sources":["../../../src/ssr/renderRouterToStream.tsx"],"sourcesContent":["import { PassThrough } from 'node:stream'\nimport ReactDOMServer from 'react-dom/server'\nimport { isbot } from 'isbot'\nimport {\n transformPipeableStreamWithRouter,\n transformReadableStreamWithRouter,\n} from '@tanstack/router-core/ssr/server'\nimport type { AnyRouter } from '@tanstack/router-core'\nimport type { ReadableStream } from 'node:stream/web'\nimport type { ReactNode } from 'react'\n\nexport const renderRouterToStream = async ({\n request,\n router,\n responseHeaders,\n children,\n}: {\n request: Request\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n if (typeof ReactDOMServer.renderToReadableStream === 'function') {\n const stream = await ReactDOMServer.renderToReadableStream(children, {\n signal: request.signal,\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n })\n\n if (isbot(request.headers.get('User-Agent'))) {\n await stream.allReady\n }\n\n const responseStream = transformReadableStreamWithRouter(\n router,\n stream as unknown as ReadableStream,\n )\n return new Response(responseStream as any, {\n status: router.stores.statusCode.get(),\n headers: responseHeaders,\n })\n }\n\n if (typeof ReactDOMServer.renderToPipeableStream === 'function') {\n const reactAppPassthrough = new PassThrough()\n\n try {\n const pipeable = ReactDOMServer.renderToPipeableStream(children, {\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n ...(isbot(request.headers.get('User-Agent'))\n ? {\n onAllReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }\n : {\n onShellReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }),\n onError: (error, info) => {\n console.error('Error in renderToPipeableStream:', error, info)\n // Destroy the passthrough stream on error\n if (!reactAppPassthrough.destroyed) {\n reactAppPassthrough.destroy(\n error instanceof Error ? error : new Error(String(error)),\n )\n }\n },\n })\n } catch (e) {\n console.error('Error in renderToPipeableStream:', e)\n reactAppPassthrough.destroy(e instanceof Error ? e : new Error(String(e)))\n }\n\n const responseStream = transformPipeableStreamWithRouter(\n router,\n reactAppPassthrough,\n )\n return new Response(responseStream as any, {\n status: router.stores.statusCode.get(),\n headers: responseHeaders,\n })\n }\n\n throw new Error(\n 'No renderToReadableStream or renderToPipeableStream found in react-dom/server. Ensure you are using a version of react-dom that supports streaming.',\n )\n}\n"],"mappings":";;;;;AAWA,IAAa,uBAAuB,OAAO,EACzC,SACA,QACA,iBACA,eAMI;AACJ,KAAI,OAAO,eAAe,2BAA2B,YAAY;EAC/D,MAAM,SAAS,MAAM,eAAe,uBAAuB,UAAU;GACnE,QAAQ,QAAQ;GAChB,OAAO,OAAO,QAAQ,KAAK;GAC3B,sBAAsB,OAAO;GAC9B,CAAC;AAEF,MAAI,MAAM,QAAQ,QAAQ,IAAI,aAAa,CAAC,CAC1C,OAAM,OAAO;EAGf,MAAM,iBAAiB,kCACrB,QACA,OACD;AACD,SAAO,IAAI,SAAS,gBAAuB;GACzC,QAAQ,OAAO,OAAO,WAAW,KAAK;GACtC,SAAS;GACV,CAAC;;AAGJ,KAAI,OAAO,eAAe,2BAA2B,YAAY;EAC/D,MAAM,sBAAsB,IAAI,aAAa;AAE7C,MAAI;GACF,MAAM,WAAW,eAAe,uBAAuB,UAAU;IAC/D,OAAO,OAAO,QAAQ,KAAK;IAC3B,sBAAsB,OAAO;IAC7B,GAAI,MAAM,QAAQ,QAAQ,IAAI,aAAa,CAAC,GACxC,EACE,aAAa;AACX,cAAS,KAAK,oBAAoB;OAErC,GACD,EACE,eAAe;AACb,cAAS,KAAK,oBAAoB;OAErC;IACL,UAAU,OAAO,SAAS;AACxB,aAAQ,MAAM,oCAAoC,OAAO,KAAK;AAE9D,SAAI,CAAC,oBAAoB,UACvB,qBAAoB,QAClB,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC,CAC1D;;IAGN,CAAC;WACK,GAAG;AACV,WAAQ,MAAM,oCAAoC,EAAE;AACpD,uBAAoB,QAAQ,aAAa,QAAQ,IAAI,IAAI,MAAM,OAAO,EAAE,CAAC,CAAC;;EAG5E,MAAM,iBAAiB,kCACrB,QACA,oBACD;AACD,SAAO,IAAI,SAAS,gBAAuB;GACzC,QAAQ,OAAO,OAAO,WAAW,KAAK;GACtC,SAAS;GACV,CAAC;;AAGJ,OAAM,IAAI,MACR,sJACD"}
@@ -7,7 +7,7 @@ var renderRouterToString = async ({ router, responseHeaders, children }) => {
7
7
  const injectedHtml = router.serverSsr.takeBufferedHtml();
8
8
  if (injectedHtml) html = html.replace(`</body>`, () => `${injectedHtml}</body>`);
9
9
  return new Response(`<!DOCTYPE html>${html}`, {
10
- status: router.stores.statusCode.state,
10
+ status: router.stores.statusCode.get(),
11
11
  headers: responseHeaders
12
12
  });
13
13
  } catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"renderRouterToString.js","names":[],"sources":["../../../src/ssr/renderRouterToString.tsx"],"sourcesContent":["import ReactDOMServer from 'react-dom/server'\nimport type { ReactNode } from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport const renderRouterToString = async ({\n router,\n responseHeaders,\n children,\n}: {\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n try {\n let html = ReactDOMServer.renderToString(children)\n router.serverSsr!.setRenderFinished()\n\n const injectedHtml = router.serverSsr!.takeBufferedHtml()\n if (injectedHtml) {\n html = html.replace(`</body>`, () => `${injectedHtml}</body>`)\n }\n\n return new Response(`<!DOCTYPE html>${html}`, {\n status: router.stores.statusCode.state,\n headers: responseHeaders,\n })\n } catch (error) {\n console.error('Render to string error:', error)\n return new Response('Internal Server Error', {\n status: 500,\n headers: responseHeaders,\n })\n } finally {\n router.serverSsr?.cleanup()\n }\n}\n"],"mappings":";;AAIA,IAAa,uBAAuB,OAAO,EACzC,QACA,iBACA,eAKI;AACJ,KAAI;EACF,IAAI,OAAO,eAAe,eAAe,SAAS;AAClD,SAAO,UAAW,mBAAmB;EAErC,MAAM,eAAe,OAAO,UAAW,kBAAkB;AACzD,MAAI,aACF,QAAO,KAAK,QAAQ,iBAAiB,GAAG,aAAa,SAAS;AAGhE,SAAO,IAAI,SAAS,kBAAkB,QAAQ;GAC5C,QAAQ,OAAO,OAAO,WAAW;GACjC,SAAS;GACV,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,2BAA2B,MAAM;AAC/C,SAAO,IAAI,SAAS,yBAAyB;GAC3C,QAAQ;GACR,SAAS;GACV,CAAC;WACM;AACR,SAAO,WAAW,SAAS"}
1
+ {"version":3,"file":"renderRouterToString.js","names":[],"sources":["../../../src/ssr/renderRouterToString.tsx"],"sourcesContent":["import ReactDOMServer from 'react-dom/server'\nimport type { ReactNode } from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport const renderRouterToString = async ({\n router,\n responseHeaders,\n children,\n}: {\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n try {\n let html = ReactDOMServer.renderToString(children)\n router.serverSsr!.setRenderFinished()\n\n const injectedHtml = router.serverSsr!.takeBufferedHtml()\n if (injectedHtml) {\n html = html.replace(`</body>`, () => `${injectedHtml}</body>`)\n }\n\n return new Response(`<!DOCTYPE html>${html}`, {\n status: router.stores.statusCode.get(),\n headers: responseHeaders,\n })\n } catch (error) {\n console.error('Render to string error:', error)\n return new Response('Internal Server Error', {\n status: 500,\n headers: responseHeaders,\n })\n } finally {\n router.serverSsr?.cleanup()\n }\n}\n"],"mappings":";;AAIA,IAAa,uBAAuB,OAAO,EACzC,QACA,iBACA,eAKI;AACJ,KAAI;EACF,IAAI,OAAO,eAAe,eAAe,SAAS;AAClD,SAAO,UAAW,mBAAmB;EAErC,MAAM,eAAe,OAAO,UAAW,kBAAkB;AACzD,MAAI,aACF,QAAO,KAAK,QAAQ,iBAAiB,GAAG,aAAa,SAAS;AAGhE,SAAO,IAAI,SAAS,kBAAkB,QAAQ;GAC5C,QAAQ,OAAO,OAAO,WAAW,KAAK;GACtC,SAAS;GACV,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,2BAA2B,MAAM;AAC/C,SAAO,IAAI,SAAS,yBAAyB;GAC3C,QAAQ;GACR,SAAS;GACV,CAAC;WACM;AACR,SAAO,WAAW,SAAS"}
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useRouter } from "./useRouter.js";
2
3
  import * as React$1 from "react";
3
4
  //#region src/useBlocker.tsx
@@ -1 +1 @@
1
- {"version":3,"file":"useBlocker.js","names":[],"sources":["../../src/useBlocker.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useRouter } from './useRouter'\nimport type {\n BlockerFnArgs,\n HistoryAction,\n HistoryLocation,\n} from '@tanstack/history'\nimport type {\n AnyRoute,\n AnyRouter,\n ParseRoute,\n RegisteredRouter,\n} from '@tanstack/router-core'\n\ntype ShouldBlockFnLocation<\n out TRouteId,\n out TFullPath,\n out TAllParams,\n out TFullSearchSchema,\n> = {\n routeId: TRouteId\n fullPath: TFullPath\n pathname: string\n params: TAllParams\n search: TFullSearchSchema\n}\n\ntype AnyShouldBlockFnLocation = ShouldBlockFnLocation<any, any, any, any>\ntype MakeShouldBlockFnLocationUnion<\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,\n> = TRoute extends any\n ? ShouldBlockFnLocation<\n TRoute['id'],\n TRoute['fullPath'],\n TRoute['types']['allParams'],\n TRoute['types']['fullSearchSchema']\n >\n : never\n\ntype BlockerResolver<TRouter extends AnyRouter = RegisteredRouter> =\n | {\n status: 'blocked'\n current: MakeShouldBlockFnLocationUnion<TRouter>\n next: MakeShouldBlockFnLocationUnion<TRouter>\n action: HistoryAction\n proceed: () => void\n reset: () => void\n }\n | {\n status: 'idle'\n current: undefined\n next: undefined\n action: undefined\n proceed: undefined\n reset: undefined\n }\n\ntype ShouldBlockFnArgs<TRouter extends AnyRouter = RegisteredRouter> = {\n current: MakeShouldBlockFnLocationUnion<TRouter>\n next: MakeShouldBlockFnLocationUnion<TRouter>\n action: HistoryAction\n}\n\nexport type ShouldBlockFn<TRouter extends AnyRouter = RegisteredRouter> = (\n args: ShouldBlockFnArgs<TRouter>,\n) => boolean | Promise<boolean>\nexport type UseBlockerOpts<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n> = {\n shouldBlockFn: ShouldBlockFn<TRouter>\n enableBeforeUnload?: boolean | (() => boolean)\n disabled?: boolean\n withResolver?: TWithResolver\n}\n\ntype LegacyBlockerFn = () => Promise<any> | any\ntype LegacyBlockerOpts = {\n blockerFn?: LegacyBlockerFn\n condition?: boolean | any\n}\n\nfunction _resolveBlockerOpts(\n opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,\n condition?: boolean | any,\n): UseBlockerOpts {\n if (opts === undefined) {\n return {\n shouldBlockFn: () => true,\n withResolver: false,\n }\n }\n\n if ('shouldBlockFn' in opts) {\n return opts\n }\n\n if (typeof opts === 'function') {\n const shouldBlock = Boolean(condition ?? true)\n\n const _customBlockerFn = async () => {\n if (shouldBlock) return await opts()\n return false\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: false,\n }\n }\n\n const shouldBlock = Boolean(opts.condition ?? true)\n const fn = opts.blockerFn\n\n const _customBlockerFn = async () => {\n if (shouldBlock && fn !== undefined) {\n return await fn()\n }\n return shouldBlock\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: fn === undefined,\n }\n}\n\nexport function useBlocker<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = false,\n>(\n opts: UseBlockerOpts<TRouter, TWithResolver>,\n): TWithResolver extends true ? BlockerResolver<TRouter> : void\n\n/**\n * @deprecated Use the shouldBlockFn property instead\n */\nexport function useBlocker(blockerFnOrOpts?: LegacyBlockerOpts): BlockerResolver\n\n/**\n * @deprecated Use the UseBlockerOpts object syntax instead\n */\nexport function useBlocker(\n blockerFn?: LegacyBlockerFn,\n condition?: boolean | any,\n): BlockerResolver\n\nexport function useBlocker(\n opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,\n condition?: boolean | any,\n): BlockerResolver | void {\n const {\n shouldBlockFn,\n enableBeforeUnload = true,\n disabled = false,\n withResolver = false,\n } = _resolveBlockerOpts(opts, condition)\n\n const router = useRouter()\n const { history } = router\n\n const [resolver, setResolver] = React.useState<BlockerResolver>({\n status: 'idle',\n current: undefined,\n next: undefined,\n action: undefined,\n proceed: undefined,\n reset: undefined,\n })\n\n React.useEffect(() => {\n const blockerFnComposed = async (blockerFnArgs: BlockerFnArgs) => {\n function getLocation(\n location: HistoryLocation,\n ): AnyShouldBlockFnLocation {\n const parsedLocation = router.parseLocation(location)\n const matchedRoutes = router.getMatchedRoutes(parsedLocation.pathname)\n if (matchedRoutes.foundRoute === undefined) {\n return {\n routeId: '__notFound__',\n fullPath: parsedLocation.pathname,\n pathname: parsedLocation.pathname,\n params: matchedRoutes.routeParams,\n search: router.options.parseSearch(location.search),\n }\n }\n\n return {\n routeId: matchedRoutes.foundRoute.id,\n fullPath: matchedRoutes.foundRoute.fullPath,\n pathname: parsedLocation.pathname,\n params: matchedRoutes.routeParams,\n search: router.options.parseSearch(location.search),\n }\n }\n\n const current = getLocation(blockerFnArgs.currentLocation)\n const next = getLocation(blockerFnArgs.nextLocation)\n\n if (\n current.routeId === '__notFound__' &&\n next.routeId !== '__notFound__'\n ) {\n return false\n }\n\n const shouldBlock = await shouldBlockFn({\n action: blockerFnArgs.action,\n current,\n next,\n })\n if (!withResolver) {\n return shouldBlock\n }\n\n if (!shouldBlock) {\n return false\n }\n\n const promise = new Promise<boolean>((resolve) => {\n setResolver({\n status: 'blocked',\n current,\n next,\n action: blockerFnArgs.action,\n proceed: () => resolve(false),\n reset: () => resolve(true),\n })\n })\n\n const canNavigateAsync = await promise\n setResolver({\n status: 'idle',\n current: undefined,\n next: undefined,\n action: undefined,\n proceed: undefined,\n reset: undefined,\n })\n\n return canNavigateAsync\n }\n\n return disabled\n ? undefined\n : history.block({ blockerFn: blockerFnComposed, enableBeforeUnload })\n }, [\n shouldBlockFn,\n enableBeforeUnload,\n disabled,\n withResolver,\n history,\n router,\n ])\n\n return resolver\n}\n\nconst _resolvePromptBlockerArgs = (\n props: PromptProps | LegacyPromptProps,\n): UseBlockerOpts => {\n if ('shouldBlockFn' in props) {\n return { ...props }\n }\n\n const shouldBlock = Boolean(props.condition ?? true)\n const fn = props.blockerFn\n\n const _customBlockerFn = async () => {\n if (shouldBlock && fn !== undefined) {\n return await fn()\n }\n return shouldBlock\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: fn === undefined,\n }\n}\n\nexport function Block<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n>(opts: PromptProps<TRouter, TWithResolver>): React.ReactNode\n\n/**\n * @deprecated Use the UseBlockerOpts property instead\n */\nexport function Block(opts: LegacyPromptProps): React.ReactNode\n\nexport function Block(opts: PromptProps | LegacyPromptProps): React.ReactNode {\n const { children, ...rest } = opts\n const args = _resolvePromptBlockerArgs(rest)\n\n const resolver = useBlocker(args)\n return children\n ? typeof children === 'function'\n ? children(resolver as any)\n : children\n : null\n}\n\ntype LegacyPromptProps = {\n blockerFn?: LegacyBlockerFn\n condition?: boolean | any\n children?: React.ReactNode | ((params: BlockerResolver) => React.ReactNode)\n}\n\ntype PromptProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n TParams = TWithResolver extends true ? BlockerResolver<TRouter> : void,\n> = UseBlockerOpts<TRouter, TWithResolver> & {\n children?: React.ReactNode | ((params: TParams) => React.ReactNode)\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"useBlocker.js","names":[],"sources":["../../src/useBlocker.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { useRouter } from './useRouter'\nimport type {\n BlockerFnArgs,\n HistoryAction,\n HistoryLocation,\n} from '@tanstack/history'\nimport type {\n AnyRoute,\n AnyRouter,\n ParseRoute,\n RegisteredRouter,\n} from '@tanstack/router-core'\n\ntype ShouldBlockFnLocation<\n out TRouteId,\n out TFullPath,\n out TAllParams,\n out TFullSearchSchema,\n> = {\n routeId: TRouteId\n fullPath: TFullPath\n pathname: string\n params: TAllParams\n search: TFullSearchSchema\n}\n\ntype AnyShouldBlockFnLocation = ShouldBlockFnLocation<any, any, any, any>\ntype MakeShouldBlockFnLocationUnion<\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,\n> = TRoute extends any\n ? ShouldBlockFnLocation<\n TRoute['id'],\n TRoute['fullPath'],\n TRoute['types']['allParams'],\n TRoute['types']['fullSearchSchema']\n >\n : never\n\ntype BlockerResolver<TRouter extends AnyRouter = RegisteredRouter> =\n | {\n status: 'blocked'\n current: MakeShouldBlockFnLocationUnion<TRouter>\n next: MakeShouldBlockFnLocationUnion<TRouter>\n action: HistoryAction\n proceed: () => void\n reset: () => void\n }\n | {\n status: 'idle'\n current: undefined\n next: undefined\n action: undefined\n proceed: undefined\n reset: undefined\n }\n\ntype ShouldBlockFnArgs<TRouter extends AnyRouter = RegisteredRouter> = {\n current: MakeShouldBlockFnLocationUnion<TRouter>\n next: MakeShouldBlockFnLocationUnion<TRouter>\n action: HistoryAction\n}\n\nexport type ShouldBlockFn<TRouter extends AnyRouter = RegisteredRouter> = (\n args: ShouldBlockFnArgs<TRouter>,\n) => boolean | Promise<boolean>\nexport type UseBlockerOpts<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n> = {\n shouldBlockFn: ShouldBlockFn<TRouter>\n enableBeforeUnload?: boolean | (() => boolean)\n disabled?: boolean\n withResolver?: TWithResolver\n}\n\ntype LegacyBlockerFn = () => Promise<any> | any\ntype LegacyBlockerOpts = {\n blockerFn?: LegacyBlockerFn\n condition?: boolean | any\n}\n\nfunction _resolveBlockerOpts(\n opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,\n condition?: boolean | any,\n): UseBlockerOpts {\n if (opts === undefined) {\n return {\n shouldBlockFn: () => true,\n withResolver: false,\n }\n }\n\n if ('shouldBlockFn' in opts) {\n return opts\n }\n\n if (typeof opts === 'function') {\n const shouldBlock = Boolean(condition ?? true)\n\n const _customBlockerFn = async () => {\n if (shouldBlock) return await opts()\n return false\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: false,\n }\n }\n\n const shouldBlock = Boolean(opts.condition ?? true)\n const fn = opts.blockerFn\n\n const _customBlockerFn = async () => {\n if (shouldBlock && fn !== undefined) {\n return await fn()\n }\n return shouldBlock\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: fn === undefined,\n }\n}\n\nexport function useBlocker<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = false,\n>(\n opts: UseBlockerOpts<TRouter, TWithResolver>,\n): TWithResolver extends true ? BlockerResolver<TRouter> : void\n\n/**\n * @deprecated Use the shouldBlockFn property instead\n */\nexport function useBlocker(blockerFnOrOpts?: LegacyBlockerOpts): BlockerResolver\n\n/**\n * @deprecated Use the UseBlockerOpts object syntax instead\n */\nexport function useBlocker(\n blockerFn?: LegacyBlockerFn,\n condition?: boolean | any,\n): BlockerResolver\n\nexport function useBlocker(\n opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,\n condition?: boolean | any,\n): BlockerResolver | void {\n const {\n shouldBlockFn,\n enableBeforeUnload = true,\n disabled = false,\n withResolver = false,\n } = _resolveBlockerOpts(opts, condition)\n\n const router = useRouter()\n const { history } = router\n\n const [resolver, setResolver] = React.useState<BlockerResolver>({\n status: 'idle',\n current: undefined,\n next: undefined,\n action: undefined,\n proceed: undefined,\n reset: undefined,\n })\n\n React.useEffect(() => {\n const blockerFnComposed = async (blockerFnArgs: BlockerFnArgs) => {\n function getLocation(\n location: HistoryLocation,\n ): AnyShouldBlockFnLocation {\n const parsedLocation = router.parseLocation(location)\n const matchedRoutes = router.getMatchedRoutes(parsedLocation.pathname)\n if (matchedRoutes.foundRoute === undefined) {\n return {\n routeId: '__notFound__',\n fullPath: parsedLocation.pathname,\n pathname: parsedLocation.pathname,\n params: matchedRoutes.routeParams,\n search: router.options.parseSearch(location.search),\n }\n }\n\n return {\n routeId: matchedRoutes.foundRoute.id,\n fullPath: matchedRoutes.foundRoute.fullPath,\n pathname: parsedLocation.pathname,\n params: matchedRoutes.routeParams,\n search: router.options.parseSearch(location.search),\n }\n }\n\n const current = getLocation(blockerFnArgs.currentLocation)\n const next = getLocation(blockerFnArgs.nextLocation)\n\n if (\n current.routeId === '__notFound__' &&\n next.routeId !== '__notFound__'\n ) {\n return false\n }\n\n const shouldBlock = await shouldBlockFn({\n action: blockerFnArgs.action,\n current,\n next,\n })\n if (!withResolver) {\n return shouldBlock\n }\n\n if (!shouldBlock) {\n return false\n }\n\n const promise = new Promise<boolean>((resolve) => {\n setResolver({\n status: 'blocked',\n current,\n next,\n action: blockerFnArgs.action,\n proceed: () => resolve(false),\n reset: () => resolve(true),\n })\n })\n\n const canNavigateAsync = await promise\n setResolver({\n status: 'idle',\n current: undefined,\n next: undefined,\n action: undefined,\n proceed: undefined,\n reset: undefined,\n })\n\n return canNavigateAsync\n }\n\n return disabled\n ? undefined\n : history.block({ blockerFn: blockerFnComposed, enableBeforeUnload })\n }, [\n shouldBlockFn,\n enableBeforeUnload,\n disabled,\n withResolver,\n history,\n router,\n ])\n\n return resolver\n}\n\nconst _resolvePromptBlockerArgs = (\n props: PromptProps | LegacyPromptProps,\n): UseBlockerOpts => {\n if ('shouldBlockFn' in props) {\n return { ...props }\n }\n\n const shouldBlock = Boolean(props.condition ?? true)\n const fn = props.blockerFn\n\n const _customBlockerFn = async () => {\n if (shouldBlock && fn !== undefined) {\n return await fn()\n }\n return shouldBlock\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: fn === undefined,\n }\n}\n\nexport function Block<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n>(opts: PromptProps<TRouter, TWithResolver>): React.ReactNode\n\n/**\n * @deprecated Use the UseBlockerOpts property instead\n */\nexport function Block(opts: LegacyPromptProps): React.ReactNode\n\nexport function Block(opts: PromptProps | LegacyPromptProps): React.ReactNode {\n const { children, ...rest } = opts\n const args = _resolvePromptBlockerArgs(rest)\n\n const resolver = useBlocker(args)\n return children\n ? typeof children === 'function'\n ? children(resolver as any)\n : children\n : null\n}\n\ntype LegacyPromptProps = {\n blockerFn?: LegacyBlockerFn\n condition?: boolean | any\n children?: React.ReactNode | ((params: BlockerResolver) => React.ReactNode)\n}\n\ntype PromptProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n TParams = TWithResolver extends true ? BlockerResolver<TRouter> : void,\n> = UseBlockerOpts<TRouter, TWithResolver> & {\n children?: React.ReactNode | ((params: TParams) => React.ReactNode)\n}\n"],"mappings":"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"}
@@ -4,7 +4,7 @@ import { isServer } from "@tanstack/router-core/isServer";
4
4
  //#region src/useCanGoBack.ts
5
5
  function useCanGoBack() {
6
6
  const router = useRouter();
7
- if (isServer ?? router.isServer) return router.stores.location.state.state.__TSR_index !== 0;
7
+ if (isServer ?? router.isServer) return router.stores.location.get().state.__TSR_index !== 0;
8
8
  return useStore(router.stores.location, (location) => location.state.__TSR_index !== 0);
9
9
  }
10
10
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"useCanGoBack.js","names":[],"sources":["../../src/useCanGoBack.ts"],"sourcesContent":["import { useStore } from '@tanstack/react-store'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\n\nexport function useCanGoBack() {\n const router = useRouter()\n\n if (isServer ?? router.isServer) {\n return router.stores.location.state.state.__TSR_index !== 0\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n return useStore(\n router.stores.location,\n (location) => location.state.__TSR_index !== 0,\n )\n}\n"],"mappings":";;;;AAIA,SAAgB,eAAe;CAC7B,MAAM,SAAS,WAAW;AAE1B,KAAI,YAAY,OAAO,SACrB,QAAO,OAAO,OAAO,SAAS,MAAM,MAAM,gBAAgB;AAI5D,QAAO,SACL,OAAO,OAAO,WACb,aAAa,SAAS,MAAM,gBAAgB,EAC9C"}
1
+ {"version":3,"file":"useCanGoBack.js","names":[],"sources":["../../src/useCanGoBack.ts"],"sourcesContent":["import { useStore } from '@tanstack/react-store'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\n\nexport function useCanGoBack() {\n const router = useRouter()\n\n if (isServer ?? router.isServer) {\n return router.stores.location.get().state.__TSR_index !== 0\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n return useStore(\n router.stores.location,\n (location) => location.state.__TSR_index !== 0,\n )\n}\n"],"mappings":";;;;AAIA,SAAgB,eAAe;CAC7B,MAAM,SAAS,WAAW;AAE1B,KAAI,YAAY,OAAO,SACrB,QAAO,OAAO,OAAO,SAAS,KAAK,CAAC,MAAM,gBAAgB;AAI5D,QAAO,SACL,OAAO,OAAO,WACb,aAAa,SAAS,MAAM,gBAAgB,EAC9C"}
@@ -18,7 +18,7 @@ import { isServer } from "@tanstack/router-core/isServer";
18
18
  function useLocation(opts) {
19
19
  const router = useRouter();
20
20
  if (isServer ?? router.isServer) {
21
- const location = router.stores.location.state;
21
+ const location = router.stores.location.get();
22
22
  return opts?.select ? opts.select(location) : location;
23
23
  }
24
24
  const previousResult = useRef(void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"useLocation.js","names":[],"sources":["../../src/useLocation.tsx"],"sourcesContent":["import { useStore } from '@tanstack/react-store'\nimport { useRef } from 'react'\nimport { replaceEqualDeep } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterState,\n} from '@tanstack/router-core'\n\nexport interface UseLocationBaseOptions<\n TRouter extends AnyRouter,\n TSelected,\n TStructuralSharing extends boolean = boolean,\n> {\n select?: (\n state: RouterState<TRouter['routeTree']>['location'],\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n}\n\nexport type UseLocationResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected\n ? RouterState<TRouter['routeTree']>['location']\n : TSelected\n\n/**\n * Read the current location from the router state with optional selection.\n * Useful for subscribing to just the pieces of location you care about.\n *\n * Options:\n * - `select`: Project the `location` object to a derived value\n * - `structuralSharing`: Enable structural sharing for stable references\n *\n * @returns The current location (or selected value).\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLocationHook\n */\nexport function useLocation<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseLocationBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseLocationResult<TRouter, TSelected> {\n const router = useRouter<TRouter>()\n\n if (isServer ?? router.isServer) {\n const location = router.stores.location.state\n return (\n opts?.select ? opts.select(location as any) : location\n ) as UseLocationResult<TRouter, TSelected>\n }\n\n const previousResult =\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(undefined)\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n return useStore(router.stores.location, (location) => {\n const selected = (\n opts?.select ? opts.select(location as any) : location\n ) as ValidateSelected<TRouter, TSelected, TStructuralSharing>\n\n if (opts?.structuralSharing ?? router.options.defaultStructuralSharing) {\n const shared = replaceEqualDeep(previousResult.current, selected)\n previousResult.current = shared\n return shared\n }\n\n return selected\n }) as UseLocationResult<TRouter, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA2CA,SAAgB,YAKd,MAEuC;CACvC,MAAM,SAAS,WAAoB;AAEnC,KAAI,YAAY,OAAO,UAAU;EAC/B,MAAM,WAAW,OAAO,OAAO,SAAS;AACxC,SACE,MAAM,SAAS,KAAK,OAAO,SAAgB,GAAG;;CAIlD,MAAM,iBAEJ,OAAiE,KAAA,EAAU;AAG7E,QAAO,SAAS,OAAO,OAAO,WAAW,aAAa;EACpD,MAAM,WACJ,MAAM,SAAS,KAAK,OAAO,SAAgB,GAAG;AAGhD,MAAI,MAAM,qBAAqB,OAAO,QAAQ,0BAA0B;GACtE,MAAM,SAAS,iBAAiB,eAAe,SAAS,SAAS;AACjE,kBAAe,UAAU;AACzB,UAAO;;AAGT,SAAO;GACP"}
1
+ {"version":3,"file":"useLocation.js","names":[],"sources":["../../src/useLocation.tsx"],"sourcesContent":["import { useStore } from '@tanstack/react-store'\nimport { useRef } from 'react'\nimport { replaceEqualDeep } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterState,\n} from '@tanstack/router-core'\n\nexport interface UseLocationBaseOptions<\n TRouter extends AnyRouter,\n TSelected,\n TStructuralSharing extends boolean = boolean,\n> {\n select?: (\n state: RouterState<TRouter['routeTree']>['location'],\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n}\n\nexport type UseLocationResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected\n ? RouterState<TRouter['routeTree']>['location']\n : TSelected\n\n/**\n * Read the current location from the router state with optional selection.\n * Useful for subscribing to just the pieces of location you care about.\n *\n * Options:\n * - `select`: Project the `location` object to a derived value\n * - `structuralSharing`: Enable structural sharing for stable references\n *\n * @returns The current location (or selected value).\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLocationHook\n */\nexport function useLocation<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseLocationBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseLocationResult<TRouter, TSelected> {\n const router = useRouter<TRouter>()\n\n if (isServer ?? router.isServer) {\n const location = router.stores.location.get()\n return (\n opts?.select ? opts.select(location as any) : location\n ) as UseLocationResult<TRouter, TSelected>\n }\n\n const previousResult =\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(undefined)\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n return useStore(router.stores.location, (location) => {\n const selected = (\n opts?.select ? opts.select(location as any) : location\n ) as ValidateSelected<TRouter, TSelected, TStructuralSharing>\n\n if (opts?.structuralSharing ?? router.options.defaultStructuralSharing) {\n const shared = replaceEqualDeep(previousResult.current, selected)\n previousResult.current = shared\n return shared\n }\n\n return selected\n }) as UseLocationResult<TRouter, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA2CA,SAAgB,YAKd,MAEuC;CACvC,MAAM,SAAS,WAAoB;AAEnC,KAAI,YAAY,OAAO,UAAU;EAC/B,MAAM,WAAW,OAAO,OAAO,SAAS,KAAK;AAC7C,SACE,MAAM,SAAS,KAAK,OAAO,SAAgB,GAAG;;CAIlD,MAAM,iBAEJ,OAAiE,KAAA,EAAU;AAG7E,QAAO,SAAS,OAAO,OAAO,WAAW,aAAa;EACpD,MAAM,WACJ,MAAM,SAAS,KAAK,OAAO,SAAgB,GAAG;AAGhD,MAAI,MAAM,qBAAqB,OAAO,QAAQ,0BAA0B;GACtE,MAAM,SAAS,iBAAiB,eAAe,SAAS,SAAS;AACjE,kBAAe,UAAU;AACzB,UAAO;;AAGT,SAAO;GACP"}
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { dummyMatchContext, matchContext } from "./matchContext.js";
2
3
  import { useRouter } from "./useRouter.js";
3
4
  import { invariant, replaceEqualDeep } from "@tanstack/router-core";
@@ -6,9 +7,8 @@ import { useStore } from "@tanstack/react-store";
6
7
  import { isServer } from "@tanstack/router-core/isServer";
7
8
  //#region src/useMatch.tsx
8
9
  var dummyStore = {
9
- state: void 0,
10
10
  get: () => void 0,
11
- subscribe: () => () => {}
11
+ subscribe: () => ({ unsubscribe: () => {} })
12
12
  };
13
13
  /**
14
14
  * Read and select the nearest or targeted route match.
@@ -20,7 +20,7 @@ function useMatch(opts) {
20
20
  const key = opts.from ?? nearestMatchId;
21
21
  const matchStore = key ? opts.from ? router.stores.getMatchStoreByRouteId(key) : router.stores.activeMatchStoresById.get(key) : void 0;
22
22
  if (isServer ?? router.isServer) {
23
- const match = matchStore?.state;
23
+ const match = matchStore?.get();
24
24
  if ((opts.shouldThrow ?? true) && !match) {
25
25
  if (process.env.NODE_ENV !== "production") throw new Error(`Invariant failed: Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`);
26
26
  invariant();
@@ -1 +1 @@
1
- {"version":3,"file":"useMatch.js","names":[],"sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport { invariant, replaceEqualDeep } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { dummyMatchContext, matchContext } from './matchContext'\nimport { useRouter } from './useRouter'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type {\n AnyRouter,\n MakeRouteMatch,\n MakeRouteMatchUnion,\n RegisteredRouter,\n StrictOrFrom,\n ThrowConstraint,\n ThrowOrOptional,\n} from '@tanstack/router-core'\n\nconst dummyStore = {\n state: undefined,\n get: () => undefined,\n subscribe: () => () => {},\n} as any\n\nexport interface UseMatchBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> {\n select?: (\n match: MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n shouldThrow?: TThrow\n}\n\nexport type UseMatchRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchBaseOptions<\n TRouter,\n TFrom,\n true,\n true,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n) => UseMatchResult<TRouter, TFrom, true, TSelected>\n\nexport type UseMatchOptions<\n TRouter extends AnyRouter,\n TFrom extends string | undefined,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> = StrictOrFrom<TRouter, TFrom, TStrict> &\n UseMatchBaseOptions<\n TRouter,\n TFrom,\n TStrict,\n TThrow,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseMatchResult<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TSelected,\n> = unknown extends TSelected\n ? TStrict extends true\n ? MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>\n : MakeRouteMatchUnion<TRouter>\n : TSelected\n\n/**\n * Read and select the nearest or targeted route match.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchHook\n */\nexport function useMatch<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TThrow extends boolean = true,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts: UseMatchOptions<\n TRouter,\n TFrom,\n TStrict,\n ThrowConstraint<TStrict, TThrow>,\n TSelected,\n TStructuralSharing\n >,\n): ThrowOrOptional<UseMatchResult<TRouter, TFrom, TStrict, TSelected>, TThrow> {\n const router = useRouter<TRouter>()\n const nearestMatchId = React.useContext(\n opts.from ? dummyMatchContext : matchContext,\n )\n\n const key = opts.from ?? nearestMatchId\n const matchStore = key\n ? opts.from\n ? router.stores.getMatchStoreByRouteId(key)\n : router.stores.activeMatchStoresById.get(key)\n : undefined\n\n if (isServer ?? router.isServer) {\n const match = matchStore?.state\n if ((opts.shouldThrow ?? true) && !match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n }\n\n invariant()\n }\n\n if (match === undefined) {\n return undefined as any\n }\n\n return (opts.select ? opts.select(match as any) : match) as any\n }\n\n const previousResult =\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n React.useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(\n undefined,\n )\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n return useStore(matchStore ?? dummyStore, (match) => {\n if ((opts.shouldThrow ?? true) && !match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n }\n\n invariant()\n }\n\n if (match === undefined) {\n return undefined\n }\n\n const selected = (\n opts.select ? opts.select(match as any) : match\n ) as ValidateSelected<TRouter, TSelected, TStructuralSharing>\n\n if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {\n const shared = replaceEqualDeep(previousResult.current, selected)\n previousResult.current = shared\n return shared\n }\n\n return selected\n }) as any\n}\n"],"mappings":";;;;;;;AAoBA,IAAM,aAAa;CACjB,OAAO,KAAA;CACP,WAAW,KAAA;CACX,uBAAuB;CACxB;;;;;AAiED,SAAgB,SAQd,MAQ6E;CAC7E,MAAM,SAAS,WAAoB;CACnC,MAAM,iBAAiB,QAAM,WAC3B,KAAK,OAAO,oBAAoB,aACjC;CAED,MAAM,MAAM,KAAK,QAAQ;CACzB,MAAM,aAAa,MACf,KAAK,OACH,OAAO,OAAO,uBAAuB,IAAI,GACzC,OAAO,OAAO,sBAAsB,IAAI,IAAI,GAC9C,KAAA;AAEJ,KAAI,YAAY,OAAO,UAAU;EAC/B,MAAM,QAAQ,YAAY;AAC1B,OAAK,KAAK,eAAe,SAAS,CAAC,OAAO;AACxC,OAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,oCAAoC,KAAK,OAAO,yBAAyB,KAAK,KAAK,KAAK,qBACzF;AAGH,cAAW;;AAGb,MAAI,UAAU,KAAA,EACZ;AAGF,SAAQ,KAAK,SAAS,KAAK,OAAO,MAAa,GAAG;;CAGpD,MAAM,iBAEJ,QAAM,OACJ,KAAA,EACD;AAGH,QAAO,SAAS,cAAc,aAAa,UAAU;AACnD,OAAK,KAAK,eAAe,SAAS,CAAC,OAAO;AACxC,OAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,oCAAoC,KAAK,OAAO,yBAAyB,KAAK,KAAK,KAAK,qBACzF;AAGH,cAAW;;AAGb,MAAI,UAAU,KAAA,EACZ;EAGF,MAAM,WACJ,KAAK,SAAS,KAAK,OAAO,MAAa,GAAG;AAG5C,MAAI,KAAK,qBAAqB,OAAO,QAAQ,0BAA0B;GACrE,MAAM,SAAS,iBAAiB,eAAe,SAAS,SAAS;AACjE,kBAAe,UAAU;AACzB,UAAO;;AAGT,SAAO;GACP"}
1
+ {"version":3,"file":"useMatch.js","names":[],"sources":["../../src/useMatch.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport { invariant, replaceEqualDeep } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { dummyMatchContext, matchContext } from './matchContext'\nimport { useRouter } from './useRouter'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type {\n AnyRouter,\n MakeRouteMatch,\n MakeRouteMatchUnion,\n RegisteredRouter,\n StrictOrFrom,\n ThrowConstraint,\n ThrowOrOptional,\n} from '@tanstack/router-core'\n\nconst dummyStore = {\n get: () => undefined,\n subscribe: () => ({ unsubscribe: () => {} }),\n} as any\n\nexport interface UseMatchBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> {\n select?: (\n match: MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n shouldThrow?: TThrow\n}\n\nexport type UseMatchRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchBaseOptions<\n TRouter,\n TFrom,\n true,\n true,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n) => UseMatchResult<TRouter, TFrom, true, TSelected>\n\nexport type UseMatchOptions<\n TRouter extends AnyRouter,\n TFrom extends string | undefined,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> = StrictOrFrom<TRouter, TFrom, TStrict> &\n UseMatchBaseOptions<\n TRouter,\n TFrom,\n TStrict,\n TThrow,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseMatchResult<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TSelected,\n> = unknown extends TSelected\n ? TStrict extends true\n ? MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>\n : MakeRouteMatchUnion<TRouter>\n : TSelected\n\n/**\n * Read and select the nearest or targeted route match.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchHook\n */\nexport function useMatch<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TThrow extends boolean = true,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts: UseMatchOptions<\n TRouter,\n TFrom,\n TStrict,\n ThrowConstraint<TStrict, TThrow>,\n TSelected,\n TStructuralSharing\n >,\n): ThrowOrOptional<UseMatchResult<TRouter, TFrom, TStrict, TSelected>, TThrow> {\n const router = useRouter<TRouter>()\n const nearestMatchId = React.useContext(\n opts.from ? dummyMatchContext : matchContext,\n )\n\n const key = opts.from ?? nearestMatchId\n const matchStore = key\n ? opts.from\n ? router.stores.getMatchStoreByRouteId(key)\n : router.stores.activeMatchStoresById.get(key)\n : undefined\n\n if (isServer ?? router.isServer) {\n const match = matchStore?.get()\n if ((opts.shouldThrow ?? true) && !match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n }\n\n invariant()\n }\n\n if (match === undefined) {\n return undefined as any\n }\n\n return (opts.select ? opts.select(match as any) : match) as any\n }\n\n const previousResult =\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n React.useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(\n undefined,\n )\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n return useStore(matchStore ?? dummyStore, (match) => {\n if ((opts.shouldThrow ?? true) && !match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n }\n\n invariant()\n }\n\n if (match === undefined) {\n return undefined\n }\n\n const selected = (\n opts.select ? opts.select(match as any) : match\n ) as ValidateSelected<TRouter, TSelected, TStructuralSharing>\n\n if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {\n const shared = replaceEqualDeep(previousResult.current, selected)\n previousResult.current = shared\n return shared\n }\n\n return selected\n }) as any\n}\n"],"mappings":";;;;;;;;AAsBA,IAAM,aAAa;CACjB,WAAW,KAAA;CACX,kBAAkB,EAAE,mBAAmB,IAAI;CAC5C;;;;;AAiED,SAAgB,SAQd,MAQ6E;CAC7E,MAAM,SAAS,WAAoB;CACnC,MAAM,iBAAiB,QAAM,WAC3B,KAAK,OAAO,oBAAoB,aACjC;CAED,MAAM,MAAM,KAAK,QAAQ;CACzB,MAAM,aAAa,MACf,KAAK,OACH,OAAO,OAAO,uBAAuB,IAAI,GACzC,OAAO,OAAO,sBAAsB,IAAI,IAAI,GAC9C,KAAA;AAEJ,KAAI,YAAY,OAAO,UAAU;EAC/B,MAAM,QAAQ,YAAY,KAAK;AAC/B,OAAK,KAAK,eAAe,SAAS,CAAC,OAAO;AACxC,OAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,oCAAoC,KAAK,OAAO,yBAAyB,KAAK,KAAK,KAAK,qBACzF;AAGH,cAAW;;AAGb,MAAI,UAAU,KAAA,EACZ;AAGF,SAAQ,KAAK,SAAS,KAAK,OAAO,MAAa,GAAG;;CAGpD,MAAM,iBAEJ,QAAM,OACJ,KAAA,EACD;AAGH,QAAO,SAAS,cAAc,aAAa,UAAU;AACnD,OAAK,KAAK,eAAe,SAAS,CAAC,OAAO;AACxC,OAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,oCAAoC,KAAK,OAAO,yBAAyB,KAAK,KAAK,KAAK,qBACzF;AAGH,cAAW;;AAGb,MAAI,UAAU,KAAA,EACZ;EAGF,MAAM,WACJ,KAAK,SAAS,KAAK,OAAO,MAAa,GAAG;AAG5C,MAAI,KAAK,qBAAqB,OAAO,QAAQ,0BAA0B;GACrE,MAAM,SAAS,iBAAiB,eAAe,SAAS,SAAS;AACjE,kBAAe,UAAU;AACzB,UAAO;;AAGT,SAAO;GACP"}
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useLayoutEffect } from "./utils.js";
2
3
  import { useRouter } from "./useRouter.js";
3
4
  import * as React$1 from "react";
@@ -1 +1 @@
1
- {"version":3,"file":"useNavigate.js","names":[],"sources":["../../src/useNavigate.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useLayoutEffect } from './utils'\nimport { useRouter } from './useRouter'\nimport type {\n AnyRouter,\n FromPathOption,\n NavigateOptions,\n RegisteredRouter,\n UseNavigateResult,\n} from '@tanstack/router-core'\n\n/**\n * Imperative navigation hook.\n *\n * Returns a stable `navigate(options)` function to change the current location\n * programmatically. Prefer the `Link` component for user-initiated navigation,\n * and use this hook from effects, callbacks, or handlers where imperative\n * navigation is required.\n *\n * Options:\n * - `from`: Optional route base used to resolve relative `to` paths.\n *\n * @returns A function that accepts `NavigateOptions`.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useNavigateHook\n */\nexport function useNavigate<\n TRouter extends AnyRouter = RegisteredRouter,\n TDefaultFrom extends string = string,\n>(_defaultOpts?: {\n from?: FromPathOption<TRouter, TDefaultFrom>\n}): UseNavigateResult<TDefaultFrom> {\n const router = useRouter()\n\n return React.useCallback(\n (options: NavigateOptions) => {\n return router.navigate({\n ...options,\n from: options.from ?? _defaultOpts?.from,\n })\n },\n [_defaultOpts?.from, router],\n ) as UseNavigateResult<TDefaultFrom>\n}\n\n/**\n * Component that triggers a navigation when rendered. Navigation executes\n * in an effect after mount/update.\n *\n * Props are the same as `NavigateOptions` used by `navigate()`.\n *\n * @returns null\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/navigateComponent\n */\nexport function Navigate<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string = string,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(props: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): null {\n const router = useRouter()\n const navigate = useNavigate()\n\n const previousPropsRef = React.useRef<NavigateOptions<\n TRouter,\n TFrom,\n TTo,\n TMaskFrom,\n TMaskTo\n > | null>(null)\n useLayoutEffect(() => {\n if (previousPropsRef.current !== props) {\n navigate(props)\n previousPropsRef.current = props\n }\n }, [router, props, navigate])\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,SAAgB,YAGd,cAEkC;CAClC,MAAM,SAAS,WAAW;AAE1B,QAAO,QAAM,aACV,YAA6B;AAC5B,SAAO,OAAO,SAAS;GACrB,GAAG;GACH,MAAM,QAAQ,QAAQ,cAAc;GACrC,CAAC;IAEJ,CAAC,cAAc,MAAM,OAAO,CAC7B;;;;;;;;;;;AAYH,SAAgB,SAMd,OAAuE;CACvE,MAAM,SAAS,WAAW;CAC1B,MAAM,WAAW,aAAa;CAE9B,MAAM,mBAAmB,QAAM,OAMrB,KAAK;AACf,uBAAsB;AACpB,MAAI,iBAAiB,YAAY,OAAO;AACtC,YAAS,MAAM;AACf,oBAAiB,UAAU;;IAE5B;EAAC;EAAQ;EAAO;EAAS,CAAC;AAC7B,QAAO"}
1
+ {"version":3,"file":"useNavigate.js","names":[],"sources":["../../src/useNavigate.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { useLayoutEffect } from './utils'\nimport { useRouter } from './useRouter'\nimport type {\n AnyRouter,\n FromPathOption,\n NavigateOptions,\n RegisteredRouter,\n UseNavigateResult,\n} from '@tanstack/router-core'\n\n/**\n * Imperative navigation hook.\n *\n * Returns a stable `navigate(options)` function to change the current location\n * programmatically. Prefer the `Link` component for user-initiated navigation,\n * and use this hook from effects, callbacks, or handlers where imperative\n * navigation is required.\n *\n * Options:\n * - `from`: Optional route base used to resolve relative `to` paths.\n *\n * @returns A function that accepts `NavigateOptions`.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useNavigateHook\n */\nexport function useNavigate<\n TRouter extends AnyRouter = RegisteredRouter,\n TDefaultFrom extends string = string,\n>(_defaultOpts?: {\n from?: FromPathOption<TRouter, TDefaultFrom>\n}): UseNavigateResult<TDefaultFrom> {\n const router = useRouter()\n\n return React.useCallback(\n (options: NavigateOptions) => {\n return router.navigate({\n ...options,\n from: options.from ?? _defaultOpts?.from,\n })\n },\n [_defaultOpts?.from, router],\n ) as UseNavigateResult<TDefaultFrom>\n}\n\n/**\n * Component that triggers a navigation when rendered. Navigation executes\n * in an effect after mount/update.\n *\n * Props are the same as `NavigateOptions` used by `navigate()`.\n *\n * @returns null\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/navigateComponent\n */\nexport function Navigate<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string = string,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(props: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): null {\n const router = useRouter()\n const navigate = useNavigate()\n\n const previousPropsRef = React.useRef<NavigateOptions<\n TRouter,\n TFrom,\n TTo,\n TMaskFrom,\n TMaskTo\n > | null>(null)\n useLayoutEffect(() => {\n if (previousPropsRef.current !== props) {\n navigate(props)\n previousPropsRef.current = props\n }\n }, [router, props, navigate])\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,YAGd,cAEkC;CAClC,MAAM,SAAS,WAAW;AAE1B,QAAO,QAAM,aACV,YAA6B;AAC5B,SAAO,OAAO,SAAS;GACrB,GAAG;GACH,MAAM,QAAQ,QAAQ,cAAc;GACrC,CAAC;IAEJ,CAAC,cAAc,MAAM,OAAO,CAC7B;;;;;;;;;;;AAYH,SAAgB,SAMd,OAAuE;CACvE,MAAM,SAAS,WAAW;CAC1B,MAAM,WAAW,aAAa;CAE9B,MAAM,mBAAmB,QAAM,OAMrB,KAAK;AACf,uBAAsB;AACpB,MAAI,iBAAiB,YAAY,OAAO;AACtC,YAAS,MAAM;AACf,oBAAiB,UAAU;;IAE5B;EAAC;EAAQ;EAAO;EAAS,CAAC;AAC7B,QAAO"}
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { routerContext } from "./routerContext.js";
2
3
  import * as React$1 from "react";
3
4
  //#region src/useRouter.tsx
@@ -1 +1 @@
1
- {"version":3,"file":"useRouter.js","names":[],"sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport { routerContext } from './routerContext'\nimport type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'\n\n/**\n * Access the current TanStack Router instance from React context.\n * Must be used within a `RouterProvider`.\n *\n * Options:\n * - `warn`: Log a warning if no router context is found (default: true).\n *\n * @returns The registered router instance.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook\n */\nexport function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {\n warn?: boolean\n}): TRouter {\n const value = React.useContext(routerContext)\n if (process.env.NODE_ENV !== 'production') {\n if ((opts?.warn ?? true) && !value) {\n console.warn(\n 'Warning: useRouter must be used inside a <RouterProvider> component!',\n )\n }\n }\n return value as any\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,UAAwD,MAE5D;CACV,MAAM,QAAQ,QAAM,WAAW,cAAc;AAC7C,KAAA,QAAA,IAAA,aAA6B;OACtB,MAAM,QAAQ,SAAS,CAAC,MAC3B,SAAQ,KACN,uEACD;;AAGL,QAAO"}
1
+ {"version":3,"file":"useRouter.js","names":[],"sources":["../../src/useRouter.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { routerContext } from './routerContext'\nimport type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'\n\n/**\n * Access the current TanStack Router instance from React context.\n * Must be used within a `RouterProvider`.\n *\n * Options:\n * - `warn`: Log a warning if no router context is found (default: true).\n *\n * @returns The registered router instance.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook\n */\nexport function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {\n warn?: boolean\n}): TRouter {\n const value = React.useContext(routerContext)\n if (process.env.NODE_ENV !== 'production') {\n if ((opts?.warn ?? true) && !value) {\n console.warn(\n 'Warning: useRouter must be used inside a <RouterProvider> component!',\n )\n }\n }\n return value as any\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAgB,UAAwD,MAE5D;CACV,MAAM,QAAQ,QAAM,WAAW,cAAc;AAC7C,KAAA,QAAA,IAAA,aAA6B;OACtB,MAAM,QAAQ,SAAS,CAAC,MAC3B,SAAQ,KACN,uEACD;;AAGL,QAAO"}
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useRouter } from "./useRouter.js";
2
3
  import { replaceEqualDeep } from "@tanstack/router-core";
3
4
  import { useRef } from "react";
@@ -20,7 +21,7 @@ function useRouterState(opts) {
20
21
  const contextRouter = useRouter({ warn: opts?.router === void 0 });
21
22
  const router = opts?.router || contextRouter;
22
23
  if (isServer ?? router.isServer) {
23
- const state = router.stores.__store.state;
24
+ const state = router.stores.__store.get();
24
25
  return opts?.select ? opts.select(state) : state;
25
26
  }
26
27
  const previousResult = useRef(void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"useRouterState.js","names":[],"sources":["../../src/useRouterState.tsx"],"sourcesContent":["import { useStore } from '@tanstack/react-store'\nimport { useRef } from 'react'\nimport { replaceEqualDeep } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterState,\n} from '@tanstack/router-core'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\n\nexport type UseRouterStateOptions<\n TRouter extends AnyRouter,\n TSelected,\n TStructuralSharing,\n> = {\n router?: TRouter\n select?: (\n state: RouterState<TRouter['routeTree']>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n} & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseRouterStateResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected ? RouterState<TRouter['routeTree']> : TSelected\n\n/**\n * Subscribe to the router's state store with optional selection and\n * structural sharing for render optimization.\n *\n * Options:\n * - `select`: Project the full router state to a derived slice\n * - `structuralSharing`: Replace-equal semantics for stable references\n * - `router`: Read state from a specific router instance instead of context\n *\n * @returns The selected router state (or the full state by default).\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterStateHook\n */\nexport function useRouterState<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseRouterStateOptions<TRouter, TSelected, TStructuralSharing>,\n): UseRouterStateResult<TRouter, TSelected> {\n const contextRouter = useRouter<TRouter>({\n warn: opts?.router === undefined,\n })\n const router = opts?.router || contextRouter\n\n // During SSR we render exactly once and do not need reactivity.\n // Avoid subscribing to the store (and any structural sharing work) on the server.\n const _isServer = isServer ?? router.isServer\n if (_isServer) {\n const state = router.stores.__store.state as RouterState<\n TRouter['routeTree']\n >\n return (opts?.select ? opts.select(state) : state) as UseRouterStateResult<\n TRouter,\n TSelected\n >\n }\n\n const previousResult =\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(undefined)\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(router.stores.__store, (state) => {\n if (opts?.select) {\n if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {\n const newSlice = replaceEqualDeep(\n previousResult.current,\n opts.select(state),\n )\n previousResult.current = newSlice\n return newSlice\n }\n return opts.select(state)\n }\n return state\n }) as UseRouterStateResult<TRouter, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2CA,SAAgB,eAKd,MAC0C;CAC1C,MAAM,gBAAgB,UAAmB,EACvC,MAAM,MAAM,WAAW,KAAA,GACxB,CAAC;CACF,MAAM,SAAS,MAAM,UAAU;AAK/B,KADkB,YAAY,OAAO,UACtB;EACb,MAAM,QAAQ,OAAO,OAAO,QAAQ;AAGpC,SAAQ,MAAM,SAAS,KAAK,OAAO,MAAM,GAAG;;CAM9C,MAAM,iBAEJ,OAAiE,KAAA,EAAU;AAG7E,QAAO,SAAS,OAAO,OAAO,UAAU,UAAU;AAChD,MAAI,MAAM,QAAQ;AAChB,OAAI,KAAK,qBAAqB,OAAO,QAAQ,0BAA0B;IACrE,MAAM,WAAW,iBACf,eAAe,SACf,KAAK,OAAO,MAAM,CACnB;AACD,mBAAe,UAAU;AACzB,WAAO;;AAET,UAAO,KAAK,OAAO,MAAM;;AAE3B,SAAO;GACP"}
1
+ {"version":3,"file":"useRouterState.js","names":[],"sources":["../../src/useRouterState.tsx"],"sourcesContent":["'use client'\n\nimport { useStore } from '@tanstack/react-store'\nimport { useRef } from 'react'\nimport { replaceEqualDeep } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterState,\n} from '@tanstack/router-core'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\n\nexport type UseRouterStateOptions<\n TRouter extends AnyRouter,\n TSelected,\n TStructuralSharing,\n> = {\n router?: TRouter\n select?: (\n state: RouterState<TRouter['routeTree']>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n} & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseRouterStateResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected ? RouterState<TRouter['routeTree']> : TSelected\n\n/**\n * Subscribe to the router's state store with optional selection and\n * structural sharing for render optimization.\n *\n * Options:\n * - `select`: Project the full router state to a derived slice\n * - `structuralSharing`: Replace-equal semantics for stable references\n * - `router`: Read state from a specific router instance instead of context\n *\n * @returns The selected router state (or the full state by default).\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterStateHook\n */\nexport function useRouterState<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseRouterStateOptions<TRouter, TSelected, TStructuralSharing>,\n): UseRouterStateResult<TRouter, TSelected> {\n const contextRouter = useRouter<TRouter>({\n warn: opts?.router === undefined,\n })\n const router = opts?.router || contextRouter\n\n // During SSR we render exactly once and do not need reactivity.\n // Avoid subscribing to the store (and any structural sharing work) on the server.\n const _isServer = isServer ?? router.isServer\n if (_isServer) {\n const state = router.stores.__store.get() as RouterState<\n TRouter['routeTree']\n >\n return (opts?.select ? opts.select(state) : state) as UseRouterStateResult<\n TRouter,\n TSelected\n >\n }\n\n const previousResult =\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(undefined)\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(router.stores.__store, (state) => {\n if (opts?.select) {\n if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {\n const newSlice = replaceEqualDeep(\n previousResult.current,\n opts.select(state),\n )\n previousResult.current = newSlice\n return newSlice\n }\n return opts.select(state)\n }\n return state\n }) as UseRouterStateResult<TRouter, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,eAKd,MAC0C;CAC1C,MAAM,gBAAgB,UAAmB,EACvC,MAAM,MAAM,WAAW,KAAA,GACxB,CAAC;CACF,MAAM,SAAS,MAAM,UAAU;AAK/B,KADkB,YAAY,OAAO,UACtB;EACb,MAAM,QAAQ,OAAO,OAAO,QAAQ,KAAK;AAGzC,SAAQ,MAAM,SAAS,KAAK,OAAO,MAAM,GAAG;;CAM9C,MAAM,iBAEJ,OAAiE,KAAA,EAAU;AAG7E,QAAO,SAAS,OAAO,OAAO,UAAU,UAAU;AAChD,MAAI,MAAM,QAAQ;AAChB,OAAI,KAAK,qBAAqB,OAAO,QAAQ,0BAA0B;IACrE,MAAM,WAAW,iBACf,eAAe,SACf,KAAK,OAAO,MAAM,CACnB;AACD,mBAAe,UAAU;AACzB,WAAO;;AAET,UAAO,KAAK,OAAO,MAAM;;AAE3B,SAAO;GACP"}
package/dist/esm/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import * as React$1 from "react";
2
3
  /**
3
4
  * React.use if available (React 19+), undefined otherwise.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":[],"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"],"mappings":";;;;;AAYA,IAAa,WAEI,QARC;AAoBlB,IAAa,kBACX,OAAO,WAAW,cAAc,QAAM,kBAAkB,QAAM;;;;AAKhE,SAAgB,YAAe,OAAoB;CAEjD,MAAM,MAAM,QAAM,OAAqC;EAC9C;EACP,MAAM;EACP,CAAC;CAEF,MAAM,UAAU,IAAI,QAAQ;AAK5B,KAAI,UAAU,QACZ,KAAI,UAAU;EACL;EACP,MAAM;EACP;AAIH,QAAO,IAAI,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BrB,SAAgB,wBACd,KACA,UACA,8BAAwD,EAAE,EAC1D,UAAkC,EAAE,EACpC;AACA,SAAM,gBAAgB;AACpB,MACE,CAAC,IAAI,WACL,QAAQ,YACR,OAAO,yBAAyB,WAEhC;EAGF,MAAM,WAAW,IAAI,sBAAsB,CAAC,WAAW;AACrD,YAAS,MAAM;KACd,4BAA4B;AAE/B,WAAS,QAAQ,IAAI,QAAQ;AAE7B,eAAa;AACX,YAAS,YAAY;;IAEtB;EAAC;EAAU;EAA6B,QAAQ;EAAU;EAAI,CAAC;;;;;;;;;;;;;;;AAgBpE,SAAgB,gBAAmB,KAA6B;CAC9D,MAAM,WAAW,QAAM,OAAU,KAAK;AACtC,SAAM,oBAAoB,WAAW,SAAS,SAAU,EAAE,CAAC;AAC3D,QAAO"}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["'use client'\nimport * 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"],"mappings":";;;;;;AAaA,IAAa,WAEI,QARC;AAoBlB,IAAa,kBACX,OAAO,WAAW,cAAc,QAAM,kBAAkB,QAAM;;;;AAKhE,SAAgB,YAAe,OAAoB;CAEjD,MAAM,MAAM,QAAM,OAAqC;EAC9C;EACP,MAAM;EACP,CAAC;CAEF,MAAM,UAAU,IAAI,QAAQ;AAK5B,KAAI,UAAU,QACZ,KAAI,UAAU;EACL;EACP,MAAM;EACP;AAIH,QAAO,IAAI,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BrB,SAAgB,wBACd,KACA,UACA,8BAAwD,EAAE,EAC1D,UAAkC,EAAE,EACpC;AACA,SAAM,gBAAgB;AACpB,MACE,CAAC,IAAI,WACL,QAAQ,YACR,OAAO,yBAAyB,WAEhC;EAGF,MAAM,WAAW,IAAI,sBAAsB,CAAC,WAAW;AACrD,YAAS,MAAM;KACd,4BAA4B;AAE/B,WAAS,QAAQ,IAAI,QAAQ;AAE7B,eAAa;AACX,YAAS,YAAY;;IAEtB;EAAC;EAAU;EAA6B,QAAQ;EAAU;EAAI,CAAC;;;;;;;;;;;;;;;AAgBpE,SAAgB,gBAAmB,KAA6B;CAC9D,MAAM,WAAW,QAAM,OAAU,KAAK;AACtC,SAAM,oBAAoB,WAAW,SAAS,SAAU,EAAE,CAAC;AAC3D,QAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.168.13",
3
+ "version": "1.168.14",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -80,7 +80,7 @@
80
80
  "@tanstack/react-store": "^0.9.3",
81
81
  "isbot": "^5.1.22",
82
82
  "@tanstack/history": "1.161.6",
83
- "@tanstack/router-core": "1.168.9"
83
+ "@tanstack/router-core": "1.168.10"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@testing-library/jest-dom": "^6.6.3",
package/src/Asset.tsx CHANGED
@@ -1,3 +1,5 @@
1
+ 'use client'
2
+
1
3
  import * as React from 'react'
2
4
  import { isServer } from '@tanstack/router-core/isServer'
3
5
  import { useRouter } from './useRouter'
@@ -1,3 +1,5 @@
1
+ 'use client'
2
+
1
3
  import * as React from 'react'
2
4
  import type { ErrorRouteComponent } from './route'
3
5
  import type { ErrorInfo } from 'react'
@@ -1,3 +1,5 @@
1
+ 'use client'
2
+
1
3
  import React from 'react'
2
4
 
3
5
  export interface ClientOnlyProps {
@@ -1,3 +1,5 @@
1
+ 'use client'
2
+
1
3
  import * as React from 'react'
2
4
  import { Asset } from './Asset'
3
5
  import { useRouter } from './useRouter'
@@ -1,3 +1,5 @@
1
+ 'use client'
2
+
1
3
  import * as React from 'react'
2
4
  import { Asset } from './Asset'
3
5
  import { useRouter } from './useRouter'
package/src/Match.tsx CHANGED
@@ -1,3 +1,5 @@
1
+ 'use client'
2
+
1
3
  import * as React from 'react'
2
4
  import { useStore } from '@tanstack/react-store'
3
5
  import {
@@ -28,7 +30,7 @@ export const Match = React.memo(function MatchImpl({
28
30
  const router = useRouter()
29
31
 
30
32
  if (isServer ?? router.isServer) {
31
- const match = router.stores.activeMatchStoresById.get(matchId)?.state
33
+ const match = router.stores.activeMatchStoresById.get(matchId)?.get()
32
34
  if (!match) {
33
35
  if (process.env.NODE_ENV !== 'production') {
34
36
  throw new Error(
@@ -47,7 +49,7 @@ export const Match = React.memo(function MatchImpl({
47
49
  <MatchView
48
50
  router={router}
49
51
  matchId={matchId}
50
- resetKey={router.stores.loadedAt.state}
52
+ resetKey={router.stores.loadedAt.get()}
51
53
  matchState={{
52
54
  routeId,
53
55
  ssr: match.ssr,
@@ -241,8 +243,8 @@ function OnRendered({ resetKey }: { resetKey: number }) {
241
243
  router.emit({
242
244
  type: 'onRendered',
243
245
  ...getLocationChangeInfo(
244
- router.stores.location.state,
245
- router.stores.resolvedLocation.state,
246
+ router.stores.location.get(),
247
+ router.stores.resolvedLocation.get(),
246
248
  ),
247
249
  })
248
250
  prevHrefRef.current = currentHref
@@ -276,7 +278,7 @@ export const MatchInner = React.memo(function MatchInnerImpl({
276
278
  }
277
279
 
278
280
  if (isServer ?? router.isServer) {
279
- const match = router.stores.activeMatchStoresById.get(matchId)?.state
281
+ const match = router.stores.activeMatchStoresById.get(matchId)?.get()
280
282
  if (!match) {
281
283
  if (process.env.NODE_ENV !== 'production') {
282
284
  throw new Error(
@@ -502,7 +504,7 @@ export const Outlet = React.memo(function OutletImpl() {
502
504
  let childMatchId: string | undefined
503
505
 
504
506
  if (isServer ?? router.isServer) {
505
- const matches = router.stores.activeMatchesSnapshot.state
507
+ const matches = router.stores.activeMatchesSnapshot.get()
506
508
  const parentIndex = matchId
507
509
  ? matches.findIndex((match) => match.id === matchId)
508
510
  : -1
package/src/Matches.tsx CHANGED
@@ -1,3 +1,5 @@
1
+ 'use client'
2
+
1
3
  import * as React from 'react'
2
4
  import { useStore } from '@tanstack/react-store'
3
5
  import { replaceEqualDeep, rootRouteId } from '@tanstack/router-core'
@@ -75,11 +77,11 @@ function MatchesInner() {
75
77
  const router = useRouter()
76
78
  const _isServer = isServer ?? router.isServer
77
79
  const matchId = _isServer
78
- ? router.stores.firstMatchId.state
80
+ ? router.stores.firstMatchId.get()
79
81
  : // eslint-disable-next-line react-hooks/rules-of-hooks
80
82
  useStore(router.stores.firstMatchId, (id) => id)
81
83
  const resetKey = _isServer
82
- ? router.stores.loadedAt.state
84
+ ? router.stores.loadedAt.get()
83
85
  : // eslint-disable-next-line react-hooks/rules-of-hooks
84
86
  useStore(router.stores.loadedAt, (loadedAt) => loadedAt)
85
87
 
@@ -238,7 +240,7 @@ export function useMatches<
238
240
  )
239
241
 
240
242
  if (isServer ?? router.isServer) {
241
- const matches = router.stores.activeMatchesSnapshot.state as Array<
243
+ const matches = router.stores.activeMatchesSnapshot.get() as Array<
242
244
  MakeRouteMatchUnion<TRouter>
243
245
  >
244
246
  return (opts?.select ? opts.select(matches) : matches) as UseMatchesResult<
@@ -1,3 +1,5 @@
1
+ 'use client'
2
+
1
3
  import * as React from 'react'
2
4
  import { Matches } from './Matches'
3
5
  import { routerContext } from './routerContext'
package/src/Scripts.tsx CHANGED
@@ -58,10 +58,9 @@ export const Scripts = () => {
58
58
  )
59
59
 
60
60
  if (isServer ?? router.isServer) {
61
- const assetScripts = getAssetScripts(
62
- router.stores.activeMatchesSnapshot.state,
63
- )
64
- const scripts = getScripts(router.stores.activeMatchesSnapshot.state)
61
+ const activeMatches = router.stores.activeMatchesSnapshot.get()
62
+ const assetScripts = getAssetScripts(activeMatches)
63
+ const scripts = getScripts(activeMatches)
65
64
  return renderScripts(router, scripts, assetScripts)
66
65
  }
67
66
 
@@ -1,3 +1,5 @@
1
+ 'use client'
2
+
1
3
  import * as React from 'react'
2
4
  import { batch, useStore } from '@tanstack/react-store'
3
5
  import {
@@ -94,8 +96,8 @@ export function Transitioner() {
94
96
  router.emit({
95
97
  type: 'onLoad', // When the new URL has committed, when the new matches have been loaded into state.matches
96
98
  ...getLocationChangeInfo(
97
- router.stores.location.state,
98
- router.stores.resolvedLocation.state,
99
+ router.stores.location.get(),
100
+ router.stores.resolvedLocation.get(),
99
101
  ),
100
102
  })
101
103
  }
@@ -107,8 +109,8 @@ export function Transitioner() {
107
109
  router.emit({
108
110
  type: 'onBeforeRouteMount',
109
111
  ...getLocationChangeInfo(
110
- router.stores.location.state,
111
- router.stores.resolvedLocation.state,
112
+ router.stores.location.get(),
113
+ router.stores.resolvedLocation.get(),
112
114
  ),
113
115
  })
114
116
  }
@@ -117,8 +119,8 @@ export function Transitioner() {
117
119
  useLayoutEffect(() => {
118
120
  if (previousIsAnyPending && !isAnyPending) {
119
121
  const changeInfo = getLocationChangeInfo(
120
- router.stores.location.state,
121
- router.stores.resolvedLocation.state,
122
+ router.stores.location.get(),
123
+ router.stores.resolvedLocation.get(),
122
124
  )
123
125
  router.emit({
124
126
  type: 'onResolved',
@@ -126,10 +128,8 @@ export function Transitioner() {
126
128
  })
127
129
 
128
130
  batch(() => {
129
- router.stores.status.setState(() => 'idle')
130
- router.stores.resolvedLocation.setState(
131
- () => router.stores.location.state,
132
- )
131
+ router.stores.status.set('idle')
132
+ router.stores.resolvedLocation.set(router.stores.location.get())
133
133
  })
134
134
 
135
135
  if (changeInfo.hrefChanged) {