Skip to content

Commit f054c0c

Browse files
authored
fix: revert "refactor: don't reparse upon navigation (#6398)" (#6468)
Revert "refactor: don't reparse upon navigation (#6398)" This reverts commit 6cbd96e.
1 parent a3c4854 commit f054c0c

18 files changed

Lines changed: 137 additions & 530 deletions

File tree

e2e/react-router/basic-file-based-code-splitting/src/routeTree.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ declare module '@tanstack/react-router' {
171171
'/_layout': {
172172
id: '/_layout'
173173
path: ''
174-
fullPath: '/'
174+
fullPath: ''
175175
preLoaderRoute: typeof LayoutRouteImport
176176
parentRoute: typeof rootRouteImport
177177
}
@@ -199,7 +199,7 @@ declare module '@tanstack/react-router' {
199199
'/_layout/_layout-2': {
200200
id: '/_layout/_layout-2'
201201
path: ''
202-
fullPath: '/'
202+
fullPath: ''
203203
preLoaderRoute: typeof LayoutLayout2RouteImport
204204
parentRoute: typeof LayoutRoute
205205
}

e2e/react-router/basic-react-query-file-based/src/routeTree.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ declare module '@tanstack/react-router' {
124124
'/_layout': {
125125
id: '/_layout'
126126
path: ''
127-
fullPath: '/'
127+
fullPath: ''
128128
preLoaderRoute: typeof LayoutRouteImport
129129
parentRoute: typeof rootRouteImport
130130
}
@@ -152,7 +152,7 @@ declare module '@tanstack/react-router' {
152152
'/_layout/_layout-2': {
153153
id: '/_layout/_layout-2'
154154
path: ''
155-
fullPath: '/'
155+
fullPath: ''
156156
preLoaderRoute: typeof LayoutLayout2RouteImport
157157
parentRoute: typeof LayoutRoute
158158
}

e2e/vue-start/custom-basepath/src/routeTree.gen.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export interface FileRoutesByFullPath {
106106
'/redirect/throw-it': typeof RedirectThrowItRoute
107107
'/users/$userId': typeof UsersUserIdRoute
108108
'/posts/': typeof PostsIndexRoute
109-
'/redirect/': typeof RedirectIndexRoute
109+
'/redirect': typeof RedirectIndexRoute
110110
'/users/': typeof UsersIndexRoute
111111
'/api/users/$userId': typeof ApiUsersUserIdRoute
112112
'/posts/$postId/deep': typeof PostsPostIdDeepRoute
@@ -155,7 +155,7 @@ export interface FileRouteTypes {
155155
| '/redirect/throw-it'
156156
| '/users/$userId'
157157
| '/posts/'
158-
| '/redirect/'
158+
| '/redirect'
159159
| '/users/'
160160
| '/api/users/$userId'
161161
| '/posts/$postId/deep'
@@ -250,7 +250,7 @@ declare module '@tanstack/vue-router' {
250250
'/redirect/': {
251251
id: '/redirect/'
252252
path: '/redirect'
253-
fullPath: '/redirect/'
253+
fullPath: '/redirect'
254254
preLoaderRoute: typeof RedirectIndexRouteImport
255255
parentRoute: typeof rootRouteImport
256256
}

packages/history/src/index.ts

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44

55
export interface NavigateOptions {
66
ignoreBlocker?: boolean
7-
/** When true, Transitioner should skip calling load() - commitLocation handles it */
8-
skipTransitionerLoad?: boolean
97
}
108

11-
/** Result of a navigation attempt (push/replace) */
12-
export type NavigationResult = { type: 'SUCCESS' } | { type: 'BLOCKED' }
13-
149
type SubscriberHistoryAction =
1510
| {
1611
type: Exclude<HistoryAction, 'GO'>
@@ -20,27 +15,18 @@ type SubscriberHistoryAction =
2015
index: number
2116
}
2217

23-
export type SubscriberArgs = {
18+
type SubscriberArgs = {
2419
location: HistoryLocation
2520
action: SubscriberHistoryAction
26-
navigateOpts?: NavigateOptions
2721
}
2822

2923
export interface RouterHistory {
3024
location: HistoryLocation
3125
length: number
3226
subscribers: Set<(opts: SubscriberArgs) => void>
3327
subscribe: (cb: (opts: SubscriberArgs) => void) => () => void
34-
push: (
35-
path: string,
36-
state?: any,
37-
navigateOpts?: NavigateOptions,
38-
) => Promise<NavigationResult>
39-
replace: (
40-
path: string,
41-
state?: any,
42-
navigateOpts?: NavigateOptions,
43-
) => Promise<NavigationResult>
28+
push: (path: string, state?: any, navigateOpts?: NavigateOptions) => void
29+
replace: (path: string, state?: any, navigateOpts?: NavigateOptions) => void
4430
go: (index: number, navigateOpts?: NavigateOptions) => void
4531
back: (navigateOpts?: NavigateOptions) => void
4632
forward: (navigateOpts?: NavigateOptions) => void
@@ -70,21 +56,6 @@ export type ParsedHistoryState = HistoryState & {
7056
key?: string // TODO: Remove in v2 - use __TSR_key instead
7157
__TSR_key?: string
7258
__TSR_index: number
73-
/** Whether to reset scroll position on this navigation (default: true) */
74-
__TSR_resetScroll?: boolean
75-
/** Session id for cached TSR internals */
76-
__TSR_sessionId?: string
77-
/** Match snapshot for fast-path on back/forward navigation */
78-
__TSR_matches?: {
79-
routeIds: Array<string>
80-
params: Record<string, string>
81-
globalNotFoundRouteId?: string
82-
searchStr?: string
83-
validatedSearches?: Array<{
84-
search: Record<string, unknown>
85-
strictSearch: Record<string, unknown>
86-
}>
87-
}
8859
}
8960

9061
type ShouldAllowNavigation = any
@@ -145,14 +116,9 @@ export function createHistory(opts: {
145116
let location = opts.getLocation()
146117
const subscribers = new Set<(opts: SubscriberArgs) => void>()
147118

148-
const notify = (
149-
action: SubscriberHistoryAction,
150-
navigateOpts?: NavigateOptions,
151-
) => {
119+
const notify = (action: SubscriberHistoryAction) => {
152120
location = opts.getLocation()
153-
subscribers.forEach((subscriber) =>
154-
subscriber({ location, action, navigateOpts }),
155-
)
121+
subscribers.forEach((subscriber) => subscriber({ location, action }))
156122
}
157123

158124
const handleIndexChange = (action: SubscriberHistoryAction) => {
@@ -164,11 +130,11 @@ export function createHistory(opts: {
164130
task,
165131
navigateOpts,
166132
...actionInfo
167-
}: TryNavigateArgs): Promise<NavigationResult> => {
133+
}: TryNavigateArgs) => {
168134
const ignoreBlocker = navigateOpts?.ignoreBlocker ?? false
169135
if (ignoreBlocker) {
170136
task()
171-
return { type: 'SUCCESS' }
137+
return
172138
}
173139

174140
const blockers = opts.getBlockers?.() ?? []
@@ -184,13 +150,12 @@ export function createHistory(opts: {
184150
})
185151
if (isBlocked) {
186152
opts.onBlocked?.()
187-
return { type: 'BLOCKED' }
153+
return
188154
}
189155
}
190156
}
191157

192158
task()
193-
return { type: 'SUCCESS' }
194159
}
195160

196161
return {
@@ -211,10 +176,10 @@ export function createHistory(opts: {
211176
push: (path, state, navigateOpts) => {
212177
const currentIndex = location.state[stateIndexKey]
213178
state = assignKeyAndIndex(currentIndex + 1, state)
214-
return tryNavigation({
179+
tryNavigation({
215180
task: () => {
216181
opts.pushState(path, state)
217-
notify({ type: 'PUSH' }, navigateOpts)
182+
notify({ type: 'PUSH' })
218183
},
219184
navigateOpts,
220185
type: 'PUSH',
@@ -225,10 +190,10 @@ export function createHistory(opts: {
225190
replace: (path, state, navigateOpts) => {
226191
const currentIndex = location.state[stateIndexKey]
227192
state = assignKeyAndIndex(currentIndex, state)
228-
return tryNavigation({
193+
tryNavigation({
229194
task: () => {
230195
opts.replaceState(path, state)
231-
notify({ type: 'REPLACE' }, navigateOpts)
196+
notify({ type: 'REPLACE' })
232197
},
233198
navigateOpts,
234199
type: 'REPLACE',

packages/react-router/src/Transitioner.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
import { useLayoutEffect, usePrevious } from './utils'
88
import { useRouter } from './useRouter'
99
import { useRouterState } from './useRouterState'
10-
import type { SubscriberArgs } from '@tanstack/history'
1110

1211
export function Transitioner() {
1312
const router = useRouter()
@@ -42,17 +41,7 @@ export function Transitioner() {
4241
// Subscribe to location changes
4342
// and try to load the new location
4443
React.useEffect(() => {
45-
const unsub = router.history.subscribe(
46-
({ navigateOpts }: SubscriberArgs) => {
47-
// If commitLocation initiated this navigation, it handles load() itself
48-
if (navigateOpts?.skipTransitionerLoad) {
49-
return
50-
}
51-
52-
// External navigation (pop, direct history.push, etc): call load normally
53-
router.load()
54-
},
55-
)
44+
const unsub = router.history.subscribe(router.load)
5645

5746
const nextLocation = router.buildLocation({
5847
to: router.latestLocation.pathname,

packages/react-router/tests/Matches.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ describe('matching on different param types', () => {
344344

345345
await act(() => render(<RouterProvider router={router} />))
346346

347-
await act(() => router.history.push(nav))
347+
act(() => router.history.push(nav))
348348

349349
const paramsToCheck = await screen.findByTestId('params')
350350
const matchesToCheck = await screen.findByTestId('matches')

packages/react-router/tests/useNavigate.test.tsx

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
fireEvent,
88
render,
99
screen,
10-
waitFor,
1110
} from '@testing-library/react'
1211

1312
import { z } from 'zod'
@@ -1317,11 +1316,9 @@ test('when setting search params with 2 parallel navigate calls', async () => {
13171316
})
13181317

13191318
render(<RouterProvider router={router} />)
1320-
await waitFor(() => {
1321-
expect(router.state.location.search).toEqual({
1322-
param1: 'param1-default',
1323-
param2: 'param2-default',
1324-
})
1319+
expect(router.state.location.search).toEqual({
1320+
param1: 'param1-default',
1321+
param2: 'param2-default',
13251322
})
13261323

13271324
const postsButton = await screen.findByRole('button', { name: 'search' })
@@ -1330,12 +1327,7 @@ test('when setting search params with 2 parallel navigate calls', async () => {
13301327

13311328
expect(await screen.findByTestId('param1')).toHaveTextContent('foo')
13321329
expect(await screen.findByTestId('param2')).toHaveTextContent('bar')
1333-
await waitFor(() => {
1334-
expect(router.state.location.search).toEqual({
1335-
param1: 'foo',
1336-
param2: 'bar',
1337-
})
1338-
})
1330+
expect(router.state.location.search).toEqual({ param1: 'foo', param2: 'bar' })
13391331
const search = new URLSearchParams(window.location.search)
13401332
expect(search.get('param1')).toEqual('foo')
13411333
expect(search.get('param2')).toEqual('bar')
@@ -1455,27 +1447,21 @@ test.each([true, false])(
14551447

14561448
fireEvent.click(postButton)
14571449

1458-
await waitFor(() => {
1459-
expect(router.state.location.pathname).toBe(`/post${tail}`)
1460-
})
1450+
expect(router.state.location.pathname).toBe(`/post${tail}`)
14611451

14621452
const searchButton = await screen.findByTestId('search-btn')
14631453

14641454
fireEvent.click(searchButton)
14651455

1466-
await waitFor(() => {
1467-
expect(router.state.location.pathname).toBe(`/post${tail}`)
1468-
expect(router.state.location.search).toEqual({ param1: 'value1' })
1469-
})
1456+
expect(router.state.location.pathname).toBe(`/post${tail}`)
1457+
expect(router.state.location.search).toEqual({ param1: 'value1' })
14701458

14711459
const searchButton2 = await screen.findByTestId('search2-btn')
14721460

14731461
fireEvent.click(searchButton2)
14741462

1475-
await waitFor(() => {
1476-
expect(router.state.location.pathname).toBe(`/post${tail}`)
1477-
expect(router.state.location.search).toEqual({ param1: 'value2' })
1478-
})
1463+
expect(router.state.location.pathname).toBe(`/post${tail}`)
1464+
expect(router.state.location.search).toEqual({ param1: 'value2' })
14791465
},
14801466
)
14811467

@@ -1774,28 +1760,22 @@ test.each([true, false])(
17741760

17751761
fireEvent.click(detail1AddBtn)
17761762

1777-
await waitFor(() => {
1778-
expect(router.state.location.pathname).toBe(`/posts/id1/detail${tail}`)
1779-
expect(router.state.location.search).toEqual({ _test: true })
1780-
})
1763+
expect(router.state.location.pathname).toBe(`/posts/id1/detail${tail}`)
1764+
expect(router.state.location.search).toEqual({ _test: true })
17811765

17821766
const detail1RemoveBtn = await screen.findByTestId('detail-btn-remove-1')
17831767

17841768
fireEvent.click(detail1RemoveBtn)
17851769

1786-
await waitFor(() => {
1787-
expect(router.state.location.pathname).toBe(`/posts/id1/detail${tail}`)
1788-
expect(router.state.location.search).toEqual({})
1789-
})
1770+
expect(router.state.location.pathname).toBe(`/posts/id1/detail${tail}`)
1771+
expect(router.state.location.search).toEqual({})
17901772

17911773
const detail2AddBtn = await screen.findByTestId('detail-btn-add-2')
17921774

17931775
fireEvent.click(detail2AddBtn)
17941776

1795-
await waitFor(() => {
1796-
expect(router.state.location.pathname).toBe(`/posts/id1/detail${tail}`)
1797-
expect(router.state.location.search).toEqual({ _test: true })
1798-
})
1777+
expect(router.state.location.pathname).toBe(`/posts/id1/detail${tail}`)
1778+
expect(router.state.location.search).toEqual({ _test: true })
17991779
},
18001780
)
18011781

packages/router-core/src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ export type {
6969
CreateLazyFileRoute,
7070
} from './fileRoute'
7171

72-
export type {
73-
MatchSnapshot,
74-
ParsedLocation,
75-
ValidatedSearchEntry,
76-
} from './location'
72+
export type { ParsedLocation } from './location'
7773
export type { Manifest, RouterManagedTag } from './manifest'
7874
export { isMatch } from './Matches'
7975
export type {

0 commit comments

Comments
 (0)