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.

Getting error "Cannot read property 'setAttribute' of undefined"

See original GitHub issue

This 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
kristoferbaxtercommented, Oct 31, 2018

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.

2reactions
pbadenskicommented, Oct 31, 2018

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:

screen shot 2018-10-31 at 17 36 19
Read more comments on GitHub >

github_iconTop 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 >

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