Skip to content

Commit 28b7093

Browse files
janicduplessiskmagiera
authored andcommitted
Fix memoizeWrap when displayName is null (#654)
`Component.displayName` can be undefined for release builds which means a bunch of components will fight for the undefined key. In my app it results in the `Switch` component rendering nothing (or probably just another component like `ScrollView`). I also added a null check since some components are being removed from RN core like ToolbarAndroid so it makes `memoizeWrap` safe in those cases.
1 parent b2f2e0d commit 28b7093

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

GestureComponents.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@ import ReactNative from 'react-native';
33

44
import createNativeWrapper from './createNativeWrapper';
55

6-
const MEMOIZED = {};
6+
const MEMOIZED = new WeakMap();
77

88
function memoizeWrap(Component, config) {
9-
const memoized = MEMOIZED[Component.displayName];
10-
if (memoized) {
11-
return memoized;
9+
if (Component == null) {
10+
return null;
1211
}
13-
return (MEMOIZED[Component.displayName] = createNativeWrapper(
14-
Component,
15-
config
16-
));
12+
let memoized = MEMOIZED.get(Component);
13+
if (!memoized) {
14+
memoized = createNativeWrapper(
15+
Component,
16+
config
17+
);
18+
MEMOIZED.set(Component, memoized);
19+
}
20+
return memoized;
1721
}
1822

1923
module.exports = {

0 commit comments

Comments
 (0)