8000 [bug] Uncaught TypeError: Cannot assign to read only property 'chosen' of object '#<Object>' since upgrade to v6.1.0 · Issue #228 · SortableJS/react-sortablejs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[bug] Uncaught TypeError: Cannot assign to read only property 'chosen' of object '#<Object>' since upgrade to v6.1.0 #228

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

Closed
Saul-Mirone opened this issue Feb 1, 2022 · 5 comments

Comments

@Saul-Mirone
Copy link

Describe the bug
After upgrate the react-sortablejs version from 6.0.3 to 6.1.0, I got this error everytime I click on my sortable list:

Uncaught TypeError: Cannot assign to read only property 'chosen' of object '#<Object>'

To Reproduce
Steps to reproduce the behavior:

  1. Go to my repo: https://github.com/Saul-Mirone/vite-plugin-book
  2. Upgrade the react-sortablejs version to 6.1.0 in packages/vite-plugin-book/package.json
  3. Run pnpm install, pnpm dev and pnpm doc in root
  4. Click on the sidebar and see error.

Expected behavior
Just work normally as v6.0.3

Information
Uncaught TypeError: Cannot assign to read only property 'chosen' of object '#'

Versions - Look in your package.json for this information:
react-sortable = ^6.0.3
react = ^x.x.x

Additional context
I use nested sortable list.

@Saul-Mirone
Copy link
Author
Saul-Mirone commented Feb 1, 2022

Update:
Is it possible that it's caused by this PR?
#226

@andresin87
Copy link
Member
andresin87 commented Feb 8, 2022

@Saul-Mirone
Copy link
Author

Still don't know why but things work fine after I made this change:
Saul-Mirone/vite-plugin-book@b949839#diff-811aee71034d5086fa8e1e23d182c2f20de005829cb071a0c1a0cf2cf4476a02R58

@conduct0
Copy link
conduct0 commented Mar 14, 2023

Still don't know why but things work fine after I made this change: Saul-Mirone/vite-plugin-book@b949839#diff-811aee71034d5086fa8e1e23d182c2f20de005829cb071a0c1a0cf2cf4476a02R58

I think it is because if you destructure the object, even if it was frozen by immer or something like that, will send a copy that can be modified. From what I saw the object is being mutated here:

// make all state false because we can't change sortable unless a mouse gesture is made.
const newList = [...props.list].map(item => Object.assign(item, {
  chosen: false,
  selected: false
}));

If I for example would make a shallow copy of item like this it wouldn't modify the original frozen object:

const newList = [...props.list].map(item => Object.assign({...item}, {
  chosen: false,
  selected: false
}));

What do you think about updating this method here?
I would be happy to submit a pull request.

@henryobiaraije
Copy link

Any fix for this yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0