Cannot read property 'data' of undefined
See original GitHub issueI’m using Goober with Preact (and Twin), and I’m having some difficulties making Goober play ball with Shadow DOM.
When I try to run something like this:
const shadowRoot = document.getElementsByTagName('app-shadow-section')[0] || false;
if( shadowRoot ) {
goober.css.call({ target: shadowRoot }, `color: red !important;`);`
}
…it does correctly add the styles (color: red !important;
) to the shadow component (app-shadow-section
), but it also gives a console error that kills the app:
Uncaught (in promise) TypeError: Cannot read property 'data' of undefined
at goober.modern.js:1
at s (goober.modern.js:1)
at Object.p (goober.modern.js:1)
at a (goober.modern.js:1)
at p.constructor (goober-global.modern.js:1)
at p.M [as render] (preact.module.js:1)
at I (preact.module.js:1)
at m (preact.module.js:1)
at I (preact.module.js:1)
at m (preact.module.js:1)
(As an aside, if I try to get the styles from a shadow component (const styleTag = ``<style id="_goober">${goober.extractCss( shadowRoot )}</style>``;
) I get a similar error:
goober.modern.js:1 Uncaught (in promise) TypeError: Cannot read property 'data' of undefined
In both cases, the shadow component exists in the DOM (as I can console log its dom node, and see the style correctly applied to it). I thought it might be related to lifecycle (etc) so tried the same code in useEffect
, but the results are exactly the same.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
angularjs - typeerror cannot read property 'data' of undefined
This error comes because there is no property of name data in your class. $scope.gridOptions. this class ...
Read more >[SOLVED] Cannot Read Property of Undefined in JavaScript
The “cannot read property of undefined” error occurs when you attempt to access a property or method of a variable that is undefined...
Read more >TypeError: Cannot read property 'data' of undefined
[0] (node:24430) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async ...
Read more >Cannot read property 'data' of undefined #1463 - GitHub
Describe the bug Loading for my profile seems to be broken. In the defense of this project though, I have a bit of...
Read more >Cannot read property 'data' of undefined in React web
Like Nuno said, it means that the JavaScript running on the device / browser is acting on invalid elements. In another words, this...
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
Oops, sorry about that. The ENV vars aren’t secret or anything; rather, there were different ones for local development.
Try creating a
.env
file in the project root with:I will also try to get a codesandbox together later
Hey – I have the public repo itself if that helps?
But I can put it onto CodeSandbox if that’s easier?
(Note: In this repo I’ve hacked together a kind-of workaround in
/src/widget/index.js
by manually moving the CSS from the<head>
to inside the Shadow DOM, via pure JavasScript).In an earlier version, inside the same
useEffect
function, I setgoober.css.bind
andgoober.styled.bind
, which weren’t working for me.