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

feat(ViewTransitions): use scrollend instead of scroll where supported #8156

Merged
merged 3 commits into from
Aug 25, 2023

Conversation

kurtextrem
Copy link
Contributor

@kurtextrem kurtextrem commented Aug 19, 2023

Changes

The scrollend mechanism seems like a better way to record the scroll position compared to throttling, so we could use it whenever a browser supports it.

Additionally, I've removed the {passive} flag from the scroll event, as it does nothing (source).

  • TODO: run pnpm exec changeset

Testing

I've tested it locally, but maybe I'm missing out how you are testing changes to this component.

Docs

Open question: Does it make sense to document we're using scrollend in modern browsers? Personally, I don't think so (implementation details), but maybe it's interesting for some techy folks.

@changeset-bot
Copy link

changeset-bot bot commented Aug 19, 2023

🦋 Changeset detected

Latest commit: ceb4253

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 Aug 19, 2023
Copy link
Member

@martrapp martrapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely an improvement! 😃

@matthewp
Copy link
Contributor

sgtm. Need a changeset and to not be in draft status. pnpm changeset

@kurtextrem kurtextrem marked this pull request as ready for review August 23, 2023 11:40
@kurtextrem
Copy link
Contributor Author

kurtextrem commented Aug 23, 2023

@martrapp @matthewp Thank you! I've added a changeset.

Pipeline seems to be failing on windows, but it's showing config errors (so not related to this PR)

@matthewp
Copy link
Contributor

matthewp commented Aug 24, 2023

Ok, want to talk through this just a little more. Does scrollend wait until the user releases their fingers from the trackpad / screen? If so, is that what we want? When reading an article your fingers may remain the entire time as you scroll slowly. Does scrollend allow us to keep the scroll position as people do this slow scroll?

cc @martrapp

@kurtextrem
Copy link
Contributor Author

When reading an article your fingers may remain the entire time as you scroll slowly

The scrollend event only fires after you lift your finger (check out the demo at the MDN page), but at least I can not think of a manual way to trigger a link after scrolling without lifting your finger. A back gesture (on Android) can also not be triggered without lifting the finger at least once again.

However, if you scroll around, keep your finger at some position and e.g. some random non-Astro JS triggers a navigation after a specific timeout, scrollend will never fire. In that case the scroll position is lost, but I'm not sure if the implementation is trying to cover that (at least not from the comment in the code, as far as I can tell).

@martrapp
Copy link
Member

martrapp commented Aug 24, 2023

I like the idea to ignore a bunch of scroll events in favor of a single scroll end event.

you could try to keep scrolling the mouse wheel while you press one handed Alt-<left-arrow>. That seems to be a corner case that we can simply ignore.

Position tracking before clicking is handled by the click handler. We only need the scroll handler for history navigation, because we can only access the "navigated to state" in the popstate handler and then it is too late to update the "navigated from state".

@matthewp matthewp requested a review from martrapp August 25, 2023 12:35
@matthewp
Copy link
Contributor

@kurtextrem Yeah good point. If I'm correct, you're saying that it's probably not possible to navigate; either by clicking a link or doing a back swipe gesture, without the scrollend occurring. That sounds right to me, and removes my fear for this.

@martrapp marked you as a reviewer if you don't mind approving this.

Copy link
Member

@martrapp martrapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be happy to approve, but ...
image
😃

@matthewp
Copy link
Contributor

Oh! Sorry about that. I'll take this comment as an approval. I guess access is only for maintainers (which you are on track to become imo).

@matthewp matthewp merged commit acf652f into withastro:main Aug 25, 2023
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.

3 participants