-
Notifications
You must be signed in to change notification settings - Fork 255
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
fix: fetchSearch #4008
base: master
Are you sure you want to change the base?
fix: fetchSearch #4008
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for looking at this! I looked closer and noticed how the tests were failing. Here is what I came up with:
submitSearch(event) {
const {
companionWindowId, fetchSearch, searchService, windowId,
} = this.props;
const { search } = this.state;
if (!search) return;
if (event && event.type === 'submit' && this.state.isSuggestionSelected) {
event.preventDefault();
return; // Do not trigger search again if a suggestion was selected
}
if (event) {
event.preventDefault();
}
fetchSearch(windowId, companionWindowId, `${searchService.id}?${new URLSearchParams({ q: search })}`, search);
}
This approach requires adding something new to the component state (isSuggestionSelected
), and also handling that elsewhere in the file (reset to false at the top of handleChange
) and also in selectItem
:
selectItem(_event, selectedItem, _reason) {
if (selectedItem && getMatch(selectedItem)) {
this.setState({ search: getMatch(selectedItem), isSuggestionSelected: true }, this.submitSearch);
}
}
That is just some ideas, it may not make sense overall but the tests are passing with that, and there are no double searches.
Ah thanks for the input for fixing the tests and updated the |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4008 +/- ##
==========================================
- Coverage 92.43% 92.18% -0.25%
==========================================
Files 203 204 +1
Lines 3581 3354 -227
==========================================
- Hits 3310 3092 -218
+ Misses 271 262 -9 ☔ View full report in Codecov by Sentry. |
@fstoe nice! This seems to fix the double request bug for me and not break anything else, but I would be curious for someone else to test it out. |
I'm curious if #3999 (rewriting these components to functions) fixes it or has the same problems. |
I just tested but unfortunately the bug persists when using the functional |
Hey,
i tried to fix this issue.
It seems like the onSubmit sends two events. The first one being undefined and the second being the actual onSubmit one. This results in the dispatching of the
action fetchSearch
two times