Skip to content

Commit

Permalink
Fix memoizeWrap when displayName is null (#654)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
janicduplessis authored and kmagiera committed Aug 23, 2019
1 parent b2f2e0d commit 28b7093
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions GestureComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ import ReactNative from 'react-native';

import createNativeWrapper from './createNativeWrapper';

const MEMOIZED = {};
const MEMOIZED = new WeakMap();

function memoizeWrap(Component, config) {
const memoized = MEMOIZED[Component.displayName];
if (memoized) {
return memoized;
if (Component == null) {
return null;
}
return (MEMOIZED[Component.displayName] = createNativeWrapper(
Component,
config
));
let memoized = MEMOIZED.get(Component);
if (!memoized) {
memoized = createNativeWrapper(
Component,
config
);
MEMOIZED.set(Component, memoized);
}
return memoized;
}

module.exports = {
Expand Down

0 comments on commit 28b7093

Please sign in to comment.