From 331dc2a998c0a2f43662efcf345f070bba01a1ed Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Mon, 21 Dec 2020 16:15:51 -0800 Subject: [PATCH] Default initialize RCTNetworking with observation disabled Summary: ## Context When you add/remove listeners from event emitters in JavaScript on iOS, we [call the NativeModule's addListener/removeListener methods](https://fburl.com/diffusion/4878jv6p). These addListener() and removeListener() methods [are implemented on the RCTEventEmitter class](https://fburl.com/diffusion/y913pqhy). All event emitters on iOS are subclasses of RCTEventEmitter. The only purpose of calling RCTEventEmitter's addListener() and removeListener() methods is to call the [subclasses' startObservation, and stopObservation methods](https://fburl.com/diffusion/rpzyfppk), and [increment/decrement a listenerCount member variable](https://fburl.com/diffusion/ktl8if26) in RCTEventEmitter, which helps catch memory leaks. RCTNetworking is a subclass of RCTEventEmitter, but it doesn't implement these startObserving/stopObserving methods. Since the [listenerCount is only used to show warnings](https://fburl.com/diffusion/i45lobil), in D24272560 (https://github.com/facebook/react-native/commit/82187bfb6b54fdffc5dadaa56e8bf97d2209708a), I disabled observation in RCTNetworking on the native side. Then in D24272663 (https://github.com/facebook/react-native/commit/dabca52f77799bcdedb6b0ec44b1f6297483a46d), I disabled RCTNetworking.addListener/removeListener NativeModule calls in JavaScript. This was gated via a QE/MC. ## Problem The default initializer of RCTNetworking doesn't initialize with observation disabled. This broke antwerp when we shipped the experiment in D24272663 (https://github.com/facebook/react-native/commit/dabca52f77799bcdedb6b0ec44b1f6297483a46d). This diff fixes that problem. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D25671343 fbshipit-source-id: d9a8ba5324a23ade8f4b0bf2ec093f3e4fb494dc --- Libraries/Network/RCTNetworking.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Libraries/Network/RCTNetworking.mm b/Libraries/Network/RCTNetworking.mm index edbbe814e6e..1869ebc35ba 100644 --- a/Libraries/Network/RCTNetworking.mm +++ b/Libraries/Network/RCTNetworking.mm @@ -157,6 +157,11 @@ static NSString *RCTGenerateFormBoundary() RCT_EXPORT_MODULE() +- (instancetype)init +{ + return [super initWithDisabledObservation]; +} + - (instancetype)initWithHandlersProvider:(NSArray> * (^)(void))getHandlers { if (self = [super initWithDisabledObservation]) {