From 2127dea4477080117b04ce9eef42ef30a2078d3f Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 24 Jun 2021 01:35:55 -0700 Subject: [PATCH] Fix initialisation error Summary: There was an initialisation error possible if the crash reporter tried to start with an initial selection (after coming from a deeplink or the notification pane), which would cause an unending update loop. Reviewed By: passy Differential Revision: D29331127 fbshipit-source-id: 14e75e483c232039e6a80aa131fa5ce7c105b670 --- .../flipper-plugin/src/ui/data-table/DataTable.tsx | 12 ++++++++---- .../src/ui/data-table/__tests__/DataTable.node.tsx | 10 ++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/desktop/flipper-plugin/src/ui/data-table/DataTable.tsx b/desktop/flipper-plugin/src/ui/data-table/DataTable.tsx index 58940b765..b5040c52d 100644 --- a/desktop/flipper-plugin/src/ui/data-table/DataTable.tsx +++ b/desktop/flipper-plugin/src/ui/data-table/DataTable.tsx @@ -357,12 +357,16 @@ export function DataTable( [dataSource, tableState.sorting], ); + const isMounted = useRef(false); useEffect( function triggerSelection() { - onSelect?.( - getSelectedItem(dataSource, tableState.selection), - getSelectedItems(dataSource, tableState.selection), - ); + if (isMounted.current) { + onSelect?.( + getSelectedItem(dataSource, tableState.selection), + getSelectedItems(dataSource, tableState.selection), + ); + } + isMounted.current = true; }, [onSelect, dataSource, tableState.selection], ); diff --git a/desktop/flipper-plugin/src/ui/data-table/__tests__/DataTable.node.tsx b/desktop/flipper-plugin/src/ui/data-table/__tests__/DataTable.node.tsx index 5ad3712c7..0b45ce42d 100644 --- a/desktop/flipper-plugin/src/ui/data-table/__tests__/DataTable.node.tsx +++ b/desktop/flipper-plugin/src/ui/data-table/__tests__/DataTable.node.tsx @@ -555,10 +555,7 @@ test('onSelect callback fires, and in order', () => { ref.current!.selectItem(2); }); - expect(events.splice(0)).toEqual([ - [undefined, []], - [item3, [item3]], - ]); + expect(events.splice(0)).toEqual([[item3, [item3]]]); act(() => { ref.current!.addRangeToSelection(0, 0); @@ -606,10 +603,7 @@ test('selection always has the latest state', () => { ref.current!.selectItem(2); }); - expect(events.splice(0)).toEqual([ - [undefined, []], - [item3, [item3]], - ]); + expect(events.splice(0)).toEqual([[item3, [item3]]]); const item3updated = { title: 'item 3 updated',