Closed Bug 2089347 Opened 13 days ago Closed 4 days ago

[wpt-sync] Sync PR 64329 - Prevent dirty slot assignments during layout and frame rect updates

Categories

(Core :: DOM: Core & HTML, task, P4)

task

Tracking

()

RESOLVED FIXED
162 Branch
Tracking Status
firefox162 --- fixed

People

(Reporter: wpt-sync, Unassigned)

References

()

Details

(Whiteboard: [wptsync downstream])

Attachments

(1 file)

Sync web-platform-tests PR 64329 into mozilla-central (this bug is closed when the sync is complete).

PR: https://github.com/web-platform-tests/wpt/pull/64329
Details from upstream follow.

Mason Freed <masonf@chromium.org> wrote:

Prevent dirty slot assignments during layout and frame rect updates

FlatTreeTraversal::TraverseParent calls Node::AssignedSlot, which
triggers SlotAssignment::RecalcAssignment if a shadow root still has
NeedsSlotAssignmentRecalc() set. During RecalcAssignment,
HTMLSlotElement::DetachDisplayLockedAssignedNodesLayoutTreeIfNeeded
synchronously detaches the layout tree of display-locked assigned
nodes. If a shadow root remains dirty into layout (e.g.
BlockNode::AttachScrollMarkers) or frame rect propagation
(LocalFrameView::PropagateFrameRectsRecursively), detaching the layout
tree mutates vectors being iterated on the stack, such as
ColumnPseudoElementsVector or LocalFrameView::plugins_.

A slottable Node stores two slot pointers on FlatTreeNodeData:
assigned_slot_ (the \<slot> it is currently slotted into in the flat
tree as a direct child of that slot's host) and manually_assigned_slot_
(the candidate \<slot> imperatively assigned via
HTMLSlotElement.prototype.assign(), which the DOM spec requires
preserving even while the node is outside the shadow host). However,
Blink also uses SlotAssignmentMode::kManual internally for User-Agent
shadow roots on \

, \<select>, and \<optgroup>, which run
Element::ManuallyAssignSlots() during
SlotAssignment::RecalcAssignment() and call ua_slot->Assign() on their
current children.

Shadow roots could remain dirty past
SlotAssignmentEngine::RecalcSlotAssignments() for two reasons:

  1. HTMLSlotElement::Assign() treated UA slots identically to author
    slots and shared Node::ManuallyAssignedSlot() for both. When a node
    previously passed to an author slot's assign() was moved into a
    \

    element, \

    's UA slot assignment ran
    ManuallyAssignSlots() -> content_slot_->Assign() inside
    RecalcAssignment(), saw previous_slot = node->ManuallyAssignedSlot()
    pointing to the author \<slot>, erased the node from the author
    slot's manually_assigned_nodes_, overwrote
    node->SetManuallyAssignedSlot(content_slot_), and called
    DidSlotChange() -> SetNeedsAssignmentRecalc() on the author shadow
    root mid-recalc. Because
    SlotAssignmentEngine::RecalcSlotAssignments() performs a single pass
    over a snapshot of shadow_roots_needing_recalc_, the newly dirtied
    author shadow root remained dirty after RecalcSlotAssignments()
    returned. Sharing Node::ManuallyAssignedSlot() also violated the DOM
    spec by destroying the node's author slot.assign() association when
    moved into \

    (and conversely allowed
    author_slot.assign(details_child) to steal a child from \

    's
    UA slot).

  2. SlotAssignment::DidRemoveSlot() for manual slotting cleared
    candidate nodes without calling SetNeedsAssignmentRecalc().

This patch fixes these issues by construction:

  • In HTMLSlotElement::Assign(), only read or modify
    Node::ManuallyAssignedSlot() and previous_slot when
    !IsInUserAgentShadowRoot(). UA slots only update their own
    manually_assigned_nodes_ set without touching
    Node::ManuallyAssignedSlot() or dirtying author shadow roots. In
    SlotAssignment::FindSlotInManualSlotting(), check the UA slots'
    ManuallyAssignedNodes() when owner_->IsUserAgent() is true.
  • Call SetNeedsAssignmentRecalc() in SlotAssignment::DidRemoveSlot()
    when a removed manual slot had candidate assigned nodes.
  • Add SlotAssignmentRecalcForbiddenScope in
    LocalFrameView::PerformLayout() and
    LocalFrameView::PropagateFrameRectsRecursively() to enforce via
    DCHECK that slot assignment recalculation is never triggered in those
    phases.

Fixed: 576736463, 575533210
Change-Id: Ib359a4b0ce88d60d6f90fdf5964979c0fdd23878
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8652233
Reviewed-by: Daniel Cheng \<dcheng@chromium.org>
Auto-Submit: Mason Freed \<masonf@chromium.org>
Commit-Queue: Daniel Cheng \<dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1729487}

Whiteboard: [wptsync downstream] → [wptsync downstream error]
Component: web-platform-tests → DOM: Core & HTML
Product: Testing → Core
Whiteboard: [wptsync downstream error] → [wptsync downstream]
Whiteboard: [wptsync downstream] → [wptsync downstream error]
Whiteboard: [wptsync downstream error] → [wptsync downstream]
Attached file Notable wpt changes —

CI Results

Ran 11 Firefox configurations based on mozilla-central, and Firefox, Chrome, and Safari on GitHub CI

Total 570 tests and 1 subtests

Status Summary

Firefox

OK : 1[GitHub] 368[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview] 369[Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
PASS : 2[GitHub] 64[Gecko-linux2204-64-wayland-debug, Gecko-linux2204-64-wayland-opt] 15225[Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt] 15249[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview] 15263[Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
FAIL : 320[Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt] 405[Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt] 406[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview]
TIMEOUT: 3[Gecko-linux2204-64-wayland-debug, Gecko-linux2204-64-wayland-opt] 5[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
ERROR : 2
NOTRUN : 3

Chrome

OK : 1
PASS : 2

Safari

OK : 1
PASS : 2

Links

Gecko CI (Treeherder)
GitHub PR Head
GitHub PR Base

Details

(See attachment for full changes)

Pushed by wptsync@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/54a0d95b565e https://hg.mozilla.org/integration/autoland/rev/9fc71cbe3149 [wpt PR 64329] - Prevent dirty slot assignments during layout and frame rect updates, a=testonly
Status: NEW → RESOLVED
Closed: 4 days ago
Resolution: --- → FIXED
Target Milestone: --- → 162 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: