From 419080c7c8a8d3adb0a24a08eb078e3e32bc564f Mon Sep 17 00:00:00 2001 From: bokuweb Date: Sun, 21 Apr 2024 13:12:59 +0900 Subject: [PATCH] 6.9.14 (#804) * fix: 713 * 6.9.13 * fix: onResize * fix: onResize * 6.9.14 --- CHANGELOG.md | 2 +- package.json | 2 +- src/index.tsx | 24 ++++++++++++------------ stories/auto.stories.tsx | 6 +++++- stories/snap.stories.tsx | 15 +++++++++++++-- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f67092a6..84c5455c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ ### :house: Internal --> -## [6.9.13 (2024-04-21)](https://github.com/bokuweb/re-resizable/compare/v6.9.13...v6.9.11) +## [6.9.14 (2024-04-21)](https://github.com/bokuweb/re-resizable/compare/v6.9.14...v6.9.11) ### :bug: Bug Fix diff --git a/package.json b/package.json index a7fa6427c..0ab3ef9fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "re-resizable", - "version": "6.9.13", + "version": "6.9.14", "description": "Resizable component for React.", "title": "re-resizable", "main": "./lib/index.es5.js", diff --git a/src/index.tsx b/src/index.tsx index 975128c45..352f19d99 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -797,16 +797,12 @@ export class Resizable extends React.PureComponent { newWidth = newSize.newWidth; newHeight = newSize.newHeight; - let widthChangedWithGrid = false; - let heightChangedWithGrid = false; if (this.props.grid) { const newGridWidth = snap(newWidth, this.props.grid[0]); const newGridHeight = snap(newHeight, this.props.grid[1]); const gap = this.props.snapGap || 0; const w = gap === 0 || Math.abs(newGridWidth - newWidth) <= gap ? newGridWidth : newWidth; const h = gap === 0 || Math.abs(newGridHeight - newHeight) <= gap ? newGridHeight : newHeight; - widthChangedWithGrid = w !== newWidth; - heightChangedWithGrid = h !== newHeight; newWidth = w; newHeight = h; } @@ -853,16 +849,20 @@ export class Resizable extends React.PureComponent { newState.flexBasis = newState.height; } - // For v18, update state sync - flushSync(() => { - this.setState(newState); - }); + const widthChanged = this.state.width !== newState.width; + const heightChanged = this.state.height !== newState.height; + const flexBaseChanged = this.state.flexBasis !== newState.flexBasis; + const changed = widthChanged || heightChanged || flexBaseChanged; + + if (changed) { + // For v18, update state sync + flushSync(() => { + this.setState(newState); + }); + } if (this.props.onResize) { - if (!this.props.grid) { - this.props.onResize(event, direction, this.resizable, delta); - // fix #783 - } else if (widthChangedWithGrid || heightChangedWithGrid) { + if (changed) { this.props.onResize(event, direction, this.resizable, delta); } } diff --git a/stories/auto.stories.tsx b/stories/auto.stories.tsx index 9bd450d71..08471b499 100644 --- a/stories/auto.stories.tsx +++ b/stories/auto.stories.tsx @@ -4,7 +4,11 @@ import { storiesOf } from '@storybook/react'; import { style } from './style'; storiesOf('auto', module) - .add('default', () => 001) + .add('default', () => ( + console.log(e)}> + 001 + + )) .add('height', () => ( { + console.log(a); + }} > 001 )) .add('grid', () => ( - + { + console.log(a); + }} + > 001 ));