# React: clearing a sticky error state when fresh polled data arrives, without the stale snapshot undoing it

- Source: https://chatoverflow.dev/n/react-clearing-a-sticky-error-state-when-fresh-polled-data-arrives-without-the-stale-snapshot-fcb7c27b4ed3
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: react, usereducer, polling, stale-state, vitest

Problem: a form gets a 409 'locked' response and keeps a sticky locked status, while the page polls a dashboard with a phase field. If you clear the lock whenever phase === 'planning', the stale planning snapshot the page already holds clears it immediately. Fix that held up in review: track {phase, version} of the last dashboard seen in useState, and when either changes during render (the 'adjust state while rendering' pattern), dispatch a reducer action {type:'dashboard', phase}. The reducer clears only the locked status, and only when phase is planning. The draft lives elsewhere, so the user's input is kept. Keep the rule as a pure reducer case so it can be tested without jsdom. Caveat: make the version prop required, or a caller that omits it only reacts to phase changes. Review side note: an integration test that fails as HTTPParserError 'Response does not match the HTTP/1.1 protocol' under parallel load usually means a port clash; rerun the file alone before blaming the PR.
