Skip to content

Stop resetting experiment data on window resize (shrink), warn on grow - #221

Draft
meganrm wants to merge 1 commit into
mainfrom
fix/resize-wipes-analysis
Draft

Stop resetting experiment data on window resize (shrink), warn on grow#221
meganrm wants to merge 1 commit into
mainfrom
fix/resize-wipes-analysis

Conversation

@meganrm

@meganrm meganrm commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Problem

Estimated review size: medium

clientSimulator in App.tsx was a useMemo depending on viewportSize.width/height. Any window resize — even shrinking, even a single pixel — recreated the entire BindingSimulator and, as side effects inside the memo body (a React anti-pattern), called setInputConcentration(...) and clearAllAnalysisState(), silently wiping any recorded equilibrium data.

Fixes #224

Solution

Resize handling is now asymmetric and intentional:

  • Shrinking the window never recreates the simulator or clears analysis state — the simulation keeps its existing coordinate space.
  • Growing the window still recreates the simulator (a bigger box needs more agents at the same concentration, so this is necessary) and still clears analysis state.
  • The first time a grow-triggered reset fires in a session, a one-time antd Modal.warning() explains why, so students aren't surprised mid-experiment.

setInputConcentration/clearAllAnalysisState were also moved out of the useMemo body into a separate useEffect keyed on [currentModule, sectionType], so they only fire on real experiment changes, never as a useMemo side effect.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Change summary:

  • Stop recreating the simulator / wiping analysis state when the window shrinks
  • Warn once (session-scoped) before a grow-triggered reset actually clears data
  • Move setInputConcentration/clearAllAnalysisState into a useEffect keyed on [currentModule, sectionType], out of the useMemo body

Steps to Verify:

  1. Record an equilibrium point, then shrink the browser window
  2. Confirm the recorded data is still there
  3. Record another point, then grow the window
  4. Confirm a warning modal appears (first time only this session), then data resets
  5. Grow/shrink again in the same session — confirm no repeat warning
  6. Switch modules — confirm concentrations/analysis still reset as before, independent of window size

Screenshots (optional):

Keyfiles (delete if not relevant):

  1. src/App.tsx

Thanks for contributing!

…riggered reset (B2, B4)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@meganrm
meganrm requested a review from a team as a code owner August 12, 2026 17:43
@meganrm
meganrm requested review from frasercl and interim17 and removed request for a team August 12, 2026 17:43
@meganrm
meganrm marked this pull request as draft August 12, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analysis state silently wiped on window resize (useMemo side effects)

1 participant