Skip to content

Announce the current name of a UIA element that gains focus while its name changes - #21130

Open
LeonarddeR wants to merge 3 commits into
nvaccess:betafrom
LeonarddeR:fixUIAFocusStaleName
Open

LeonarddeR wants to merge 3 commits into
nvaccess:betafrom
LeonarddeR:fixUIAFocusStaleName

Conversation

@LeonarddeR

Copy link
Copy Markdown
Collaborator

Link to issue number:

Fixes #21116

Summary of the issue:

When a UI Automation element gains focus, NVDA reports its name from the values UI Automation cached when the application raised the focus event. Some applications raise the focus event just before they change the element's name. NVDA then announces the old name.

Description of user facing changes:

NVDA announces the current name of an item that gains focus while its name changes. Examples are a message in Unigram after jumping through a long chat, and a file in File Explorer after renaming it.

Description of developer facing changes:

None.

Description of development approach:

NVDA registers its UI Automation event handlers with a cache request. When an application raises an event, UI Automation fetches the requested properties at that moment. It delivers them together with the event. The name is one of these properties.

Since #20608, the object NVDA creates for an event uses these cached values. Before that, the object ignored them. It asked the application for the name when NVDA handled the event. Such a request waits for the application's user interface thread. By then, the application has usually finished changing the name. NVDA 2026.2 therefore announced the new name.

This pull request changes two things:

  1. The object NVDA creates for a focus event no longer takes the name from the cached event values. The focus event handler passes a set of cached properties without the name. This set is _focusEventCachedPropertyIDs in UIAHandler. It is passed as initialUIACachedPropertyIDs.
  2. When an object gains focus, NVDA already fetches several properties in one request to the application. The name is now part of that request. This set is _focusPrefetchUIAPropertyIDs on the UIA NVDAObject.

NVDA now reads the name when it handles the focus event, as it did in 2026.2. The normal path makes no extra request, because the name joins a request NVDA already made. Code that reads the name earlier asks the application directly, as in 2026.2. Examples are overlay class selection and app modules.

Testing strategy:

The bug reproduces in File Explorer only occasionally, so File Explorer is not a reliable test.

@FrayxRulez, could you please test a build of this pull request with Unigram 13.1.1 or earlier?

Known issues with pull request:

None

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

Objects created for UIA focus events no longer use the name cached with
the event. The name is fetched with the other properties prefetched on
focus.

Fixes nvaccess#21116

Assisted-by: Claude:claude-opus-5-5
@LeonarddeR
LeonarddeR requested a review from a team as a code owner November 10, 2026 09:04
@LeonarddeR
LeonarddeR requested review from SaschaCowley and a balanced review from Copilot November 10, 2026 09:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The stale-name fix lacks automated regression coverage verifying both exclusion of Name from the initial focus-event cache and retrieval of the current name during focus prefetch.

1 open issue
What changed in this PR

This PR addresses #21116 by refreshing UI Automation element names during focus handling, avoiding stale announcements introduced by event-cache reuse in #20608.

Changes:

  • Excludes Name from cached properties used to construct focus-event objects.
  • Adds Name to the existing batched focus-property fetch.
  • Documents the user-facing fix for cases such as Unigram messages and renamed files.
File Description
user_docs/​en/​changes.md Adds a changelog entry for corrected focus announcements.
source/​UIAHandler/​__init__.py Excludes cached names when constructing focus-event objects.
source/​NVDAObjects/​UIA/​__init__.py Includes names in focus prefetch and annotates the property set.

Review effort: Balanced

Comment thread source/NVDAObjects/UIA/__init__.py Resolved

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.

2 participants