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.

After 7.4.5 this.props.connectDragPreview(getEmptyImage() fails intermittently

See original GitHub issue

Describe the bug After 7.4.5 this.props.connectDragPreview(getEmptyImage()) fails intermittently

To Reproduce Steps to reproduce the behavior:

  1. Implement a draggable item
  2. this.props.connectDragPreview(getEmptyImage())
  3. Use 7.4.5, see it works
  4. Use any 7.X later than that and see a drag preview that shouldn’t be there

Expected behavior If I don’t want to see the default “transparent drag image” I shouldn’t

Screenshots The “token” is being dragged down and to the left. Large card is my <CustomDragLayer /> as expected and the transparent “token” is the default react-dnd drag preview I have explicitly turned off image

Desktop (please complete the following information):

  • OS: Linux, Windows, macOS
  • Browser electron
  • Version 4.X

Additional context Love the library, looking at upgraded to 8.x so I can’t say for sure if it happens in the 8 branch but 7 is DEFINITELY having a regression!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
SeaOfTeacommented, Jun 29, 2019

No no, sorry, I’m not a contributor to react-dnd. What I meant is that I was suffering the same issue, but rewrote my component to use the hooks API instead of the ‘Legacy Decorator API’. It seems like the bug is specifically contained to the Legacy Decorator API. I had a look in the code changes for 7.0.0 but couldn’t see anything that should cause this. See the docs (http://react-dnd.github.io/react-dnd/about) You will need v7.6.0 or above, but it will possibly resolve your issue.

An example of the difference would be:

Before:

componentDidMount() {
  this.props.connectDragPreview(getEmptyImage())
}

After:

  const [,, preview] = useDrag({
    item: ITEM,
  });

  useEffect(() => {
    preview(getEmptyImage(), { captureDraggingState: true })
  }, [])
0reactions
SeaOfTeacommented, Jul 4, 2019

@framerate Could you do me a favor: go into your node modules for react-dnd, look for SourceConnector.js and apply this change (5e41e1e#diff-cacafac45de5a5b9470facf20161ce95R181) to see if that corrects your DragPreview problem?

I’ve just tried this myself, and can confirm this fixes the issue for me. @darthtrevino

Read more comments on GitHub >

github_iconTop Results From Across the Web

How does react-dnd's connectDragPreview() work?
The standard preview appears with this code. I then tried to wrap my connectDragSource in my component's render() method with connectDragPreview ...
Read more >
Top 5 react-dnd-html5-backend Code Examples - Snyk
componentDidMount() { // Replace the native drag preview with an empty image. this.props.connectDragPreview(getEmptyImage(), { captureDraggingState: true, }); ...
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