Skip to content

Conversation

@Kangaroux
Copy link

@Kangaroux Kangaroux commented Sep 10, 2025

Description

When using browser nav the browser fires the popstate event before any of the router callbacks go off, and it can't be intercepted. Therefore we can't rely on events to save the scroll position when using the back/forward buttons. This sets up an interval timer to periodically save the scroll position.

For more info see: #4 (comment)

Linked Issues

fixes #3
fixes #4

Additional context

back/forward buttons

When using browser nav the browser fires the popstate event. It fires
this event before any of the router callbacks go off and it can't be
intercepted, therefore we can't save scroll position before popstate
fires.

The other option is to not rely on events for saving scroll pos and
instead just do it periodically. This fixes the popstate issue as well
as components whose DOM updates before the router callbacks. Waiting too
late could mean the element no longer exists or its size has changed.
@Kangaroux Kangaroux marked this pull request as draft September 10, 2025 21:11
@Kangaroux Kangaroux marked this pull request as ready for review September 10, 2025 21:59
@Kangaroux
Copy link
Author

@antfu when you have a moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant