Getting error "Cannot read property 'setAttribute' of undefined"
See original GitHub issueThis issue can be quite overwhelming, happened to me when trying to use worker-dom with a pretty large library (https://github.com/handsontable/handsontable).
Error stack:
Uncaught TypeError: Cannot read property 'setAttribute' of undefined
at Object.0 (mutator.js:69)
at MUTATION_QUEUE.forEach.mutation (mutator.js:134)
at Array.forEach (<anonymous>)
at syncFlush (mutator.js:133)
at requestAnimationFrame (mutator.js:122)
Code in mutator.js (Line 69 highlighted with a comment):
[1 /* CHARACTER_DATA */](mutation, target) {
const value = mutation[18 /* value */];
if (value) {
// Sanitization not necessary for textContent.
target.textContent = getString(value);
} // **Line 69**
},
Seems that target
is undefined
. I added some debugging code to storeNodes
and it never stores the node with id
that is being requested. id
requested is 28 & storeNodes
only gets called starting with 68.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
JS - Cannot read property 'setAttribute' of null - Stack Overflow
It is because all of your calls to document.getElementById are failing to find anything since there aren't any elements with those IDs.
Read more >TypeError: Cannot read property 'setAttribute' of undefined
Can confirm it is caused by nested tables. Worked around the issue by using a list inside the grid. Just an FYI, this...
Read more >TypeError: Cannot read property 'setAttribute' of undefined
Currently I am using ckeditor version 4.5. 7. and in this version I am facing issue with "Uncaught TypeError: Cannot read property 'setAttribute'...
Read more >uncaught type error cannot read property set attribute of ...
When we create a custom ui component in Magento 2, it shows the console error “Uncaught TypeError: Cannot read properties of undefined (reading ......
Read more >Uncaught TypeError: Cannot read property 'setAttribute' of null ...
This is not an Awesomplete bug, but a result of how the DOM works. :) You are running your code before the DOM...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That is so awesome to see! Your patch makes sense, and we should address the issue.
We have an open PR #135 which likely fixes the issue in a different manner, by inverting the current hydration system… moving hydration from main-thread to worker.
I spent a bit more time debugging this. Based on my relatively shallow and mostly intuitive understanding I created a PoC fix: https://github.com/pricingmonkey/worker-dom/commit/146361baec36767971174d534fab854166898794
I think it might be that creating detached nodes might be causing an issue, since it was only document.body that was passed in during hydration. I extended hydration from single element to array of nodes & added passing of all nodes. It solved this issue.
P.S. Once this is resolved handsontable (which is quite complex JS library) rerenders via worker-dom! This project is absolutely amazing 😄
I know this might not be the right place… I’m extremely excited seeing how nicely the UI rerendering gets offloaded to the webworker, so let me share this: