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.

Expected to find a valid target.

See original GitHub issue

This is reproducible by simply using the Tree-to-tree dragging example in development mode.

How: Select a node to copy/move to the last position of another tree and drag it a little bit more under that. Reason: It is looking for a targetId which is not there. If the last valid target id is T3, this will cause the dnd to look for a targetId of T5, which is not there. DragDropMonitorImpl.js is where I debugged this. Example: SortableError

Source Code:

import React, { Component } from 'react';
import SortableTree from 'react-sortable-tree';
// In your own app, you would need to use import styles once in the app
// import 'react-sortable-tree/styles.css';

class App extends Component {
  constructor(props) {
    super(props);

    this.state = {
      treeData1: [
        { title: 'node1', children: [{ title: 'node 1.1' }] },
        { title: 'node2' },
      ],
      treeData2: [{ title: 'node3' }],
      shouldCopyOnOutsideDrop: false,
    };
  }

  render() {
    // Both trees need to share this same node type in their
    // `dndType` prop
    const externalNodeType = 'yourNodeType';
    const { shouldCopyOnOutsideDrop } = this.state;
    return (
      <div>
        <div
          style={{
            height: 350,
            width: 350,
            float: 'left',
            border: 'solid black 1px',
          }}
        >
          <SortableTree
            treeData={this.state.treeData1}
            onChange={treeData1 => this.setState({ treeData1 })}
            dndType={externalNodeType}
            shouldCopyOnOutsideDrop={shouldCopyOnOutsideDrop}
          />
        </div>

        <div
          style={{
            height: 350,
            width: 350,
            float: 'left',
            border: 'solid black 1px',
          }}
        >
          <SortableTree
            treeData={this.state.treeData2}
            onChange={treeData2 => this.setState({ treeData2 })}
            dndType={externalNodeType}
            shouldCopyOnOutsideDrop={shouldCopyOnOutsideDrop}
          />
        </div>

        <div style={{ clear: 'both' }} />

        <div>
          <label htmlFor="should-copy" style={{ fontSize: '0.8rem' }}>
            Enable node copy via <b>shouldCopyOnOutsideDrop</b>:
            <input
              type="checkbox"
              id="should-copy"
              value={shouldCopyOnOutsideDrop}
              onChange={event =>
                this.setState({
                  shouldCopyOnOutsideDrop: event.target.checked,
                })
              }
            />
          </label>
        </div>
      </div>
    );
  }
}

export default App;

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
sinanyaman95commented, Jun 17, 2021

I am no longer using this library, but I had figured out that this error is only visible in development mode. No such error in production mode.

2reactions
pasieronencommented, Feb 13, 2021

There’s an open PR #740 that should fix this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught Error: Invariant Violation: Expected to find a valid ...
When simulateBeginDrag began, it sent the drop target (instead of the drag source) to the validator, which correctly failed. The solution was to ......
Read more >
React DnD Expected to find a valid target - Stack Overflow
If one of the items belongs to another parent I get "Expected to find a valid target." as soon as the drag over...
Read more >
gaearon/react-dnd - Gitter
and i try to create a mini demo , first dnd is ok, but second is Uncaught Invariant Violation: Expected to find a...
Read more >
React Dnd Expected To Find A Valid Target - ADocLib
and i try to create a mini demo first dnd is ok but second is Uncaught Invariant Violation: Expected to find a valid...
Read more >
"Uncaught Invariant Violation: Expected to find a valid target ...
"Uncaught Invariant Violation: Expected to find a valid target." after cancelling a drag into the react sortable tree.
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