-
Notifications
You must be signed in to change notification settings - Fork 214
[bug] Uncaught TypeError: Cannot assign to read only property 'chosen' of object '#<Object>' when using 6.0.4 with immutable data #237
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
Comments
If anyone comes this way, I was able to fix this issue on my side with:
I think the point that the library shouldn't modify the state it receives should still stand... It should only read it. |
I'm having the same issue using data from my Redux store on v6.1.4. |
@ecfaria works with version 6.0.3 |
Same issue using Redux with Redux Toolkit here, with react-sortablejs v6.1.4 |
I am seeing the same issue in 6.1.1 while using React 18 and Recoil. Also, this only shows when React.StrictMode is used |
Also React 18 + Recoil + StrictMode, is there any solution? |
Yeah, I am seeing the same issue with zustand and react-sortablejs v6.1.4. |
Any fix? |
same issue... import { useMemo } from "react";
import {
ItemInterface,
ReactSortable,
ReactSortableProps,
Sortable as SortableLib,
Store,
} from "react-sortablejs";
function arrayEquals(a: any, b: any) {
return (
Array.isArray(a) &&
Array.isArray(b) &&
a.length === b.length &&
a.every((val, index) => val === b[index])
);
}
export default function Sortable<T extends ItemInterface>({
children,
list,
setList,
...rest
}: ReactSortableProps<T>) {
const mutableList = useMemo(() => {
return list.map((item) => ({ ...item }));
}, [list]);
function handleList(updatedList: T[], sortable: SortableLib | null, store: Store) {
if (
!arrayEquals(
updatedList.map((l) => l.id),
mutableList.map((l) => l.id),
)
) {
setList(updatedList, sortable, store);
}
}
return (
<ReactSortable list={mutableList} setList={handleList} {...rest}>
{children}
</ReactSortable>
);
} |
Uh oh!
There was an error while loading. Please reload this page.
Hi!
Everything works fine for me in v6.0.3 but as soon as I use 6.0.4 or above, I get the error mentioned above.
I've tried 6.1.x as well but the issue is still present. It seems to be due to the changes made in this commit: 362cbd5
Spreading (as done in 6.0.3) seems to work fine but
Object.assign
won't work.Note:
immer
so that could be related.react-sortable
(orsortable
?) is adding extra keys to the list of objects passed into the props. It feels like it could create bugs easily.To Reproduce
Steps to reproduce the behavior:
Expected behavior
For Sortable to work beautifully just like in 6.0.3 ;)
Information
This is required. Issues without this critical information will be closed.
Versions - Look in your
package.json
for this information:react-sortable = 6.0.4
react = 17.0.2
Additional context
I'm doing nesting and it works flawlessly 🤷♂️
The text was updated successfully, but these errors were encountered: