Skip to content

A snapshot older than the last click moves the browser's keyboard focus off the pane just clicked #585

Closed

Description

@yansfil

What happened

After a fast run of clicks between two panes, the browser's keyboard focus can end on the pane that was not clicked last, and keys typed right after go to that pane.
The page moves DOM focus to the pane each arriving snapshot names, with no way to tell a snapshot older than the operator's last click from a real external focus move.
A snapshot that was already on its way when the last click was sent therefore pulls DOM focus back to the earlier pane (a programmatic move that sends nothing), and it stays there until the snapshot that reflects the last click arrives.
Under load that window was a few hundred milliseconds in CI and in a local run.

What you expected

Keys typed after a click go to the pane that was clicked last, whatever order snapshots arrive in.
A snapshot that predates the last click must not move DOM focus; a genuine external focus move (the core following Herdr) still must.

Steps to reproduce

  1. Open a workspace with two panes on a loaded machine (CPU saturated, the local reproduction used four yes processes).
  2. Click pane 2 and pane 1 alternately about 20 times each in under a second, ending on pane 1.
  3. Type a few characters immediately after the last click, before the pane header settles.
  4. The characters can arrive in pane 2's input; Hide then follows Herdr back to pane 1 (pane.focus.followed, "Herdr focused pane 1; Hide was on pane 2") a few hundred milliseconds later.

Versions

  • hide: main at c76670cf (the failing CI run was 3e0013de)
  • Herdr: 0.9.1 (pinned)
  • macOS: CI macOS runner and a local macOS 15 (Darwin 24.1) machine; the web shell in headless Chromium

Diagnostics

  • CI run 37346156867 (main push, macOS, pane-focus-ordering "rapid pane clicks ... leave keys on the last pane"): the typed marker is in pane 2's input log and pane 1's holds only mouse reports; the hided log shows pane.focus.requested entries arriving up to 565 ms after typing began and pane.focus.followed from pane 2 to pane 1 at 898 ms.
  • Local, under load, a DOM trace of the failing run: focusin on pane 2 and data-focused pane 2 = true at 170 to 240 ms before the typing, with no click on pane 2 near it; the last click of the burst was on pane 1.
  • Local measurement of the old test barrier: in 2 of 42 runs it returned while hided had accepted 24 and 36 of the 40 focus changes the page had sent, the window in which snapshots older than the last click are still arriving.
  • The test was fixed by waiting for hided to accept every click before typing (PR Wait for hided to accept every click of a burst before typing into the last pane #575), which makes it deterministic but does not make the product contract hold without waiting.

Proposed fix

Let the page tell a snapshot older than its last click from a real move, by state rather than by time.

  • The page numbers each operator focus_pane it sends (1, 2, 3, ... per connection).
  • The core records the number of the last operator focus it applied and publishes it with the focused pane in each snapshot.
  • The page moves DOM focus to the snapshot's pane only when that number has caught up with the last one it sent; until then the snapshot predates a click the core has not applied, and DOM focus stays on the last-clicked pane.
  • Once the number has caught up, a snapshot that names another pane is a real move (the core followed Herdr, or refused or timed out and kept its value) and the page follows it as today.

A time window ("ignore snapshot focus for N ms after a click") is not proposed: it fails again under heavier load and also swallows real external moves inside the window.
The change crosses the snapshot wire and the core's focus handling, so the pull request lists both under the files to watch.

Where

  • web/src/PaneView.tsx:207: the effect that calls focusTerminal(paneId) whenever its pane becomes the snapshot's focused pane.
  • web/src/terminals.ts:166 and :175: followingSnapshot and focusTerminal, which move DOM focus without telling the core.
  • web/src/terminals.ts:569: the textarea focus listener that sends focus_pane with origin: "operator" for a real click.
  • herdr-core/src/runtime/session.rs: the core owns the focused pane and publishes it in each snapshot, so the snapshot has to say which operator focus it already includes if the page is to tell a stale one from a real move.

Done when

  • A test shows deterministically that a snapshot older than the operator's last click does not move DOM focus: hold the core's snapshot with the page's last focus_pane sent but not yet reflected (a unit test of the store and effect, or an e2e that holds the snapshot frame at the WebSocket boundary), deliver the stale snapshot, and assert the textarea of the last-clicked pane still holds focus; then deliver the snapshot that reflects the click and assert it still does.
  • A snapshot that reports a different focus with no pending operator click (an external Herdr move the core followed) still moves DOM focus, with a test.
  • The pull request reports click-to-snapshot latency for one click idle and for a 40-click burst under load, measured as docs/PERFORMANCE_TESTING.md describes, so the size of the backlog itself is known.
  • pane-focus-ordering.spec.ts keeps passing without the wait for hided to accept every click, or says why that wait is still needed.

Activity

  1. added
    bug
    on Oct 6, 2026
  2. yansfil commented on Oct 6, 2026

    @yansfil
    ContributorAuthor

    #589로 고쳤습니다. page가 operator focus마다 번호를 붙이고, snapshot이 core가 적용한 마지막 번호(focused.operator_focus)를 돌려줍니다. page는 그 번호가 따라잡은 뒤에만 snapshot의 focus를 따릅니다. 이 gate를 빼면 held-snapshot e2e가 3/3 실패합니다.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions