Skip to content

Refactor the effect on the sponsors and fix a position caching bug #815

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

Merged
merged 1 commit into from
Jan 16, 2021

Conversation

skirtles-code
Copy link
Contributor

@skirtles-code skirtles-code commented Jan 16, 2021

I was investigating #195. This doesn't necessarily fix all the problems reported there but it may help.

The Patreon Sponsors on the homepage are shown in grayscale until the page has scrolled to a certain point. I made the following observations:

  1. The cached value for sponsorTop is not always correct. Elements can move when content loads, it doesn't require a page resize for things to move. This could be why Sponsor gray/color change is jumpy #195 observed the transition occurring in a strange place.
  2. The listeners were never removed. This didn't actually cause any errors but they do leak when you navigate away to a different page.
  3. The code directly manipulates DOM elements rather than using Vue to perform the updates.
  4. I don't know why there's a check for window. The hook is called during SSR so that shouldn't be necessary.

I've refactored it to use Vue in a more idiomatic way. This also removed a big chunk of the code. The caching of sponsorTop is gone and the listener is removed when leaving the page.

I don't believe there was any significant performance benefit from caching the offsetTop value. Style recalcs and page reflows shouldn't be a factor here.

Aside from fixing the caching bug, I have not changed the point at which the transition occurs or the speed of the transition.

@NataliaTepluhina NataliaTepluhina merged commit 7eda94f into vuejs:master Jan 16, 2021
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