Skip to content
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

(Sporadic) Error in Gesto.move component on rotating/scaling (Cannot read properties of undefined (reading 'prevClients') #930

Closed
HolgerSeith opened this issue May 26, 2023 · 5 comments
Labels
bug Something isn't working checking

Comments

@HolgerSeith
Copy link

HolgerSeith commented May 26, 2023

Environments

  • Framework name: React
  • Framework version: 18.2
  • Moveable Component version: 0.50.7
  • Testable Address(optional): unfortunately none

Description

(Thanks alot for your amazing library!)

We get the following sparadic (does not occur each time) error on rotating or scaling. (Seems to happen if you execute rotating / scaling several times)
Similar error is described here: #695 (we have no edge dragging active)
Wo do not have any clue what the problem is or how to fix/workaround it.

Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'prevClients') at Gesto.move (d:\dev\application\node_modules\gesto\src\Gesto.ts:161:9) at setCustomDrag (d:\dev\application\node_modules\react-moveable\src\gesto\CustomGesto.ts:12:5) at fillTransformEvent (d:\dev\application\node_modules\react-moveable\src\gesto\GestoUtils.ts:462:5) at dragControl (d:\dev\application\node_modules\react-moveable\src\ables\Scalable.ts:375:16) at trigger (d:\dev\application\node_modules\react-moveable\src\gesto\getAbleGesto.ts:89:9) at <anonymous> (d:\dev\application\node_modules\react-moveable\src\gesto\getAbleGesto.ts:134:51) at <anonymous> (d:\dev\application\node_modules\react-moveable\src\gesto\getAbleGesto.ts:134:9) at triggerAble (d:\dev\application\node_modules\react-moveable\src\gesto\getAbleGesto.ts:116:5) at <anonymous> (d:\dev\application\node_modules\react-moveable\src\gesto\getAbleGesto.ts:296:17) at <anonymous> (d:\dev\application\node_modules\@scena\event-emitter\src\EventEmitter.ts:150:13) at __proto.emit (d:\dev\application\node_modules\@scena\event-emitter\src\EventEmitter.ts:149:9) at Gesto._this.onDrag (d:\dev\application\node_modules\gesto\src\Gesto.ts:409:17)

Configuration of Moveable:

      <Moveable
        ref={moveableRef}
        origin={true}
        pinchOutside={false}
        pinchable={false}
        snappable={true}
        draggable={true}
        scalable={true}
        target={targetRef}
        keepRatio={keepRatio}
        rotatable={true}
        isDisplaySnapDigit={false}
        isDisplayInnerSnapDigit={false}
        snapDirections={{
          top: true, left: true, bottom: true, right: true, center: true, middle: true,
        }}
	       onDragEnd={
          (e) => {
            if (!e.isDrag) {
              return;
            }
              ...
             }	
		...
/>
@HolgerSeith HolgerSeith changed the title (Sparadic) Error in Gesto.move component on rotating/scaling (Cannot read properties of undefined (reading 'prevClients') (Sporadic) Error in Gesto.move component on rotating/scaling (Cannot read properties of undefined (reading 'prevClients') May 30, 2023
@daybrush daybrush added the bug Something isn't working label May 31, 2023
@daybrush
Copy link
Owner

@HolgerSeith

I'm not sure why either.

I have a few questions about errors.

  1. Is there code that calls .stopDrag?
  2. Have you ever tried multitouch?
  3. Has the cursor ever left the window?
  4. Has the target ever changed? (set, release, change)

@daybrush daybrush added this to the 0.48.0 milestone May 31, 2023
@HolgerSeith
Copy link
Author

  1. No
  2. No
  3. No
  4. (probably) no.

I have managed to reproduce my problem: https://codesandbox.io/s/react-moveable-forked-129q8e?file=/src/App.tsx
(I don't know, whether that is a valid scenario.)
Steps:

  1. Move rectangle to different position
  2. Scale the rectangle

Happens on mouseDown at 2.).
Just happens if you execute the 2nd step quickly after the first.

@daybrush
Copy link
Owner

daybrush commented Jun 1, 2023

@HolgerSeith

I think it's a React 18 async issue.

It is recommended to use flushSync to use Moveable in React 18.
import { flushSync } from "react-dom";

<Moveable
    flushSync={flushSync} />

daybrush added a commit that referenced this issue Jun 2, 2023
@daybrush daybrush removed this from the 0.48.0 milestone Jun 3, 2023
@HolgerSeith
Copy link
Author

Thanks a lot; works for me.

(I close the issue as "completed"; not 100% sure whether that is correct)

@johnsoncherian
Copy link

I face the same issue in my app. But only when I try to resize a component for the first time. If I try again it starts working. flushSync does not work. The targets change dynamically in my app. Any help appreciated. Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working checking
Projects
None yet
Development

No branches or pull requests

3 participants