@samitouri / QOS-React-2 / commits / d4acbe85d5

Fixed possible undefined error in TreeContext reducer (#24501)

Brian Vaughn committed May 5, 2022 at 11:46 UTC d4acbe85d55b6048d65b6ff258b7996516d4aa58
1 file changed +4 -6
packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js
+4 -6
@@ -377,12 +377,11 @@ function reduceTreeState(store: Store, state: State, action: Action): State {
377 }
378 break;
379 case 'SELECT_PREVIOUS_ELEMENT_WITH_ERROR_OR_WARNING_IN_TREE': {
380 - if (store.errorCount === 0 && store.warningCount === 0) {
380 + const elementIndicesWithErrorsOrWarnings = store.getElementsWithErrorsAndWarnings();
381 + if (elementIndicesWithErrorsOrWarnings.length === 0) {
382 return state;
383 }
384
384 - const elementIndicesWithErrorsOrWarnings = store.getElementsWithErrorsAndWarnings();
385 -
385 let flatIndex = 0;
386 if (selectedElementIndex !== null) {
387 // Resume from the current position in the list.
@@ -419,12 +418,11 @@ function reduceTreeState(store: Store, state: State, action: Action): State {
418 break;
419 }
420 case 'SELECT_NEXT_ELEMENT_WITH_ERROR_OR_WARNING_IN_TREE': {
422 - if (store.errorCount === 0 && store.warningCount === 0) {
421 + const elementIndicesWithErrorsOrWarnings = store.getElementsWithErrorsAndWarnings();
422 + if (elementIndicesWithErrorsOrWarnings.length === 0) {
423 return state;
424 }
425
426 - const elementIndicesWithErrorsOrWarnings = store.getElementsWithErrorsAndWarnings();
427 -
426 let flatIndex = -1;
427 if (selectedElementIndex !== null) {
428 // Resume from the current position in the list.