From 36a6b4c52dd3e0323ea9801e4d1cf9ea44b1e537 Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 1 Jun 2026 17:09:38 -0500 Subject: [PATCH] fix(main): keep prefs.mode in sync and rAF-coalesce mutation observer --- src/main.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index d1bbdbc..c868bf2 100644 --- a/src/main.js +++ b/src/main.js @@ -27,6 +27,7 @@ function start() { }, onModeChange: (m) => { store.setMode(m); + prefs.mode = m; applyMode(); }, onPosChange: (pos) => store.setPos(pos), @@ -85,9 +86,15 @@ function start() { render(); // watch DOM for attribute changes + let pending = false; const observer = new MutationObserver(() => { - const a = currentAttribute(); - if (a && (a.attr !== lastAttr || a.current !== lastSnapshot?.current)) render(); + if (pending) return; + pending = true; + requestAnimationFrame(() => { + pending = false; + const a = currentAttribute(); + if (a && (a.attr !== lastAttr || a.current !== lastSnapshot?.current)) render(); + }); }); observer.observe(document.body, { childList: true, subtree: true, characterData: true });