From 98e139344180fd39887f62042945f147f7feaacd Mon Sep 17 00:00:00 2001 From: easrng Date: Fri, 18 Feb 2022 14:11:54 -0500 Subject: [PATCH] tweak append stuff --- frontend/lib/chat.mjs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/lib/chat.mjs b/frontend/lib/chat.mjs index b3ef682..46f802c 100644 --- a/frontend/lib/chat.mjs +++ b/frontend/lib/chat.mjs @@ -56,7 +56,8 @@ const setupChatboxEvents = (socket) => { button.classList.add("selected"); }; let results = await findEmojis(search); - for (let i = 0; i < results.length; i += 100) { + let yieldAt = performance.now() + 13; + for (let i = 0; i < results.length; i += 10) { emojiAutocomplete.append.apply( emojiAutocomplete, results.slice(i, i + 1000).map(([name, replaceWith, ext], i) => { @@ -98,7 +99,11 @@ const setupChatboxEvents = (socket) => { emojiAutocomplete.children[0].scrollIntoView(); select(emojiAutocomplete.children[0]); } - await new Promise((cb) => setTimeout(cb, 0)); + const now = performance.now(); + if (now > yieldAt) { + yieldAt = now + 13; + await new Promise((cb) => setTimeout(cb, 0)); + } } autocompleting = false; }