@samitouri / QOS-React-1 / commits / 26855e4680

[react-native] Fix misleading crash when view config is not found (#30970)

## Summary When a view config can not be found, it currently errors with `TypeError: Cannot read property 'bubblingEventTypes' of null`. Instead invariant at the correct location and prevent further processing of the null viewConfig to improve the error logged. ## How did you test this change? Build and run RN playground app referencing an invalid native view through `requireNativeComponent`.

Pieter De Baets committed Sep 16, 2024 at 17:51 UTC 26855e4680dedb21f2c73a069ed691822a242db1
1 file changed +4 -5
scripts/rollup/shims/react-native/ReactNativeViewConfigRegistry.js
+4 -5
@@ -93,8 +93,8 @@ export function register(name: string, callback: () => ViewConfig): string {
93 * This configuration will be lazy-loaded from UIManager.
94 */
95 export function get(name: string): ViewConfig {
96 - let viewConfig;
97 - if (!viewConfigs.has(name)) {
96 + let viewConfig = viewConfigs.get(name);
97 + if (viewConfig == null) {
98 const callback = viewConfigCallbacks.get(name);
99 if (typeof callback !== 'function') {
100 invariant(
@@ -109,15 +109,14 @@ export function get(name: string): ViewConfig {
109 );
110 }
111 viewConfig = callback();
112 + invariant(viewConfig, 'View config not found for component `%s`', name);
113 +
114 processEventTypes(viewConfig);
115 viewConfigs.set(name, viewConfig);
116
117 // Clear the callback after the config is set so that
118 // we don't mask any errors during registration.
119 viewConfigCallbacks.set(name, null);
118 - } else {
119 - viewConfig = viewConfigs.get(name);
120 }
121 - invariant(viewConfig, 'View config not found for name %s', name);
121 return viewConfig;
122 }