From 1d41cb3d295da31d548e7de3dfc4d54f196329cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=93=E3=81=8B=E3=82=8A?= <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sun, 5 Jul 2026 13:08:44 +0900 Subject: [PATCH] =?UTF-8?q?perf(frontend):=20UNIX=E6=99=82=E8=A8=88?= =?UTF-8?q?=E3=82=A6=E3=82=A3=E3=82=B8=E3=82=A7=E3=83=83=E3=83=88=E3=81=A7?= =?UTF-8?q?requestAnimationFrame=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=20(#17665)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontend/src/widgets/WidgetUnixClock.vue | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/frontend/src/widgets/WidgetUnixClock.vue b/packages/frontend/src/widgets/WidgetUnixClock.vue index 1bb361664f..7100c55e17 100644 --- a/packages/frontend/src/widgets/WidgetUnixClock.vue +++ b/packages/frontend/src/widgets/WidgetUnixClock.vue @@ -60,6 +60,7 @@ const { widgetProps, configure } = useWidgetPropsManager(name, ); let intervalId: number | null = null; +let rafRequestId: number | null = null; const ss = ref(''); const ms = ref(''); const showColon = ref(false); @@ -81,18 +82,34 @@ const tick = () => { prevSec = ss.value; }; -tick(); - -watch(() => widgetProps.showMs, () => { - if (intervalId) window.clearInterval(intervalId); - intervalId = window.setInterval(tick, widgetProps.showMs ? 10 : 1000); -}, { immediate: true }); - -onUnmounted(() => { +const clearTimers = () => { if (intervalId) { window.clearInterval(intervalId); intervalId = null; } + if (rafRequestId) { + window.cancelAnimationFrame(rafRequestId); + rafRequestId = null; + } +}; + +tick(); + +watch(() => widgetProps.showMs, (to) => { + clearTimers(); + + if (to) { + rafRequestId = window.requestAnimationFrame(function loop() { + tick(); + rafRequestId = window.requestAnimationFrame(loop); + }); + } else { + intervalId = window.setInterval(tick, 1000); + } +}, { immediate: true }); + +onUnmounted(() => { + clearTimers(); }); defineExpose({