Commit graph

10 commits

Author SHA1 Message Date
infinite-persistence 59a8b9d663 WaitUntilOnPage: take scaling into account
It was waiting too near the viewport to load on certain zoom levels. This will maintain the same physical distance for the "approaching viewport" buffer regardless of zoom levels.
2021-07-12 17:06:30 -04:00
infinite-persistence 033b03e6e4
WaitUntilOnPage: respond to window resizing or zooming. 2021-07-05 12:06:55 +08:00
infinite-persistence bb8fb038ca
WaitUntilOnPage: add option to load when approaching viewport 2021-07-05 12:06:54 +08:00
infinite-persistence 9745d6df3e
WaitUntilOnPage: Fix scroll listener always registered + bump debounce ms
## Issue
The scroll listener never unregisters, and is always registering itself on every scroll. I believe it was done that way to also handle the case of "element is already in viewport when mounted".

## Change
Tried to separate both "element is already in viewport when mounted" and "element scrolled into viewport" into different effects.

The timeout value used is a bit arbitrary, but is needed because the initial size is (0, 0), and to debounce any layout shifts. Reasoning: If an element is explicitly placed under this wrapper, the additional delay is acceptable since it's meant to be lazy-loaded anyway.
2021-07-05 12:06:54 +08:00
infinite-persistence 524370711c
WaitUntilOnPage: Reduce debounce ms; remove unused hack
(1) Reduced the debouncing duration so that the final element can be rendered asap after visible.
  - If the user is scrolling non-stop, it would continue to debounce and the GUI ends up not showing the final element.
  - 25ms seems enough to prevent the initial false-positive that occurs in the scenario of "adjacent/upper elements resized late, so our element was briefly on screen when mounted". If not enough, we can make this a parameter.

(2) Removed `lastUpdateDate` that was a quick hack for Recommended section. We don't use it on that element anymore, so remove the hack to keep the file clean.
2021-06-15 16:28:11 +08:00
infinite-persistence df2c274216
WaitUntilOnPage: handle large items; add optional placeholder element.
(1) The previous code assumed the element is always smaller than the screen. When used on large items like "homepage categories", it'll never load because the element exceeds the screen width or height.

(2) Added optional placeholder element. This allows us to put a cheaper element while waiting, so that the layout doesn't shift when we finally render. This is visually better when scrolling, and complies with Web Vitals.
2021-06-15 16:28:10 +08:00
Sean Yesmunt 248e578422 new comments 2020-09-29 17:12:32 -04:00
infiinte-persistence 0ab5ca080e Fix 'Related' being loaded on Autoplay despite not visible.
## Issue
In the `Autoplay` case, if the `WaitUntilOnPage` has already opened the gates previously, the next video's Related will be loaded regardless of scroll position.

## Changes
Add a `lastUpdateDate` prop to `WaitUntilOnPage` to allow the parent to reset the gating state.

I don't really like the `lastUpdateDate` prop since it's purpose is not intuitive. Is there a standard way to do a "one-time trigger" from the parent?
2020-07-29 17:56:38 -04:00
infiinte-persistence 1383b19817 WaitUntilOnPage: Debounce to fix false positives.
There are cases where `WaitUntilOnPage` will incorrectly render, such as at the beginning if the upper components hasn't expanded to full size, so `WaitUntilOnPage` would be briefly visible.

Added a 300ms debounce to fix this, which would also improve scrolling performance a bit by doing less. Hopefully 300ms is enough for the upper components to inflate to full size.
2020-07-29 17:56:38 -04:00
Sean Yesmunt 3d352593f3 defer rendering related/comments until user scrolls down 2020-06-01 10:28:13 -04:00