Skip to content

Conversation

@david-crespo
Copy link
Collaborator

See comment, I couldn't get v7_startTransition to work because it breaks the scroll restore test in all three browsers. The really strange thing is that I could not reproduce the issue when I did the actions manually. I suspect there's something funny about how Playwright handles goBack and goForward — it seemed like (in the tests only) the navigation state was not changing to loading and back, which is what we rely on to tell when to save the current scroll position before the page goes away.

export function useScrollRestoration(container: React.RefObject<HTMLElement>) {
const key = `scroll-position-${useLocation().key}`
const { state } = useNavigation()
useEffect(() => {
if (state === 'loading') {
setScrollPosition(key, container.current?.scrollTop ?? 0)
} else if (state === 'idle') {
container.current?.scrollTo(0, getScrollPosition(key))
}
}, [key, state, container])
}

@vercel
Copy link

vercel bot commented Jun 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
console ✅ Ready (Inspect) Visit Preview Jun 28, 2024 3:55pm

@david-crespo david-crespo merged commit 8febc79 into main Jun 28, 2024
@david-crespo david-crespo deleted the rr-v7-future-flags branch June 28, 2024 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants