Execution — bi-08-layout
Steps extracted from CONCEPTS.md. Read the concepts first; this file is the doing.
Record results in observation.md; tick checkpoints in verification.md.
6. Lab — mini-browser M7–M9
Input: DOM + computed style (from bi-07). Output: layout tree + geometry.
- Layout tree construction: skip
display:none, synthesise an anonymous box for at least one case. - Block layout: width from containing block, height from content, margins/padding/border.
- Nested boxes and margin behaviour. Implement margin collapsing, then write down the three rules you had to encode.
- Inline layout: line boxes, text measurement, line breaking. Use a fixed-width font metric so it is deterministic.
- Basic flex:
flex-direction: row,flex-grow,flex-basis. - Intrinsic sizing: implement
max-contentfor a subtree. Observe that you now need a second pass. - Dirty-layout tracking + result caching. Give each box a constraint-space-equivalent key; skip relayout when the key is unchanged. Measure the hit rate on a resize.
Deliverable: a measurement of stage 7's cache hit rate under (a) a window resize, (b) a single deep text change, and a written explanation of why the two differ so much.
7. Failure Lab
- Forced synchronous layout. Build the read/write loop. Measure at n = 100/1000/5000 and plot. Then batch and re-measure. Name the complexity class of each.
- Break the cache key. Make your constraint-space key omit one input (say, available inline size). Find markup that now renders wrong. This demonstrates precisely why caching requires complete inputs.
- Mutate a fragment after publishing it. Show a downstream consumer reading stale or inconsistent geometry. This is the bug immutability prevents.
- Physical-thinking bug. Hard-code left/right somewhere, then run your engine in RTL.
8. Debugging Exercise
- In DevTools, find layout events for a forced synchronous layout; confirm the count matches your loop's iterations.
- Construct two DOM changes with the same visual result, one triggering layout and one not. Explain by property.
- In the checkout, find where a cached layout result is reused, and the exact condition under which it is not. Write the condition in one English sentence.
- Find an anonymous box being created. What invariant made it necessary?