Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export class BlockScrollStrategy extends ScrollStrategy {
* ```
*/
public attach(): void {
// Prevent scroll from mouse/trackpad/touch before it occurs.
// `{ passive: false }` is required — without it, browsers ignore preventDefault() on these events.
// This also fixes Safari bug #17217 where the scroll event fires after the compositor has already
// scrolled, making scroll-position reset ineffective for wheel/touch input.
this._document.addEventListener('wheel', this.preventDefault, { passive: false });
this._document.addEventListener('touchmove', this.preventDefault, { passive: false });
// Handles keyboard-driven scrolling (arrow keys, spacebar, Page Up/Down) as a fallback,
Comment on lines +39 to +43
// since keyboard input cannot be intercepted via wheel/touchmove.
this._document.addEventListener('scroll', this.onScroll, true);
}

Expand All @@ -44,6 +52,8 @@ export class BlockScrollStrategy extends ScrollStrategy {
* ```
*/
public detach(): void {
this._document.removeEventListener('wheel', this.preventDefault);
this._document.removeEventListener('touchmove', this.preventDefault);
this._document.removeEventListener('scroll', this.onScroll, true);
this._sourceElement = null;
this._initialScrollTop = 0;
Expand All @@ -62,4 +72,8 @@ export class BlockScrollStrategy extends ScrollStrategy {
this._sourceElement.scrollTop = this._initialScrollTop;
this._sourceElement.scrollLeft = this._initialScrollLeft;
};

private preventDefault = (ev: Event) => {
ev.preventDefault();
};
}
Loading