From 72a29c71d25ab3fabc159da63d620031d5c6c516 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 29 Nov 2026 05:39:59 +0100 Subject: [PATCH] frame: events are routed against the frame the user saw, before the drain and the bind Finding events-read-new-tree-old-geometry. Core::frame routes the frame's events first, against the last drawn geometry and the tree bound when it was drawn, then switches surface, drains provider updates and binds. Captures mint from what the user saw. Test: the provider unchecks a toggle in the frame the user clicks it checked; the mint carries the unchecked value, in Pixels at 1 and 1.5 and in Cells. Co-Authored-By: Claude Opus 5.5 --- crates/thing-core/src/frame.rs | 9 +++++---- crates/thing-core/tests/input.rs | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/crates/thing-core/src/frame.rs b/crates/thing-core/src/frame.rs index f8c6d0b..51f671e 100644 --- a/crates/thing-core/src/frame.rs +++ b/crates/thing-core/src/frame.rs @@ -124,13 +124,17 @@ impl Core { pub fn frame(&mut self, input: FrameInput, ports: Ports<'_>) -> FrameOutput { let FrameInput { now, viewport, scale, events } = input; let port = ports.state; + let mut diagnostics = std::mem::take(&mut self.notes); + // Input is judged entirely against the frame the user saw: its geometry and the values bound + // into it. Nothing of this frame (the surface it switches to, the provider updates it drains, + // the tree it binds) is in place yet, so no event reads a world the user did not look at. + diagnostics.extend(self.route(&events, scale, now, ports.ids, port)); let mut changes = Vec::new(); if self.wanted != self.shown { self.switch(port, &mut changes); } changes.extend(port.drain()); - let mut diagnostics = std::mem::take(&mut self.notes); let mut effects = Vec::new(); let mut rebound = false; for change in &changes { @@ -167,9 +171,6 @@ impl Core { None => self.held.push(resume), } } - // Pointer events act on what the user saw: the last good frame, before this frame's state is - // laid out, each in the order the host saw it. Keys, text and focus change nothing yet. - diagnostics.extend(self.route(&events, scale, now, ports.ids, port)); // Results of this frame are applied above, before the deadline is judged: a late result that was // already queued wins over the timeout. diagnostics.extend(self.commands.tick(now, port, &mut self.ledger)); diff --git a/crates/thing-core/tests/input.rs b/crates/thing-core/tests/input.rs index 6c23a10..0a82970 100644 --- a/crates/thing-core/tests/input.rs +++ b/crates/thing-core/tests/input.rs @@ -21,7 +21,7 @@ use thing_testkit::fixture::Fixture; use thing_testkit::ids::SeqIds; use thing_testkit::measure::FixedMeasure; use thing_testkit::mem_state::MemState; -use thing_testkit::state::{self, Item}; +use thing_testkit::state::{self, Item, Settings}; const PROVIDER: &str = "provider.pointer"; const FEED: &str = "provider.feed"; @@ -837,6 +837,25 @@ fn events_in_one_frame_act_on_the_frame_the_user_saw_and_the_next_frame_draws_th } } +#[test] +fn a_click_is_judged_against_the_values_the_user_saw_not_the_ones_the_provider_wrote_in_the_same_frame() { + for mode in MODES { + let fixture = Fixture::F04Form; + let mut state = MemState::from_fixture(fixture); + state::script(fixture, &mut state); + let document = fixture.load().surfaces.remove(0); + let mut seen = MemState::from_fixture(fixture); + state::script(fixture, &mut seen); + let toggle = inside(Rig::new(seen, &document, mode).rect("enabled")); + let mut host = Host::new(state, &document, mode); + // The user saw `enabled` checked. In the frame they click it the provider writes it unchecked. + host.state.put_state(&ProviderId::new("provider.settings"), "current", &Settings { enabled: false, volume: 40.0, theme: "dark".into() }); + let output = host.frame(vec![down(toggle), up(toggle)]); + assert_eq!(output.outbound.len(), 1, "{mode:?}"); + assert_eq!(output.outbound[0].captured[0].value, InputValue::Bool(BoolValue { value: false }), "{mode:?}: they unchecked what they saw checked"); + } +} + #[test] fn a_surface_left_mid_press_drops_the_press_and_a_stray_up_does_nothing() { let (one, mut two) = (controls_surface(), controls_surface());