Skip to content

perf: replace scroll listener with IntersectionObserver - #659

Open
airajena wants to merge 1 commit into
containers:mainfrom
airajena:perf/play-on-scroll-intersection-observer
Open

perf: replace scroll listener with IntersectionObserver#659
airajena wants to merge 1 commit into
containers:mainfrom
airajena:perf/play-on-scroll-intersection-observer

Conversation

@airajena

@airajena airajena commented Aug 8, 2026

Copy link
Copy Markdown

Concisely describe the change

The PlayOnScroll component was checking getBoundingClientRect() on every scroll event to determine whether the video should play or pause. Since the component is mounted four times on /features, this meant four synchronous layout reads were happening on every scroll.

Replaced the scroll listener with an IntersectionObserver using a threshold of 1, keeping the same fully-visible behavior while avoiding the repeated layout reads during scrolling.

Verified with yarn typecheck and yarn build, and manually checked /features to make sure videos still play and pause correctly while scrolling.

Fixes: #656

Before screenshot / screen recording

Screenshot 2026-08-09 000056

After screenshot / screen recording

image

Checklist

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all
    commits. (git commit -s). (If needed, use git commit -s --amend). The author email must match
    the sign-off email address. See CONTRIBUTING.md
    for more information.
  • Referenced issues using Fixes: #00000 in commit message (if applicable)
  • PR description, commit message, and GitHub comments are human-written, per LLM Policy

The PlayOnScroll component was checking getBoundingClientRect() on every
scroll event to determine whether the video should play or pause. Since
the component is mounted four times on /features, this meant four
synchronous layout reads were happening on every scroll.

Replaced the scroll listener with an IntersectionObserver using a
threshold of 1, keeping the same fully-visible behavior while avoiding
the repeated layout reads during scrolling.

Verified with yarn typecheck and yarn build, and manually checked /features
to make sure videos still play and pause correctly while scrolling.

Fixes: containers#656
Signed-off-by: airajena <airajena0@gmail.com>
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.

perf: PlayOnScroll uses an unthrottled scroll listener instead of IntersectionObserver

1 participant