Skip to content

Commit

Permalink
fix(Search): prevent duplicate API called when suggestions are fetched
Browse files Browse the repository at this point in the history
In production build, the number of Suggestions looks duplicated (or worst)
In order to prevent the duplicate called, we should set the fetching
indicator directly when we call indexFiles method
  • Loading branch information
trollepierre committed Sep 2, 2022
1 parent 7394f78 commit acc29f0
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TYPE_DIRECTORY, makeNormalizedFile } from './helpers'
class SuggestionProvider extends React.Component {
componentDidMount() {
const { intent } = this.props
this.hasIndexedFiles = false
this.hasIndexFilesBeenLaunched = false

// re-attach the message listener for the intent to receive the suggestion requests
window.addEventListener('message', event => {
Expand Down Expand Up @@ -39,7 +39,8 @@ class SuggestionProvider extends React.Component {
* @returns {Promise<void>} nothing
*/
async provideSuggestions(query, id, intent) {
if (!this.hasIndexedFiles) {
if (!this.hasIndexFilesBeenLaunched) {
this.hasIndexFilesBeenLaunched = true
await this.indexFiles()
}

Expand Down Expand Up @@ -96,7 +97,6 @@ class SuggestionProvider extends React.Component {
)

this.fuzzyPathSearch = new FuzzyPathSearch(normalizedFiles)
this.hasIndexedFiles = true
}

render() {
Expand Down

0 comments on commit acc29f0

Please sign in to comment.