Learn / Who changes state

Messages carry intent, not results worked out from the last frame

Typing "Dowel" faster than an inline editor opened used to leave only "l" in the box.

Why? Foldkit renders on the next animation frame. While a fast typist presses five keys inside one frame, the DOM still shows the view as it was last drawn — before the editor opened. Because the view still saw a closed cell, each key handler sent EditStarted({ draft: key }), and update restarted the edit on every keystroke.

The same frame-lag bug appears in four other places:

  • Submitting right after typing: Pressing Enter in a todo input within a frame of typing sent the empty draft the form was last drawn with, adding nothing.
  • Double-clicking a sort header: Two clicks in one frame both read "ascending" from the drawn button and both sent Sorted({ direction: 'ascending' }) instead of toggling to descending.
  • Resized columns during a drag: Computing a drop target during pointermove landed columns by widths that a resize had changed before release.
  • Clicking an open menu's button: Clicking the trigger moved focus away from the menu so it closed, and the click — bound on the last frame — reopened it on the next frame.

The rule is simple: a Message states what the user did, and update computes what it means against the current Model.

Instead ofSendAnd update
The next sort direction (Sorted({ sort }))The column clicked (Sorted({ column }))Toggles model.sort via PostSort.toggle
Starting an edit per key (EditStarted({ draft }))The key typed (EditTyped({ text }))Starts an edit or appends to the open one
A drop index computed on pointermovePointer offset at release (ColumnDragEnded)Computes drop target from current columns
The menu item label as drawnIts index (MenuChosen({ index }))Reads the item from the live menu
The draft string as drawn (RequestedTodo)The submit intent (DraftSubmitted())Reads model.draft from the Model

Close a menu when focus leaves the wrapper holding both the menu and its trigger button, rather than on blur of the menu alone.

Testing fast input with held frames

A test that awaits a redraw between clicks will never catch frame-lag bugs. Use Frames.track() from foldkit-mixins/testing to hold animation frames during a sequence of events (frames.hold()), dispatch rapid clicks or keystrokes against the stale DOM, and then call frames.release() to verify update computed the right result from the live Model. See examples/registry/test/page.test.ts for a full browser test using Frames.track().