Fixed possible undefined error in TreeContext reducer (#24501)

This commit is contained in:
Brian Vaughn
2022-05-05 11:46:57 -04:00
committed by GitHub
parent 024a7274fb
commit d4acbe85d5

View File

@@ -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.