Repository navigation
Commit 1db1ee7
authored
Skip static view config verification without native view configs
## Summary:
A bridgeless host can turn on static view config verification with `NativeComponentRegistry.setRuntimeConfigProvider(() => ({native: false, verify: true}))`. If the host has no legacy view config interop binding, each native component then logs a `console.error` the first time it is used:
```
[ReactNative Architecture][JS] 'getViewManagerConfig('RCTView')' is not available in the new React Native architecture. If 'RCTView' has a ViewManager and you want to retrieve its native ViewConfig, please turn on the native ViewConfig interop layer. ...
```
In bridgeless mode, `UIManager.getViewManagerConfig` reads native view configs from the binding `global.RN$LegacyInterop_UIManager_getConstants`. Without it, the call logs the error above and returns null, so verification does nothing. The binding is absent when:
- `useNativeViewConfigsInBridgelessMode` is off. It is off in `ReactNativeFeatureFlagsDefaults`; the stock entry points turn it on (`RCTReactNativeFactory` on iOS, `ReactNativeNewArchitectureFeatureFlagsDefaults` on Android), so this affects hosts that set up feature flags another way.
- An iOS app is built with `RCT_REMOVE_LEGACY_COMPONENT_INTEROP`, which compiles the binding out (`RCTInstance.mm`). RNTester, which turns verification on in bridgeless development builds, logs these errors only in that case.
`NativeComponentRegistry.get` now skips verification when the binding is absent. Nothing was verified in that case, so the only change is that the errors stop.
`getWithFallback_DEPRECATED`, with no runtime config provider set, checks that a component exists with `getViewManagerConfig(name) != null`, which without the binding logs the error and returns the fallback for a component that exists. It now calls `hasViewManagerConfig(name)`: the same null check on the old architecture, and a query of the native component registry in bridgeless mode. That query throws if `global.__nativeComponentRegistry__hasComponent` is missing (`NativeComponentRegistryUnstable.js`), so the change reaches every bridgeless host; every host here installs it before running JavaScript (`RCTInstance.mm`, `ComponentNameResolverBinding` on Android, `ReactHost.cpp` in `ReactCxxPlatform`); development builds already call `hasViewManagerConfig` when `AppContainer-dev.js` loads `DebuggingOverlay.js`.
## Changelog:
[GENERAL] [FIXED] - Stop logging a `getViewManagerConfig` error for every component when static view config verification is on in bridgeless mode, and stop `getWithFallback_DEPRECATED` from returning the fallback for a registered component there
## Test Plan:
```sh
yarn jest --runInBand packages/react-native/Libraries/NativeComponent/__tests__/NativeComponentRegistry-test.js
```
`NativeComponentRegistry-test.js` is new. With `NativeComponentRegistry.js` from `main`, the case for bridgeless mode without the binding fails (verification requests the native view config), and so does the `getWithFallback_DEPRECATED` case (it returns the fallback for a registered component). Replacing either half of the new condition (`global.RN$Bridgeless === true`, or the check for `global.RN$LegacyInterop_UIManager_getConstants`) with `true` fails the case that covers it. The tests set or remove the binding themselves.
```sh
yarn jest --runInBand packages/react-native/Libraries/NativeComponent packages/react-native/Libraries/ReactNative packages/react-native/Libraries/Utilities/__tests__/codegenNativeComponent-test.js
```
These pass, as do Flow, ESLint and Prettier. Not run: an app without the binding.
Differential Revision: D135948468
Pull Request resolved: #603611 parent a1673b7 commit 1db1ee7
2 files changed
Lines changed: 180 additions & 1 deletion
File tree
- packages/react-native/Libraries/NativeComponent
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
79 | 94 | | |
80 | 95 | | |
81 | 96 | | |
| |||
149 | 164 | | |
150 | 165 | | |
151 | 166 | | |
152 | | - | |
| 167 | + | |
153 | 168 | | |
154 | 169 | | |
155 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
0 commit comments