-
Notifications
You must be signed in to change notification settings - Fork 367
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
Resize handle lagging behind mouse cursor #237
Comments
Thanks, this is the first I've heard of something like this. We use I'd say what's more concerning is that you're "losing" data somehow, which should never happen. It sounds like something is capturing mouse events or creating an early exit from |
I have a similar problem. |
@smooth038 can help me solution? |
Here are the changes we made. Simply run a Hope this helps! fix-resizing-and-dragging-issues.zip By the way, we did not investigate further why the issue was arising, as we have other priorities and the problem is now fixed. But I will keep you updated if I have any news. EDIT: Just in case, the |
@smooth038 - Thank you for your patches. Using same solution as |
Problem Report
We have been using react-grid-layout for some time in our application, as we have a dashboard page with many different resizable and draggable widgets. We had no problem for the longest time.
Recently, we did an upgrade of our main UI library, and somehow the performance of the application dropped noticeably, but not too big a deal. Except for one thing, when we resized or dragged a widget in a dashboard with many other widgets, the handle would move 2-3 times more slowly than the mouse cursor, creating an increasing gap between the two, and making the resizing/dragging process very difficult and unpleasant.
We could not find any obvious issue with our code, other than the fact that the application needs some important refactoring in order to limit the number of unnecessary re-renders and improve the overall performances, but that will have to wait a little bit. We also noticed that the issue was already there before the major library update, only on a much smaller scale and no one would notice it.
Since the issue seemed to come from the react-grid-layout and react-resizable libraries, we investigated and found a way to fix the issue within the libraries' code.
When dragging or resizing, the resulting size or position of the widget is calculated in the
resizeHandler
by adding the difference in X and Y of every mousemove event, using thedeltaX
anddeltaY
fields of the event. In our case, it seems that for some reason, only some proportion of the mousemove events were actually processed, while others would be dropped, which means that the sum of all deltas was not equivalent to the displacement of the cursor.I modified the code so that instead, we would do the following (this example is for react-resizable but we did something equivalent in react-grid-layout for dragging) :
onResizeStart
event, save the original size of the widget (props.width
andprops.height
) and the position of the mouse cursor at beginning of resize (lastX
andlastY
of the event, which are absolute values)resizeHandler
, calculate the resulting size by using the original size and adding the difference between the actual cursor position (lastX
andlastY
) and the initial position of the cursor at beginning of resize.By doing this, we were able to effectively correct the problematic behavior that we had and made a custom version of both libraries that we published on our local artifactory repository.
I tried to reproduce the issue by using your sandbox link (thank you!) and adding some artificial processing (finding a certain number of prime numbers for fun) in the rendering of the widgets in the hope of making the browser drop some mouse events, but with no luck. Maybe some of you may have an idea on how we could reproduce this? If useful, maybe I can share a video of the bug, but I'll probably need to hide some stuff because of non-disclosure agreements, so it will take me a bit of time.
I understand that, unless we can reproduce this consistently, we can't really consider this as a bug in the library. However, I wanted to raise the issue in case other people experience it, and see what you guys think about this. I wonder, was there a reason why we are using the
deltaX/Y
approach rather than usinglastX/Y
?If you are interested in seeing the modifications that we made to fix the issue on our end, let me know and I can open a PR.
Thanks a lot for your time,
System Info
Node Version: 20.8.1
Browser: Chrome, Firefox, Edge (was fine on a mac with Arc, but I think that's because the machine was really fast)
OS: Ubuntu, Windows
Reproduction
Unfortunately I was unable to reproduce the issue in a sandbox, but here is how we reproduced it in our application:
The text was updated successfully, but these errors were encountered: