-
-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Conditionally update positions onResizeStop
causes strange jiggle
#900
Comments
I came up with a workaround. The idea is setting a key on the Rnd element, and update the key if the function MyRnd() {
const [state, setState] = useState({x, y, width, height })
const [key, updateKey] = useReducer(x => x + 1, 0)
const onResizeStop = useCallback(() => {
if (!shouldCommitResize()) {
updateKey();
return;
}
setState(newState);
});
return (
<Rnd
key={key}
position={{...}}
size={{...}}
onResizeStop={onResizeStop}
/>
);
} I've implemented this on the issue codesandbox |
The issue is that In my case, it can be solved by removing this line as it seems that an update is not needed at that point anyway. Line 515 in 23d312c
Did not check whole state flow or codebase, so I am not sure from which part that wrong value comes from, but it is definitely a wrong value, and it would be better to fix it there instead of removing the line above. |
@bokuweb It might be easier for you to spot where exactly the issue comes from, but if you are tight on time, I could possibly do a pull request. |
@Rados51 Thanks. If it's okay, may I request a pull request? |
Overview of the problem
I'm using react-rnd 10.4.1 [x.x.x]
My browser is: Chrome 108.0.5359.125 on Windows
I am sure this issue is not a duplicate?
Reproduced project
https://codesandbox.io/s/react-rnd-conditionally-resize-jiggle-cvkm8d?file=/src/App.tsx
Description
I want to implement a rnd block in controlled mode, with the constraint that if the block violates some rules (in the above case, the rule is cross the black line) when resizing, then bypass the operation.
It seems to work after resizing. However, when refocus on the rnd block, a strange jiggle happened. But the states (x/y/width/height) aren't changed.
Steps to Reproduce
Expected behavior
The rnd block stays where it was before resizing
Actual behavior
The rnd block moves.
The text was updated successfully, but these errors were encountered: