Skip to content

script: More carefully handle dirty root and descendant damage marking - #61656

Merged
servo-wpt-sync merged 1 commit into
web-platform-tests:masterfrom
servo:servo_export_46906
Aug 4, 2026
Merged

servo-wpt-sync merged 1 commit into
web-platform-tests:masterfrom
servo:servo_export_46906

Conversation

@servo-wpt-sync

@servo-wpt-sync servo-wpt-sync commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

Script passes a dirty root to layout along with setting the
HAS_DIRTY_DESCENDANTS flag on elements at or below that root indicating
that children need to be traversed. There was an undocumented invariant
that no nodes above that dirty root were marked with
HAS_DIRTY_DESCENDANTS, as the flag itself was used to determine
when the dirty root is raised to some common ancestor of the old dirty
root and a damaged node.

There were some problems with the old implementation and this change
fixes them by hewing closer to Gecko (from which we took this design).
Notably:

  • In the complex situation where we cannot trivially calculate the dirty
    root, we now calculate it by walking up from the old dirty root and
    finding the first element which already has the flag set.
  • When removing nodes from the flat tree, if they were the previous
    dirty root, the dirty root is cleared.
  • Ensure that all marking traversals for the HAS_DIRTY_DESCENDANTS flag
    marking happen in the flat tree.
  • When slotting nodes into <slot> elements, the style and layout data
    of fallback content is cleared, and the dirty root is potentially reset.
  • Comments are added everywhere in this tricky algorithm explaining what
    the heck is going on.
  • The new debug assertion for the invariant found a case where we were
    triggering restyles too late before a relayout -- when setting selection flags.
    This is moved earlier in the method.

Testing: This change adds a new WPT crash test.
Fixes: #46024.
Fixes: #46883.

Reviewed in servo/servo#46906

@wpt-pr-bot wpt-pr-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The review process for this patch is being conducted in the Servo project.

@servo-wpt-sync
servo-wpt-sync force-pushed the servo_export_46906 branch 2 times, most recently from 485e297 to 26a254b Compare July 31, 2026 16:09
Script passes a dirty root to layout along with setting the
HAS_DIRTY_DESCENDANTS flag on elements at or below that root indicating
that children need to be traversed. There was an undocumented invariant
that no nodes above that dirty root were marked with
HAS_DIRTY_DESCENDANTS, as the flag itself was used to determine
when the dirty root is raised to some common ancestor of the old dirty
root and a damaged node.

There were some problems with the old implementation and this change
fixes them by hewing closer to Gecko (from which we took this design).
Notably:

- In the complex situation where we cannot trivially calculate the dirty
  root, we now calculate it by walking up from the old dirty root and
  finding the first element which already has the flag set.
- When removing nodes from the flat tree, if they were the previous
  dirty root, the dirty root is cleared.
- Ensure that all marking traversals for HAS_DIRTY_DESCENDANTS flag
  marking happen in the flat tree.
- When slotting nodes into `<slot>` elements, the style and layout data
  of fallback content is cleared, and the dirty root is potentially reset.
- Comments are added everywhere in this tricky algorithm explaining what
  the heck is going on.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
@servo-wpt-sync
servo-wpt-sync merged commit 1091575 into web-platform-tests:master Aug 4, 2026
20 checks passed
@servo-wpt-sync
servo-wpt-sync deleted the servo_export_46906 branch August 4, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants