Repository navigation
fix(layout): include block-in-inline children in inline geometry - #2820
lanyue-llk wants to merge 3 commits into
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of 18384f1
Changes needed (2)
-
Nested inline still reports zero-width geometry —
moli-layout/src/layout_tree/source_query.rs:425. The filter needsstructural_parent == Some(principal).record_structural_childrenkeeps the first owner (world.rs, "first owner deliberately wins"), so in<a><span><div style="width:120px;height:20px"></div></span></a>the div's structural parent is thespan.aalso splits, but the div is never counted for it, soakeeps only zero-width edge fragments andclick()on the link still fails. This is the same bug as #2760 on a common card-link shape. Headless Chrome 157 (body margin 0, 800px viewport) givesa.getBoundingClientRect()=span.getBoundingClientRect()=[0,20,800,20]: the block counts for both inlines. Smallest fix: instead of comparing the direct parent only, walkstructural_parentfrom each candidate box. Continue while the intermediate box is a non-atomic inline (it hasInlineBoxfragments), and include the box if the walk reachesprincipal. Each box is still visited once, so nothing is counted twice. Add<a><span><div>toinline_with_block_child_reports_the_block_geometry. Checked and correctly excluded: blocks inside an inline-block (Chrome[50,40,120,18]= the inline-block line box) and abspos/float children. These stay in the continuation run, becausesplit_inline_boxsplits onlyis_block_in_flowchildren, which matches Chrome. -
Inlines without block children still pay for the new scan —
source_query.rs:411-433. Every element with anInlineBoxfragment (eachspan,a,em) now gets a second full pass overself.boxes, even when no split happened. In the batch path (query.rs:293/296, whichsource_outputsanswers from one pass), the cost grows from one pass to one plus one pass per inline source. For example,Range.getClientRects()(range_algorithms/geometry.rs:121) queries every element in the range. The Cost table (per-elementgetClientRectson an article) cannot show this. Smallest fix: scan only when the output already holds a continuation fragment, i.e. someoutput.fragmentsbox is notprincipal. Continuations exist only after a block-in-inline split, so ordinary inlines return their fragments with no extra work.
Other checks, no finding:
- getClientRects/getBoundingClientRect, DOM.getContentQuads, scrollIntoView and the batch path all go through
geometry_fragment_ids. getBoxModel is unchanged, as the body says. - Hit-testing is unaffected: the point lands on the div, whose DOM ancestor is the link.
- Empty anchors (
<a id=x></a>) keep their zero-width rect, because edges are dropped only when split blocks exist. Chrome returns one[x,y,0,18]rect here too. - The body discloses the 120 vs 800 bounding-rect difference.
- The new test fails without the fix. I read
contenteditable_atomic_inline_selection_keeps_order_effects_and_culling: it is a block editor with an inline-block and a paint snapshot of the selection, with no block-in-inline and no client-rect/quad query. The body's claim that the PR does not cause its failure is credible. - CI: Clippy, Format and the harness checks pass. Nextest and the CDP smoke test were still pending at review time.
- Body:
Closes #2760, title and Cost section are present. Picture: pending (placeholder only).
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of 492d2c3 (round 2)
Changes needed (1)
Round-1 items: (1) fixed. split_from_principal walks structural_parent only through boxes that own InlineBox fragments, so <a><span><div> reports the div for both inlines. It stops at atomic inlines, inline-block, replaced, float and abspos boxes, because collect_box (inline.rs) gives them no InlineBox fragments, and at blocks, whose own fragments are Box/Line only. (2) fixed. The gate is exact. Only the principal and its InlineSplitContinuation boxes carry geometry_source == element (pseudo boxes have source: None), and an InlineBox fragment is registered only on its own box_id. Wrapping across lines, bidi runs and ::first-line therefore produce more fragments with the principal's id but never a different id, so the scan runs only after a real block-in-inline split. Each element is computed independently, so querying span and a together does not double-count, and a split-out block never appears in output.fragments as well.
moli-layout/src/layout_tree/source_query.rs:449-455: the block filter adds atomic, float and abspos boxes that sit inside a nested inline. A candidate is kept when its formatting parent'sgeometry_source != owner. For a box inside a nested inline, that parent is the nested inline itself (e.g.span), which also passes the check. Example:<a><span><img></span><div>…</div></a>, or<a><span><b style="position:absolute;top:-999px">tip</b></span><div>…</div></a>.asplits, so the gate fires. Theimg/bwalksspan→aand is not inline, and its parentspan≠a, so its Box fragment is added toa'sgetClientRects()/DOM.getContentQuads. Chromium leaves it out: the inline's rects are its line fragments plus the block-in-inline part. With the abspos case,getBoundingClientRect()grows toward the tooltip. After the top-sort, the abspos quad becomesquads[0], so Puppeteer clicks the hidden tooltip's position and misses the link. When the sameimgis a direct child ofa, it is correctly left out (its parent is the principal or a continuation). That inconsistency shows this is a gap in the filter.
Smallest fix: keep only boxes whose formatting parent is not an inline box, i.e. replace thegeometry_source != ownertest with.is_some_and(|parent| !has_inline_fragment(parent)). That covers exactly the blocks moved out by the split, which now sit under the block container. Theownerbinding can then go. Add one assertion toinline_with_nested_inline_block_child_reports_the_block_geometry, e.g. an inline-block or float child ofspan, thatastill reports one rect.
Cost: the scan is O(boxes × inline depth) and runs only for split inlines. source_output is already O(boxes) per query, so the asymptotic cost per query is unchanged, and the Range ×20 row is consistent with that. CI on 492d2c3 (run 43218760661) is still queued for Nextest, Clippy, the release builds and CDP smoke; Format and the harness jobs pass. The body says the renderer/protocol geometry filter was run "after the review follow-up" only for moli-layout, so please confirm Nextest is green apart from contenteditable_atomic_inline_selection_keeps_order_effects_and_culling.
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of 8d6ad16 (round 3, final)
No blocking findings
Checked:
- Filter (
moli-layout/src/layout_tree/source_query.rs:442-454): a box counts only if it has no inline fragment, itsstructural_parentchain reaches the principal through inline boxes only, and its formattingparentis not an inline box.split_inline_box(moli-layout/src/builder.rs:644-680) moves out only in-flow blocks. Atomic inlines, floats and abspos stay in the inline/continuation run, so their formatting parent is inline and they are excluded. That covers the round-2 tooltip case (<a><span><b abspos>). a1/a2: the div's parent is the container, so it is included. a3: positive-width text fragments are kept, the block is added and the rects are sorted by y. a4: the span ancestor has inline fragments, so the walk passes through it. - Scope: the delta from 492d2c3 is the formatting-parent condition plus the test extension. The whole PR touches only
source_query.rsandphase5_output_contract.rs. Builder, frozen tree and box model are unchanged. - Cost: for an element without a continuation fragment, the gate is one
any()over its own fragments and returns the borrowed slice (Cow). No allocation and no box scan. - Test:
inline_with_nested_inline_block_child_reports_the_block_geometryadds inline-block and abspos children of the span, which is the case the round-2 filter got wrong. - CI (run 43222634113): Format, Node, Python and Windows pass. Clippy, Nextest, release builds and CDP smoke are still queued. No failures.
Optional notes:
- Body: the renderer/protocol nextest bullet appears twice.
- When a split has happened, each query scans every box, which is O(boxes) per split inline. That is fine for click-path queries. If a page-wide sweep over many card links ever shows up in profiles, collect the split blocks per principal once.
CI Regression ReportSource CI run · source state at render:
Release regression — ✅ HEAD/base failures 0/0; raw binary +0.013411%Package and image size
Startup latency and PSS
Concurrency matrix
Frontend differential — ✅ 1,020/1,020 cases matched; 0 issues
Agent episodes · Moli vs Chromium — ✅ 8/8 Moli episodes passed; 0 failures
Runtime and CDP session contracts — ✅ 26 contract cases; 0 failures
CDP smoke — ✅ 118/118 groups passed; 1,784 scenariosWorkers: 4 · cumulative group time: 466.44 s · failed groups: 0
WebMainBench · 545 pages — ✅ 545/545 completed; 0 unexpected failures
Frozen HTML · Linux · Diagnostics: All artifact fields are parsed by the trusted default-branch renderer; missing or invalid inputs remain visible as unavailable. |
Sequential Navigation Soak A/B✅ HEAD completed the 200-navigation resilience and memory observation. One browser process, one target, and one CDP session navigate CSDN → SegmentFault → Huaban → example.com repeatedly. This run issued 200 Common ancestor Session resilience
A public-page failure is reported separately from an unrecoverable session. The soak requires all navigation attempts, zero failed recovery, zero lifecycle/network ordering violations, and complete resource evidence. Process-tree memory
HEAD memory by 50-navigation quarter
Raw reports and per-navigation boundary samples: workflow run and full Public-site timing and memory are observational. Use the A/B deltas and trend shape as evidence, not as a deterministic performance threshold. |
Spider Bench A/B✅ All benchmark browser service runs completed; results are informational. Public HEAD: 184 / 240 rows; 38 / 48 sites produced rows; 10 unexpected empty sites. ✅ Deterministic fixture contract is clean. Common ancestor Public 48-site run · informational
Public-site content, timing, and memory are noisy. This single A/B run reports evidence only; site outcome counts explain missing rows without treating them as a deterministic regression. CPU and memory timelinesThese are bounded 40-point views of the same complete process-tree samples used by the HTML report. CPU uses 100% per occupied logical core; memory lines are RSS first and PSS second when complete PSS samples are available. Basexychart-beta
title "Base CPU"
x-axis "Elapsed seconds" [1.537, 2.539, 3.039, 4.04, 4.542, 5.543, 6.545, 7.046, 8.549, 10.052, 11.555, 13.056, 14.556, 15.558, 17.06, 18.562, 20.062, 21.564, 23.067, 24.569, 26.071, 27.072, 28.574, 30.075, 31.579, 33.08, 34.583, 36.084, 37.086, 38.588, 40.091, 41.592, 43.093, 44.595, 46.096, 47.098, 48.6, 50.103]
y-axis "CPU percent" 0 --> 200
line [105.89, 123.78, 112, 131.79, 135.62, 131.66, 141.73, 141.76, 129.68, 125.78, 5.99, 8, 4, 99.82, 57.89, 0, 117.96, 95.79, 103.89, 105.82, 151.69, 131.89, 111.82, 105.93, 11.97, 125.81, 101.95, 29.93, 113.83, 2, 27.98, 0, 31.98, 9.99, 127.91, 157.81, 7.99, 79.79]
xychart-beta
title "Base memory: RSS then PSS"
x-axis "Elapsed seconds" [0.036, 1.537, 2.539, 3.039, 4.04, 4.542, 5.543, 6.545, 7.046, 8.549, 10.052, 11.555, 13.056, 14.556, 15.558, 17.06, 18.562, 20.062, 21.564, 23.067, 24.569, 26.071, 27.072, 28.574, 30.075, 31.579, 33.08, 34.583, 36.084, 37.086, 38.588, 40.091, 41.592, 43.093, 44.595, 46.096, 47.098, 48.6, 50.103, 51.545]
y-axis "Memory MiB" 0 --> 500
line [13.95, 99.47, 111.39, 129.38, 138.82, 150.1, 135.38, 131.71, 143.87, 159.42, 138.07, 119.39, 123.52, 122.68, 148.95, 139.44, 133.36, 148.96, 147.62, 265.9, 193.71, 169.39, 143.72, 148.8, 144.91, 131.04, 188.19, 234.34, 224.48, 234.33, 231.89, 232.05, 231.17, 228.27, 152.67, 168.7, 141.47, 141.73, 145.16, 0]
line [10.5, 95.29, 107.87, 125.89, 135.17, 146.71, 131.68, 128.23, 140.2, 155.92, 134.42, 115.87, 119.99, 119, 145.49, 135.59, 129.51, 145.43, 144.72, 262.85, 190.2, 166.8, 140.29, 145.85, 141.51, 127.58, 184.83, 230.54, 221.02, 230.7, 228.43, 228.59, 227.71, 224.78, 149.21, 162.88, 137.49, 138.19, 141.55, 0]
HEADxychart-beta
title "HEAD CPU"
x-axis "Elapsed seconds" [1.538, 2.539, 3.04, 4.042, 5.545, 7.048, 8.55, 10.052, 11.052, 12.555, 14.055, 15.557, 17.058, 18.059, 19.559, 21.061, 21.562, 22.564, 24.064, 25.565, 26.566, 28.069, 29.571, 31.073, 32.575, 33.576, 35.078, 36.58, 38.082, 39.582, 40.582, 42.084, 43.584, 45.087, 46.588, 47.089, 47.59, 49.091]
y-axis "CPU percent" 0 --> 200
line [27.97, 101.86, 133.73, 89.87, 127.7, 109.83, 127.88, 39.99, 119.97, 15.97, 10, 153.99, 13.98, 52.02, 91.99, 131.66, 99.78, 119.87, 103.98, 91.93, 125.91, 107.75, 75.81, 27.99, 145.79, 105.87, 53.96, 99.98, 25.98, 2, 0, 24, 54.03, 27.98, 101.87, 155.83, 113.82, 140.05]
xychart-beta
title "HEAD memory: RSS then PSS"
x-axis "Elapsed seconds" [0.037, 1.538, 2.539, 3.04, 4.042, 5.545, 7.048, 8.55, 10.052, 11.052, 12.555, 14.055, 15.557, 17.058, 18.059, 19.559, 21.061, 21.562, 22.564, 24.064, 25.565, 26.566, 28.069, 29.571, 31.073, 32.575, 33.576, 35.078, 36.58, 38.082, 39.582, 40.582, 42.084, 43.584, 45.087, 46.588, 47.089, 47.59, 49.091, 50.266]
y-axis "Memory MiB" 0 --> 500
line [13.94, 94.57, 106.4, 117.34, 118.58, 139.79, 146.47, 137.43, 150.41, 157.82, 117.43, 122.99, 141.99, 124.26, 135.54, 141.39, 174.39, 242.37, 181.55, 200.67, 139.2, 165.2, 155.46, 145.43, 139.57, 193.36, 241.16, 223.41, 233.77, 229.41, 231.48, 230.67, 230.57, 150.49, 141.46, 163.99, 168.49, 144.27, 182.63, 0]
line [10.46, 90.93, 102.82, 113.9, 114.93, 136.11, 142.87, 133.77, 146.75, 154.19, 113.76, 119.33, 137.47, 120.6, 131.89, 137.74, 170.78, 238.74, 177.94, 197.01, 135.7, 161.84, 151.82, 141.77, 135.93, 189.72, 237.52, 219.76, 230.13, 225.77, 227.84, 227.02, 226.93, 146.84, 139.06, 160.37, 164.29, 140.62, 178.99, 0]
Deterministic fixture · required contractThe fixture exercises 15 routes: 8 are expected to emit rows and 7 intentionally exercise empty, loading, or timeout behavior.
Full HTML, JSON, CSV, logs, and page snapshots: workflow run and full The public-web A/B is informational. The exact HEAD fixture contract runs as a separate required CI check; timing and public-site content deltas remain non-blocking. |
8d6ad16 to
07a4ed2
Compare

**Track:** Trajectory Replay (Browser Eval). Replaces part of #756.Closes #2760.
Replaces part of #756.
Problem
An inline element whose child is a block or flex box (e.g. a card link
<a><div>…</div></a>) reported only its zero-width inline edge fragments, soDOM.getContentQuads,getClientRects()andgetBoundingClientRect()returned zero-area geometry. Puppeteer and Playwright discard zero-area quads, soclick()on a visibly rendered link failed. Repro (issue fixture,moli serve --layout):DOM.getContentQuadson#a1(<a><div 120×20>),#a2(<a><div display:flex>),#a3(before<div 100×20>after).Reproduce (steps from #2760)
DOM.getContentQuadsfor#a1,#a2and#a3over CDP (moli serve --layout), ormoli fetch --layout <url> --eval 'JSON.stringify(a1.getBoundingClientRect())'.Expected (Chromium)
#a1:[[0,0,120,0,120,20,0,20]]#a2:[[0,20,120,20,120,40,0,40]]#a3: three quads, with a 100×20 middle quad for the blocka1.getBoundingClientRect().widthis 800Actual
Every quad has zero width, and
#a3's middle (block) quad is missing.Change
moli-layout/src/layout_tree/source_query.rs: block-in-inline splitting moves the block children out of the inline box (they become siblings of the inline's continuations), so nothing reported them as part of the inline.client_rects_for_outputandcontent_quads_for_outputnow also include, for an inline element, the box fragments of the boxes whose pre-normalization parent (structural_parent) is this inline but whose formatting parent is not one of its continuations — exactly the blocks split out of it. The ancestry walk passes through non-atomic inlines, so<a><span><div>reports the div for both theaand thespan; a box is included only when its formatting parent is not an inline box, so atomic inlines (images, inline-blocks) and floats/abspos boxes inside a nested inline (e.g. an absolutely positioned tooltip<span><b style=position:absolute>) are not included. The scan runs only when the element's fragments include a continuation box, which exists only after a block-in-inline split, so ordinary inlines do no extra work. When such blocks exist, the inline's zero-width edge fragments are dropped and the rects are ordered top to bottom. No builder or frozen-tree change; blocks inside a nested inline-block keep their own parent and are not included.Tests: new
inline_with_nested_inline_block_child_reports_the_block_geometry(<a><span><div>plus an inline-block and an abspos child of the span: both inlines report the block, never the inline-block or abspos box; fails with the previous filter) andinline_with_block_child_reports_the_block_geometry(one rect equal to the block's border box, for both client rects and content quads);split_inline_continuations_remain_mapped_to_the_originating_elementnow expects three rects (before text, the 50px block, after text) instead of two.Known difference:
getBoundingClientRect()of#a1is the block's box (width 120); Chromium reports 800 because its anonymous block-in-inline wrapper spans the container.DOM.getBoxModelof such an inline is unchanged.Verification
Before: debug build of
origin/mainf935014; after: debug build of this branch.cargo fmt --all: clean.cargo clippy -p moli-layout --all-targets --all-features -- -D warnings: passed.cargo nextest run -p moli-layout: 332 passed (head 8d6ad16).cargo nextest run -p moli-renderer-v8 -p moli-protocol -p moli-protocol-server -E 'test(quad) | test(client_rect) | test(bounding) | test(geometry) | test(scroll_into_view) | test(inline)'on head 8d6ad16: 448 passed, 1 failed (contenteditable_atomic_inline_selection_keeps_order_effects_and_culling, same failure with this change reverted).<a id=a5><span><b style="position:absolute;top:-999px">tip</b></span><div 120×20>:a5.getClientRects()→ only the block[0,112,120,20].<a id=a4><span><div 120×20>:getBoundingClientRectmain[0,76,29.3,40]→ this PR[0,92,120,20].Cost
Debug builds,
/usr/bin/time -l, median of 5 runs, two interleaved rounds (shared host):moli serve --layout)moli fetch --layoutof a local 46 KB article,getClientRects()on everya,p,tdReview follow-up measurement (head 492d2c3; base rebuilt from this branch's parent),
Range.getClientRects()over the whole article body, 20 times (13,820 rects), median of 5, two rounds: main 1.100 / 1.040 s, 135.0 / 134.9 MB → this PR 1.060 / 1.060 s, 135.2 / 135.0 MB. Repro: main 1.279 / 1.327 s → this PR 1.479 / 1.256 s (host noise; 120 MB both).The extra box scan runs only when an element's own fragments include an inline continuation, i.e. after a block-in-inline split; every other element (including ordinary inlines and Range queries over them) returns its own fragments without a second pass.