LibWeb: Fix style inheritance for slotted elements

Two issues prevented slotted elements from correctly inheriting
styles from their assigned slot:

1. Element::element_to_inherit_style_from() was skipping the slot
   element and returning the shadow host instead. This meant slotted
   elements inherited from the host, completely ignoring any styles
   on the slot itself.

2. When a slot element's style changed during the style tree walk,
   its assigned (slotted) nodes were never marked for recomputation.
   The tree walk follows the DOM tree, but slotted elements are DOM
   children of the shadow host, not the slot, so they were missed.

Fix (1) by returning the slot directly as the inheritance parent.
Fix (2) by marking assigned nodes dirty in update_style_recursively
when a slot's style changes.
This commit is contained in:
Andreas Kling
2026-02-12 20:12:12 +01:00
committed by Andreas Kling
parent 8804eb89e0
commit fb11732526
Notes: github-actions[bot] 2026-02-13 09:23:49 +00:00
4 changed files with 20 additions and 7 deletions

View File

@@ -65,9 +65,6 @@
// 5. Slotted element: changing the slot's style must affect the slotted child,
// since the slot is the flat tree parent and inheritance follows the flat tree.
// FIXME: Ladybird doesn't currently propagate inherited style changes through
// slots to slotted elements. When that bug is fixed, these should show
// red and green respectively instead of black.
const shadowRoot = slotHost.shadowRoot;
const theSlot = shadowRoot.getElementById("the-slot");
theSlot.style.color = "red";