Reduce idle timer updates and stabilize toolbox normalization
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s

This commit is contained in:
Shinuwa 2026-09-09 20:04:45 +02:00
parent cce3f3c7f8
commit c096cc07fe
3 changed files with 10 additions and 4 deletions

View file

@ -31,16 +31,20 @@ import {
} from "./timerOptions.js";
export function TimerModule({ toolboxId, moduleId, context, textExchangeOpen }) {
const data = context.normalizeTimerData(context.getModuleData(toolboxId, moduleId, { activeTab: "stopwatch" }));
const rawData = context.getModuleData(toolboxId, moduleId, { activeTab: "stopwatch" });
const data = useMemo(() => context.normalizeTimerData(rawData), [context, rawData]);
const textContent = context.moduleText?.timer || {};
const activeTab = data.activeTab;
const [nowMs, setNowMs] = useState(getNowMs);
const countdownDraft = useDraftForm(DEFAULT_COUNTDOWN_FORM);
const clockActive = Boolean(data.stopwatch.startedAt || data.countdowns.some((countdown) => countdown.autoRefresh));
useEffect(() => {
if (!clockActive) return undefined;
const intervalId = window.setInterval(() => setNowMs(getNowMs()), 50);
return () => window.clearInterval(intervalId);
}, []);
}, [clockActive]);
const stopwatchElapsedMs = data.stopwatch.startedAt
? data.stopwatch.elapsedMs + Math.max(0, nowMs - data.stopwatch.startedAt)