Skip to content

Commit

Permalink
remove duplicate calls for querySelector
Browse files Browse the repository at this point in the history
  • Loading branch information
NoamAnisfeld authored Feb 20, 2024
1 parent 699779d commit 92ed71f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ const waitForElement = (selector, target = document) => {
reject(new Error('Time out to wait for the element ' + selector));
}, waitElementTimeOot);

if (target.querySelector(selector)) {
return resolve(target.querySelector(selector));
const wishedElement = target.querySelector(selector);
if (wishedElement) {
return resolve(wishedElement);
}

const observer = new MutationObserver(() => {
if (target.querySelector(selector)) {
resolve(target.querySelector(selector));
const wishedElement = target.querySelector(selector);
if (wishedElement) {
resolve(wishedElement);
observer.disconnect();
}
});
Expand Down

0 comments on commit 92ed71f

Please sign in to comment.