@tanstack/react-router 1.168.13 → 1.168.15
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.
- package/dist/cjs/Asset.cjs +1 -0
- package/dist/cjs/Asset.cjs.map +1 -1
- package/dist/cjs/CatchBoundary.cjs +1 -0
- package/dist/cjs/CatchBoundary.cjs.map +1 -1
- package/dist/cjs/ClientOnly.cjs +1 -0
- package/dist/cjs/ClientOnly.cjs.map +1 -1
- package/dist/cjs/HeadContent.cjs +1 -0
- package/dist/cjs/HeadContent.cjs.map +1 -1
- package/dist/cjs/HeadContent.dev.cjs +1 -0
- package/dist/cjs/HeadContent.dev.cjs.map +1 -1
- package/dist/cjs/Match.cjs +9 -8
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Matches.cjs +6 -5
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/RouterProvider.cjs +1 -0
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/Scripts.cjs +5 -4
- package/dist/cjs/Scripts.cjs.map +1 -1
- package/dist/cjs/Transitioner.cjs +9 -8
- package/dist/cjs/Transitioner.cjs.map +1 -1
- package/dist/cjs/headContentUtils.cjs +6 -6
- package/dist/cjs/headContentUtils.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/index.dev.cjs +1 -0
- package/dist/cjs/link.cjs +2 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/matchContext.cjs +1 -0
- package/dist/cjs/matchContext.cjs.map +1 -1
- package/dist/cjs/not-found.cjs +1 -1
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/routerContext.cjs +1 -0
- package/dist/cjs/routerContext.cjs.map +1 -1
- package/dist/cjs/routerStores.cjs +2 -2
- package/dist/cjs/routerStores.cjs.map +1 -1
- package/dist/cjs/ssr/RouterClient.cjs +1 -1
- package/dist/cjs/ssr/RouterClient.cjs.map +1 -1
- package/dist/cjs/ssr/renderRouterToStream.cjs +2 -2
- package/dist/cjs/ssr/renderRouterToStream.cjs.map +1 -1
- package/dist/cjs/ssr/renderRouterToString.cjs +1 -1
- package/dist/cjs/ssr/renderRouterToString.cjs.map +1 -1
- package/dist/cjs/useBlocker.cjs +1 -0
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useCanGoBack.cjs +1 -1
- package/dist/cjs/useCanGoBack.cjs.map +1 -1
- package/dist/cjs/useLocation.cjs +1 -1
- package/dist/cjs/useLocation.cjs.map +1 -1
- package/dist/cjs/useMatch.cjs +4 -4
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useNavigate.cjs +1 -0
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useRouter.cjs +1 -0
- package/dist/cjs/useRouter.cjs.map +1 -1
- package/dist/cjs/useRouterState.cjs +2 -1
- package/dist/cjs/useRouterState.cjs.map +1 -1
- package/dist/cjs/utils.cjs +1 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/esm/Asset.js +1 -0
- package/dist/esm/Asset.js.map +1 -1
- package/dist/esm/CatchBoundary.js +1 -0
- package/dist/esm/CatchBoundary.js.map +1 -1
- package/dist/esm/ClientOnly.js +1 -0
- package/dist/esm/ClientOnly.js.map +1 -1
- package/dist/esm/HeadContent.dev.js +1 -0
- package/dist/esm/HeadContent.dev.js.map +1 -1
- package/dist/esm/HeadContent.js +1 -0
- package/dist/esm/HeadContent.js.map +1 -1
- package/dist/esm/Match.js +9 -8
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.js +6 -5
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.js +1 -0
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/Scripts.js +5 -4
- package/dist/esm/Scripts.js.map +1 -1
- package/dist/esm/Transitioner.js +9 -8
- package/dist/esm/Transitioner.js.map +1 -1
- package/dist/esm/headContentUtils.js +6 -6
- package/dist/esm/headContentUtils.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.dev.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/link.js +2 -1
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/matchContext.js +1 -0
- package/dist/esm/matchContext.js.map +1 -1
- package/dist/esm/not-found.js +1 -1
- package/dist/esm/not-found.js.map +1 -1
- package/dist/esm/routerContext.js +1 -0
- package/dist/esm/routerContext.js.map +1 -1
- package/dist/esm/routerStores.js +3 -3
- package/dist/esm/routerStores.js.map +1 -1
- package/dist/esm/ssr/RouterClient.js +1 -1
- package/dist/esm/ssr/RouterClient.js.map +1 -1
- package/dist/esm/ssr/renderRouterToStream.js +2 -2
- package/dist/esm/ssr/renderRouterToStream.js.map +1 -1
- package/dist/esm/ssr/renderRouterToString.js +1 -1
- package/dist/esm/ssr/renderRouterToString.js.map +1 -1
- package/dist/esm/useBlocker.js +1 -0
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/useCanGoBack.js +1 -1
- package/dist/esm/useCanGoBack.js.map +1 -1
- package/dist/esm/useLocation.js +1 -1
- package/dist/esm/useLocation.js.map +1 -1
- package/dist/esm/useMatch.js +4 -4
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useNavigate.js +1 -0
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useRouter.js +1 -0
- package/dist/esm/useRouter.js.map +1 -1
- package/dist/esm/useRouterState.js +2 -1
- package/dist/esm/useRouterState.js.map +1 -1
- package/dist/esm/utils.js +1 -0
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/Asset.tsx +2 -0
- package/src/CatchBoundary.tsx +2 -0
- package/src/ClientOnly.tsx +2 -0
- package/src/HeadContent.dev.tsx +2 -0
- package/src/HeadContent.tsx +2 -0
- package/src/Match.tsx +11 -9
- package/src/Matches.tsx +8 -6
- package/src/RouterProvider.tsx +2 -0
- package/src/Scripts.tsx +5 -10
- package/src/Transitioner.tsx +13 -16
- package/src/headContentUtils.tsx +6 -6
- package/src/index.dev.tsx +2 -0
- package/src/index.tsx +5 -0
- package/src/link.tsx +3 -1
- package/src/matchContext.tsx +2 -0
- package/src/not-found.tsx +2 -2
- package/src/routerContext.tsx +2 -0
- package/src/routerStores.ts +3 -3
- package/src/ssr/RouterClient.tsx +1 -1
- package/src/ssr/renderRouterToStream.tsx +2 -2
- package/src/ssr/renderRouterToString.tsx +1 -1
- package/src/useBlocker.tsx +2 -0
- package/src/useCanGoBack.ts +1 -1
- package/src/useLocation.tsx +1 -1
- package/src/useMatch.tsx +6 -5
- package/src/useNavigate.tsx +2 -0
- package/src/useRouter.tsx +2 -0
- package/src/useRouterState.tsx +3 -1
- package/src/utils.ts +1 -0
|
@@ -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.
|
|
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":["
|
|
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
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["
|
|
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.
|
|
3
|
+
"version": "1.168.15",
|
|
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.
|
|
83
|
+
"@tanstack/router-core": "1.168.11"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@testing-library/jest-dom": "^6.6.3",
|
package/src/Asset.tsx
CHANGED
package/src/CatchBoundary.tsx
CHANGED
package/src/ClientOnly.tsx
CHANGED
package/src/HeadContent.dev.tsx
CHANGED
package/src/HeadContent.tsx
CHANGED
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.
|
|
33
|
+
const match = router.stores.matchStores.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.
|
|
52
|
+
resetKey={router.stores.loadedAt.get()}
|
|
51
53
|
matchState={{
|
|
52
54
|
routeId,
|
|
53
55
|
ssr: match.ssr,
|
|
@@ -62,7 +64,7 @@ export const Match = React.memo(function MatchImpl({
|
|
|
62
64
|
// The matchId prop is stable for this component's lifetime (set by Outlet),
|
|
63
65
|
// and reconcileMatchPool reuses stores for the same matchId.
|
|
64
66
|
|
|
65
|
-
const matchStore = router.stores.
|
|
67
|
+
const matchStore = router.stores.matchStores.get(matchId)
|
|
66
68
|
if (!matchStore) {
|
|
67
69
|
if (process.env.NODE_ENV !== 'production') {
|
|
68
70
|
throw new Error(
|
|
@@ -241,8 +243,8 @@ function OnRendered({ resetKey }: { resetKey: number }) {
|
|
|
241
243
|
router.emit({
|
|
242
244
|
type: 'onRendered',
|
|
243
245
|
...getLocationChangeInfo(
|
|
244
|
-
router.stores.location.
|
|
245
|
-
router.stores.resolvedLocation.
|
|
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.
|
|
281
|
+
const match = router.stores.matchStores.get(matchId)?.get()
|
|
280
282
|
if (!match) {
|
|
281
283
|
if (process.env.NODE_ENV !== 'production') {
|
|
282
284
|
throw new Error(
|
|
@@ -355,7 +357,7 @@ export const MatchInner = React.memo(function MatchInnerImpl({
|
|
|
355
357
|
return out
|
|
356
358
|
}
|
|
357
359
|
|
|
358
|
-
const matchStore = router.stores.
|
|
360
|
+
const matchStore = router.stores.matchStores.get(matchId)
|
|
359
361
|
if (!matchStore) {
|
|
360
362
|
if (process.env.NODE_ENV !== 'production') {
|
|
361
363
|
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.
|
|
507
|
+
const matches = router.stores.matches.get()
|
|
506
508
|
const parentIndex = matchId
|
|
507
509
|
? matches.findIndex((match) => match.id === matchId)
|
|
508
510
|
: -1
|
|
@@ -515,7 +517,7 @@ export const Outlet = React.memo(function OutletImpl() {
|
|
|
515
517
|
// Subscribe directly to the match store from the pool instead of
|
|
516
518
|
// the two-level byId → matchStore pattern.
|
|
517
519
|
const parentMatchStore = matchId
|
|
518
|
-
? router.stores.
|
|
520
|
+
? router.stores.matchStores.get(matchId)
|
|
519
521
|
: undefined
|
|
520
522
|
|
|
521
523
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
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.
|
|
80
|
+
? router.stores.firstId.get()
|
|
79
81
|
: // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
80
|
-
useStore(router.stores.
|
|
82
|
+
useStore(router.stores.firstId, (id) => id)
|
|
81
83
|
const resetKey = _isServer
|
|
82
|
-
? router.stores.loadedAt.
|
|
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
|
|
|
@@ -140,7 +142,7 @@ export function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {
|
|
|
140
142
|
|
|
141
143
|
if (!(isServer ?? router.isServer)) {
|
|
142
144
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
143
|
-
useStore(router.stores.
|
|
145
|
+
useStore(router.stores.matchRouteDeps, (d) => d)
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
return React.useCallback(
|
|
@@ -238,7 +240,7 @@ export function useMatches<
|
|
|
238
240
|
)
|
|
239
241
|
|
|
240
242
|
if (isServer ?? router.isServer) {
|
|
241
|
-
const matches = router.stores.
|
|
243
|
+
const matches = router.stores.matches.get() as Array<
|
|
242
244
|
MakeRouteMatchUnion<TRouter>
|
|
243
245
|
>
|
|
244
246
|
return (opts?.select ? opts.select(matches) : matches) as UseMatchesResult<
|
|
@@ -248,7 +250,7 @@ export function useMatches<
|
|
|
248
250
|
}
|
|
249
251
|
|
|
250
252
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
251
|
-
return useStore(router.stores.
|
|
253
|
+
return useStore(router.stores.matches, (matches) => {
|
|
252
254
|
const selected = opts?.select
|
|
253
255
|
? opts.select(matches as Array<MakeRouteMatchUnion<TRouter>>)
|
|
254
256
|
: (matches as any)
|
package/src/RouterProvider.tsx
CHANGED
package/src/Scripts.tsx
CHANGED
|
@@ -58,25 +58,20 @@ export const Scripts = () => {
|
|
|
58
58
|
)
|
|
59
59
|
|
|
60
60
|
if (isServer ?? router.isServer) {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
)
|
|
64
|
-
const scripts = getScripts(router.stores.activeMatchesSnapshot.state)
|
|
61
|
+
const activeMatches = router.stores.matches.get()
|
|
62
|
+
const assetScripts = getAssetScripts(activeMatches)
|
|
63
|
+
const scripts = getScripts(activeMatches)
|
|
65
64
|
return renderScripts(router, scripts, assetScripts)
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
|
|
69
68
|
const assetScripts = useStore(
|
|
70
|
-
router.stores.
|
|
69
|
+
router.stores.matches,
|
|
71
70
|
getAssetScripts,
|
|
72
71
|
deepEqual,
|
|
73
72
|
)
|
|
74
73
|
// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
|
|
75
|
-
const scripts = useStore(
|
|
76
|
-
router.stores.activeMatchesSnapshot,
|
|
77
|
-
getScripts,
|
|
78
|
-
deepEqual,
|
|
79
|
-
)
|
|
74
|
+
const scripts = useStore(router.stores.matches, getScripts, deepEqual)
|
|
80
75
|
|
|
81
76
|
return renderScripts(router, scripts, assetScripts)
|
|
82
77
|
}
|
package/src/Transitioner.tsx
CHANGED
|
@@ -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 {
|
|
@@ -15,17 +17,14 @@ export function Transitioner() {
|
|
|
15
17
|
const [isTransitioning, setIsTransitioning] = React.useState(false)
|
|
16
18
|
// Track pending state changes
|
|
17
19
|
const isLoading = useStore(router.stores.isLoading, (value) => value)
|
|
18
|
-
const
|
|
19
|
-
router.stores.hasPendingMatches,
|
|
20
|
-
(value) => value,
|
|
21
|
-
)
|
|
20
|
+
const hasPending = useStore(router.stores.hasPending, (value) => value)
|
|
22
21
|
|
|
23
22
|
const previousIsLoading = usePrevious(isLoading)
|
|
24
23
|
|
|
25
|
-
const isAnyPending = isLoading || isTransitioning ||
|
|
24
|
+
const isAnyPending = isLoading || isTransitioning || hasPending
|
|
26
25
|
const previousIsAnyPending = usePrevious(isAnyPending)
|
|
27
26
|
|
|
28
|
-
const isPagePending = isLoading ||
|
|
27
|
+
const isPagePending = isLoading || hasPending
|
|
29
28
|
const previousIsPagePending = usePrevious(isPagePending)
|
|
30
29
|
|
|
31
30
|
router.startTransition = (fn: () => void) => {
|
|
@@ -94,8 +93,8 @@ export function Transitioner() {
|
|
|
94
93
|
router.emit({
|
|
95
94
|
type: 'onLoad', // When the new URL has committed, when the new matches have been loaded into state.matches
|
|
96
95
|
...getLocationChangeInfo(
|
|
97
|
-
router.stores.location.
|
|
98
|
-
router.stores.resolvedLocation.
|
|
96
|
+
router.stores.location.get(),
|
|
97
|
+
router.stores.resolvedLocation.get(),
|
|
99
98
|
),
|
|
100
99
|
})
|
|
101
100
|
}
|
|
@@ -107,8 +106,8 @@ export function Transitioner() {
|
|
|
107
106
|
router.emit({
|
|
108
107
|
type: 'onBeforeRouteMount',
|
|
109
108
|
...getLocationChangeInfo(
|
|
110
|
-
router.stores.location.
|
|
111
|
-
router.stores.resolvedLocation.
|
|
109
|
+
router.stores.location.get(),
|
|
110
|
+
router.stores.resolvedLocation.get(),
|
|
112
111
|
),
|
|
113
112
|
})
|
|
114
113
|
}
|
|
@@ -117,8 +116,8 @@ export function Transitioner() {
|
|
|
117
116
|
useLayoutEffect(() => {
|
|
118
117
|
if (previousIsAnyPending && !isAnyPending) {
|
|
119
118
|
const changeInfo = getLocationChangeInfo(
|
|
120
|
-
router.stores.location.
|
|
121
|
-
router.stores.resolvedLocation.
|
|
119
|
+
router.stores.location.get(),
|
|
120
|
+
router.stores.resolvedLocation.get(),
|
|
122
121
|
)
|
|
123
122
|
router.emit({
|
|
124
123
|
type: 'onResolved',
|
|
@@ -126,10 +125,8 @@ export function Transitioner() {
|
|
|
126
125
|
})
|
|
127
126
|
|
|
128
127
|
batch(() => {
|
|
129
|
-
router.stores.status.
|
|
130
|
-
router.stores.resolvedLocation.
|
|
131
|
-
() => router.stores.location.state,
|
|
132
|
-
)
|
|
128
|
+
router.stores.status.set('idle')
|
|
129
|
+
router.stores.resolvedLocation.set(router.stores.location.get())
|
|
133
130
|
})
|
|
134
131
|
|
|
135
132
|
if (changeInfo.hrefChanged) {
|
package/src/headContentUtils.tsx
CHANGED
|
@@ -194,14 +194,14 @@ export const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {
|
|
|
194
194
|
return buildTagsFromMatches(
|
|
195
195
|
router,
|
|
196
196
|
nonce,
|
|
197
|
-
router.stores.
|
|
197
|
+
router.stores.matches.get(),
|
|
198
198
|
assetCrossOrigin,
|
|
199
199
|
)
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
|
|
203
203
|
const routeMeta = useStore(
|
|
204
|
-
router.stores.
|
|
204
|
+
router.stores.matches,
|
|
205
205
|
(matches) => {
|
|
206
206
|
return matches.map((match) => match.meta!).filter(Boolean)
|
|
207
207
|
},
|
|
@@ -282,7 +282,7 @@ export const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {
|
|
|
282
282
|
|
|
283
283
|
// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
|
|
284
284
|
const links = useStore(
|
|
285
|
-
router.stores.
|
|
285
|
+
router.stores.matches,
|
|
286
286
|
(matches) => {
|
|
287
287
|
const constructed = matches
|
|
288
288
|
.map((match) => match.links!)
|
|
@@ -327,7 +327,7 @@ export const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {
|
|
|
327
327
|
|
|
328
328
|
// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
|
|
329
329
|
const preloadLinks = useStore(
|
|
330
|
-
router.stores.
|
|
330
|
+
router.stores.matches,
|
|
331
331
|
(matches) => {
|
|
332
332
|
const preloadLinks: Array<RouterManagedTag> = []
|
|
333
333
|
|
|
@@ -359,7 +359,7 @@ export const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {
|
|
|
359
359
|
|
|
360
360
|
// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
|
|
361
361
|
const styles = useStore(
|
|
362
|
-
router.stores.
|
|
362
|
+
router.stores.matches,
|
|
363
363
|
(matches) =>
|
|
364
364
|
(
|
|
365
365
|
matches
|
|
@@ -379,7 +379,7 @@ export const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {
|
|
|
379
379
|
|
|
380
380
|
// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
|
|
381
381
|
const headScripts: Array<RouterManagedTag> = useStore(
|
|
382
|
-
router.stores.
|
|
382
|
+
router.stores.matches,
|
|
383
383
|
(matches) =>
|
|
384
384
|
(
|
|
385
385
|
matches
|
package/src/index.dev.tsx
CHANGED
package/src/index.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
1
3
|
export {
|
|
2
4
|
defer,
|
|
3
5
|
isMatch,
|
|
@@ -326,6 +328,9 @@ export type {
|
|
|
326
328
|
InferSelected,
|
|
327
329
|
ValidateUseSearchResult,
|
|
328
330
|
ValidateUseParamsResult,
|
|
331
|
+
SerializerExtensions,
|
|
332
|
+
RegisteredSerializableInput,
|
|
333
|
+
Serializable,
|
|
329
334
|
} from '@tanstack/router-core'
|
|
330
335
|
|
|
331
336
|
export { ScriptOnce } from './ScriptOnce'
|
package/src/link.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 { flushSync } from 'react-dom'
|
|
@@ -205,7 +207,7 @@ export function useLinkProps<
|
|
|
205
207
|
const isActive = (() => {
|
|
206
208
|
if (externalLink) return false
|
|
207
209
|
|
|
208
|
-
const currentLocation = router.stores.location.
|
|
210
|
+
const currentLocation = router.stores.location.get()
|
|
209
211
|
|
|
210
212
|
const exact = activeOptions?.exact ?? false
|
|
211
213
|
|
package/src/matchContext.tsx
CHANGED
package/src/not-found.tsx
CHANGED
|
@@ -15,8 +15,8 @@ export function CatchNotFound(props: {
|
|
|
15
15
|
const router = useRouter()
|
|
16
16
|
|
|
17
17
|
if (isServer ?? router.isServer) {
|
|
18
|
-
const pathname = router.stores.location.
|
|
19
|
-
const status = router.stores.status.
|
|
18
|
+
const pathname = router.stores.location.get().pathname
|
|
19
|
+
const status = router.stores.status.get()
|
|
20
20
|
const resetKey = `not-found-${pathname}-${status}`
|
|
21
21
|
|
|
22
22
|
return (
|
package/src/routerContext.tsx
CHANGED
package/src/routerStores.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { batch,
|
|
1
|
+
import { batch, createAtom } from '@tanstack/react-store'
|
|
2
2
|
import {
|
|
3
3
|
createNonReactiveMutableStore,
|
|
4
4
|
createNonReactiveReadonlyStore,
|
|
@@ -19,8 +19,8 @@ export const getStoreFactory: GetStoreConfig = (opts) => {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
return {
|
|
22
|
-
createMutableStore:
|
|
23
|
-
createReadonlyStore:
|
|
22
|
+
createMutableStore: createAtom,
|
|
23
|
+
createReadonlyStore: createAtom,
|
|
24
24
|
batch: batch,
|
|
25
25
|
}
|
|
26
26
|
}
|
package/src/ssr/RouterClient.tsx
CHANGED
|
@@ -7,7 +7,7 @@ let hydrationPromise: Promise<void | Array<Array<void>>> | undefined
|
|
|
7
7
|
|
|
8
8
|
export function RouterClient(props: { router: AnyRouter }) {
|
|
9
9
|
if (!hydrationPromise) {
|
|
10
|
-
if (!props.router.stores.matchesId.
|
|
10
|
+
if (!props.router.stores.matchesId.get().length) {
|
|
11
11
|
hydrationPromise = hydrate(props.router)
|
|
12
12
|
} else {
|
|
13
13
|
hydrationPromise = Promise.resolve()
|
|
@@ -36,7 +36,7 @@ export const renderRouterToStream = async ({
|
|
|
36
36
|
stream as unknown as ReadableStream,
|
|
37
37
|
)
|
|
38
38
|
return new Response(responseStream as any, {
|
|
39
|
-
status: router.stores.statusCode.
|
|
39
|
+
status: router.stores.statusCode.get(),
|
|
40
40
|
headers: responseHeaders,
|
|
41
41
|
})
|
|
42
42
|
}
|
|
@@ -79,7 +79,7 @@ export const renderRouterToStream = async ({
|
|
|
79
79
|
reactAppPassthrough,
|
|
80
80
|
)
|
|
81
81
|
return new Response(responseStream as any, {
|
|
82
|
-
status: router.stores.statusCode.
|
|
82
|
+
status: router.stores.statusCode.get(),
|
|
83
83
|
headers: responseHeaders,
|
|
84
84
|
})
|
|
85
85
|
}
|
package/src/useBlocker.tsx
CHANGED
package/src/useCanGoBack.ts
CHANGED
|
@@ -6,7 +6,7 @@ export function useCanGoBack() {
|
|
|
6
6
|
const router = useRouter()
|
|
7
7
|
|
|
8
8
|
if (isServer ?? router.isServer) {
|
|
9
|
-
return router.stores.location.
|
|
9
|
+
return router.stores.location.get().state.__TSR_index !== 0
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
// eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
|
package/src/useLocation.tsx
CHANGED
|
@@ -52,7 +52,7 @@ export function useLocation<
|
|
|
52
52
|
const router = useRouter<TRouter>()
|
|
53
53
|
|
|
54
54
|
if (isServer ?? router.isServer) {
|
|
55
|
-
const location = router.stores.location.
|
|
55
|
+
const location = router.stores.location.get()
|
|
56
56
|
return (
|
|
57
57
|
opts?.select ? opts.select(location as any) : location
|
|
58
58
|
) as UseLocationResult<TRouter, TSelected>
|
package/src/useMatch.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 { invariant, replaceEqualDeep } from '@tanstack/router-core'
|
|
@@ -19,9 +21,8 @@ import type {
|
|
|
19
21
|
} from '@tanstack/router-core'
|
|
20
22
|
|
|
21
23
|
const dummyStore = {
|
|
22
|
-
state: undefined,
|
|
23
24
|
get: () => undefined,
|
|
24
|
-
subscribe: () => () => {},
|
|
25
|
+
subscribe: () => ({ unsubscribe: () => {} }),
|
|
25
26
|
} as any
|
|
26
27
|
|
|
27
28
|
export interface UseMatchBaseOptions<
|
|
@@ -112,12 +113,12 @@ export function useMatch<
|
|
|
112
113
|
const key = opts.from ?? nearestMatchId
|
|
113
114
|
const matchStore = key
|
|
114
115
|
? opts.from
|
|
115
|
-
? router.stores.
|
|
116
|
-
: router.stores.
|
|
116
|
+
? router.stores.getRouteMatchStore(key)
|
|
117
|
+
: router.stores.matchStores.get(key)
|
|
117
118
|
: undefined
|
|
118
119
|
|
|
119
120
|
if (isServer ?? router.isServer) {
|
|
120
|
-
const match = matchStore?.
|
|
121
|
+
const match = matchStore?.get()
|
|
121
122
|
if ((opts.shouldThrow ?? true) && !match) {
|
|
122
123
|
if (process.env.NODE_ENV !== 'production') {
|
|
123
124
|
throw new Error(
|
package/src/useNavigate.tsx
CHANGED
package/src/useRouter.tsx
CHANGED
package/src/useRouterState.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
1
3
|
import { useStore } from '@tanstack/react-store'
|
|
2
4
|
import { useRef } from 'react'
|
|
3
5
|
import { replaceEqualDeep } from '@tanstack/router-core'
|
|
@@ -57,7 +59,7 @@ export function useRouterState<
|
|
|
57
59
|
// Avoid subscribing to the store (and any structural sharing work) on the server.
|
|
58
60
|
const _isServer = isServer ?? router.isServer
|
|
59
61
|
if (_isServer) {
|
|
60
|
-
const state = router.stores.__store.
|
|
62
|
+
const state = router.stores.__store.get() as RouterState<
|
|
61
63
|
TRouter['routeTree']
|
|
62
64
|
>
|
|
63
65
|
return (opts?.select ? opts.select(state) : state) as UseRouterStateResult<
|
package/src/utils.ts
CHANGED