Skip to content

Conversation

@Enderjua
Copy link

what this fixes

fixes the ratio bar disappearing when you scroll. turns out there was a check that removed the bar element whenever it left the viewport, but it didn't come back unless you clicked something.

related issue

fixes #1252

changes

removed the isInViewport check in src/bar.js that was calling rateBar.remove().

the bar now just stays in the dom. when createRateBar gets called (either from navigation or voting), it updates the existing bar instead of trying to recreate it. way simpler.

why the old code existed

dug through the git history - the isInViewport thing was added in commit b5382ba (nov 2022) to deal with "ghost elements" from youtube's spa navigation.

makes sense in theory, but it had a flaw: it couldn't tell the difference between a stale element and an element that's just off-screen because you scrolled. so it nuked the bar on every scroll.

testing i did

scroll test

scrolled down until buttons were off screen, scrolled back up. bar stayed visible. ✓

checked for memory leaks

navigated through 10+ videos really fast, then ran this in console:

document.querySelectorAll('#ryd-bar-container').length

always returned 1, never created duplicates. ✓

navigation test

clicked between videos, bar updated with new stats immediately. ✓

other stuff

  • shorts: still works fine (they use separate logic)
  • mobile: no issues (different code path)
  • clicking like/dislike: bar updates correctly

breaking changes?

nope. just removes some unnecessary dom manipulation.

why this is safe

  • the bar uses a unique id (ryd-bar-container), so you can't have duplicates
  • when youtube swaps out the ui during navigation, the old bar gets cleaned up automatically by the browser's gc
  • modern browsers are already smart about not rendering off-screen elements, so keeping it in the dom doesn't hurt performance

tested locally on firefox & chrome, everything works smoothly.

removed isInViewport check that was removing the bar when scrolled
off screen. the bar now persists and gets updated in-place instead
of being destroyed/recreated.

fixes #[issue_number]

background:
- the check was added to clean up ghost elements from youtube's spa
- but it couldn't tell scroll vs stale element apart
- caused the bar to vanish permanently when scrolling

tested:
- scroll up/down: bar persists
- 10+ video navigations: no memory leaks (querySelectorAll = 1)
- shorts/mobile: no regressions
- like/dislike clicks: still works
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.

[Bug] Like/Dislike ratio bar are disappearing permanently when scrolled out of viewport

1 participant