stackblitz / core

Online IDE powered by Visual Studio Code ⚡️
https://stackblitz.com
MIT License
10.33k stars 930 forks source link

Remount component so componentWillUnmount() runs #39

Closed philholden closed 5 years ago

philholden commented 7 years ago

I am experiencing problems with setInterval(). This is because componentWillUnmount() is not getting called when the view is refreshed on key presses. I am making a network request every minute on setInterval. But a new request is being created every minute for every key stroke in the editor.

I had the same problem in ReactPlaygroundStyled and got round it by unmounting the root before re-eval:

ReactDOM.unmountComponentAtNode(this.mountNode)

https://github.com/ncredinburgh/react-playground-buble/blob/master/packages/react-playground-bare/src/components/react-playground-bare.js

EricSimons commented 7 years ago

Good catch — I actually implemented this a while back but it must've gotten overridden 😅 Will fix asap!

For the time being, here's a working example that you can fork off of that will do this properly: https://stackblitz.com/edit/unmount-react?file=index.js