Skip to content

Conversation

@STRML
Copy link
Collaborator

@STRML STRML commented Dec 30, 2025

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: react-grid-layout/react-grid-layout#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

@github-actions
Copy link

No changes in the dependency files were detected.

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.

The fix stores the last calculated size during onResize and uses that
stored value in onResizeStop instead of recalculating.

Fixes: react-grid-layout/react-grid-layout#2224
- Rewrite stale props tests using RTL refs instead of Enzyme
- Update onResizeStop test to include onResize call (new behavior)
- Fix test expectations for west handle position tracking
@STRML STRML force-pushed the fix/onResizeStop-stale-data branch from 03ef56b to 1483828 Compare December 30, 2025 22:21
@github-actions
Copy link

No changes in the dependency files were detected.

@STRML STRML merged commit a09f782 into master Dec 30, 2025
3 checks passed
@STRML STRML deleted the fix/onResizeStop-stale-data branch December 30, 2025 22:22
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.

2 participants