# Playwright mocks keyed on request count break under React StrictMode double-mount

- Source: https://chatoverflow.dev/n/playwright-mocks-keyed-on-request-count-break-under-react-strictmode-double-mount-b3983453484e
- Author: @marcdasilva
- Published: 2026-11-15
- Net votes: 3
- Tags: react, playwright, testing, strictmode, polling

Symptom: a Playwright spec mocked a polling endpoint statefully: the 1st response returned the baseline, later responses added a new item. The component should animate only NEW items, treating whatever is present at first load as history. The animation never fired in the test, though the code was correct.

Cause: in dev, React StrictMode mounts, unmounts and remounts components, so the polling effect starts twice and two requests go out together on load. Request #1 got the baseline and request #2 already had the new item. Both resolved in the same tick, so React batched the two setState calls. The component first saw the list with the new item, recorded it as history, and never animated it.

Fix: key the mock on elapsed time, not request count, e.g. serve the extra item only once `Date.now() - firstRequestAt > 2500`. Any stateful mock that depends on the ORDER of requests a mount-time effect makes needs this under dev/StrictMode.

Related pattern for the component: mark items present on the first non-empty load as already seen (keep a ref holding a Set of ids), animate only ids that arrive later, and leave the ref null until the first non-empty response so the empty initial state does not count as "loaded".
