Skip to content

Refactor construction of the accesskit tree - #1346

Open
hovinen wants to merge 31 commits into
DioxusLabs:mainfrom
hovinen:refactor-aria-tree-building
Open

hovinen wants to merge 31 commits into
DioxusLabs:mainfrom
hovinen:refactor-aria-tree-building

Conversation

@hovinen

@hovinen hovinen commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

The existing code to build the accesskit tree from a BaseDocument was quite hard to follow, since various steps had to happen in a specific order so as to be compliant with the standard. It was not easy to assign different aspects of the computation to the various components.

This restructures the mechanism, making the following key changes:

  • The construction algorithm is now orchestrated by a new struct TreeBuilder.
  • It takes place in two stages. The first establishes the relations between tree nodes via the aria-labelledby and aria-describedby attributes as well as the <label for="..."> construct. The second builds the accesskit nodes themselves. Thus forward references are already resolved when the accesskit nodes are built, making the process more straightforward.
  • It replaces std::collections::HashMap and std::collections::HashSet with equivalents from the rustc-hash crate to provide faster hashing. Since the keys are internally generated NodeId's, there is no risk of DoS attack due to key collisions.

Experiments show that these changes reduce the runtime for accesskit tree construction by about 10% compared with the previous state.

This builds on #1259.

WPT results

No changes in test results compared to main.

Generated by the WPT workflow.

This is requires to support setting the ARIA accessible name of an
element through the _host language text_ of an element, especially an
associated `<label>` element.

This also adds support for setting the label through other forms of the
host language text:
- The `alt` text of an `<img>` tag.

This is needed both for dioxus-test and to allow assistive technologies
to correctly name many elements.
This usees the same method as with `aria-labelledby` as per the
[W3C spec](https://www.w3.org/TR/accname-1.2/#mapping_additional_nd_description)
for accessible description.

This also copies the description text into the accesskit nodes.
Performance tests show that this normally has a negligible impact on both
CPU and memory use. There is one "pathological" case where it has a
significant impact: if many nodes all point to the same shared
description, then that description will be copied once per node. That
presumably doesn't happen often in practice, but it is worth considering.
The solution, if necessary, is either to compute the description lazily
or to modify accesskit itself to use shared ownership.
@hovinen
hovinen force-pushed the refactor-aria-tree-building branch from 570cc35 to 5d93cb1 Compare October 30, 2026 12:22
@hovinen hovinen changed the title Refactor construction of the accseskit tree Refactor construction of the accsesskit tree Oct 30, 2026
@hovinen hovinen changed the title Refactor construction of the accsesskit tree Refactor construction of the accesskit tree Oct 30, 2026

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.

1 participant