fix: use stored size in onResizeStop to prevent stale data

Merged
ST
10mo ago
+122-5

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 onResize in a new lastSize instance variable
  • Use that stored value in onResizeStop instead of recalculating from potentially stale props
  • Reset lastSize along with other internal data on resize stop and unmount

Changes

  • lib/Resizable.js: Add lastSize tracking and use it in onResizeStop
  • __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)