Skip to content

Commit

Permalink
[COMMUNITY] Debounce requestIdleCallback a single time every 100ms, a…
Browse files Browse the repository at this point in the history
…s opposed to call requestIdleCallback on debounce method

Potential fix for #12031
  • Loading branch information
cagonzalezcs authored and jprusik committed Jan 13, 2025
1 parent fb4d7e8 commit ff54bb4
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,9 @@ export class CollectAutofillContentService implements CollectAutofillContentServ
}

if (!this.mutationsQueue.length) {
requestIdleCallbackPolyfill(debounce(this.processMutations, 100), { timeout: 500 });
// # Switch the order of these two to process the list of mutations, within
// # an idle moment in the event loop, only once every 100 ms
debounce(this.processMutations, 100);
}
this.mutationsQueue.push(mutations);
};
Expand Down Expand Up @@ -982,7 +984,9 @@ export class CollectAutofillContentService implements CollectAutofillContentServ
const queueLength = this.mutationsQueue.length;

if (!this.domQueryService.pageContainsShadowDomElements()) {
this.checkPageContainsShadowDom();
// # Request idle callback here, checking if a page contains
// # shadowDOMs is a heavy operation and doesn't have to be done immediately.
requestIdleCallbackPolyfill(this.checkPageContainsShadowDom, { timeout: 500 });
}

for (let queueIndex = 0; queueIndex < queueLength; queueIndex++) {
Expand Down

0 comments on commit ff54bb4

Please sign in to comment.