GeezerVison is showing github.com — [React Native] Improve errors for invalid ViewConfig getter functions… · react/react@32e5c97
File treeExpand file treeCollapse file tree Open diff view settings packages/react-native-renderer/src __mocks__/react-native/Libraries/ReactPrivate
scripts/rollup/shims/react-native
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativeViewConfigRegistry.js +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -78,6 +78,12 @@ exports.register = function(name: string, callback: ViewConfigGetter): string { | 78 | 78 | 'Tried to register two views with the same name %s', | 79 | 79 | name, | 80 | 80 | ); | | 81 | + invariant( | | 82 | + typeof callback === 'function', | | 83 | + 'View config getter callback for component `%s` must be a function (received `%s`)', | | 84 | + name, | | 85 | + callback === null ? 'null' : typeof callback, | | 86 | + ); | 81 | 87 | viewConfigCallbacks.set(name, callback); | 82 | 88 | return name; | 83 | 89 | }; | @@ -94,8 +100,9 @@ exports.get = function(name: string): ReactNativeBaseComponentViewConfig<> { | 94 | 100 | if (typeof callback !== 'function') { | 95 | 101 | invariant( | 96 | 102 | false, | 97 | | - 'View config not found for name %s.%s', | | 103 | + 'View config getter callback for component `%s` must be a function (received `%s`).%s', | 98 | 104 | name, | | 105 | + callback === null ? 'null' : typeof callback, | 99 | 106 | typeof name[0] === 'string' && /[a-z]/.test(name[0]) | 100 | 107 | ? ' Make sure to start component names with a capital letter.' | 101 | 108 | : '', | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/__tests__/ReactNativeError-test.internal.js +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -32,6 +32,18 @@ describe('ReactNativeError', () => { | 32 | 32 | .computeComponentStackForErrorReporting; | 33 | 33 | }); | 34 | 34 |
| | 35 | + it('should throw error if null component registration getter is used', () => { | | 36 | + expect(() => { | | 37 | + try { | | 38 | + createReactNativeComponentClass('View', null); | | 39 | + } catch (e) { | | 40 | + throw new Error(e.toString()); | | 41 | + } | | 42 | + }).toThrow( | | 43 | + 'Invariant Violation: View config getter callback for component `View` must be a function (received `null`)', | | 44 | + ); | | 45 | + }); | | 46 | + | 35 | 47 | it('should be able to extract a component stack from a native view', () => { | 36 | 48 | const View = createReactNativeComponentClass('View', () => ({ | 37 | 49 | validAttributes: {foo: true}, | |
Collapse file Copy file name to clipboardExpand all lines: scripts/rollup/shims/react-native/ReactNativeViewConfigRegistry.js +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -75,6 +75,12 @@ exports.register = function(name: string, callback: ViewConfigGetter): string { | 75 | 75 | 'Tried to register two views with the same name %s', | 76 | 76 | name, | 77 | 77 | ); | | 78 | + invariant( | | 79 | + typeof callback === 'function', | | 80 | + 'View config getter callback for component `%s` must be a function (received `%s`)', | | 81 | + name, | | 82 | + callback === null ? 'null' : typeof callback, | | 83 | + ); | 78 | 84 | viewConfigCallbacks.set(name, callback); | 79 | 85 | return name; | 80 | 86 | }; | @@ -91,8 +97,9 @@ exports.get = function(name: string): ReactNativeBaseComponentViewConfig<> { | 91 | 97 | if (typeof callback !== 'function') { | 92 | 98 | invariant( | 93 | 99 | false, | 94 | | - 'View config not found for name %s.%s', | | 100 | + 'View config getter callback for component `%s` must be a function (received `%s`).%s', | 95 | 101 | name, | | 102 | + callback === null ? 'null' : typeof callback, | 96 | 103 | typeof name[0] === 'string' && /[a-z]/.test(name[0]) | 97 | 104 | ? ' Make sure to start component names with a capital letter.' | 98 | 105 | : '', | |
|