Skip to content

Commit 0f1b17c

Browse files
fix(react-router): reset invalid status of route after loader ran again (#2483)
1 parent 2ba59e7 commit 0f1b17c

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

packages/react-router/src/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,6 +2394,7 @@ export class Router<
23942394
...prev,
23952395
isFetching: loaderRunningAsync ? prev.isFetching : false,
23962396
loaderPromise: undefined,
2397+
invalid: false,
23972398
}))
23982399
})(),
23992400
)

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,29 @@ describe('router matches URLs to route definitions', () => {
580580
])
581581
})
582582
})
583+
584+
describe('invalidate', () => {
585+
it('after router.invalid(), routes should be `valid` again after loading', async () => {
586+
const { router } = createTestRouter(
587+
createMemoryHistory({ initialEntries: ['/'] }),
588+
)
589+
590+
await act(() => router.load())
591+
592+
router.state.matches.forEach((match) => {
593+
expect(match.invalid).toBe(false)
594+
})
595+
596+
await act(() => router.invalidate())
597+
598+
router.state.matches.forEach((match) => {
599+
expect(match.invalid).toBe(false)
600+
})
601+
602+
await act(() => router.load())
603+
604+
router.state.matches.forEach((match) => {
605+
expect(match.invalid).toBe(false)
606+
})
607+
})
608+
})

0 commit comments

Comments
 (0)