From 649a196e4bd7be7fbf501b767209336b0a82ef3e Mon Sep 17 00:00:00 2001 From: Jonathan Prusik Date: Wed, 22 Jan 2025 17:08:25 -0500 Subject: [PATCH] partial revert of 374ea6a (#13018) --- .../services/collect-autofill-content.service.spec.ts | 2 +- .../src/autofill/services/collect-autofill-content.service.ts | 3 +-- apps/browser/src/autofill/utils/index.ts | 4 +++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/browser/src/autofill/services/collect-autofill-content.service.spec.ts b/apps/browser/src/autofill/services/collect-autofill-content.service.spec.ts index f15c3e4c389..7471c298917 100644 --- a/apps/browser/src/autofill/services/collect-autofill-content.service.spec.ts +++ b/apps/browser/src/autofill/services/collect-autofill-content.service.spec.ts @@ -21,7 +21,7 @@ jest.mock("../utils", () => { const utils = jest.requireActual("../utils"); return { ...utils, - debounce: jest.fn((fn, wait) => setTimeout(() => fn(), wait)), + debounce: jest.fn((fn) => fn), }; }); diff --git a/apps/browser/src/autofill/services/collect-autofill-content.service.ts b/apps/browser/src/autofill/services/collect-autofill-content.service.ts index 8ccf726aa69..b858af25fae 100644 --- a/apps/browser/src/autofill/services/collect-autofill-content.service.ts +++ b/apps/browser/src/autofill/services/collect-autofill-content.service.ts @@ -947,8 +947,7 @@ export class CollectAutofillContentService implements CollectAutofillContentServ } if (!this.mutationsQueue.length) { - // 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); + requestIdleCallbackPolyfill(debounce(this.processMutations, 100), { timeout: 500 }); } this.mutationsQueue.push(mutations); }; diff --git a/apps/browser/src/autofill/utils/index.ts b/apps/browser/src/autofill/utils/index.ts index 0e102dcfd99..614a5b014f2 100644 --- a/apps/browser/src/autofill/utils/index.ts +++ b/apps/browser/src/autofill/utils/index.ts @@ -37,7 +37,9 @@ export function requestIdleCallbackPolyfill( return globalThis.requestIdleCallback(() => callback(), options); } - return globalThis.setTimeout(() => callback(), 1); + const timeoutDelay = options?.timeout || 1; + + return globalThis.setTimeout(() => callback(), timeoutDelay); } /**