Skip to content

Reset scroll tracking across document resizes#525

Open
Fryuni wants to merge 1 commit into
masterfrom
scroll-on-navigate
Open

Reset scroll tracking across document resizes#525
Fryuni wants to merge 1 commit into
masterfrom
scroll-on-navigate

Conversation

@Fryuni

@Fryuni Fryuni commented Jul 14, 2026

Copy link
Copy Markdown
Member

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 userScrolled event then reports an impossible previous position outside the new document.

Solution: Each pending scroll sequence now captures its document scrollWidth and scrollHeight. 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: InteractionMonitor now listens for the window resize event 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 passed
  • npm run validate
  • npx eslint src/interactionMonitor.ts test/interactionMonitor.test.ts

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (not applicable; internal tracking behavior)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing interaction monitor unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules (not applicable)
  • I have checked my code and corrected any misspellings

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@croct/sdk@525

commit: 8f2b397

@Fryuni Fryuni added the bug Something isn't working label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant