fix(workbench): cap visible timing ticker steps (#2007)
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
import { onBeforeUnmount, readonly, ref, watch, type Ref } from "vue";
|
import { onBeforeUnmount, readonly, ref, watch, type Ref } from "vue";
|
||||||
|
|
||||||
const TICK_INTERVAL_MS = 1000;
|
const TICK_INTERVAL_MS = 1000;
|
||||||
|
const MAX_VISIBLE_TICK_STEP_MS = TICK_INTERVAL_MS;
|
||||||
|
|
||||||
const nowMs = ref(Date.now());
|
const nowMs = ref(Date.now());
|
||||||
const activeSubscribers = new Map<symbol, boolean>();
|
const activeSubscribers = new Map<symbol, boolean>();
|
||||||
@@ -30,8 +31,18 @@ export function useWorkbenchNowTicker(enabled: Ref<boolean>) {
|
|||||||
return { nowMs: readonly(nowMs), refreshNow };
|
return { nowMs: readonly(nowMs), refreshNow };
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshNow(): void {
|
function refreshNow(reset = false): void {
|
||||||
nowMs.value = Date.now();
|
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 {
|
function reconcileTimer(): void {
|
||||||
@@ -40,7 +51,7 @@ function reconcileTimer(): void {
|
|||||||
// elapsed/recent labels advance monotonically instead of jumping on resume.
|
// elapsed/recent labels advance monotonically instead of jumping on resume.
|
||||||
const shouldRun = isBrowser() && hasActiveSubscriber();
|
const shouldRun = isBrowser() && hasActiveSubscriber();
|
||||||
if (shouldRun && timer === null) {
|
if (shouldRun && timer === null) {
|
||||||
refreshNow();
|
refreshNow(true);
|
||||||
timer = window.setInterval(refreshNow, TICK_INTERVAL_MS);
|
timer = window.setInterval(refreshNow, TICK_INTERVAL_MS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user