Description
(I'd originally mentioned this in #1028, but since that's closed I wanted to open an issue for it to get some extra visibility)
Steps to reproduce
- Write a component that performs cleanup in componentWillUnmount
- visit a page containing that component
- navigate away with turbolinks
Expected behavior
componentWillUnmount is called
Actual behavior
componentWillUnmount is never called
System configuration
Sprockets or Webpacker version: 6.4.1
React-Rails version: -
Rect_UJS version: 2.6.2
Rails version: 7.0.2
Ruby version: 3.1
What's the expected way of cleaning up react components on leaving the page?
Some of our components use setInterval to do something every x seconds, which call clearInterval in componentWillUnmount. Others might load and/or decode a large file, which gets aborted in componentWillUnmount.
I could possibly clean these up by having each component listen for turbolinks cleanup events, but having those components have to know that they're living in a turbolinks+react_ujs stack seems like unnecessary coupling.
I think this used to work, but PR1135 removed cleanup in favour of fixing the scroll-position restoration. That seems like something that should have been fixed upstream in Turbolinks rather than removing component-unmounts from ReactUJS ..?