Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(frontend): a clock step must not consume a display's own deadline
zchpeterf54882fad4c9
diff --git a/frontend/src/components/HumanizeTs.test.tsx b/frontend/src/components/HumanizeTs.test.tsxindex a43fb9e88e..09f5e3d006 100644--- a/frontend/src/components/HumanizeTs.test.tsx+++ b/frontend/src/components/HumanizeTs.test.tsx@@ -135,6 +135,14 @@ describe("HumanizeTs", () => {expect(overlayText()).toContain("relative:45100");});+ test("shows nothing for a time that is not a time", () => {+ // An unvalidated string reaching `new Date(...)` gives NaN, and Intl throws+ // on it; the row should lose its timestamp, not the page its subtree.+ const { container, root } = mount();+ act(() => root.render(<HumanizeTs ts={Number.NaN} />));+ expect(container.textContent).toBe("");+ });+test("omits the tooltip when tooltip is false", async () => {const { container, root } = mount();act(() => root.render(<HumanizeTs ts={1000} tooltip={false} />));diff --git a/frontend/src/components/HumanizeTs.tsx b/frontend/src/components/HumanizeTs.tsxindex 9d4dc3c559..1798b9599b 100644--- a/frontend/src/components/HumanizeTs.tsx+++ b/frontend/src/components/HumanizeTs.tsx@@ -88,7 +88,15 @@ export function HumanizeTs({useTranslation();const tsMs = ts * 1000;const { label: labelReading, Hidden } = MODES[mode];- const label = useTimeReading(labelReading, tsMs);+ // An unvalidated string reaching `new Date(...)` gives NaN, which `Intl`+ // throws on; a row loses its timestamp rather than the page its subtree.+ const label = useTimeReading(+ labelReading,+ Number.isFinite(tsMs) ? tsMs : undefined+ );+ if (label === undefined) {+ return null;+ }if (!tooltip) {return <span className={className}>{label}</span>;}diff --git a/frontend/src/hooks/useTimeReading.test.tsx b/frontend/src/hooks/useTimeReading.test.tsxindex 8c16841002..5eca240f3a 100644--- a/frontend/src/hooks/useTimeReading.test.tsx+++ b/frontend/src/hooks/useTimeReading.test.tsx@@ -267,6 +267,30 @@ describe("useTimeReading", () => {expect(renders[0]).toBe(2);});+ test("keeps a display's own deadline through a backward step", () => {+ // The step invalidates the value, not the boundary: an absolute instant a+ // display already declared is still when it next changes.+ const deadlineMs = Date.now() + 30_000;+ const { renders } = mount([+ { changesAtMs: onceAt(deadlineMs) },+ // A neighbour on the second, so a tick lands while the clock is still+ // below the mark and the step is detected.+ { changesAtMs: () => Math.floor(Date.now() / 1_000) * 1_000 + 1_000 },+ ]);++ vi.setSystemTime(Date.now() - 5_000);+ act(() => {+ vi.advanceTimersByTime(1_000);+ });+ const afterStep = renders[0];++ // Advance to the deadline it declared, and no further.+ act(() => {+ vi.advanceTimersByTime(deadlineMs - Date.now());+ });+ expect(renders[0]).toBe(afterStep + 1);+ });+test("wakes every display when the wall clock steps backward", () => {// Each boundary was computed on the later clock; on the earlier one it can// be far off in either direction.diff --git a/frontend/src/hooks/useTimeReading.ts b/frontend/src/hooks/useTimeReading.tsindex 79ec3c87a5..2420681069 100644--- a/frontend/src/hooks/useTimeReading.ts+++ b/frontend/src/hooks/useTimeReading.ts@@ -6,7 +6,7 @@ import type { TimeReading } from "@/utils/datetime";** Each subscriber declares the instant its rendering next changes, so the clock* holds one timeout, set for the earliest of those, and wakes only the- * subscribers that are due. A woken subscriber normally re-renders and declares+ * subscribers that are due. A due subscriber normally re-renders and declares* its next instant; one that names the same instant again -- a boundary held* stale, say -- is re-checked after a resync interval rather than on every* neighbour's wake.@@ -74,8 +74,13 @@ function tick(): void {}let nextMs = Number.POSITIVE_INFINITY;for (const subscriber of subscribers) {- if (clockSteppedBack || subscriber.changesAtMs <= nowMs) {+ const isDue = subscriber.changesAtMs <= nowMs;+ if (isDue) {subscriber.changesAtMs = nowMs + RESYNC_MS;+ }+ // A step invalidates the value a display is showing, not the instant it+ // declared: that is absolute, so it survives and still gets its own wake.+ if (isDue || clockSteppedBack) {subscriber.wake();lastWakeMs = nowMs;}