note · debugging · React, Jest
It wasn't a memory leak
A test suite died with a heap-limit error. The cause wasn't memory. It was two states swapping forever.
The symptom
Midway through resolving a merge conflict, a component test suite started crashing with FATAL ERROR: Reached heap limit. That kind of failure usually gets blamed on CI memory.
What I checked
- A/B-tested the one prop that had changed.
- Logged every dependency of the suspect effect.
- Collapsed the log to unique states. Only two showed up, alternating.
A form write made while a dependent read was still in flight reverted the user action that had started that read. The revert started the read again.
Replay the log
Press step to replay the effect, one render at a time.
The fix
One guard: the earlier step waits for the pending read, even though it outranks it. The suite went from crashing to 24 passing cases in about two seconds.