Skip to content

Commit bbdecfc

Browse files
committed
fix: fix multiple page views
1 parent 0980877 commit bbdecfc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/smooth/src/router/HiddenRouter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function HiddenRouter({ children }) {
4242
const { history } = useRouter()
4343
const hiddenHistory = useHiddenHistory()
4444
const promises = useRef([])
45+
const timeoutRef = useRef()
4546

4647
const flush = useCallback(() => {
4748
if (promises.current.length || !hiddenHistory.state) return
@@ -60,7 +61,8 @@ export function HiddenRouter({ children }) {
6061
}
6162
// 65ms is 4 frames, pretty invisible when we change page
6263
// it ensures that React have time to start a new request for an example
63-
setTimeout(() => flush(), 65)
64+
clearTimeout(timeoutRef.current)
65+
timeoutRef.current = setTimeout(() => flush(), 65)
6466
})
6567
promises.current.push(promise)
6668
},

0 commit comments

Comments
 (0)