@tanstack/react-router 1.168.5 → 1.168.6
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/Match.cjs +19 -14
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useBlocker.d.cts +2 -2
- package/dist/esm/Match.js +19 -14
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/useBlocker.d.ts +2 -2
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/llms/rules/api.d.ts +1 -1
- package/dist/llms/rules/api.js +1 -1
- package/package.json +1 -1
- package/src/Match.tsx +34 -39
- package/src/useBlocker.tsx +2 -2
package/dist/llms/rules/api.js
CHANGED
|
@@ -3570,7 +3570,7 @@ The \`useBlocker\` hook accepts a single _required_ argument, an option object:
|
|
|
3570
3570
|
- Think of this function as telling the router if it should block the navigation, so returning \`true\` mean that it should block the navigation and \`false\` meaning that it should be allowed
|
|
3571
3571
|
|
|
3572
3572
|
\`\`\`ts
|
|
3573
|
-
|
|
3573
|
+
type ShouldBlockFnLocation<...> = {
|
|
3574
3574
|
routeId: TRouteId
|
|
3575
3575
|
fullPath: TFullPath
|
|
3576
3576
|
pathname: string
|
package/package.json
CHANGED
package/src/Match.tsx
CHANGED
|
@@ -17,11 +17,8 @@ import { SafeFragment } from './SafeFragment'
|
|
|
17
17
|
import { renderRouteNotFound } from './renderRouteNotFound'
|
|
18
18
|
import { ScrollRestoration } from './scroll-restoration'
|
|
19
19
|
import { ClientOnly } from './ClientOnly'
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
ParsedLocation,
|
|
23
|
-
RootRouteOptions,
|
|
24
|
-
} from '@tanstack/router-core'
|
|
20
|
+
import { useLayoutEffect } from './utils'
|
|
21
|
+
import type { AnyRoute, RootRouteOptions } from '@tanstack/router-core'
|
|
25
22
|
|
|
26
23
|
export const Match = React.memo(function MatchImpl({
|
|
27
24
|
matchId,
|
|
@@ -204,7 +201,7 @@ function MatchView({
|
|
|
204
201
|
</matchContext.Provider>
|
|
205
202
|
{matchState.parentRouteId === rootRouteId ? (
|
|
206
203
|
<>
|
|
207
|
-
<OnRendered />
|
|
204
|
+
<OnRendered resetKey={resetKey} />
|
|
208
205
|
{router.options.scrollRestoration && (isServer ?? router.isServer) ? (
|
|
209
206
|
<ScrollRestoration />
|
|
210
207
|
) : null}
|
|
@@ -214,42 +211,40 @@ function MatchView({
|
|
|
214
211
|
)
|
|
215
212
|
}
|
|
216
213
|
|
|
217
|
-
// On Rendered can't happen above the root layout because it
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
// error that occurred above the root layout (like bad head/link tags,
|
|
223
|
-
// which is common).
|
|
224
|
-
function OnRendered() {
|
|
214
|
+
// On Rendered can't happen above the root layout because it needs to run after
|
|
215
|
+
// the route subtree has committed below the root layout. Keeping it here lets
|
|
216
|
+
// us fire onRendered even after a hydration mismatch above the root layout
|
|
217
|
+
// (like bad head/link tags, which is common).
|
|
218
|
+
function OnRendered({ resetKey }: { resetKey: number }) {
|
|
225
219
|
const router = useRouter()
|
|
226
220
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
221
|
+
if (isServer ?? router.isServer) {
|
|
222
|
+
return null
|
|
223
|
+
}
|
|
230
224
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
225
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
226
|
+
const prevHrefRef = React.useRef<string | undefined>(undefined)
|
|
227
|
+
|
|
228
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
229
|
+
useLayoutEffect(() => {
|
|
230
|
+
const currentHref = router.latestLocation.href
|
|
231
|
+
|
|
232
|
+
if (
|
|
233
|
+
prevHrefRef.current === undefined ||
|
|
234
|
+
prevHrefRef.current !== currentHref
|
|
235
|
+
) {
|
|
236
|
+
router.emit({
|
|
237
|
+
type: 'onRendered',
|
|
238
|
+
...getLocationChangeInfo(
|
|
239
|
+
router.stores.location.state,
|
|
240
|
+
router.stores.resolvedLocation.state,
|
|
241
|
+
),
|
|
242
|
+
})
|
|
243
|
+
prevHrefRef.current = currentHref
|
|
244
|
+
}
|
|
245
|
+
}, [router.latestLocation.state.__TSR_key, resetKey, router])
|
|
246
|
+
|
|
247
|
+
return null
|
|
253
248
|
}
|
|
254
249
|
|
|
255
250
|
export const MatchInner = React.memo(function MatchInnerImpl({
|
package/src/useBlocker.tsx
CHANGED
|
@@ -12,12 +12,12 @@ import type {
|
|
|
12
12
|
RegisteredRouter,
|
|
13
13
|
} from '@tanstack/router-core'
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
type ShouldBlockFnLocation<
|
|
16
16
|
out TRouteId,
|
|
17
17
|
out TFullPath,
|
|
18
18
|
out TAllParams,
|
|
19
19
|
out TFullSearchSchema,
|
|
20
|
-
> {
|
|
20
|
+
> = {
|
|
21
21
|
routeId: TRouteId
|
|
22
22
|
fullPath: TFullPath
|
|
23
23
|
pathname: string
|