undefined in "searchResults" but present in "rawResults"
See original GitHub issueHi Luca,
me again^^
I have the following, quite strange behaviour.
You can add entries to the list of elements, that can be searched with mini-search. While you add the new entry, the query stays active.
The result should be, if the new entry matches the query, it should be displayed.
So, if the input data changes I perform search via a useEffect hook and display the new data.
But what happens is that despite having a match in the raw results (correct field, correct match, everything ok), the entry in searchResult is undefined causing a crash.
useEffect(() => {
if (data && !isFirstRender.current) {
removeAll();
addAll(data);
}
isFirstRender.current = false;
}, [data]);
useEffect(() => {
if (data) {
search(filter.query, {
filter: filterOptions.categoryField && filter.categories.length > 0 ? matchCategory : undefined,
});
}
}, [data, filter, filterOptions, matchCategory]);
The order of execution is correct, double checked on that.
Result looks like:
rawResults
[
{
"id": "6a901953144c411580520ed07B4567",
"terms": [
"einholung"
],
"score": 8.600445452294665,
"match": {
"einholung": [
"custom.bezeichnung"
]
},
"custom.kategorien": [
"Gefahr in Verzug",
"Sicherheit",
"Qualität"
]
},
{
"id": "h1662s",
"terms": [
"einholungsbums"
],
"score": 4.152082359120152,
"match": {
"einholungsbums": [
"custom.bezeichnung"
]
},
"custom.kategorien": [
"Gefahr in Verzug"
]
}
]
[
{
"id": "6a901953144c411580520ed07B4567",
"datum": "2020-09-17T20:34:56.170914Z",
"custom": {
"id": "6a901953144c411580520ed07a21ef39",
"erstelldatum": "2020-09-17T20:34:56.170914Z",
"baumassnahmenId": "45042621",
"bezeichnung": "Einholung weiterer Informationen",
"kategorien": [
"Gefahr in Verzug",
"Sicherheit",
"Qualität"
],
.....
},
undefined -> Where the second element should be.
]
Help would be highly appreciated. I’m kind of confused…
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
vscode/settingsEditor2.ts at main - GitHub
these setters need to exist because this extends from EditorPane ... searchResults: ISearchResult[] | null; rawResults: ISearchResult[] | null; ...
Read more >Why is my search query returning undefined, while my page ...
Why is my search query returning undefined, while my page populates with the ... It fixes the url, but my search results are...
Read more >WWE Raw Results: Winners, Grades, Reaction and Highlights ...
Welcome to Bleacher Report's coverage and recap of WWE Raw on December 19. Last week saw Adam Pearce fire Bobby Lashley, shocking the...
Read more >Bird Conservation International: Volume 26 - Issue 1
The importance of spring hunting in Malta on European Turtle-Dove Streptopelia turtur and Common Quail Coturnix coturnix populations.
Read more >WWE Raw Results: Winners, News And Notes On December ...
WWE Raw results as Bobby Lashley is fired by Adam Pearce. ... seem like he had found a joint that belonged to Matt...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi Luca:
Here you go: https://codepen.io/florianmatz/pen/xxqEaGE?
Steps to reproduce:
What’s completely weird:
If you switch the datasets BEFORE you perform the reproduction steps, it works like a charm. So, what’s important to reproduce: Only with data, that has not been indexed before… So make sure you’ve reloaded the codepen before testing it.
Here you find a short screen recording, if my description was too confusing… 😃 https://we.tl/t-3Xpiz6bMq6
It kind of seems, that the indexing is done, but the mapping of terms -> results is not ready yet… (if that makes any sense at all 😛)
Great news @florianmatz , the problem was indeed in
react-minisearch
. It was usinguseState
instead ofuseRef
to store local values such as the map of documents by ID: the problem is that setting the state is asynchronous, while adding/removing things to the index is synchronous by default. Therefore, the effective order of update of the index and the map of documents by ID was swapped, and under certain conditions this would surface as the bug you found.The new version 3.0.3 of
react-minisearch
fixes the problem, and seems to work well with your app: https://codepen.io/lucaong/pen/yLMVxxyThanks again for reporting this, and for the reproduction example on codepen! I am closing the issue, but feel free to comment on it if you find out that it is not completely solved.