qwen-code/packages/webui/src/hooks
chinesepowered d92c3b27ba
fix(webui): route useLocalStorage functional updates through prev state (#6905)
* fix(webui): route useLocalStorage functional updates through prev state

setValue applied a functional updater to the closed-over storedValue instead
of React's previous state, so two setValue(fn) calls batched in one render
both derived from the same base — the first update was lost and the
stale-derived value was persisted to localStorage. Route the update through
the setStoredValue(prev => …) form and persist the committed value. Adds a
jsdom regression test for the batched-update case.

* refactor(webui): persist via effect and guard against throwing updaters

Address review:
- Restore error handling around the functional updater: a throwing
  updater is caught and leaves state unchanged (previously it could
  propagate through render and crash the tree).
- Move the localStorage write into an effect so the state updater stays
  pure (StrictMode-safe), keeping a first-run baseline ref so the initial
  value is never written on mount.
- Add tests for the no-mount-write contract, invalid-JSON hydration
  fallback, and state updating when setItem throws.
2026-07-15 05:03:04 +00:00
..
useFollowupSuggestions.test.tsx fix(webui): honor skipped followup accept callbacks (#6862) 2026-07-14 15:05:16 +00:00
useFollowupSuggestions.ts fix(webui): honor skipped followup accept callbacks (#6862) 2026-07-14 15:05:16 +00:00
useLocalStorage.test.tsx fix(webui): route useLocalStorage functional updates through prev state (#6905) 2026-07-15 05:03:04 +00:00
useLocalStorage.ts fix(webui): route useLocalStorage functional updates through prev state (#6905) 2026-07-15 05:03:04 +00:00
useTheme.ts feat(webui): migrate icons, Tooltip, WaitingMessage from vscode-ide-companion 2026-01-15 19:53:19 +08:00