From 36b64827db5853514797c4a6ee1e8ccfae555383 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Thu, 5 May 2022 10:26:17 -0400 Subject: [PATCH] Fixed possible undefined error in TreeContext reducer --- .../src/devtools/views/Components/TreeContext.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js b/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js index f6854468dc6eb..0252ac350fd99 100644 --- a/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js +++ b/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js @@ -377,12 +377,11 @@ function reduceTreeState(store: Store, state: State, action: Action): State { } break; case 'SELECT_PREVIOUS_ELEMENT_WITH_ERROR_OR_WARNING_IN_TREE': { - if (store.errorCount === 0 && store.warningCount === 0) { + const elementIndicesWithErrorsOrWarnings = store.getElementsWithErrorsAndWarnings(); + if (elementIndicesWithErrorsOrWarnings.length === 0) { return state; } - const elementIndicesWithErrorsOrWarnings = store.getElementsWithErrorsAndWarnings(); - let flatIndex = 0; if (selectedElementIndex !== null) { // Resume from the current position in the list. @@ -419,12 +418,11 @@ function reduceTreeState(store: Store, state: State, action: Action): State { break; } case 'SELECT_NEXT_ELEMENT_WITH_ERROR_OR_WARNING_IN_TREE': { - if (store.errorCount === 0 && store.warningCount === 0) { + const elementIndicesWithErrorsOrWarnings = store.getElementsWithErrorsAndWarnings(); + if (elementIndicesWithErrorsOrWarnings.length === 0) { return state; } - const elementIndicesWithErrorsOrWarnings = store.getElementsWithErrorsAndWarnings(); - let flatIndex = -1; if (selectedElementIndex !== null) { // Resume from the current position in the list.