Preact: componentDidMount fires before child component is attached to DOM

Created on 24 Feb 2016  路  7Comments  路  Source: preactjs/preact

I have an easy repro here: http://jsfiddle.net/pvbvj23o/

bug has fix help wanted

Most helpful comment

Yup, on my to-do list. thx.

All 7 comments

Interesting. Debugger shows it's attached to the parentNode from <App>, but <App> hasn't yet been appended to the DOM itself. I'd love to avoid deferring componentDidMount(), since that would cost a traversal during render, but that might be the only way. Are you sure React only calls this hook once the whole tree is mounted?

Maybe just a straight up queue would be okay here. It only happens at the root (because render() is special-cased).

Looks like React only calls the hook once the element is mounted: https://jsfiddle.net/x6xpdkjL/

The docs seem to confirm: https://facebook.github.io/react/docs/component-specs.html#mounting-componentdidmount

Awesome, thanks for investigating. I'll try to look into this tonight. I have confirmed the bug is still present in 4.0.1.

Still present in 4.5.

Yup, on my to-do list. thx.

Hooray!! 馃憦 馃帀 馃嵒

Released in 5.2.0-beta.0.

Was this page helpful?
0 / 5 - 0 ratings