Closed Bug 2066409 Opened 27 days ago Closed 7 days ago

Toggling overflow on an ancestor fires a spurious scroll event on a scrolled descendant

Categories

(Core :: Layout: Scrolling and Overflow, defect, P3)

defect

Tracking

()

RESOLVED FIXED
158 Branch
Tracking Status
firefox158 --- fixed

People

(Reporter: dao, Assigned: hiro)

References

(Blocks 1 open bug)

Details

Attachments

(2 files, 1 obsolete file)

Setting and then removing overflow on an ancestor of a scrolled element dispatches a scroll event on that element, though its scroll position and every metric are unchanged. Per spec scroll fires when the scroll position changes, so nothing should fire here.

Testcase:

<div id="host">
  <div id="scroller" style="height:100px;overflow-y:auto">
    <div style="height:2000px"></div>
  </div>
</div>

STR:

  1. scroller.scrollTop = 50, let it settle
  2. host.style.overflow = "hidden", read layout, host.style.removeProperty("overflow"), read layout
  3. Wait a frame

Actual: one scroll event on #scroller. scrollTop, clientHeight, scrollHeight and the host's height are identical before, during and after.

Expected: no scroll event.

Only overflow does it -- overflow: clip, background-color and contain: paint, set and removed the same way, fire nothing. The frame reconstruction from the ancestor becoming a scroll container looks like the trigger.

Bug 2066403 is a consumer that hit this: panel-list sets overflow: hidden on its parent while it measures for positioning, and its own scroll-to-hide listener reads the resulting event as the anchor moving, closing the menu it just opened.

Open in Firefox; the table fills itself in on load. Each row scrolls #scroller to 50, lets it settle, then sets and removes one property on its ancestor #host and counts scroll events on #scroller.

Firefox 156.0a1 (local opt build):

set on #host, then removed scroll events metrics unchanged
overflow: hidden 1 yes
overflow: clip 0 yes
overflow: scroll 1 yes
background-color: red 0 yes
contain: paint 0 yes

So it is the ancestor becoming a scroll container that does it: hidden and scroll both fire one event, clip -- which clips without creating a scroll container -- fires none. scrollTop, clientHeight and scrollHeight are identical before, during and after in every row.

Severity: -- → S3
Priority: -- → P3

ScrollToRestoredPosition re-establishes a position the content already had,
either across a frame reconstruction or from session history. Nothing is
scrolled, so the scrolling events shouldn't run. Chrome fires nothing in
either case.

Assignee: nobody → hikezoe.birchill
Status: NEW → ASSIGNED

A reconstruction re-establishes a position the content already had, so nothing
scrolled and the scrolling events shouldn't run. Chrome fires nothing there
either.

Session history restore keeps firing, so the restore reason has to reach
ScrollToRestoredPosition: both restores go through the docShell's
nsILayoutHistoryState, and ScrollOrigin::Restore alone cannot tell them apart.

Attachment #9640869 - Attachment is obsolete: true
Attachment #9640829 - Attachment description: Bug 2066409 - Don't fire a scroll event when restoring a scroll position. r?#layout-reviewers → Bug 2066409 - Don't fire a scroll event when a frame reconstruction restores the scroll position. r?#layout-reviewers
Attachment #9640829 - Attachment description: Bug 2066409 - Don't fire a scroll event when a frame reconstruction restores the scroll position. r?#layout-reviewers → Bug 2066409 - Don't fire a scroll event when restoring a non-root scroll position. r?#layout-reviewers
Blocks: 2071241
No longer blocks: 2066403
See Also: → 2066403
Pushed by hikezoe.birchill@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/77f86bec3345 https://hg.mozilla.org/integration/autoland/rev/31ffe32f402f Don't fire a scroll event when restoring a non-root scroll position. r=layout-reviewers,emilio

Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/62661 for changes under testing/web-platform/tests

Status: ASSIGNED → RESOLVED
Closed: 7 days ago
Resolution: --- → FIXED
Target Milestone: --- → 158 Branch

Upstream PR merged by moz-wptsync-bot

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: