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

Tree: onDrop should not attempt a copy of node values #5080

Closed
hugo-vrijswijk opened this issue Oct 11, 2023 · 0 comments · Fixed by #5081
Closed

Tree: onDrop should not attempt a copy of node values #5080

hugo-vrijswijk opened this issue Oct 11, 2023 · 0 comments · Fixed by #5081
Assignees
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@hugo-vrijswijk
Copy link
Contributor

Describe the bug

onDrop does a JSON.parse(JSON.stringify(props.value)) to copy nodes. I assume this has to do with reference equality. This has a few issues when implementing drag'n'drop:

  1. Information is lost. As values are serialized/deserialized they do not always serialize back into the same object. Some cases of this include Date, Map, Set, Regexp, BigInt, Infinity, functions and custom classes
  2. Not all values are serializable. Circular structures cannot be serialized to JSON, thus throwing a TypeError

Reproducer

https://codesandbox.io/s/primereact-test-forked-p5vxlv?file=/src/index.js

PrimeReact version

10.0.3

React version

17.x

Language

ALL

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

  1. Open sandbox

  2. Drag one node to another

  3. Observer circular reference TypeError

  4. Comment out node 3

  5. Drag one node to another

  6. Observe console.log with different data than the original node

Expected behavior

Drag'n'drop should not edit node data.

I'm willing to add a PR for this. I made a small test and just copying the values array seems to work fine. Is this expected? Or should a more deeper/recursive copy be done?

@hugo-vrijswijk hugo-vrijswijk added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Oct 11, 2023
@melloware melloware added Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Oct 11, 2023
@melloware melloware modified the milestone: 10.0.4 Oct 11, 2023
@melloware melloware added Status: Discussion Issue or pull request needs to be discussed by Core Team and removed Status: Discussion Issue or pull request needs to be discussed by Core Team labels Oct 11, 2023
@melloware melloware added this to the 10.0.4 milestone Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants