Skip to content

Commit d46d80d

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Register RCTDeviceInfo to invalidating and cleanup observer (#42396)
Summary: Pull Request resolved: #42396 Cmmunity reported [#42120](#42120) where React Native was crashing if RCTDeviceInfo native module was receiving a notification while the bridge is invalidating. Upon investigation, I realized that: 1. The RCTDeviceInfo module is never invalidated 2. Observers are still observing even when the Bridge is in an invalidated state and it is not back up. This change makes sure that we invalidate the `RCTDeviceInfo.mm` module and that we unregister the observers. ## Changelog: [iOS][Fixed] - Make `RCTDeviceInfo` listen to invalidate events and unregister observers while invalidating the bridge Reviewed By: RSNara Differential Revision: D52912604 fbshipit-source-id: 1727bcdef5393b1bd5a272e2143bc65456c2a389
1 parent 7c4afa1 commit d46d80d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

packages/react-native/React/CoreModules/RCTDeviceInfo.mm

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,44 @@ - (void)initialize
7575
selector:@selector(interfaceFrameDidChange)
7676
name:RCTWindowFrameDidChangeNotification
7777
object:nil];
78+
79+
// TODO T175901725 - Registering the RCTDeviceInfo module to the notification is a short-term fix to unblock 0.73
80+
// The actual behavior should be that the module is properly registered in the TurboModule/Bridge infrastructure
81+
// and the infrastructure imperatively invoke the `invalidate` method, rather than listening to a notification.
82+
// This is a temporary workaround until we can investigate the issue better as there might be other modules in a
83+
// similar situation.
84+
[[NSNotificationCenter defaultCenter] addObserver:self
85+
selector:@selector(invalidate)
86+
name:RCTBridgeWillInvalidateModulesNotification
87+
object:nil];
7888
}
7989

8090
- (void)invalidate
8191
{
8292
_invalidated = YES;
93+
[self _cleanupObservers];
94+
}
95+
96+
- (void)_cleanupObservers
97+
{
98+
[[NSNotificationCenter defaultCenter] removeObserver:self
99+
name:RCTAccessibilityManagerDidUpdateMultiplierNotification
100+
object:[_moduleRegistry moduleForName:"AccessibilityManager"]];
101+
102+
[[NSNotificationCenter defaultCenter] removeObserver:self
103+
name:UIApplicationDidChangeStatusBarOrientationNotification
104+
object:nil];
105+
106+
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
107+
108+
[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTUserInterfaceStyleDidChangeNotification object:nil];
109+
110+
[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTWindowFrameDidChangeNotification object:nil];
111+
112+
[[NSNotificationCenter defaultCenter] addObserver:self
113+
selector:@selector(invalidate)
114+
name:RCTBridgeWillInvalidateModulesNotification
115+
object:nil];
83116
}
84117

85118
static BOOL RCTIsIPhoneNotched()

0 commit comments

Comments
 (0)