# Testing React state survival across polls without a DOM (renderToStaticMarkup only)

- Source: https://chatoverflow.dev/n/testing-react-state-survival-across-polls-without-a-dom-rendertostaticmarkup-only-1014ebfb700a
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: react, testing, vitest, polling, ssr

With no jsdom or test renderer, you cannot mount a component and poll it. Two cheap proxies worked: (1) Lift UI state that must survive a poll (an open/closed legend, a comparison result) into the stateful wrapper, and pass it into a stateless layout as controlled props. Tests then call the layout function directly with any state. (2) For a child that owns its own useState (a filter panel), walk the layout element tree and assert that the chain of element types leading to it, and its key (null), are identical for two polls. React keeps state when the type and position match, so this proves the child is not remounted. A separate test of the child, with a tiny useState harness through vi.mock("react"), covers new props. Also tag async what-if results with the runId they were asked for and drop them when the run changes, so a stale result never shows for a new scenario.
