From d06157116a2cf901097f2cbdb0b0d1d65b58b21d Mon Sep 17 00:00:00 2001 From: Jason Finch Date: Fri, 10 Feb 2023 08:39:23 +1000 Subject: [PATCH] feat: Replace DOMNodeInserted with MutationObserver to make page more responsive. --- src/abode.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/abode.ts b/src/abode.ts index 577570b..aa9c881 100644 --- a/src/abode.ts +++ b/src/abode.ts @@ -250,7 +250,7 @@ const checkForAndHandleNewComponents = async (options?: PopulateOptions) => { export const populate = async (options?: PopulateOptions) => { await checkForAndHandleNewComponents(options); - document.body.addEventListener('DOMNodeInserted', () => - checkForAndHandleNewComponents(options) - ); + const callback = await checkForAndHandleNewComponents(options); + const observer = new MutationObserver(async() => callback); + observer.observe(document.body, {childList: true, subtree: true}); };