Skip to content

Commit 01682c5

Browse files
authored
fix(solid-router): use Solid.useTransition (#5801)
1 parent fcf1a82 commit 01682c5

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

packages/solid-router/src/Transitioner.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function Transitioner() {
1919
return null
2020
}
2121

22-
const [isTransitioning, setIsTransitioning] = Solid.createSignal(false)
22+
const [isSolidTransitioning, startSolidTransition] = Solid.useTransition()
2323

2424
// Track pending state changes
2525
const hasPendingMatches = useRouterState({
@@ -29,20 +29,15 @@ export function Transitioner() {
2929
const previousIsLoading = usePrevious(isLoading)
3030

3131
const isAnyPending = () =>
32-
isLoading() || isTransitioning() || hasPendingMatches()
32+
isLoading() || isSolidTransitioning() || hasPendingMatches()
3333
const previousIsAnyPending = usePrevious(isAnyPending)
3434

3535
const isPagePending = () => isLoading() || hasPendingMatches()
3636
const previousIsPagePending = usePrevious(isPagePending)
3737

3838
router.startTransition = (fn: () => void | Promise<void>) => {
39-
setIsTransitioning(true)
40-
Solid.startTransition(async () => {
41-
try {
42-
await fn()
43-
} finally {
44-
setIsTransitioning(false)
45-
}
39+
Solid.startTransition(() => {
40+
startSolidTransition(fn)
4641
})
4742
}
4843

packages/solid-router/tests/store-updates-during-navigation.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe("Store doesn't update *too many* times during navigation", () => {
137137
// that needs to be done during a navigation.
138138
// Any change that increases this number should be investigated.
139139
// Note: Solid has different update counts than React due to different reactivity
140-
expect(updates).toBe(13)
140+
expect(updates).toBe(10)
141141
})
142142

143143
test('redirection in preload', async () => {
@@ -173,7 +173,7 @@ describe("Store doesn't update *too many* times during navigation", () => {
173173
// that needs to be done during a navigation.
174174
// Any change that increases this number should be investigated.
175175
// Note: Solid has different update counts than React due to different reactivity
176-
expect(updates).toBe(12)
176+
expect(updates).toBe(9)
177177
})
178178

179179
test('nothing', async () => {
@@ -200,7 +200,7 @@ describe("Store doesn't update *too many* times during navigation", () => {
200200
// This number should be as small as possible to minimize the amount of work
201201
// that needs to be done during a navigation.
202202
// Any change that increases this number should be investigated.
203-
expect(updates).toBe(8)
203+
expect(updates).toBe(7)
204204
})
205205

206206
test('hover preload, then navigate, w/ async loaders', async () => {

0 commit comments

Comments
 (0)