fix(workbench): cap visible timing ticker steps (#2007)

This commit is contained in:
Lyon
2026-06-24 02:40:35 +08:00
committed by GitHub
parent 6dcf833f8a
commit b61fb4e65c
@@ -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<symbol, boolean>();
@@ -30,8 +31,18 @@ export function useWorkbenchNowTicker(enabled: Ref<boolean>) {
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;
}