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

Prevent early scrolling during history navigation (experimental). #301

Merged
merged 1 commit into from
Feb 25, 2015

Conversation

nicksay
Copy link
Contributor

@nicksay nicksay commented Feb 25, 2015

When handling a history change event, save the current position and scroll to
that (current) position immediately after handling the event to prevent the
browser from incorrectly scrolling too early.

The browser default behavior is to scroll to the position when pushState was
called just after firing a popState event. This is okay only if using
pushState to move around a single page or if all content can be rendered
synchronously during the popState event handling. Since navigation content
updates are asynchronous (either from cache or from network), avoid this early
scroll by immediately scrolling back to the current position after the event.
The proper position is then (re)set once the content is updated.

For now, guard this behavior behind the experimental-scroll-position config.

Progress on #285.

When handling a history change event, save the current position and scroll to
that (current) position immediately after handling the event to prevent the
browser from incorrectly scrolling too early.

The browser default behavior is to scroll to the position when `pushState` was
called just after firing a `popState` event.  This is okay only if using
`pushState` to move around a single page or if all content can be rendered
synchronously during the `popState` event handling.  Since navigation content
updates are asynchronous (either from cache or from network), avoid this early
scroll by immediately scrolling back to the current position after the event.
The proper position is then (re)set once the content is updated.

For now, guard this behavior behind the `experimental-scroll-position` config.

Progress on youtube#285.
@nicksay nicksay force-pushed the scroll-back-handling branch from 7729bc9 to 740131f Compare February 25, 2015 03:53
@DavidCPhillips
Copy link
Contributor

LGTM. I'm a bit worried about the jank, but we'll try it out and see how it looks on some slower machines.

nicksay added a commit that referenced this pull request Feb 25, 2015
Prevent early scrolling during history navigation (experimental).
@nicksay nicksay merged commit 2102d95 into youtube:master Feb 25, 2015
@nicksay nicksay deleted the scroll-back-handling branch February 25, 2015 23:51
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