Skip to content

Commit

Permalink
[react-native] Fix misleading crash when view config is not found (#3…
Browse files Browse the repository at this point in the history
…0970)

## 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`.
  • Loading branch information
javache authored Sep 16, 2024
1 parent 9f4e461 commit 26855e4
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}

0 comments on commit 26855e4

Please sign in to comment.