Skip to content

Commit fa5a90b

Browse files
committed
working scroll restoration
1 parent b76c0df commit fa5a90b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/solid-router/src/Transitioner.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,19 @@ export function Transitioner() {
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+
// Execute fn synchronously to check if it returns a Promise
40+
let result: void | Promise<void>
41+
Solid.startTransition(() => {
42+
result = fn()
4643
})
44+
45+
// If fn returned a Promise, track the transition state
46+
if (result! instanceof Promise) {
47+
setIsTransitioning(true)
48+
result.finally(() => {
49+
setIsTransitioning(false)
50+
})
51+
}
4752
}
4853

4954
// Subscribe to location changes

0 commit comments

Comments
 (0)