Closed Bug 2086762 Opened 1 month ago Closed 23 days ago

Blurred text input scrolls the page back into view on the next frame after focus(); blur(); scrollTo()

Categories

(Core :: DOM: UI Events & Focus Handling, defect)

defect

Tracking

()

RESOLVED FIXED
161 Branch
Tracking Status
firefox161 --- fixed

People

(Reporter: florian, Assigned: florian)

References

(Blocks 1 open bug)

Details

Attachments

(1 external file)

Focusing an <input> or <textarea> makes nsFocusManager::ScrollIntoView queue an async selection scroll (TextControlElement::ScrollSelectionIntoViewAsync(ScrollAncestors::Yes), added in bug 1644366). It runs at the next refresh tick and also scrolls the control's ancestors.

That scroll still runs after the control is blurred. So input.focus(); input.blur(); window.scrollTo(0, 0); leaves the page scrolled back to the input on the next frame, overriding the explicit scroll.

This is why layout/forms/test/test_bug562447.html perma-fails in the standalone mochitest variant (skipped there since bug 2026600). Multi-test runs hide it because the test frame has scrolling="no".

Proposed fix: on blur, limit any pending selection scroll of the text control to its own scroller (ScrollFirstAncestorOnly).

Focusing an input or textarea queues an async selection scroll that also scrolls its ancestors, so calling focus() then blur() then scrollTo(0, 0) brings the page back to the input on the next refresh tick. On blur, the pending scroll is now limited to the text control's own scroller.

test_bug562447.html now waits for a refresh tick, so it fails without the fix in standalone runs, where the test frame can scroll; remove the skip-if from bug 2026600.

Blocks: 2086769
Severity: -- → S3
Pushed by fqueze@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/66add401cdbb https://hg.mozilla.org/integration/autoland/rev/98d478361be0 Don't let the selection scroll queued by focusing a text control scroll the page after it loses focus, r=dom-core-reviewers,masayuki,smaug.
Status: ASSIGNED → RESOLVED
Closed: 23 days ago
Resolution: --- → FIXED
Target Milestone: --- → 161 Branch

Authored by https://github.com/fqueze
https://github.com/mozilla/enterprise-firefox/commit/66add401cdbb6aad6c99167ff23ce14e6036504a
[enterprise-main] Bug 2086762 - Don't let the selection scroll queued by focusing a text control scroll the page after it loses focus, r=dom-core-reviewers,masayuki,smaug.

(via GitHub webhook, authenticated as shared-secret)

QA Whiteboard: [qa-triage-done-c162/b161]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: