Skip to content

Commit

Permalink
Fix a race condition
Browse files Browse the repository at this point in the history
Had a case where onChange ran before the google search widget was
rendered and got an exception that the searchInput was undefined.
Therefore, adding this if-gaurd.
  • Loading branch information
liliakai committed Sep 4, 2023
1 parent b4c8396 commit abfff64
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/TagsEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ const TagsEditor = () => {
setSelected(newSelected);

const searchInput = document.querySelector('input.gsc-input');
searchInput.value = constructGoogleQuery(newSelected);
const searchButton = document.querySelector('button.gsc-search-button');
searchButton.click();
if (searchInput) {
searchInput.value = constructGoogleQuery(newSelected);
const searchButton = document.querySelector('button.gsc-search-button');
searchButton.click();
}

newSelected.forEach(function(name) {
let newSuggested = new Set(suggested);
Expand Down

0 comments on commit abfff64

Please sign in to comment.