question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Projected position is wrong

See original GitHub issue

Describe the Bug

After making use of react-dnd and adding simple drag and drop support, i found that the projected position I am getting is completely off. What makes it even more irregular is that it doesnt always happen. So when not moving the camera/view at all, sometimes it would project correctly sometimes not. But as soon as you move around and the transform changes form [0,0,1], the projected position starts to jump around.

I’ve included a sandbox, just open it up and try dropping. If it doesnt happen, try refreshing once or twice and try again. Its very irregular and doesnt always happen.

Your Example Website or App

https://codesandbox.io/s/sandpack-project-forked-2pwdnu?file=/App.js

Steps to Reproduce the Bug or Issue

  1. Open sandbox
  2. Try dropping once
  3. If it doesnt project wrong, refresh
  4. Try again
  5. Repeat from steps 2-4 with diferent usecases, such as first panning or zooming then dropping.

Expected behavior

It should calculate the correct position

Screenshots or Videos

https://user-images.githubusercontent.com/45233935/184307094-06069039-1a75-4b60-ab43-cb83bf5509ff.mov

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Wiz1991commented, Aug 15, 2022

The issue here is that reactflow.project gets updated after the first render but not the reactflow object itself.

Easiest way to fix this:

const { project } = useReactFlow();

pass that project function to the onDrop deps array => everything works as expected.

Yeah, was about to update the issue with this. Did not notice the react-dnd hook was memoized. Works as expected.

1reaction
bcakmakoglucommented, Aug 12, 2022

Seems like your position calculation is not correct.

This works completely fine for me in the sandbox you linked:

const offset = monitor.getClientOffset();

const position = {
        x: offset.x,
        y: offset.y
	};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix data when it appears in the wrong place - Learn ArcGIS
The only way to undo the tool is to run it again and redefine the original coordinate system. Click Run.
Read more >
Wrong position when reprojecting layers from EPSG:32651 ...
I solved it. I used the define projection tool to solve the problem where the layer has same projection but different extent.
Read more >
Projection Error When Evaluating True Position of Threaded ...
My quality team is telling me there is projection error when evaluating the .030" true position on the opposite end of the part...
Read more >
Tissue Projection Errors - Practical Panoramic Imaging
Hard Tissue Projection Errors. 1. Spine – The first hard tissue error can occur when the patient assumes the “head extended” position.
Read more >
Do your projected views in a Solidworks drawing seem to be ...
Do your projected views in a Solidworks drawing seem to be wrong? Here's how you can solve it. Report ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found