we (web engine): Experimental web browser project to understand the limits of Claude
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix normalize_children to wrap inline content alongside floats

When a container has only float children and bare inline content (no
in-flow block siblings), normalize_children returned early without
wrapping the inline content in anonymous blocks. This caused the text
to be silently dropped during layout_block_children since compute_layout
is a no-op for TextRun/Inline boxes.

Include floated children in the has_block check so that inline content
gets properly wrapped in anonymous blocks and laid out through the
inline formatting context.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+44 -2
+44 -2
crates/layout/src/lib.rs
··· 462 462 return children; 463 463 } 464 464 465 - // Only consider in-flow children for block/inline normalization. 466 - let has_block = children.iter().any(|c| is_in_flow(c) && is_block_level(c)); 465 + // Consider in-flow block children and floated children as "block-level" 466 + // for normalization purposes. When floats are present alongside inline 467 + // content, the inline content must be wrapped in anonymous blocks so that 468 + // `layout_block_children` can lay it out via its inline formatting context. 469 + let has_block = children 470 + .iter() 471 + .any(|c| (is_in_flow(c) && is_block_level(c)) || is_floated(c)); 467 472 if !has_block { 468 473 return children; 469 474 } ··· 5428 5433 float_right, 5429 5434 ); 5430 5435 } 5436 + } 5437 + 5438 + #[test] 5439 + fn bare_text_alongside_float_is_laid_out() { 5440 + // When a container has only float children + bare text (no block 5441 + // siblings), the text should still be wrapped in an anonymous block 5442 + // and laid out correctly. 5443 + let mut doc = Document::new(); 5444 + let root = doc.root(); 5445 + let html = doc.create_element("html"); 5446 + let body = doc.create_element("body"); 5447 + let container = doc.create_element("div"); 5448 + let float_elem = doc.create_element("div"); 5449 + let text = doc.create_text("Hello world"); 5450 + doc.append_child(root, html); 5451 + doc.append_child(html, body); 5452 + doc.append_child(body, container); 5453 + doc.append_child(container, float_elem); 5454 + doc.append_child(container, text); 5455 + doc.set_attribute(container, "style", "width: 400px;"); 5456 + doc.set_attribute( 5457 + float_elem, 5458 + "style", 5459 + "float: left; width: 100px; height: 50px;", 5460 + ); 5461 + 5462 + let tree = layout_doc(&doc); 5463 + let body_box = &tree.root.children[0]; 5464 + let container_box = &body_box.children[0]; 5465 + 5466 + // The text should be wrapped in an anonymous block and produce text lines. 5467 + let has_text = container_box.children.iter().any(|c| !c.lines.is_empty()); 5468 + assert!( 5469 + has_text, 5470 + "bare text alongside a float should be laid out (found {} children, none with text lines)", 5471 + container_box.children.len(), 5472 + ); 5431 5473 } 5432 5474 }