Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes for back navigation in the view transition client-side router #8491

Merged
merged 3 commits into from
Sep 11, 2023
Merged

Bugfixes for back navigation in the view transition client-side router #8491

merged 3 commits into from
Sep 11, 2023

Conversation

martrapp
Copy link
Member

@martrapp martrapp commented Sep 10, 2023

Changes

L266 + L351: This fix was mainly triggered by a bug I introduced with 3.0.11: backward navigation was no longer possible when starting from a history state that was not pushed by the CSR (e.g. navigate to a #fragment on a VT page and navigate to another page from there).

Other change: the handling of self links used to call pushState, so you would have that jump in the history as well. But that doesn't really work, because we would do transitions at history navigation. (in popstate it is not possible to see if we have been on the same page before, otherwise we could prevent transitions for those).

pushState is required for the self-link to update the browser's address bar. So I have reintroduced it. In popstate, the navigation of self-links is now detected by negative values for scrollY. This way, the history navigation for self-links can be filtered and the scroll position can be updated without starting view transitions.

+ Improvement of the comment that describes the reload of the CSR.

Testing

added e2e test for back navigation after transition form position navigated to by #fragment URL.

Docs

n/a bug fix

@changeset-bot
Copy link

changeset-bot bot commented Sep 10, 2023

🦋 Changeset detected

Latest commit: 00305a7

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Sep 10, 2023
@martrapp martrapp changed the title Back scroll Bugfixes for back navigation in the view transition client-side router Sep 10, 2023
@matthewp matthewp merged commit 0ca332b into withastro:main Sep 11, 2023
13 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Sep 11, 2023
@martrapp martrapp deleted the back-scroll branch September 11, 2023 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants