-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
TypeError: Cannot add property tableData, object is not extensible #1979
Comments
Can you reproduce that in a sandbox? Because I am using the same architecture and it works for me. Can you also share a console.log of the orders you are adding? Last but not least, can you verify if orders are frozen? |
@Domino987 Ok I will try in sandbox. What do you mean by frozen orders? also if i do:
it works, but this is workaround, not fix |
Yes you are creating a new object with that map, what happens if you do not add the empty tabledata object to it? |
Ok check this sandbox. https://codesandbox.io/embed/pensive-wilbur-j50qd?fontsize=14&hidenavigation=1&theme=dark |
Object.isFrozen(tableData[0]) returns true, so redux toolkit in fact freezes your obejcts. That is causing the errors. I am closing the issue, since this is not a material table error. But the mutation of the passed objects will be removed in the future. |
How soon? I now migrated from React Apollo 2.6 to 3.1 and in new version Apollo locking objects in Apollo cache. So when using these objects with material-table, getting same error. Its preventing to upgrade to Apollo 3.0 and higher. |
For those coming here due to issue I mentioned earlier (incompatibility with @apollo/client). I have found a temporary workaround. In order to avoid the issue of incompatibility between immutable new Apollo cache and requirement of material-table for data to be mutable, I changed InMemoryCache import to be from apollo-cache-inmemory, which most likely will be deprecated soon. Luckily it still works and can be plugged into new Apollo client. So I think material-table should still implement a way to work with immutable data, since the workaround I mentioned above is only temporary till old Apollo package will be deprecated. |
Hi thanks for the workaround for Apollo. I do not know the exact timeline but I will talk to the other maintainers to get started as soon as possible. |
I'm also using new @apollo/client and having same issue after upgrade. |
It works only in some cases. Also same solution was given above by @da1z. |
Same problem with Redux toolkit https://redux-toolkit.js.org/ Is there any plan to stop modifying the input data? |
Same problem with migrating to @apollo/client but I found a more robust solution. If you simply map through the rows and use the function Object.assign({}, buf) you can convert them to writable objects. This works for me. Example:
|
PS: Object.assign can also be used if you use mutations. Just use |
While it is possible, it is very complex and will have impact on performance, especially as the table data size grows. When using Apollo's useMutation to update a record, it will update the record in the Apollo cache (as long it's ID didn't change, which is the normal behavior for updates). The moment it happens, useQuery will cause the component to re-render with new set of data. So now need to iterate through updated data and for each record iterate through original data to find record by ID, because I'm not sure if Apollo will always give data in same order in array (which also requires to have original data in component state, while normally not required for Apollo data, since Apollo already provide re-render mechanism for data changes). |
how did you make it work? When I using apollo-cache-inmemory I get this error:
Another solution is to |
like this:
The link is complex, I create it from split of 3 links - uploadLink, WebsocketLink and authLink. |
Has anyone looked at this issue? I would like to use InMemoryCache provided by Apollo instead of custom one I have to use as a workaround (see workaround provided above). As a solution approach recommendation, please allow us to provide material-table function to mutate data object via new property. This way we can use Apollo facility to mutate object in Apollo cache as described here: #4543 |
There won't be a real fix for this unless |
@chattling I get the same error as @francescovenica. |
Not sure why it doesn't work for you. It works for me. I can give you full code how I create ApolloClient instance to see if something you missed, but like I said, mine is quite complex..
And the versions in package.json are:
|
I'm not sure why this issue was closed, this is definitely still a problem. The |
Yes it's closed because mbrn abandoned the project and we cannot fix this without him. Try the community fork material-table-core with many updates and the data will not be mutated anymore. |
Ah! Thanks @Domino987, I wasn't aware of that fork. I'll take a look and hopefully I can start to use that |
So this happens because the object is frozen and when you pass a frozen object material can not manipulate the data with the frozen object. So you could pass a copy of the object ... for example:
If there is a better solution please show here 👍 |
Hello.
Using this table with redux and react-redux.
and getting error:
My code looks like:
Am I missing something. Thanks!
The text was updated successfully, but these errors were encountered: