Closed pdanpdan closed 2 months ago
Nice digging :+1:
I'm open for a PR, but I wonder if requestAnimationFrame
would break the following?
I know it's a Chrome problem :)
Is there a bug report or Stack Overflow answer attesting that?
Closing as it isn't a Vike bug, but let's continue the conversation.
I am more interested for the moment if someone else can reproduce it. For the loading inconvenience I can just patch vike in the project :)
That onPageHide(saveScrollPosition)
is the culprit - it's trying to write sync in history while chrome does something else with history and all goes south.
I also reported it in chromium issue tracker but for the moment I have no feedback.
Neat. How about we disable that line for Chrome and see whether Chrome users complain about the scroll position not being restored at the right position?
My findings after some more tests:
window.history.replaceState
called from saveScrollPosition
called onPageHide
autoSaveScrollPosition
function onPageHide(saveScrollPosition)
is replaced with onPageHide(() => requestAnimationFrame(saveScrollPosition))
all seems to work as expectedscroll
So if you agree I would go on and make a PR for it.
Ok sounds good :+1:
Description
Setup:
Test:
The problem would be just a nuisance but after reload I can no longer inspect the response in the Network tab of DevTools.
I traced it to the
onPageHide
hook that tries to execute tasks in synchronous mode on reload. https://github.com/vikejs/vike/blob/93017bedc0e5f88ff40a9b3a9b379c607576fd03/vike/utils/onPageVisibilityChange.ts#L7 A solution would be to call the listener in arequestAnimationFrame
.I know it's a Chrome problem :)