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

TypeError: Cannot read properties of undefined (reading 'id') #705

Closed
floele opened this issue Dec 21, 2022 · 8 comments
Closed

TypeError: Cannot read properties of undefined (reading 'id') #705

floele opened this issue Dec 21, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@floele
Copy link

floele commented Dec 21, 2022

Hi,

unfortunately I cannot reproduce reliably, but it seems that with the introduction of #619 the following exception occurs:

       Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'id')
    at material-table.js:1273:1
    at Array.map (<anonymous>)
    at reduceByDefaultSort (material-table.js:1271:1)
    at getDefaultCollectionSort (material-table.js:1261:1)
    at MaterialTable.setDataManagerFields (material-table.js:776:1)
    at MaterialTable.componentDidUpdate (material-table.js:835:1)
    at commitLifeCycles (react-dom.development.js:20684:1)
    at commitLayoutEffects (react-dom.development.js:23426:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)

It occurs when switching views in my application, so I assume when loading/unloading tables.
Reason seems to be that sometimes the list of sort columns does not contain objects with a "tableData" object attached:

image

  • OS: Win11
  • Browser: Edge, Firefox

Any ideas?

@floele floele added the bug Something isn't working label Dec 21, 2022
@Domino987
Copy link
Contributor

Can you provide a sandbox?

@floele
Copy link
Author

floele commented Dec 24, 2022

I did try to reproduce it in a sandbox but wasn't successful.

@Domino987
Copy link
Contributor

Ok that makes it difficult to validate. Did you use the latest version in the sandbox?

@floele
Copy link
Author

floele commented Dec 25, 2022

I created a new sandbox based on the link in the bug description: https://codesandbox.io/s/material-table-starter-template-forked-474it9?file=/src/index.js

I suppose it should have been the latest version in this case?

@Domino987
Copy link
Contributor

Domino987 commented Dec 25, 2022

Yes always, or else might has been fixed or introduced between versions. But the sandbox works for me, soooo😅

@floele
Copy link
Author

floele commented Dec 25, 2022

I know that in my app the problem gets fixed if I remove the defaultSort attribute from the column but as mentioned before I was unable to reproduce that in a sandbox. This is an example table definition that causes issues:

    <MaterialTable
        columns={[
            { title: "Name", field: "description", defaultSort: "asc", editable: "never" },
            { title: "Value", field: "value" },
        ]}
        options={{
            paging: false,
            showTitle: false,
            actionsColumnIndex: 2,
            padding: "dense"
        }}
        data={settings}
        editable={{
            isEditable: (rowData) => true,
            isDeletable: (rowData) => false,
            onRowUpdate: (newData, oldData) =>
            {
                    const newList = [...settings];
                    const target = newList.find((el) => el.key === oldData?.key);
                    if (target) {
                        const index = newList.indexOf(target);
                        newList[index] = newData;
                        setSettings([...newList]);
                    }
            }
        }}
    />

@ghyoo91 ghyoo91 mentioned this issue Dec 28, 2022
@ghyoo91
Copy link

ghyoo91 commented Dec 28, 2022

It can be reproduced in this page : https://codesandbox.io/s/new-tree-znzku?file=/src/App.js

And I think the reproduction's conditions are

  1. Use defaultSort option in the columns.
  2. Prior componentDidUpdate before the data is applied.(In codesandbox, I just add the "setData([])")

I made a pull request for fix this case, but there may be a better solution.

@Domino987
Copy link
Contributor

Is fixed in the latest version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants