Repository navigation
[BUGFIX] Only follow scrolling for sticky and fixed spotlight targets - #161
Merged
Merged
Conversation
This was referenced Nov 9, 2026
The scroll listener for sticky and fixed targets recomputed all holes on every scroll frame, on every page: getBoundingClientRect for all targets and unionRects, which grows quadratically. This took about 0.4 ms per frame with 50 targets and 3.7 ms with 1000 targets. Whether a target or one of its ancestors is sticky or fixed is checked when the targets are selected now. The scroll listener is only added for such targets, so scrolling runs no code on other pages.
Whether a target depends on scrolling was only checked when the targets were selected. A header that a script makes fixed while scrolling, by toggling a class, was static at that time, so its hole stayed in place and the overlay covered it. On main, the holes followed it. Class and style changes of the ancestors of the targets are observed now. They check again whether the holes have to follow the scrolling and recompute the holes when this changes.
Kanti
force-pushed
the
bugfix/spotlight-scroll-only-for-sticky
branch
from
November 9, 2026 16:20
1f1f8e9 to
f3e7e23
Compare
Kanti
added a commit
that referenced
this pull request
Nov 9, 2026
…164) Since #161, the holes only followed the scrolling for sticky and fixed targets and targets in scroll containers. A class or style change of an ancestor only recomputed the holes when it started or stopped this. So targets that a script moves while scrolling, e.g. a parallax effect that sets a transform on a section, or a reveal effect that removes a class with an offset, kept their old holes, and the overlay covered them. 1.10.4 recomputed the holes on every scroll event and followed them. A class or style change of an ancestor of the targets recomputes the holes now, at most once per frame. Pages without such changes still run no code while scrolling.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Follow-up to #159. Its scroll listener recomputed all holes on every scroll frame, on every page, also without any sticky or fixed target:
getBoundingClientRectfor all targets plusunionRects, which grows quadratically. Measured on a fast machine: about 0.4 ms per frame with 50 targets, 1.2 ms with 300 and 3.7 ms with 1000. The overlay path was not rewritten, but #144 had made scrolling run no script at all, and that was lost. The existing test only counted writes of the path and passed with and without this work.Implemented behavior
positionfixedorstickyis checked when the targets are selected: inhighlight()and inrefreshTargets()(resize, mutation, toggle), not while scrolling. Across shadow roots the host counts as ancestor. Ancestors shared by several targets are checked once.updateHoles()without measuring the document are unchanged.Tests
spotlight-overlay.test.js(browser): the test for static targets counts thegetBoundingClientRectcalls while scrolling three times and expects none, instead of counting writes of the path. It fails without the fix (6 calls).npm run test: 93 passing,npm run lint