refactor(web): collapse duplicated focus-retry loops and pointer hint lists - #3079
Conversation
… lists Three cleanups to duplication that recent work left behind. `event.util.ts` carried three near-identical animation-frame retry loops (`focusCalendarEventElement`, `focusCalendarEventElementAfterDiscard`, `refocusEventElement`), each with its own copy of the magic 30 and its own off-by-one accounting: two tried 30 times, the third tried 31. Collapse them onto one `focusAcrossFrames` helper with a single named budget; each caller now supplies only the predicate that finds its target. Its test file repeated the same rAF-stubbing harness three times; that is now built once. `PointerHint`'s `isContextualAttempt` enumerated every pointer action id, so each new action had to be registered twice (here and in `pointerHintMessage`) or the hint would flash for 400ms instead of 2500ms. It now derives from the attempt: anything that is not `unknown` is contextual. The same file hardcoded its shortcut letters instead of reading the shared constants, and one had already drifted: the event-open hint advertised `S` to reveal event shortcuts, but the binding is `h` (`KEYMAP.eventJump`), and `S` is the Saturday/Sunday jump prefix. Both letters now come from the constants that own them, with a regression test on the corrected copy. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DCRGg7GX4J57nPqVVDvsFs
|
The same What the failing job actually did: every test it ran passed, the last one ( It also cannot be this diff: the change is four files under Re-running the failed jobs in that run once. Every other check on this head is green: Generated by Claude Code |
Summary
Technical-debt sweep over changes merged in the last 7 days (#3017–#3078). Three pieces of duplication that recent work left behind, one of which had already drifted into a user-visible bug.
1. Three copies of the same animation-frame retry loop (
packages/web/src/common/utils/event/event.util.ts)focusCalendarEventElement,focusCalendarEventElementAfterDiscard, andrefocusEventElementeach carried their owntryFocusclosure, their own copy of the magic30, and their own off-by-one accounting (++attempts < 30,attempts < 30,attemptsLeft-- > 0) — so two of them retried 30 times and the third retried 31. They now share onefocusAcrossFrames(findTarget, { startOnNextFrame })helper with a single namedFOCUS_RETRY_FRAMESbudget; each caller supplies only the predicate that finds its target. The 31st retry is gone, which is the only behavior change.2. A pointer-action list that had to be maintained in two places (
PointerHint.tsx)isContextualAttemptenumerated every entry ofPOINTER_ACTIONSplus both grid kinds — i.e. "everything exceptunknown" spelled out longhand. It grew by one line per PR (startTrialin #3050,reconnectGooglein #3064,upNextDismissin #3074); forgetting to extend it makes a new action's hint flash for 400ms instead of 2500ms. It now derives from the attempt directly.3. Hardcoded shortcut letters that had drifted from the constants that own them (
PointerHint.tsx)The start-trial hint hardcoded
Srather thanSTART_TRIAL_SHORTCUT_KEY, and the event-open hint advertisedPress S to reveal event shortcuts— but the binding ish(KEYMAP.eventJump), andSis the Saturday/Sunday jump prefix, so following the hint did something else entirely. That copy came in with #3017 and had no test. Both letters now read from the constants, and the corrected copy has a regression test.Simplicity
Net line count is roughly flat, but three retry loops become one and two parallel lists become zero: adding a pointer action or remapping
hno longer requires editing a second place that nothing enforces. The test file's rAF-stubbing harness was also written out three times and is now built once.Automated validation
bun test:web— 1537 pass, 0 fail (182 files)bun run lint— exit 0 (same 23 pre-existing warnings asmain)bun run type-check— cleanBehavior-preserving apart from the two intended corrections: the 31st retry in
refocusEventElement, and the event-open hint now namingHinstead ofS.Independent review
Not run — this is a self-contained refactor with existing coverage on all three focus helpers and on every
PointerHintmessage branch. The diff is 4 files / 243 lines, inside theautofix-merge-guard.shrails (≤8 files, ≤250 lines, no denylisted path).Test plan
Added:
focusCalendarEventElementgives up once the retry budget is spent;PointerHintteaches the event-jump key when no sequence is assigned yet.🤖 Generated with Claude Code
https://claude.ai/code/session_01DCRGg7GX4J57nPqVVDvsFs
Generated by Claude Code