Reset scroll tracking across document resizes#525
Open
Fryuni wants to merge 1 commit into
Open
Conversation
commit: |
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.
Summary
Automatically tracked scroll positions are only meaningful for the document and viewport in which they were captured. This PR prevents scroll sequences from spanning incompatible page dimensions and establishes a usable baseline before the first scroll after a window resize.
SPA document changes
Problem: An SPA can replace a long page with a much shorter one while a scroll sequence is pending. For example, a start position near 7,000px can survive navigation to a page that is only 1,000px tall. The next automatic
userScrolledevent then reports an impossible previous position outside the new document.Solution: Each pending scroll sequence now captures its document
scrollWidthandscrollHeight. A dimension mismatch discards the stale sequence and starts a new one from the current position. Debounced flushes recheck the dimensions as well, covering changes that happen after the last scroll event but before the timer expires. Valid events emit the dimensions captured with their positions.Window resizes
Problem: Waiting until the next scroll event to notice a resize uses that first event only to reset the baseline, so the first post-resize movement can be missed. A pending pre-resize sequence can also relate positions captured under different viewport scales.
Solution:
InteractionMonitornow listens for the windowresizeevent while enabled. A resize cancels the pending debounce, discards the old sequence without emitting it, and immediately records the current clamped and rounded scroll position plus document dimensions. The first subsequent scroll is therefore measured from the resize-time baseline. Disabling the monitor removes the resize listener.Verification
npx jest -c jest.config.mjs --runInBand test/interactionMonitor.test.ts— 20 tests passednpm run validatenpx eslint src/interactionMonitor.ts test/interactionMonitor.test.tsChecklist