Closed milantarami closed 9 months ago
Hi.
Cannot read properties of undefined (reading 'disabled')
This error suggests that you are doing something like object.disabled
where object
is undefined.
This may not be related to the TreeItem component but rather how you handle functions.
If you still think the error is related to the component, can you provide a codesandbox that reproduces the error?
You can fork this template: https://material-ui.com/r/issue-template-latest
The problem is here . It trying to access undefined properties node.disabled
& node.parentId
It worked when
Fix1 : replace node.disabled
with node?.disabled
in line 148, 154
Fix2: replace node.parentId
with node?.parentId
in line 152
Hey, Thanks. I just had a look, and we already check if node
is undefined or not first before checking node.disabled
or node.parentId
. Could you console.log node
in your case and tell me what it is?
yeah but can you show me where it is checked if node
hasOwnProperty disabled
& parentId
before accessing it ... may i didn't find it
yeah but can you show me where it is checked if node hasOwnProperty disabled & parentId before accessing it ... may i didn't find it
I don't think this is relevant to your error, and we actually don't need it because isDisabled
function already has if conditionals to check if these values exist. If node.disabled
or node.parentId
was undefined, the function would've just returned false
and an error throw is not expected. The error you shared tells us that node
is undefined. As I asked, Could you console.log node
in your case and tell me what it is?
I had set disabled prop default false. I don't think this is a issue with node , node looks find but what is this unexpected bug. Note : this was working fine in v4 This disabled prop is introduced in v5 and i am getting this unexpected bug
It throws error in random tree node.
Can you provide a codesandbox that reproduces the error?
You can fork this template: https://material-ui.com/r/issue-template-latest
Since the issue is missing key information, and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information.
So, does somebody know how to fix that? I have same issue.
So, does somebody know how to fix that? I have same issue.
I was getting the error "Uncaught TypeError: Cannot read properties of undefined (reading 'disabled')", Stack appears to have the error somewhere in the TreeItem code.... (Not a Javacsript expert, so my be wrong, but I'm pretty sure the error did no originate in my code...)
TypeError: Cannot read properties of undefined (reading 'disabled')
at TreeItem (http://localhost:3000/static/js/bundle.js:42204:82)
<rest of call stack snipped>
the root cause turned out to be adding nodes with duplicate NodeId. Uniquifying NodeId's stopped this. YMMV
@jsteinbergTCALLC That's not the only problem, I'm literally having a set of nodes, each one have a complete different nodeId. Yet I get the same issue.
So, does somebody know how to fix that? I have same issue.
I had solved the issue by creating a override of an file and module replacement in webpack config in my laravel project
const webpack = require("webpack");
const path = require("path");
// Define your asset paths
const jsSrc = "resources/js";
const jsDist = "public/dist/js";
// Mix Configuration
mix.js(`${jsSrc}/app.js`, `${jsDist}/app.js`)
.react()
.extract(["react", "react-dom"])
.webpackConfig({
resolve: {
extensions: [".js", ".jsx", ".json"],
alias: {
"@": path.resolve(__dirname, jsSrc),
},
},
plugins: [
new webpack.NormalModuleReplacementPlugin(
new RegExp(
"node_modules\\/@mui\\/x-tree-view\\/internals\\/plugins\\/useTreeViewNodes\\/useTreeViewNodes\\.js$"
),
path.resolve(
__dirname,
"./node_modules_overrides/@mui/x-tree-view/internals/plugins/useTreeViewNodes/useTreeViewNodes.js"
)
),
],
});
// BrowserSync Configuration
mix.browserSync({
proxy: "localhost:8000",
open: false,
notify: false,
});
// Additional Production Configuration
if (mix.inProduction()) {
mix.version();
}
Duplicates
Latest version
Current behavior 😯
Note : this was working fine in v4 recently i upgraded to v5
i am building a tree view with an async data which works well at first but randomly clicking the label which fetches async data & build children ..... at some point of random clicks it throws error Can't read disabled property at TreeItem
Expected behavior 🤔
No response
Steps to reproduce 🕹
No response
Context 🔦
No response
Your environment 🌎
Tested on : Microsoft Edge latest version Mozilla latest version Chrome latest version