mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Prevent NPE in measure during measure/teardown race
Summary: When stopSurface is called, Fabric might be processing a commit and performing measurements even as the context is being removed from the FabricUIManager map. Just return a 0 from `measure` if we can't get a context. This prevents crashes during teardown for measured views that will never be visible anyway. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D22604716 fbshipit-source-id: 67be8d272afd35fc4c2b51b371939c5623e97f73
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ee8a0cfa5a
commit
f00795dc90
@@ -466,8 +466,19 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
|
||||
float minHeight,
|
||||
float maxHeight,
|
||||
@Nullable float[] attachmentsPositions) {
|
||||
|
||||
// This could be null if teardown/navigation away from a surface on the main thread happens
|
||||
// while a commit is being processed in a different thread. By contract we expect this to be
|
||||
// possible at teardown, but this race should *never* happen at startup.
|
||||
@Nullable
|
||||
ReactContext context =
|
||||
rootTag < 0 ? mReactApplicationContext : mReactContextForRootTag.get(rootTag);
|
||||
|
||||
// Don't both measuring if we can't get a context.
|
||||
if (context == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return mMountingManager.measure(
|
||||
context,
|
||||
componentName,
|
||||
|
||||
Reference in New Issue
Block a user