Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: ab7cea82fa11083830493260bdccf58b5246ffa0
      
https://github.com/WebKit/WebKit/commit/ab7cea82fa11083830493260bdccf58b5246ffa0
  Author: Ahmad Saleem <[email protected]>
  Date:   2026-07-27 (Mon, 27 Jul 2026)

  Changed paths:
    M 
LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/snap-after-relayout/multiple-aligned-targets/prefer-first-in-tree-order-expected.txt
    M Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp

  Log Message:
  -----------
  [CSS Scroll Snap] Aligned snap targets are not selected in tree order
https://bugs.webkit.org/show_bug.cgi?id=319733
rdar://182571341

Reviewed by Simon Fraser.

When multiple snap areas are aligned at the same offset, snap target
selection breaks the tie by "first in tree order"
(ScrollSnapAnimatorState::selectSnapTargetForAxis), which assumes
snapAreas/snapAreasIDs are built in tree order. But
updateSnapOffsetsForScrollableArea() iterates
RenderView::boxesWithScrollSnapPositions(), a hash set with arbitrary
iteration order, so the box chosen as "first in tree order" was
effectively random.

Rather than sorting every snap box in the scroller into tree order up
front, insert each snap area's index into its offset's snapAreaIndices
in tree order relative only to the other indices already tied at that
exact offset (almost always zero or one of them). This avoids an
O(n log n) sort of all snap boxes on every layout in exchange for a
handful of treeOrder() comparisons limited to actual aligned ties,
while still keeping the tree-order comparison itself on the main
thread, since ScrollSnapAnimatorState::selectSnapTargetForAxis (which
consumes the already-ordered snapAreaIndices) can run on the scrolling
thread, where live DOM access is unsafe.

* 
LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/snap-after-relayout/multiple-aligned-targets/prefer-first-in-tree-order-expected.txt:
 Progressions
* Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp:
(WebCore::updateSnapOffsetsForScrollableArea):

Canonical link: https://commits.webkit.org/317997@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to