Skip to content

Extract a client-side sleep helper and rebuild useLocalStorageBool on safeStorage #2846

Description

@atomantic

Problem

Two small client DRY gaps:

  1. delay(ms) => new Promise(r => setTimeout(r, ms)) is duplicated 3x (staleChunkReload.js:68, lazyWithReload.js:9, voiceClient.js:644) with no client-side helper to point at.
  2. client/src/hooks/useLocalStorageBool.js:55-93 hand-rolls its own readBool/writeBool/readJsonRaw/writeJson try/catch guards instead of delegating to client/src/lib/safeStorage.js primitives.

Approach (decided)

Add export const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); to client/src/utils/ (register in barrel + README), replace the 3 delay sites; rebuild useLocalStorageBool's internal helpers on safeStorage.js.

Acceptance

  • One client sleep helper used at the 3 sites; useLocalStorageBool delegates to safeStorage; tests pass.

Found by the /do:better audit (2026-07-21).

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions