Skip to content

Components not cleaned up with turbo links navigation, part 2. #1184

Description

@jdelStrother

(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 ..?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions