From 6045dfd741238754f0b237b49f6d8db11ab280ac Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Mon, 13 Oct 2025 13:35:43 -0400 Subject: [PATCH] Simplify zapthreads embed initialization --- blog.html | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/blog.html b/blog.html index acfda804..87894025 100644 --- a/blog.html +++ b/blog.html @@ -21013,35 +21013,25 @@ } return options; } - const zapthreadsCleanupMap = new WeakMap(); - async function initializeZapthreadsEmbed(element) { - if (!(element instanceof Element)) return; - const previousCleanup = zapthreadsCleanupMap.get(element); - if (typeof previousCleanup === "function") { - try { - previousCleanup(); - } catch (error) { - console.error("[zapthreads] cleanup failed", error); - } - zapthreadsCleanupMap.delete(element); + async function mountZapthreadsEmbed(element) { + if (!(element instanceof Element) || !element.isConnected) { + return; } - if (!element.isConnected) return; try { - const cleanup = await initZapthreadsEmbed({ + await initZapthreadsEmbed({ root: element, options: getZapthreadsOptions(element), dataUtils: zapthreadsDataUtils, }); - if (typeof cleanup === "function") { - zapthreadsCleanupMap.set(element, cleanup); - } } catch (error) { console.error("[zapthreads] failed to initialize embed", error); } } function initializeZapthreadsEmbeds() { - document.querySelectorAll("zap-threads").forEach((element) => { - initializeZapthreadsEmbed(element); + const elements = document.querySelectorAll("zap-threads"); + if (elements.length === 0) return; + elements.forEach((element) => { + mountZapthreadsEmbed(element); }); } if (document.readyState === "loading") {