AssertLaidOut when unlocking a display lock with a dirty holder

#40063752 Area: Blink>Layout / content-visibility CL 8614327 In Review

Summary

Problem

A content-visibility: hidden element (the display-lock holder) stops dirty-bit propagation at itself. A descendant that calls SetNeedsLayout() marks the holder as ChildNeedsFullLayout but leaves the chain above it clean.

When the lock is removed, DisplayLockContext::MarkForLayoutIfNeeded() calls layout_object->SetChildNeedsLayout() on the holder. That helper early-returns from MarkContainerChainForLayout() if the object was already child-dirty -- so ancestors stay clean, the unlocked subtree is unreachable from the next layout, and LayoutObject::AssertLaidOut() trips in debug builds.

Fix (CL 8614327)

Call MarkContainerChainForLayout() explicitly in the child_layout_was_blocked_ branch of MarkForLayoutIfNeeded(), gated on the MarkAncestorsOnDisplayLockUnlock runtime flag (status: "stable", default on, kill switch).

if (child_layout_was_blocked_ || HasStashedScrollOffset()) {
  layout_object->SetChildNeedsLayout();
  child_layout_was_blocked_ = false;
  if (RuntimeEnabledFeatures::MarkAncestorsOnDisplayLockUnlockEnabled()) {
    // SetChildNeedsLayout() skips the ancestors when this object was
    // already child-dirty, but dirty-bit propagation from the locked
    // subtree stopped here, so they are clean.
    layout_object->MarkContainerChainForLayout();
  }
}

Shape of the tree

outer                 clean
  lock  (c-v:hidden)  child-dirty  <-- propagation stops here
    inner             needs-layout <-- the actual dirty node

without the fix, after unlock:

outer                 still clean  <-- not visited by layout
  lock                child-dirty
    inner             needs-layout <-- unreachable -> AssertLaidOut (debug)

Repro walk-through

The sampler at sampler.html?step=3 sets up outer > lock > inner, drops content-visibility: hidden on lock, mutates inner.style.width inside the locked subtree, removes the lock, and reports inner.getBoundingClientRect().width.

unlock-dirty-holder -- content_shell with the flag off vs on

Live render in your browser. Walks through steps 0-3 and reports the measured inner width.
Expected: PASS, 420px
content_shell with the fix enabled -- inner lays out to 420px, PASS.
Diff mask (empty)
0 px differ. In release content_shell the final layout settles to the same visible state with or without the fix -- a later paint invalidation re-dirties the chain -- so the bug is only directly observable as the AssertLaidOut DCHECK trip in debug.

content_shell: before / after

Before: --disable-blink-features=MarkAncestorsOnDisplayLockUnlock
beforeflag disabled (bug path): same final layout in release
After: --enable-blink-features=MarkAncestorsOnDisplayLockUnlock
afterflag enabled (default): same final layout, no DCHECK trip in debug

Why the screenshots look identical

AssertLaidOut() is a DCHECK-only guard. In a release build the unlocked subtree still gets laid out eventually -- any subsequent paint-invalidation walker re-dirties the chain -- so the final pixels match. The direct observable regression is the debug-build DCHECK firing, pinned by the two unit tests (UnlockWithBlockedChildLayoutMarksAncestors and its ...Disabled twin) that assert ChildNeedsFullLayout on the common ancestor right after unlock.

Verification

Local

Links

Issue 40063752 CL 8614327 standalone sampler.html