Screen-reader actions can target the wrong widget when IDs shift between frames
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 22/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- rust, wasm
- Domain
- data-visualization, desktop
Research direction
Start with the minimal reproduction in the issue and run it to see Confirm's click land on Cancel. Relevant code is in src/context.rs around the AccessKit action dispatch, src/ui.rs around UiBuilder::id_salt (scope_id.with(salt).with(next_auto_id_salt)), and src/containers/popup.rs where Popup::default_response_id derives the popup key. Done means the action is ignored or correctly routed when IDs shift, and menu_button stays open across a preceding insert or removal.
Written by the indexing model from the issue text.
Description
Description
In egui 0.37.0, automatically generated widget IDs can change between frames when widgets earlier in the same UI appear or disappear.
This creates two related problems:
- Accessibility actions can activate the wrong control. A screen reader identifies a widget in one frame, but its action is processed in a later frame. If widget IDs have shifted, the action can be delivered to a different control.
- Persistent menu state can be lost. An open menu can close unexpectedly when a preceding widget appears or disappears, even though the menu itself has not changed.
Although egui documents automatically generated IDs as unstable, accessibility action dispatch and menu state both rely on these IDs across frames.
This can result in unintended user actions rather than merely losing visual state.
Observed behaviour
We discovered this issue while testing SuperBlender's operation bar.
- A preview was updating, displaying a busy spinner before the Confirm and Cancel buttons.
- A screen reader identified the Confirm button.
- The preview finished, causing the spinner to disappear.
- The automatically generated widget IDs shifted.
- The screen reader's pending Confirm action was delivered to Cancel.
The operation was cancelled instead of confirmed.
We independently reproduced another symptom: an open menu closes when a widget appears or disappears before its button. This also affects mouse users.
Minimal reproduction
The following reproduces the accessibility action misrouting using plain egui, without SuperBlender application code.
use egui::accesskit::{Action, ActionRequest, TreeId};
let ctx = egui::Context::default();
let mut confirm = egui::Id::NULL;
for frame in 0..2 {
let events = if frame == 1 {
vec![egui::Event::AccessKitActionRequest(ActionRequest {
action: Action::Click,
target_tree: TreeId::ROOT,
target_node: confirm.accesskit_id(),
data: None,
})]
} else {
Vec::new()
};
let _ = ctx.run_ui(
egui::RawInput {
events,
..Default::default()
},
|ui| {
ui.horizontal(|ui| {
if frame == 0 {
ui.spinner(); // background work, finished by frame 1
}
let response = ui.button("Confirm");
if ui.button("Cancel").clicked() {
println!("the Confirm request activated Cancel");
}
if frame == 0 {
confirm = response.id;
}
});
},
);
}
Result
The Action::Click request targets the ID originally assigned to Confirm.
After the spinner disappears, that ID is assigned to Cancel instead.
The output is:
the Confirm request activated Cancel
The same underlying identity problem affects menu_button: opening a menu and then inserting or removing a widget before its button can cause the menu to close unexpectedly.
Technical investigation
1. Accessibility actions use widget IDs across frames
A widget's AccessKit node ID corresponds to its egui ID.
A screen reader can read the accessibility tree from one frame and submit an action that is handled in a subsequent frame.
In src/context.rs (around line 1769 in egui 0.37.0), egui processes the action using the target ID.
However, Ui::next_auto_id generates IDs based on widget placement. Its documentation explicitly notes that IDs can change when widgets are inserted or removed before them.
Consequently, an action can be delivered to a different widget that has inherited the previous ID.
2. Menu state also depends on these IDs
menu_button stores its open state using Popup::default_response_id.
In src/containers/popup.rs (around line 722):
response.id.with("popup")
When the button's automatically generated ID changes, the popup's state key changes too.
This causes an open menu to close when preceding UI content changes.
3. push_id does not resolve the problem
We initially attempted to stabilise affected controls using push_id.
However, a child created through UiBuilder::id_salt still incorporates the automatically generated ID salt:
scope_id.with(salt).with(next_auto_id_salt)
See src/ui.rs, approximately lines 258–259 in egui 0.37.0.
Therefore, inserting or removing earlier widgets can still shift child IDs inside the salted scope.
Using an explicit UiBuilder::scope_id avoids this problem by assigning a stable scope identity.
Expected behaviour
- An accessibility action should never activate a different control merely because automatically generated IDs shifted between frames.
- If an accessibility action refers to a widget that can no longer be identified safely, it should be ignored rather than redirected to an unrelated widget.
- Persistent menu state should remain associated with the intended menu control.
- The distinction between
push_idand an explicitly stablescope_idshould be documented clearly.
Actual behaviour
- A screen-reader action intended for Confirm can activate Cancel.
- An open menu can close unexpectedly when preceding widgets change.
push_iddoes not prevent either problem when child IDs remain dependent on automatic placement.
Workaround
In SuperBlender, we introduced a widgets::stable_ids helper that uses an explicit stable scope identity.
It now protects affected controls, including:
- Confirm and Cancel
- Preview details
- Retry preview
- UV tool selector
Two regression tests verify the behaviour.
Both tests fail if the stable-ID implementation is replaced with push_id alone.
This addresses the identified cases in our application, but other controls using automatically generated IDs may still be affected.
Possible improvements
Accessibility action validation
Before dispatching an accessibility action, verify that the widget associated with the target ID still corresponds to the node originally published to the accessibility client.
For example, a mismatch in role or label could cause the action to be rejected instead of delivered to another control.
Stable menu identities
Allow menu_button to use a stable explicit identity for its persistent state, potentially through an ID-salt API similar to ComboBox::from_id_salt.
Documentation
Clarify that push_id introduces an ID namespace but does not necessarily stabilise the automatically generated IDs of its children when preceding sibling structure changes.
Document the recommended approach for controls whose identities must persist across frames, particularly controls exposed through accessibility APIs.
Related work
The following egui pull requests address warnings about IDs changing between passes within a single frame:
- #8316
- #8543
- #8670
They do not appear to address accessibility action routing or menu state across separate frames.
No duplicate report covering these specific symptoms was identified during our investigation.
Environment
- egui: 0.37.0
- accesskit: 0.25.2
- Rust: 1.100.0
- Reproduction: Plain egui, without SuperBlender-specific code
- Originally discovered: Automated headless GUI testing in SuperBlender
Verification status
- Accessibility action misrouting reproduced in plain egui.
- Menu state loss reproduced independently.
push_idconfirmed insufficient to stabilise the affected child IDs.- Explicit stable scope IDs resolve the identified cases in SuperBlender.
- Regression tests added for the stable-ID behaviour.
- Not yet verified against the latest egui
mainbranch.
- Dominant language
- Rust
- Stars
- 32.6k
- Forks
- 2.5k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 71
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from emilk/egui
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
egui_extras: column resize cursor reverts to default between press and drag thresholdPossibly taken @2tsoftwareapp claimed this 8 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
`egui-wgpu` defaults to `PowerPreference::HighPerformance` instead of `None`Possibly taken @SEshaan claimed this 16 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
Similar issues
-
autofixer: follow-up triage: bug triage: classified triage: correctness triage: has-reproducer
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
tursodatabase/turso#13221 ·
Maintainers usually reply within 1 day
-
Update Wasmtime to 48.0.11 for RUSTSEC-2026-0648Possibly taken @flyingrobots claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
flyingrobots/edict#457 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
O-windows relnotes relnotes-needs-review relnotes-tracking-issue T-libs
Difficulty 1/5 Under an hour Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
approved
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
fritzprix/libr-agent#3266 ·
Maintainers usually reply within 1 day