Uncaught (in promise) TypeError: Cannot read property 'firstChild' of undefined
Opened this issue · 2 comments
avdeev commented
Doesn't work for me. Failed with this error:
preact-shadow-root.es.js:17 Uncaught (in promise) TypeError: Cannot read property 'firstChild' of undefined
at o.update (preact-shadow-root.es.js:17)
at o.shouldComponentUpdate (preact-shadow-root.es.js:8)
at A (index.js?c988:113)
at eval (children.js?b0ec:95)
at x (children.js?b0ec:252)
at x (children.js?b0ec:254)
at b (children.js?b0ec:43)
at $ (index.js?c988:347)
at A (index.js?c988:205)
at eval (children.js?b0ec:95)
iongion commented
I've go the same, apparently, this.base
is null in componentDidMount
iongion commented
I found a possible source for this, at least in my case
const node = document.creatElement('<div>');
render(
<LoginDialog
mode={context.mode}
onLogin={options.onLogin}
onLogout={options.onLogout}
passwordRecoveryUrl={options.passwordRecoveryUrl}
/>,
node,
node.firstElementChild as Element
);
So, the way I am injecting this is the culprit, node.firstElementChild
is obviously empty.
Solution
const node = document.creatElement('<div>');
node.innerHTML = '<div></div>'; // <------ THIS LINE SOLVES IT, MAKES A firstElementChild exist
render(
<LoginDialog
mode={context.mode}
onLogin={options.onLogin}
onLogout={options.onLogout}
passwordRecoveryUrl={options.passwordRecoveryUrl}
/>,
node,
node.firstElementChild as Element
);