From 122dc37afe4bbe8a8bcdcfc3f4c9c5ebd61cbb01 Mon Sep 17 00:00:00 2001 From: Logan Daniels Date: Fri, 24 Aug 2018 14:17:45 -0700 Subject: [PATCH] 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 --- Libraries/Lists/FlatList.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index 607919efa..da1158aa4 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -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 extends React.PureComponent, 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(