Repository: servo/servo
File: components/layout/dom_traversal.rs (Rust)

Code before:
        }
    } else {
        for child in parent_element_info.node.children() {
            if child.is_text_node() {
                let info = NodeAndStyleInfo::new(
                    child,
                    child.style(&context.style_context),
                    child.take_restyle_damage(),
                );
                handler.handle_text(&info, child.node_text_content());
            } else if child.is_element() {
                traverse_element(child, context, handler);
            }
        }
    }

    traverse_eager_pseudo_element(PseudoElement::After, parent_element_info, context, handler);
}

fn traverse_element<'dom>(
    element: ServoThreadSafeLayoutNode<'dom>,
    context: &LayoutContext,
    handler: &mut impl TraversalHandler<'dom>,
) {
    let damage = element.take_restyle_damage();
    if damage.contains(LayoutDamage::recollect_box_tree_children().into()) {
        element.unset_all_pseudo_boxes();
    }

    let replaced = ReplacedContents::for_element(element, context);
    let style = element.style(&context.style_context);
    let info = NodeAndStyleInfo::new(element, style, damage);

    match Display::from(info.style.get_box().display) {
        Display::None => element.unset_all_boxes(),
        Display::Contents => {
            if replaced.is_some() {
                // `display: content` on a replaced element computes to `display: none`
                // <https://drafts.csswg.org/css-display-3/#valdef-display-contents>
                element.unset_all_boxes()
            } else {
                let shared_inline_styles: SharedInlineStyles = (&info).into();
                element
                    .box_slot()
                    .set(LayoutBox::DisplayContents(shared_inline_styles.clone()));

                handler.enter_display_contents(shared_inline_styles);
                traverse_children_of(&info, context, handler);
                handler.leave_display_contents();
            }
        },

Review comment (suggestion):
```suggestion
    if damage.has_box_damage() {
```

Code after:
            handler.handle_text(parent_element_info, "\u{200B}".into());
        } else {
            handler.handle_text(parent_element_info, node_text_content);
        }
    } else {
        for child in parent_element_info.node.children() {
            if child.is_text_node() {
                let info = NodeAndStyleInfo::new(
                    child,
                    child.style(&context.style_context),
                    child.take_restyle_damage(),
                );
                handler.handle_text(&info, child.node_text_content());
            } else if child.is_element() {
                traverse_element(child, context, handler);
            }
        }
    }

    traverse_eager_pseudo_element(PseudoElement::After, parent_element_info, context, handler);
}

fn traverse_element<'dom>(
    element: ServoThreadSafeLayoutNode<'dom>,
    context: &LayoutContext,
    handler: &mut impl TraversalHandler<'dom>,
) {
    let damage = element.take_restyle_damage();
    if damage.has_box_damage() {
        element.unset_all_pseudo_boxes();
    }

    let style = element.style(&context.style_context);
    let info = NodeAndStyleInfo::new(element, style, damage);

    match Display::from(info.style.get_box().display) {
        Display::None => element.unset_all_boxes(),
        Display::Contents => {
            if ReplacedContents::for_element(element, context).is_some() {
                // `display: content` on a replaced element computes to `display: none`
                // <https://drafts.csswg.org/css-display-3/#valdef-display-contents>
                element.unset_all_boxes()
            } else {
                let shared_inline_styles: SharedInlineStyles = (&info).into();
                element
                    .box_slot()
                    .set(LayoutBox::DisplayContents(shared_inline_styles.clone()));

                handler.enter_display_contents(shared_inline_styles);
                traverse_children_of(&info, context, handler);
                handler.leave_display_contents();