@tanstack/react-router 1.168.12 → 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.
- package/dist/cjs/Asset.cjs +1 -0
- package/dist/cjs/Asset.cjs.map +1 -1
- package/dist/cjs/CatchBoundary.cjs +9 -6
- 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 +6 -5
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Matches.cjs +4 -3
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +2 -2
- package/dist/cjs/RouterProvider.cjs +1 -0
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/Scripts.cjs +3 -2
- package/dist/cjs/Scripts.cjs.map +1 -1
- package/dist/cjs/Transitioner.cjs +6 -5
- package/dist/cjs/Transitioner.cjs.map +1 -1
- package/dist/cjs/headContentUtils.cjs +1 -1
- 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 +3 -3
- 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 +9 -6
- 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 +6 -5
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.d.ts +2 -2
- package/dist/esm/Matches.js +4 -3
- 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 +3 -2
- package/dist/esm/Scripts.js.map +1 -1
- package/dist/esm/Transitioner.js +6 -5
- package/dist/esm/Transitioner.js.map +1 -1
- package/dist/esm/headContentUtils.js +1 -1
- 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 +3 -3
- 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 +16 -20
- package/src/ClientOnly.tsx +2 -0
- package/src/HeadContent.dev.tsx +2 -0
- package/src/HeadContent.tsx +2 -0
- package/src/Match.tsx +8 -6
- package/src/Matches.tsx +8 -10
- package/src/RouterProvider.tsx +2 -0
- package/src/Scripts.tsx +3 -4
- package/src/Transitioner.tsx +10 -10
- package/src/headContentUtils.tsx +1 -1
- 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 +4 -3
- 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.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.
|
|
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
package/src/CatchBoundary.tsx
CHANGED
|
@@ -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'
|
|
@@ -36,9 +38,19 @@ class CatchBoundaryImpl extends React.Component<{
|
|
|
36
38
|
}) => React.ReactNode
|
|
37
39
|
onCatch?: (error: Error, errorInfo: ErrorInfo) => void
|
|
38
40
|
}> {
|
|
39
|
-
state = { error: null } as { error: Error | null; resetKey
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
state = { error: null } as { error: Error | null; resetKey?: string | number }
|
|
42
|
+
|
|
43
|
+
static getDerivedStateFromProps(
|
|
44
|
+
props: { getResetKey: () => string | number },
|
|
45
|
+
state: { resetKey?: string | number; error: Error | null },
|
|
46
|
+
) {
|
|
47
|
+
const resetKey = props.getResetKey()
|
|
48
|
+
|
|
49
|
+
if (state.error && state.resetKey !== resetKey) {
|
|
50
|
+
return { resetKey, error: null }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return { resetKey }
|
|
42
54
|
}
|
|
43
55
|
static getDerivedStateFromError(error: Error) {
|
|
44
56
|
return { error }
|
|
@@ -46,30 +58,14 @@ class CatchBoundaryImpl extends React.Component<{
|
|
|
46
58
|
reset() {
|
|
47
59
|
this.setState({ error: null })
|
|
48
60
|
}
|
|
49
|
-
componentDidUpdate(
|
|
50
|
-
prevProps: Readonly<{
|
|
51
|
-
getResetKey: () => string
|
|
52
|
-
children: (props: { error: any; reset: () => void }) => any
|
|
53
|
-
onCatch?: ((error: any, info: any) => void) | undefined
|
|
54
|
-
}>,
|
|
55
|
-
prevState: any,
|
|
56
|
-
): void {
|
|
57
|
-
if (prevState.error && prevState.resetKey !== this.state.resetKey) {
|
|
58
|
-
this.reset()
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
61
|
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
62
62
|
if (this.props.onCatch) {
|
|
63
63
|
this.props.onCatch(error, errorInfo)
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
render() {
|
|
67
|
-
// If the resetKey has changed, don't render the error
|
|
68
67
|
return this.props.children({
|
|
69
|
-
error:
|
|
70
|
-
this.state.resetKey !== this.props.getResetKey()
|
|
71
|
-
? null
|
|
72
|
-
: this.state.error,
|
|
68
|
+
error: this.state.error,
|
|
73
69
|
reset: () => {
|
|
74
70
|
this.reset()
|
|
75
71
|
},
|
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.activeMatchStoresById.get(matchId)?.
|
|
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.
|
|
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.
|
|
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.activeMatchStoresById.get(matchId)?.
|
|
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.
|
|
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'
|
|
@@ -22,11 +24,8 @@ import type {
|
|
|
22
24
|
MakeRouteMatchUnion,
|
|
23
25
|
MaskOptions,
|
|
24
26
|
MatchRouteOptions,
|
|
25
|
-
NoInfer,
|
|
26
27
|
RegisteredRouter,
|
|
27
|
-
ResolveRelativePath,
|
|
28
28
|
ResolveRoute,
|
|
29
|
-
RouteByPath,
|
|
30
29
|
ToSubOptionsProps,
|
|
31
30
|
} from '@tanstack/router-core'
|
|
32
31
|
|
|
@@ -78,11 +77,11 @@ function MatchesInner() {
|
|
|
78
77
|
const router = useRouter()
|
|
79
78
|
const _isServer = isServer ?? router.isServer
|
|
80
79
|
const matchId = _isServer
|
|
81
|
-
? router.stores.firstMatchId.
|
|
80
|
+
? router.stores.firstMatchId.get()
|
|
82
81
|
: // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
83
82
|
useStore(router.stores.firstMatchId, (id) => id)
|
|
84
83
|
const resetKey = _isServer
|
|
85
|
-
? router.stores.loadedAt.
|
|
84
|
+
? router.stores.loadedAt.get()
|
|
86
85
|
: // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
87
86
|
useStore(router.stores.loadedAt, (loadedAt) => loadedAt)
|
|
88
87
|
|
|
@@ -180,10 +179,9 @@ export type MakeMatchRouteOptions<
|
|
|
180
179
|
// If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns
|
|
181
180
|
children?:
|
|
182
181
|
| ((
|
|
183
|
-
params?:
|
|
184
|
-
TRouter['
|
|
185
|
-
|
|
186
|
-
>['types']['allParams'],
|
|
182
|
+
params?: Expand<
|
|
183
|
+
ResolveRoute<TRouter, TFrom, TTo>['types']['allParams']
|
|
184
|
+
>,
|
|
187
185
|
) => React.ReactNode)
|
|
188
186
|
| React.ReactNode
|
|
189
187
|
}
|
|
@@ -242,7 +240,7 @@ export function useMatches<
|
|
|
242
240
|
)
|
|
243
241
|
|
|
244
242
|
if (isServer ?? router.isServer) {
|
|
245
|
-
const matches = router.stores.activeMatchesSnapshot.
|
|
243
|
+
const matches = router.stores.activeMatchesSnapshot.get() as Array<
|
|
246
244
|
MakeRouteMatchUnion<TRouter>
|
|
247
245
|
>
|
|
248
246
|
return (opts?.select ? opts.select(matches) : matches) as UseMatchesResult<
|
package/src/RouterProvider.tsx
CHANGED
package/src/Scripts.tsx
CHANGED
|
@@ -58,10 +58,9 @@ 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.activeMatchesSnapshot.get()
|
|
62
|
+
const assetScripts = getAssetScripts(activeMatches)
|
|
63
|
+
const scripts = getScripts(activeMatches)
|
|
65
64
|
return renderScripts(router, scripts, assetScripts)
|
|
66
65
|
}
|
|
67
66
|
|
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 {
|
|
@@ -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.
|
|
98
|
-
router.stores.resolvedLocation.
|
|
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.
|
|
111
|
-
router.stores.resolvedLocation.
|
|
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.
|
|
121
|
-
router.stores.resolvedLocation.
|
|
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.
|
|
130
|
-
router.stores.resolvedLocation.
|
|
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) {
|
package/src/headContentUtils.tsx
CHANGED
|
@@ -194,7 +194,7 @@ export const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {
|
|
|
194
194
|
return buildTagsFromMatches(
|
|
195
195
|
router,
|
|
196
196
|
nonce,
|
|
197
|
-
router.stores.activeMatchesSnapshot.
|
|
197
|
+
router.stores.activeMatchesSnapshot.get(),
|
|
198
198
|
assetCrossOrigin,
|
|
199
199
|
)
|
|
200
200
|
}
|
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<
|
|
@@ -117,7 +118,7 @@ export function useMatch<
|
|
|
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