Fix bug when blur command received on node without XamlRoot #12051
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Type of Change
Erase all that don't apply.
Why
We are seeing crashes on quit when the blur command is called roughly around the same time that the React instance is being shut down. It's likely because the result of tryGetXamlRoot is null.
What
This change falls back on the GetFocusedElement() overload without any parameters if the XamlRoot is null, as supplying a null parameter will result in a NPE.
Testing
It's a tricky race condition to repro, but I did validate that passing a null XamlRoot value to
FocusManager::GetFocusedElement(XamlRoot)
will throw an exception.Changelog
Should this change be included in the release notes: yes
Fix for NPE when blur command is received while React instance is shutting down.
Microsoft Reviewers: Open in CodeFlow