mirror of
https://github.com/anomalyco/opentui.git
synced 2026-04-25 13:06:00 +03:00
[GH-ISSUE #346] Keypress event leaks causing unintended automatic ITEM_SELECTED #858
Labels
No labels
bug
core
documentation
feature
good first issue
help wanted
pull-request
question
react
solid
tmux
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/opentui#858
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @hsulab on GitHub (Nov 25, 2025).
Original GitHub issue: https://github.com/anomalyco/opentui/issues/346
Description
When a
SelectRenderable(s0) handlesITEM_SELECTED, and the handler makes another selector (s1) visible and focuses it, the same keypress event leaks into s1, causing s1 to immediately fire its ownITEM_SELECTEDevent and automatically select its first option.This happens without any user input.
Currently, the workaround is using
setTimeoutorqueueMicrotask. I wonder if this can be fixed or there is better practice?Expected behaviour
Actual behaviour
Reproduce
@kommander commented on GitHub (Nov 26, 2025):
Ah I think I see what's happening, the events are synchronous, so when calling s1.focus() it attaches the event listener immediately while still executing the key event, mutating the listeners array while iterating over it.
Should be a simple enough fix I think, in
lib/KeyHandler.tsit needs to use[...listeners]for iteration so the listeners mutation does not execute newly added listeners in the same tick.Needs a simple reproduction in a test to make sure it behaves.
@hsulab commented on GitHub (Nov 27, 2025):
Many thanks! I just made a pull request.