fix: use stored size in onResizeStop to prevent stale data
Merged
ST
10mo ago+122+122+012345678901234567890123456789-5-5-0123456789
Summary
Fix a bug where onResizeStop would report stale/incorrect size data due to React's batched state updates.
The Problem
onResizeStop was recalculating size from props.width/height, but due to React's batched state updates, these props may not have updated yet when onResizeStop fires. This caused the callback to report stale/incorrect size data, particularly noticeable with west/north handles.
This bug was identified in react-grid-layout: https://github.com/react-grid-layout/react-grid-layout/pull/2224
The Fix
- Store the last calculated size during
onResizein a newlastSizeinstance variable - Use that stored value in
onResizeStopinstead of recalculating from potentially stale props - Reset
lastSizealong with other internal data on resize stop and unmount
Changes
lib/Resizable.js: AddlastSizetracking and use it inonResizeStop__tests__/Resizable.test.js: Add tests for the stale props scenario
Test plan
- Lint passes
- Flow type checking passes
- Tests pass (requires #249 to be merged first for test infrastructure)