Deeply compare viewabilityConfigs to avoid triggering invariant unnecessarily

Summary:
Currently, modifying a component that renders a FlatLists while Hot Reloading is enabled will trigger an invariant inside FlatList for changing viewabilityConfig on the fly. This happens because it checks object equality between the configs.

By checking equality of the config's *properties* instead, we maintain the efficacy of the invariant but keep it from falsely triggering during development.

Reviewed By: sahrens

Differential Revision: D9466129

fbshipit-source-id: 67149e9e70ad7b2e2584bb7ec03e2dea26ef45e8
This commit is contained in:
Logan Daniels 2018-08-24 14:17:45 -07:00 committed by Facebook Github Bot
parent d2c27f5bff
commit 122dc37afe
1 changed files with 2 additions and 1 deletions

View File

@ -9,6 +9,7 @@
*/
'use strict';
const deepDiffer = require('deepDiffer');
const MetroListView = require('MetroListView'); // Used as a fallback legacy option
const React = require('React');
const View = require('View');
@ -472,7 +473,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
'Changing onViewableItemsChanged on the fly is not supported',
);
invariant(
prevProps.viewabilityConfig === this.props.viewabilityConfig,
!deepDiffer(prevProps.viewabilityConfig, this.props.viewabilityConfig),
'Changing viewabilityConfig on the fly is not supported',
);
invariant(