componentWillUnmount sometimes called after unmounting?
See original GitHub issueHi
I am experiencing a case where componentWillUnmount
is called after it is unmounted.
See this fiddle: https://jsfiddle.net/0tdkrhhh/1/
And here is the minimal code:
import preact from 'preact';
class A extends preact.Component {
componentDidMount() {
console.log('A.componentDidMount, '+document.querySelectorAll('.a').length)
}
componentWillUnmount() {
console.log('A.componentWillUnmount, '+document.querySelectorAll('.a').length)
console.log(document.body.innerHTML)
}
render() {
return (
<p class="a">A</p>
)
}
}
const B = () => {
return (
<div></div>
)
}
const app = document.getElementById('preact-app')
preact.render(
<div id="preact-app">
<A/>
<B/>
</div>,
document.body,
app
)
preact.render(
<div id="preact-app">
<B/>
</div>,
document.body,
app
)
The output is
A.componentDidMount, 1 <-- DOM element was found
A.componentWillUnmount, 0 <-- DOM element was not found
<div></div> <-- DOM structure
but as I understand the function componentWillUnmount
the output should be
A.componentDidMount, 1 <-- DOM element was found
A.componentWillUnmount, 1 <-- DOM element was found
<div><p class="a">A</p></div> <-- DOM structure
By the way, if component <B> is omitted, everything works as expected.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Why did componentDidMount run after componentWillUnmount?
componentWillUnmount will be called once when the component is getting unmount. But I observed in the console that componentDidMount is being ...
Read more >How to use componentWillUnmount with Functional ...
I want to display an dialog box on unmount and When user cancels it should stop unmounting the component. Right now, even if...
Read more >ReactJS componentWillUnmount() Method - GeeksforGeeks
The componentWillUnmount() method allows us to execute the React code when the component gets destroyed or unmounted from the DOM (Document ...
Read more >Component Lifecycle | Build with React JS
Components are unmounted when the parent component is no longer rendered or the parent component performs an update that does not render this ......
Read more >Prevent React setState on unmounted Component
The shown warning(s) usually show up when this.setState() is called in a component even though the component got already unmounted.
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 FreeTop 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
Top GitHub Comments
@developit I found it vdom/diff.js#L228 This has been uninstalled but componentWillUnmount triggered on:
so top-level render and setState() are all the same
Repair the code
I need open a pull request?fix
This is fixed in
master
👍