@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.
@@ -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
- interface ShouldBlockFnLocation<...> {
3573
+ type ShouldBlockFnLocation<...> = {
3574
3574
  routeId: TRouteId
3575
3575
  fullPath: TFullPath
3576
3576
  pathname: string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.168.5",
3
+ "version": "1.168.6",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
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 type {
21
- AnyRoute,
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 actually
218
- // renders a dummy dom element to track the rendered state of the app.
219
- // We render a script tag with a key that changes based on the current
220
- // location state.__TSR_key. Also, because it's below the root layout, it
221
- // allows us to fire onRendered events even after a hydration mismatch
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
- const prevLocationRef = React.useRef<undefined | ParsedLocation<{}>>(
228
- undefined,
229
- )
221
+ if (isServer ?? router.isServer) {
222
+ return null
223
+ }
230
224
 
231
- return (
232
- <script
233
- key={router.latestLocation.state.__TSR_key}
234
- suppressHydrationWarning
235
- ref={(el) => {
236
- if (
237
- el &&
238
- (prevLocationRef.current === undefined ||
239
- prevLocationRef.current.href !== router.latestLocation.href)
240
- ) {
241
- router.emit({
242
- type: 'onRendered',
243
- ...getLocationChangeInfo(
244
- router.stores.location.state,
245
- router.stores.resolvedLocation.state,
246
- ),
247
- })
248
- prevLocationRef.current = router.latestLocation
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({
@@ -12,12 +12,12 @@ import type {
12
12
  RegisteredRouter,
13
13
  } from '@tanstack/router-core'
14
14
 
15
- interface ShouldBlockFnLocation<
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