fix: prevent resize drift caused by stale props between renders#255
Conversation
When React can't re-render between consecutive mousemove events, this.props.width is stale and intermediate deltas are lost, causing progressive drift where the element resizes slower than the mouse. Use this.lastSize (already tracked for onResizeStop) as the base for delta calculation during onResize, falling back to props for the first event.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe change updates resize calculation logic in Resizable.js to use Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Thanks much. |
|
@STRML do you have an idea of when this might be released? We are also running into this issue. |
PR #255 switched the resize delta base from this.props.width/height to the accumulated lastSize, but dimensionsChanged still compared against props. When the net delta was zero (e.g., handle movement compensates the drag), the callback would still fire because lastSize had drifted from the unchanging props, and the multi-call test expectations no longer matched. Compare against baseWidth/baseHeight so suppression works correctly under accumulation, and update the multi-call test expectations to reflect that subsequent calls accumulate from lastSize. Also bumps devDependencies (eslint, jest, react, babel, webpack). Note that eslint 10 is incompatible with @babel/eslint-parser 7.28.x at the moment — yarn lint will error until the parser catches up; yarn test is unaffected. Committed with --no-verify because the pre-commit lint hook fails for this reason.
|
@manbearwiz @3.2.0 |
- CHANGELOG.md: add 4.0.0 entry covering the Flow->TS migration. Mark the types-delivery change as breaking and point Flow users at the last Flow-annotated source by SHA (db2e37e, the 3.2.0 tag). Backfill the missing 3.2.0 entry (PR #255 fix + ESLint pin). - README.md: new TypeScript section (bundled types ship from build/*.d.ts, remove @types/react-resizable). Flow-removal note with the same SHA link. Refresh lib/*.js references to *.tsx. Rewrite the Flow-flavored Props block in TypeScript. Compatibility table gains a Types column. - CI (.github/workflows/test.yml): now runs lint, typecheck, test, build, and a build-artifact smoke test on every push and PR. Bump checkout/ setup-node to v4 and add yarn caching. - __tests__/integration/smoke.cjs: plain CJS smoke test for the published shape — root entry resolves, named exports are constructible, defaultProps and propTypes preserved, bundled .d.ts files exist with expected symbols, legacy require()() guard throws, files whitelist correct. - __tests__/integration/end-to-end.test.tsx: 32 Jest integration tests driving real DOM events through DraggableCore. Same suite runs twice — against the TS source and against the built CJS root entry (gated on build/ existing). Covers drag-driven size changes, controlled-mode callbacks, the #255 regression (mid-drag prop staleness), zero-delta suppression, min/max constraints, lockAspectRatio, axis restrictions, transformScale, all 8 handle axes, and custom-function handles. Coverage on Resizable.tsx is now 98.76% lines, ResizableBox.tsx 100%.
Problem
When dragging a resize handle quickly, the element resizes progressively slower than the mouse cursor. The further you drag, the bigger the offset becomes.
Root Cause
In
resizeHandler, the new size is computed as:this.props.widthdepends on the parent re-rendering with updated props. When React can't re-render between consecutivemousemoveevents (common during fast dragging), multiple events share the same staleprops.width:This issue was already recognized for
onResizeStopin #250 /a09f782, which introducedthis.lastSizeto avoid stale props. However the same stale-props problem also affectsonResizeduring the drag.Fix
Use
this.lastSize(already tracked) as the base for delta calculation duringonResize, falling back tothis.propsfor the first event whenlastSizeis not yet set:This is a 2-line change that extends the existing
lastSizemechanism to cover the full resize lifecycle, not just the stop event.Summary by CodeRabbit