Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed possible undefined error in TreeContext reducer #24501

Merged
merged 1 commit into from
May 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't make as much sense to check store.errorCount and store.warningCount here because we don't use those values. We use the tuples array returned by getElementsWithErrorsAndWarnings – and while this should always match up, it seems like a small improvement to make this reducer check the actual value it uses rather than the one it's derived from.

return state;
}

const elementIndicesWithErrorsOrWarnings = store.getElementsWithErrorsAndWarnings();

let flatIndex = 0;
if (selectedElementIndex !== null) {
// Resume from the current position in the list.
Expand Down Expand Up @@ -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.
Expand Down