From 326438a6f9266be2a7d89d20d0bacd6de326c3d0 Mon Sep 17 00:00:00 2001 From: ussoewwin <136552381+ussoewwin@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:11:01 +0900 Subject: [PATCH 1/4] access: a popup's node this update does not carry leaves no dangling controls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit accesskit_consumer's Node::controls() unwraps every id in the relation, so an update whose controls names a node it does not carry aborts the app once the host's UIA adapter applies it. In PhotoCraft on Windows, clicking Image, Edit or Layer in the menu bar did exactly that (photocraft#15597), and on one machine Filter too — an ordering difference per menu. emit.rs adds every open popup's id, and a menu reports its popup open on a frame where the popup's own node is not emitted. The runtime plugin now prunes the finished update in output_hook, keeping a controls id only when the same update carries its node. Other relations are untouched: they are built from nodes the pass wrote. The tests fail without the change: the relation keeps an id with no node. --- crates/ui-contract/src/runtime/egui/access.rs | 65 ++++++++++++++++++- crates/ui-contract/src/runtime/egui/plugin.rs | 6 +- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/crates/ui-contract/src/runtime/egui/access.rs b/crates/ui-contract/src/runtime/egui/access.rs index 8eee24e44..8250b26c7 100644 --- a/crates/ui-contract/src/runtime/egui/access.rs +++ b/crates/ui-contract/src/runtime/egui/access.rs @@ -10,9 +10,7 @@ mod text; mod tree; use crate::runtime::pass_state; -#[cfg(feature = "testing")] -use egui::FullOutput; -use egui::{Context, Id, IdMap, IdSet, ViewportId}; +use egui::{Context, FullOutput, Id, IdMap, IdSet, ViewportId}; use std::collections::HashMap; use super::pass; @@ -200,3 +198,64 @@ fn hide_behind_modal(ctx: &Context, viewport: ViewportId, written: &IdSet) { pub(crate) fn tree_of(output: &mut FullOutput) -> Option { output.platform_output.accesskit_update.take().map(AccessTree::new) } + +/// Drops relations that name a node this update does not carry. +/// +/// A menu reports its popup open on a frame where the popup's own node is not emitted (the ordering +/// differs per menu), and `runtime::access::emit` puts that id in `controls`. A host's UIA adapter +/// unwraps every `controls` lookup (`accesskit_consumer`'s `Node::controls`), so one id with no node +/// in the same update aborts the app: photocraft#15597, where clicking Image, Edit or Layer — and on +/// one machine Filter — closed PhotoCraft on the click that opened the menu. +pub(crate) fn drop_dangling_relations(output: &mut FullOutput) { + let Some(update) = output.platform_output.accesskit_update.as_mut() else { return }; + prune_controls(update); +} + +/// The step itself, for the tests: every `controls` id of `update` that names no node of `update` is +/// dropped. Other relations keep their ids: they are built from nodes this pass wrote. +fn prune_controls(update: &mut egui::accesskit::TreeUpdate) { let ids: std::collections::HashSet = update.nodes.iter().map(|(id, _)| *id).collect(); + for (_, node) in update.nodes.iter_mut() { + if node.controls().iter().all(|id| ids.contains(id)) { + continue; + } + let kept: Vec = node.controls().iter().copied().filter(|id| ids.contains(id)).collect(); + node.set_controls(kept); + } +} + + +#[cfg(test)] +mod tests { + use super::*; + use egui::accesskit::{Node, NodeId, Role, TreeId, TreeUpdate}; + + fn update(controls: Vec, carried: Vec) -> TreeUpdate { + let mut node = Node::new(Role::Button); + node.set_controls(controls); + TreeUpdate { + nodes: carried.into_iter().map(|id| (id, Node::new(Role::Button))).chain(std::iter::once((NodeId(1), node))).collect(), + tree: None, + tree_id: TreeId::ROOT, + focus: NodeId(1), + } + } + + /// A popup that reports itself open on a frame where its node is not emitted leaves its id in + /// `controls`; the host's UIA adapter unwraps that lookup and aborts (photocraft#15597). The id + /// that has a node stays. + #[test] + fn controls_keep_the_ids_the_update_carries_and_drop_the_rest() { + let mut tree = update(vec![NodeId(2), NodeId(9)], vec![NodeId(2)]); + prune_controls(&mut tree); + let kept: Vec = tree.nodes.iter().find(|(id, _)| *id == NodeId(1)).map(|(_, node)| node.controls().to_vec()).unwrap_or_default(); + assert_eq!(kept, vec![NodeId(2)], "the id without a node is gone, the one with a node stays"); + } + + #[test] + fn controls_with_every_node_carried_are_left_alone() { + let mut tree = update(vec![NodeId(2)], vec![NodeId(2)]); + prune_controls(&mut tree); + let kept: Vec = tree.nodes.iter().find(|(id, _)| *id == NodeId(1)).map(|(_, node)| node.controls().to_vec()).unwrap_or_default(); + assert_eq!(kept, vec![NodeId(2)]); + } +} diff --git a/crates/ui-contract/src/runtime/egui/plugin.rs b/crates/ui-contract/src/runtime/egui/plugin.rs index efa49785b..6ae26f33b 100644 --- a/crates/ui-contract/src/runtime/egui/plugin.rs +++ b/crates/ui-contract/src/runtime/egui/plugin.rs @@ -1,7 +1,7 @@ //! The plugin impl, its registration and hook order, and the plugin lock. use crate::runtime::frame; -use egui::{Context, Plugin, RawInput, Ui}; +use egui::{Context, FullOutput, Plugin, RawInput, Ui}; /// The runtime's plugin. egui holds a plugin's mutex while it calls a hook, so the struct holds no state: /// every record lives in context data behind its own lock. @@ -17,6 +17,10 @@ impl Plugin for RuntimePlugin { frame::input_hook(ctx, input); } + fn output_hook(&mut self, ctx: &Context, output: &mut FullOutput) { + let _ = ctx; + crate::runtime::egui::access::drop_dangling_relations(output); + } fn on_begin_pass(&mut self, ui: &mut Ui) { frame::begin_pass(ui); } From c6537b6d07b0d8c2d3f9eb498c447a81145e1664 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 19 Nov 2026 04:09:37 +0000 Subject: [PATCH 2/4] access: rustfmt --- crates/ui-contract/src/runtime/egui/access.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-contract/src/runtime/egui/access.rs b/crates/ui-contract/src/runtime/egui/access.rs index 8250b26c7..69359c87d 100644 --- a/crates/ui-contract/src/runtime/egui/access.rs +++ b/crates/ui-contract/src/runtime/egui/access.rs @@ -213,7 +213,8 @@ pub(crate) fn drop_dangling_relations(output: &mut FullOutput) { /// The step itself, for the tests: every `controls` id of `update` that names no node of `update` is /// dropped. Other relations keep their ids: they are built from nodes this pass wrote. -fn prune_controls(update: &mut egui::accesskit::TreeUpdate) { let ids: std::collections::HashSet = update.nodes.iter().map(|(id, _)| *id).collect(); +fn prune_controls(update: &mut egui::accesskit::TreeUpdate) { + let ids: std::collections::HashSet = update.nodes.iter().map(|(id, _)| *id).collect(); for (_, node) in update.nodes.iter_mut() { if node.controls().iter().all(|id| ids.contains(id)) { continue; @@ -223,7 +224,6 @@ fn prune_controls(update: &mut egui::accesskit::TreeUpdate) { let ids: std::c } } - #[cfg(test)] mod tests { use super::*; From 4ec453ed5a604c443fe17109b5c61c8460fd22bb Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 19 Nov 2026 06:38:55 +0000 Subject: [PATCH 3/4] access: the controls tests live in the integration binary --- crates/ui-contract/src/runtime/egui/access.rs | 42 ++----------------- crates/ui-contract/src/testing/access.rs | 6 +++ .../ui-contract/tests/it/access/controls.rs | 37 ++++++++++++++++ crates/ui-contract/tests/it/access/mod.rs | 1 + 4 files changed, 47 insertions(+), 39 deletions(-) create mode 100644 crates/ui-contract/tests/it/access/controls.rs diff --git a/crates/ui-contract/src/runtime/egui/access.rs b/crates/ui-contract/src/runtime/egui/access.rs index 69359c87d..f02dfc930 100644 --- a/crates/ui-contract/src/runtime/egui/access.rs +++ b/crates/ui-contract/src/runtime/egui/access.rs @@ -211,9 +211,9 @@ pub(crate) fn drop_dangling_relations(output: &mut FullOutput) { prune_controls(update); } -/// The step itself, for the tests: every `controls` id of `update` that names no node of `update` is -/// dropped. Other relations keep their ids: they are built from nodes this pass wrote. -fn prune_controls(update: &mut egui::accesskit::TreeUpdate) { +/// The step itself: every `controls` id of `update` that names no node of `update` is dropped. Other +/// relations keep their ids: they are built from nodes this pass wrote. +pub(crate) fn prune_controls(update: &mut egui::accesskit::TreeUpdate) { let ids: std::collections::HashSet = update.nodes.iter().map(|(id, _)| *id).collect(); for (_, node) in update.nodes.iter_mut() { if node.controls().iter().all(|id| ids.contains(id)) { @@ -223,39 +223,3 @@ fn prune_controls(update: &mut egui::accesskit::TreeUpdate) { node.set_controls(kept); } } - -#[cfg(test)] -mod tests { - use super::*; - use egui::accesskit::{Node, NodeId, Role, TreeId, TreeUpdate}; - - fn update(controls: Vec, carried: Vec) -> TreeUpdate { - let mut node = Node::new(Role::Button); - node.set_controls(controls); - TreeUpdate { - nodes: carried.into_iter().map(|id| (id, Node::new(Role::Button))).chain(std::iter::once((NodeId(1), node))).collect(), - tree: None, - tree_id: TreeId::ROOT, - focus: NodeId(1), - } - } - - /// A popup that reports itself open on a frame where its node is not emitted leaves its id in - /// `controls`; the host's UIA adapter unwraps that lookup and aborts (photocraft#15597). The id - /// that has a node stays. - #[test] - fn controls_keep_the_ids_the_update_carries_and_drop_the_rest() { - let mut tree = update(vec![NodeId(2), NodeId(9)], vec![NodeId(2)]); - prune_controls(&mut tree); - let kept: Vec = tree.nodes.iter().find(|(id, _)| *id == NodeId(1)).map(|(_, node)| node.controls().to_vec()).unwrap_or_default(); - assert_eq!(kept, vec![NodeId(2)], "the id without a node is gone, the one with a node stays"); - } - - #[test] - fn controls_with_every_node_carried_are_left_alone() { - let mut tree = update(vec![NodeId(2)], vec![NodeId(2)]); - prune_controls(&mut tree); - let kept: Vec = tree.nodes.iter().find(|(id, _)| *id == NodeId(1)).map(|(_, node)| node.controls().to_vec()).unwrap_or_default(); - assert_eq!(kept, vec![NodeId(2)]); - } -} diff --git a/crates/ui-contract/src/testing/access.rs b/crates/ui-contract/src/testing/access.rs index e3f440cc8..b1a80a5d5 100644 --- a/crates/ui-contract/src/testing/access.rs +++ b/crates/ui-contract/src/testing/access.rs @@ -10,6 +10,12 @@ pub fn tree_of(output: &mut crate::runtime::egui::fixture::FullOutput) -> Access crate::runtime::egui::access::tree_of(output).unwrap_or_else(AccessTree::none) } +/// Drops every `controls` id of `update` that names no node of `update`, as the runtime does to each +/// frame's AccessKit output. +pub fn prune_controls(update: &mut egui::accesskit::TreeUpdate) { + crate::runtime::egui::access::prune_controls(update); +} + /// Opens the label scope of `container` with `label`, as a field container's body step does; the container's /// report step closes it. pub fn begin_label_scope(ctx: &Context, container: Id, label: FieldLabel) { diff --git a/crates/ui-contract/tests/it/access/controls.rs b/crates/ui-contract/tests/it/access/controls.rs new file mode 100644 index 000000000..81e3435f0 --- /dev/null +++ b/crates/ui-contract/tests/it/access/controls.rs @@ -0,0 +1,37 @@ +//! Relations that name a node the update does not carry. + +use craft_ui::testing::access::prune_controls; +use craft_ui::testing::trial; +use egui::accesskit::{Node, NodeId, Role, TreeId, TreeUpdate}; + +fn update(controls: Vec, carried: Vec) -> TreeUpdate { + let mut node = Node::new(Role::Button); + node.set_controls(controls); + TreeUpdate { + nodes: carried.into_iter().map(|id| (id, Node::new(Role::Button))).chain(std::iter::once((NodeId(1), node))).collect(), + tree: None, + tree_id: TreeId::ROOT, + focus: NodeId(1), + } +} + +fn controls_of_first(tree: &TreeUpdate) -> Vec { + tree.nodes.iter().find(|(id, _)| *id == NodeId(1)).map(|(_, node)| node.controls().to_vec()).unwrap_or_default() +} + +/// A popup that reports itself open on a frame where its node is not emitted leaves its id in +/// `controls`; the host's UIA adapter unwraps that lookup and aborts (photocraft#15597). The id +/// that has a node stays. +#[trial] +fn controls_keep_the_ids_the_update_carries_and_drop_the_rest() { + let mut tree = update(vec![NodeId(2), NodeId(9)], vec![NodeId(2)]); + prune_controls(&mut tree); + assert_eq!(controls_of_first(&tree), vec![NodeId(2)], "the id without a node is gone, the one with a node stays"); +} + +#[trial] +fn controls_with_every_node_carried_are_left_alone() { + let mut tree = update(vec![NodeId(2)], vec![NodeId(2)]); + prune_controls(&mut tree); + assert_eq!(controls_of_first(&tree), vec![NodeId(2)]); +} diff --git a/crates/ui-contract/tests/it/access/mod.rs b/crates/ui-contract/tests/it/access/mod.rs index 67a826aac..3e9415678 100644 --- a/crates/ui-contract/tests/it/access/mod.rs +++ b/crates/ui-contract/tests/it/access/mod.rs @@ -1,6 +1,7 @@ //! The accessibility emitter: the label scope and merge rule, announcements, modal inertness, viewports. mod bounds; +mod controls; mod face_record; mod face_state; mod nodes; From d7804c73c21a225a855469c7333f6e4d3f8ed987 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 19 Nov 2026 07:41:02 +0000 Subject: [PATCH 4/4] access: the controls step reaches the tests through runtime::egui --- crates/ui-contract/src/runtime/egui/access.rs | 2 +- crates/ui-contract/src/testing/access.rs | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/crates/ui-contract/src/runtime/egui/access.rs b/crates/ui-contract/src/runtime/egui/access.rs index f02dfc930..a996c6550 100644 --- a/crates/ui-contract/src/runtime/egui/access.rs +++ b/crates/ui-contract/src/runtime/egui/access.rs @@ -213,7 +213,7 @@ pub(crate) fn drop_dangling_relations(output: &mut FullOutput) { /// The step itself: every `controls` id of `update` that names no node of `update` is dropped. Other /// relations keep their ids: they are built from nodes this pass wrote. -pub(crate) fn prune_controls(update: &mut egui::accesskit::TreeUpdate) { +pub fn prune_controls(update: &mut egui::accesskit::TreeUpdate) { let ids: std::collections::HashSet = update.nodes.iter().map(|(id, _)| *id).collect(); for (_, node) in update.nodes.iter_mut() { if node.controls().iter().all(|id| ids.contains(id)) { diff --git a/crates/ui-contract/src/testing/access.rs b/crates/ui-contract/src/testing/access.rs index b1a80a5d5..2d05eb316 100644 --- a/crates/ui-contract/src/testing/access.rs +++ b/crates/ui-contract/src/testing/access.rs @@ -3,19 +3,13 @@ use crate::runtime::access::{FieldLabel, scope}; use egui::{Context, Id}; -pub use crate::runtime::egui::access::{AccessTree, Declared, NodeKey}; +pub use crate::runtime::egui::access::{AccessTree, Declared, NodeKey, prune_controls}; /// The AccessKit tree a finished pass of a viewport produced, taken out of its output; empty when it made none. pub fn tree_of(output: &mut crate::runtime::egui::fixture::FullOutput) -> AccessTree { crate::runtime::egui::access::tree_of(output).unwrap_or_else(AccessTree::none) } -/// Drops every `controls` id of `update` that names no node of `update`, as the runtime does to each -/// frame's AccessKit output. -pub fn prune_controls(update: &mut egui::accesskit::TreeUpdate) { - crate::runtime::egui::access::prune_controls(update); -} - /// Opens the label scope of `container` with `label`, as a field container's body step does; the container's /// report step closes it. pub fn begin_label_scope(ctx: &Context, container: Id, label: FieldLabel) {