question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ghyoo91commented, 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.

0reactions
floelecommented, 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]);
                    }
            }
        }}
    />
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read properties of undefined (reading 'id')
I have this error in my terminal: TypeError: Cannot read properties of undefined (reading 'id').
Read more >
Cannot read properties of undefined (reading 'id') - TrackJS
TypeError is a subset of JavaScript Error that is thrown when code attempts to do something that does not exist on the target...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
The TypeError: Cannot read property of undefined is one of the most common type errors in JavaScript. It occurs when a property is...
Read more >
cannot read properties of undefined (reading 'id') angular
The following exception is thrown: "ERROR TypeError: Cannot read properties of undefined (reading 'ID')". Expected result. The method should return the index of ......
Read more >
sfdx force:auth:web:login results in Cannot read properties of ...
"Cannot read properties of undefined (reading 'id'). This is most likely not an error with the Salesforce CLI. Please ensure all information ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found