Skip to content

Commit a8916e5

Browse files
Shreyas-Sarkarbirkskyum
authored andcommitted
fix: Links always scroll to URL hash on hover
1 parent 3a14ffc commit a8916e5

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/react-router/src/Transitioner.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,22 @@ export function Transitioner() {
108108
}, [isPagePending, previousIsPagePending, router])
109109

110110
useLayoutEffect(() => {
111-
// The router was pending and now it's not
112111
if (previousIsAnyPending && !isAnyPending) {
112+
const changeInfo = getLocationChangeInfo(router.state)
113113
router.emit({
114114
type: 'onResolved',
115-
...getLocationChangeInfo(router.state),
115+
...changeInfo,
116116
})
117117

118-
router.__store.setState((s) => ({
118+
router.__store.setState((s: typeof router.state) => ({
119119
...s,
120120
status: 'idle',
121121
resolvedLocation: s.location,
122122
}))
123123

124-
handleHashScroll(router)
124+
if (changeInfo.hrefChanged) {
125+
handleHashScroll(router)
126+
}
125127
}
126128
}, [isAnyPending, previousIsAnyPending, router])
127129

packages/solid-router/src/Transitioner.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ export function Transitioner() {
122122
Solid.on(
123123
[isAnyPending, previousIsAnyPending],
124124
([isAnyPending, previousIsAnyPending]) => {
125-
// The router was pending and now it's not
126125
if (previousIsAnyPending.previous && !isAnyPending) {
126+
const changeInfo = getLocationChangeInfo(router.state)
127127
router.emit({
128128
type: 'onResolved',
129-
...getLocationChangeInfo(router.state),
129+
...changeInfo,
130130
})
131131

132132
router.__store.setState((s) => ({
@@ -135,7 +135,9 @@ export function Transitioner() {
135135
resolvedLocation: s.location,
136136
}))
137137

138-
handleHashScroll(router)
138+
if (changeInfo.hrefChanged) {
139+
handleHashScroll(router)
140+
}
139141
}
140142
},
141143
),

0 commit comments

Comments
 (0)