react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Bridge] RCTBridgeModuleClassesByModuleID is tripped up on KVO

Open jwyld opened this issue 11 years ago • 4 comments

In the RCT_DEBUG block of this function, it's attempting to do a scan across all classes for registered classes. If a class has been exported to React but is also being used for KVO, the KVO system automatically adds a "NSKVONotifying_" prefixed subclass as well. For example, exporting a "FooBar" class for which I end up observing will produce a "NSKVONotifying_FooBar" subclass as well. Both will conform to the RCTBridgeModule protocol. The "NSKVONotifying_FooBar" class is not really exported, but RCTBridgeModuleClassesByModuleID questions whether it should be.

It looks like this part of the function is not long-lived. The one issue is this is logged using the error level which causes a red box on typical install and run. Perhaps, this could be dropped to a warn? The other option is to spend time trying to make the code smarter about detecting this situation. I'm not sure if it's worth it for short-lived code though.

jwyld avatar Jun 11 '15 10:06 jwyld

~~Once https://github.com/facebook/react-native/pull/1583 is merged,~~ can you see if this issue is present on master? One of the commits in that PR changes the native module registration to use +[load] which the KVO support subclasses shouldn't invoke.

ide avatar Jun 11 '15 10:06 ide

With v0.6.0-rc, I still see it.

To reproduce, perform the following prior to instantiation of the bridge: RCTDatePickerManager *test = [[RCTDatePickerManager alloc] init]; [test addObserver:self forKeyPath:@"bridge" options:(NSKeyValueObservingOptionNew) context:nil];

jwyld avatar Jun 16 '15 17:06 jwyld

The patch that changes module loading is planned to go out Friday with 0.7.0-RC.

ide avatar Jun 16 '15 18:06 ide

Looks like this was fixed with .70. @brentvatne already solved

browniefed avatar Jul 20 '15 19:07 browniefed