TypeScript
fix(web): thread jump hints wait for their delay on every hold (#25636)
Julius Marminge5effca10b3eb
diff --git a/apps/web/src/components/Sidebar.logic.browser.test.tsx b/apps/web/src/components/Sidebar.logic.browser.test.tsxindex c7c5e6bcb24..329783cf186 100644--- a/apps/web/src/components/Sidebar.logic.browser.test.tsx+++ b/apps/web/src/components/Sidebar.logic.browser.test.tsx@@ -1,7 +1,7 @@import { describe, expect, it, vi } from "vite-plus/test";-import { render } from "../../test/render";-import { useSnoozeWakeClock } from "./Sidebar.logic";+import { act, fakeTimers, render } from "../../test/render";+import { useSnoozeWakeClock, useThreadJumpHintsVisible } from "./Sidebar.logic";const MOUNTED_AT_MS = Date.parse("2026-10-24T08:00:00.000Z");@@ -31,3 +31,29 @@ describe("useSnoozeWakeClock", () => {await expect.element(screen.getByRole("status")).toHaveTextContent(String(lastWakeMs));});});++function JumpHints(props: { readonly held: boolean }) {+ return <output>{useThreadJumpHintsVisible(props.held) ? "shown" : "hidden"}</output>;+}++describe("useThreadJumpHintsVisible", () => {+ it("waits for the delay again on a second hold", async () => {+ // The first render reads the clock.+ using _timers = fakeTimers({ now: 0 });+ await using screen = await render(<JumpHints held />, {+ // A bare hook host; nothing here links or navigates.+ router: false,+ });+ await act(() => vi.advanceTimersByTime(1_000));+ await expect.element(screen.getByRole("status")).toHaveTextContent("shown");++ await screen.rerender(<JumpHints held={false} />);+ await expect.element(screen.getByRole("status")).toHaveTextContent("hidden");+ await act(() => vi.advanceTimersByTime(1_000));++ await screen.rerender(<JumpHints held />);+ await expect.element(screen.getByRole("status")).toHaveTextContent("hidden");+ await act(() => vi.advanceTimersByTime(1_000));+ await expect.element(screen.getByRole("status")).toHaveTextContent("shown");+ });+});diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.tsindex 475ca412711..90264caa287 100644--- a/apps/web/src/components/Sidebar.logic.ts+++ b/apps/web/src/components/Sidebar.logic.ts@@ -670,10 +670,13 @@ type ThreadStatusInput = Pick<*/export function useThreadJumpHintsVisible(shouldShow: boolean): boolean {const [showAt, setShowAt] = React.useState<number | null>(null);- let nextShowAt = shouldShow ? showAt : null;- if (shouldShow && showAt === null) nextShowAt = deadlineAfter(THREAD_JUMP_HINT_SHOW_DELAY_MS);- if (nextShowAt !== showAt) setShowAt(nextShowAt);- return useDeadlinePassed(nextShowAt);+ // The clock is read inside the updater: the compiler caches a bare clock read+ // in render once per instance, so a second hold would reuse the first deadline.+ // React discards this render and re-runs with the update.+ if (shouldShow !== (showAt !== null)) {+ setShowAt(shouldShow ? () => deadlineAfter(THREAD_JUMP_HINT_SHOW_DELAY_MS) : null);+ }+ return useDeadlinePassed(showAt);}export function resolveThreadLastVisitedAt(