From 26855e4680dedb21f2c73a069ed691822a242db1 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 16 Sep 2024 17:51:00 +0100 Subject: [PATCH] [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`. --- .../shims/react-native/ReactNativeViewConfigRegistry.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/rollup/shims/react-native/ReactNativeViewConfigRegistry.js b/scripts/rollup/shims/react-native/ReactNativeViewConfigRegistry.js index 98e03187c74a5..5f53e7634afde 100644 --- a/scripts/rollup/shims/react-native/ReactNativeViewConfigRegistry.js +++ b/scripts/rollup/shims/react-native/ReactNativeViewConfigRegistry.js @@ -93,8 +93,8 @@ export function register(name: string, callback: () => ViewConfig): string { * This configuration will be lazy-loaded from UIManager. */ export function get(name: string): ViewConfig { - let viewConfig; - if (!viewConfigs.has(name)) { + let viewConfig = viewConfigs.get(name); + if (viewConfig == null) { const callback = viewConfigCallbacks.get(name); if (typeof callback !== 'function') { invariant( @@ -109,15 +109,14 @@ export function get(name: string): ViewConfig { ); } viewConfig = callback(); + invariant(viewConfig, 'View config not found for component `%s`', name); + processEventTypes(viewConfig); viewConfigs.set(name, viewConfig); // Clear the callback after the config is set so that // we don't mask any errors during registration. viewConfigCallbacks.set(name, null); - } else { - viewConfig = viewConfigs.get(name); } - invariant(viewConfig, 'View config not found for name %s', name); return viewConfig; }