Skip to content

engine: Deliver queued component events before the next input's handlers - #4264

Open
huacnlee wants to merge 1 commit into
mainfrom
agent/T-13026-event-order
Open

huacnlee wants to merge 1 commit into
mainfrom
agent/T-13026-event-order

Conversation

@huacnlee

@huacnlee huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member

Fixes #4256

What changed

Within one batch of input messages, a plain view's event (Input onFocus / onChange) ran its JS handler while the batch was handled, but a Rust component's event (nsh-base Button onPress) was only queued and reached JS in commit(). JS heard a press after the text typed after it.

Now, before an input event is handled, the engine delivers what the core has already queued for JS (component events, results), in order. The delivery loop that commit() used is moved into State::deliver_events and shared; commit() behaves as before.

Testing

  • New components::a_components_event_reaches_js_before_a_later_plain_event_in_one_batch (nsh-engine): fails on main (log hold|after|button), passes with the fix (log hold|button|after).
  • cargo test -p nsh-engine --test engine components::: 126 passed. Full nsh-engine tests: only the websocket::* tests fail, and they fail the same way on main on this host (local network environment).
  • Linux repro from the issue (Xvfb, GTK on X11, keys via XTest: Tab, then F9 Return Tab x in one burst), 5 trials each:

Before (main):

EV 3 held
EV 4 input focus
EV 5 input change "x"
EV 6 button press

(5 of 5)

After:

EV 3 held
EV 4 button press
EV 5 input focus
EV 6 input change "x"

(5 of 5)

On headless sway (Wayland) the keys did not land in one batch on main either, so that run did not reproduce the bug; with the fix the order was also correct there (5 of 5).

Risk

  • Event delivery path in nsh-engine for every input event. When the core has queued events, JS's posted calls (run_posted) and the queued events now run before the next input's handler instead of at the end of the batch. This is the order things happened in, but code that relied on component events arriving after later plain events would see a change.
  • No public API change. Mouse moves still return before the new check; other events pay one is_empty check.

How to revert

Revert this PR.

🤖 Noop (rust-maintainer) · Opus 5.5 acting for @huacnlee

🤖 Generated with Claude Code

A Rust component's event (nsh-base Button onPress) was queued for JS until
commit, while a plain view's event later in the same input batch ran its
JS handler at once, so JS heard them out of order. Before an input event
is handled, the events the core queued for JS are now delivered first.

Fixes #4256

Agent: rust-maintainer
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A Rust component's event (e.g. Button onPress) reaches JS after a plain view's event that came later in the same input batch

1 participant