diff --git a/web/hwlab-cloud-web/src/composables/useWorkbenchNowTicker.ts b/web/hwlab-cloud-web/src/composables/useWorkbenchNowTicker.ts index f8e7a93d..a635a92d 100644 --- a/web/hwlab-cloud-web/src/composables/useWorkbenchNowTicker.ts +++ b/web/hwlab-cloud-web/src/composables/useWorkbenchNowTicker.ts @@ -4,6 +4,7 @@ import { onBeforeUnmount, readonly, ref, watch, type Ref } from "vue"; const TICK_INTERVAL_MS = 1000; +const MAX_VISIBLE_TICK_STEP_MS = TICK_INTERVAL_MS; const nowMs = ref(Date.now()); const activeSubscribers = new Map(); @@ -30,8 +31,18 @@ export function useWorkbenchNowTicker(enabled: Ref) { return { nowMs: readonly(nowMs), refreshNow }; } -function refreshNow(): void { - nowMs.value = Date.now(); +function refreshNow(reset = false): void { + const wallNow = Date.now(); + if (reset) { + nowMs.value = wallNow; + return; + } + const previous = Number(nowMs.value); + if (!Number.isFinite(previous) || wallNow <= previous) { + nowMs.value = wallNow; + return; + } + nowMs.value = Math.min(wallNow, previous + MAX_VISIBLE_TICK_STEP_MS); } function reconcileTimer(): void { @@ -40,7 +51,7 @@ function reconcileTimer(): void { // elapsed/recent labels advance monotonically instead of jumping on resume. const shouldRun = isBrowser() && hasActiveSubscriber(); if (shouldRun && timer === null) { - refreshNow(); + refreshNow(true); timer = window.setInterval(refreshNow, TICK_INTERVAL_MS); return; }