mirror of
https://github.com/bitwarden/browser.git
synced 2025-02-24 02:41:54 +01:00
[PM-16719] [COMMUNITY] Debounce requestIdleCallback a single time every 100ms, as opposed to call requestIdleCallback on debounce method (#12695)
* [COMMUNITY] Debounce requestIdleCallback a single time every 100ms, as opposed to call requestIdleCallback on debounce method Potential fix for #12031 * [COMMUNITY] Fixing broken jest mock of the debounce utils method * [COMMUNITY] Fixing broken jest mock of the debounce utils method * [COMMUNITY] Fixing broken jest mock of the debounce utils method
This commit is contained in:
parent
795ad78a4e
commit
374ea6af7c
@ -21,7 +21,7 @@ jest.mock("../utils", () => {
|
|||||||
const utils = jest.requireActual("../utils");
|
const utils = jest.requireActual("../utils");
|
||||||
return {
|
return {
|
||||||
...utils,
|
...utils,
|
||||||
debounce: jest.fn((fn) => fn),
|
debounce: jest.fn((fn, wait) => setTimeout(() => fn(), wait)),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -947,7 +947,8 @@ export class CollectAutofillContentService implements CollectAutofillContentServ
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.mutationsQueue.length) {
|
if (!this.mutationsQueue.length) {
|
||||||
requestIdleCallbackPolyfill(debounce(this.processMutations, 100), { timeout: 500 });
|
// Collect all mutations and debounce the processing of those mutations by 100ms to ensure we don't process too many mutations at once.
|
||||||
|
debounce(this.processMutations, 100);
|
||||||
}
|
}
|
||||||
this.mutationsQueue.push(mutations);
|
this.mutationsQueue.push(mutations);
|
||||||
};
|
};
|
||||||
@ -982,7 +983,8 @@ export class CollectAutofillContentService implements CollectAutofillContentServ
|
|||||||
const queueLength = this.mutationsQueue.length;
|
const queueLength = this.mutationsQueue.length;
|
||||||
|
|
||||||
if (!this.domQueryService.pageContainsShadowDomElements()) {
|
if (!this.domQueryService.pageContainsShadowDomElements()) {
|
||||||
this.checkPageContainsShadowDom();
|
// Checking if a page contains shadowDOM elements is a heavy operation and doesn't have to be done immediately, so we can call this within an idle moment on the event loop.
|
||||||
|
requestIdleCallbackPolyfill(this.checkPageContainsShadowDom, { timeout: 500 });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let queueIndex = 0; queueIndex < queueLength; queueIndex++) {
|
for (let queueIndex = 0; queueIndex < queueLength; queueIndex++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user