Goal: explain a visual change through the pipeline
A button changing text does not mean a string assignment automatically produces a correct picture. The Rust evaluator mutates the lesson DOM, and style, layout, and display-list generation consume that same DOM. Explain the connection from event to function, mutation, recomputation, and visible output. Compare nodes and intermediate results before and after the change rather than inspecting only the final screenshot.
Start with mutate_text and render_document in the distributed source. Wave four extends the existing static rendering pipeline; it does not replace it with the host browser DOM. The Rust arena remains the input. Distinguishing interface elements from lesson nodes reveals whether you are observing Rust-produced display information or behavior accidentally supplied by the surrounding host page.
Separate node identity from its child content
getElementById returns a handle associated with the Rust arena. Changing textContent changes an element's content, but does not justify assuming the target element itself acquired a new identifier. Follow the target separately from its children, and inspect which descendants the implementation replaces. Previously held descendant references should not be assumed valid without checking the actual mutation rules.
Identity connects event targeting to later rendering evidence. Replacing an element with a newly created lookalike can affect stored references and registered listeners. Distinguish the string id attribute, the arena's numeric identifier, and identifiers carried into drawing information. Sharing a familiar name does not make these representations interchangeable; each has a specific role in the pipeline.
Style, layout, and drawing have different outputs
Style resolves supported properties such as colors or dimensions from rules and attributes. Layout uses those results and content to calculate boxes. A display list describes drawing operations and their order. Compare a color-only attribute change with a longer text replacement that affects geometry. The difference helps locate which stage's output changed and which stage merely consumed a changed input.
This renderer is not a complete CSS implementation or a replacement for production browser typography. Supported attributes and rules are limited by the source. Recomputing the document after mutation can still teach causal correctness, but should not be described as an incremental invalidation optimization. First establish the correct pipeline; reducing unnecessary work is a separate engineering exercise.
Worked trace: what changes after a click
Suppose status initially displays Ready and a named click function is registered. Dispatch invokes that function, textContent becomes Done, and the renderer reads the updated content. The table separates those boundaries. Observing event delivery differs from observing a changed drawing string; skipping intermediate stages turns explanation into guesswork.
Choose one numeric target identifier and follow that element through the stages. Include both shorter and longer text replacements, because a longer string can expose stale layout more clearly. These example strings describe a reasoning exercise, not fixed measurements copied from a recording. Determine actual geometry using the distributed renderer's rules and returned output, and preserve the distinction between an illustrative trace and execution evidence.
| Stage | Input | Observable change |
|---|---|---|
| Dispatch | Target identifier and listeners | Named function invocation |
| Mutation | status in the same arena | Ready → Done |
| Recompute | Updated DOM and CSS | Style and layout |
| Draw | Updated display commands | New text is displayed |
Distinguish no change from failed change
A normal case changes text and a supported attribute on an existing element. A boundary case sets the same value again: the picture may remain identical even though the handler executed. A failure case uses a missing element or unsupported operation. The shared symptom of an unchanged screen does not make these cases equivalent.
Potential causes include a wrong target, absent registration, handler failure, missing recomputation, or presentation of an old result. Inspect the Rust DOM first, then style and layout, and finally drawing commands. If a diagnostic occurred, establish which changes completed before it. Do not assume automatic rollback; use the remaining state as evidence to locate the failing boundary.
Runnable Rust: derive new drawing data from one target
This standalone host Rust program mutates a node and derives new drawing data. Its width rule is deliberately artificial: eight units per character is neither production typography nor the distributed browser's measurement contract. Making that assumption explicit isolates identity, old drawing data, and new drawing data. Passing this snippet does not establish correctness of the complete renderer.
The previous Draw is a saved value and does not update itself when Node changes. Calling render again produces a new value. Assertions check preserved identity, changed width and color, and repeatable output from unchanged state. Investigate those three properties in the real trace as well, separating mistaken targeting, missed recomputation, and unnecessary nondeterminism into different failure classes.
#[derive(Clone)]
struct Node { id: u32, text: String, color: &'static str }
#[derive(Debug, PartialEq)]
struct Draw { id: u32, text: String, width: usize, color: &'static str }
fn render(n: &Node) -> Draw {
Draw { id: n.id, text: n.text.clone(), width: n.text.chars().count() * 8,
color: n.color }
}
fn main() {
let mut node = Node { id: 7, text: "Hi".into(), color: "black" };
let before = render(&node);
node.text = "Hello".into(); node.color = "red";
let after = render(&node);
assert_eq!(before.id, after.id);
assert_eq!((before.width, after.width), (16,40));
assert_eq!(after.color, "red");
assert_eq!(render(&node), after);
println!("node={} width:{}->{} color={}", after.id, before.width, after.width, after.color);
}Compare CLI and WASM using identical input
Use identical HTML, CSS, JavaScript, and event sequences when comparing CLI and WASM. Compare structured Rust results as well as screenshots. Surrounding interface typography can differ while lesson DOM and drawing data remain equivalent. This separates engine computation from presentation. If only one side's input changes, an output difference cannot reliably identify an engine inconsistency.
For intermediate event effects, run short prefixes: the first event, then the first two events, and so on. Comparing those results can identify the smallest event that caused a change more efficiently than scanning a long trace. Record that each prefix is replayed from the initial input. Describing it as continuation from a saved screen would imply different reproduction conditions.
Exercise: collect four before-and-after observations
Create an input where a click replaces short text with longer text and changes one supported attribute. Predict handler order, new DOM content, style differences, and layout or drawing differences before running. Collect those four observations afterward and associate them through the target identifier. If you predicted a width change, identify the implementation rule supporting that expectation.
Prepare controls that set the same value, reference a missing target, and contain no events. Describe which stages ran and which state changed, rather than only whether the screen moved. For an extension, construct two event sequences with the same final DOM and explain matching final drawings alongside different intermediate traces. Distinguishing final state from execution history completes the causal explanation.