Mitigate device info main queue modules crash#51662
Closed
RSNara wants to merge 1 commit into
Closed
Conversation
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D75537894 |
Summary:
## Changes
DeviceInfo: Deafult fontScale to 1 when accessibility manager isn't available
# Analysis
**The problem:** For reasons that we don't understand, accessibility manager is sometimes nil, when deviceinfo needs it. This is a long-standing issue in react native.
```
_constants = @{
@"Dimensions" : [self _exportedDimensions],
// Note:
// This prop is deprecated and will be removed in a future release.
// Please use this only for a quick and temporary solution.
// Use <SafeAreaView> instead.
@"isIPhoneX_deprecated" : @(RCTIsIPhoneNotched()),
};
```
```
- (NSDictionary *)_exportedDimensions
{
RCTAssert(!_invalidated, @"Failed to get exported dimensions: RCTDeviceInfo has been invalidated");
RCTAssert(_moduleRegistry, @"Failed to get exported dimensions: RCTModuleRegistry is nil");
RCTAccessibilityManager *accessibilityManager =
(RCTAccessibilityManager *)[_moduleRegistry moduleForName:"AccessibilityManager"];
if (!accessibilityManager) {
return nil;
}
CGFloat fontScale = accessibilityManager ? accessibilityManager.multiplier : 1.0;
return RCTExportedDimensions(fontScale);
}
```
**The crash:** When accessibility manager is nil, device info tries to insert nil into an NSDictionary, and crashes.
We found a possible repro of this issue: [launch facebook, log out, and log back in](https://www.internalfb.com/diff/D72020801?transaction_fbid=982516293994114).
**Why this surged now:** Recently, we started initializing device info during react native init. That means this code-path just runs much more often.
# Mitigation
Remove the return nil in `[self _exportedDimensions]`. Instead, just default the fontScale to 1 when the accessibility manager isn't available.
**This should be safe:** If we assume that accessibility manager eventually becomes available, the fontScale will eventually become correct. Device info will send the updated fontScale to js when it becomes available: [native](https://www.internalfb.com/code/fbsource/[ec6fd664a9cd]/xplat/js/react-native-github/packages/react-native/React/CoreModules/RCTDeviceInfo.mm?lines=231-232), [js](https://www.internalfb.com/code/fbsource/[ec6fd664a9cd]/xplat/js/react-native-github/packages/react-native/Libraries/Utilities/Dimensions.js?lines=120-125).
# Long-term fix
Understand why accessibility manager is nil.
Changelog: [Internal]
Differential Revision: D75537894
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D75537894 |
Collaborator
|
This pull request was successfully merged by @RSNara in 0b8db7e When will my fix make it into a release? | How to file a pick request? |
Contributor
|
This pull request has been merged in 0b8db7e. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
Changes
DeviceInfo: Deafult fontScale to 1 when accessibility manager isn't available
Analysis
The problem: For reasons that we don't understand, accessibility manager is sometimes nil, when deviceinfo needs it. This is a long-standing issue in react native.
The crash: When accessibility manager is nil, device info tries to insert nil into an NSDictionary, and crashes.
We found a possible repro of this issue: launch facebook, log out, and log back in.
Why this surged now: Recently, we started initializing device info during react native init. That means this code-path just runs much more often.
Mitigation
Remove the return nil in
[self _exportedDimensions]. Instead, just default the fontScale to 1 when the accessibility manager isn't available.This should be safe: If we assume that accessibility manager eventually becomes available, the fontScale will eventually become correct. Device info will send the updated fontScale to js when it becomes available: native, js.
Long-term fix
Understand why accessibility manager is nil.
Changelog: [Internal]
Differential Revision: D75537894