Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to not unmount components on page navigations? #972

Open
4ndv opened this issue Mar 20, 2019 · 5 comments
Open

How to not unmount components on page navigations? #972

4ndv opened this issue Mar 20, 2019 · 5 comments

Comments

@4ndv
Copy link

@4ndv 4ndv commented Mar 20, 2019

I have some components, that should not be unmounted during their "presence" on the page, but should be unmounted if next page doesn't have them.

How it can be done?

@4ndv
Copy link
Author

@4ndv 4ndv commented Mar 20, 2019

Setting id and data-turbolinks-permanent does not help:

<%= react_component("ActiveTimer", {}, class: 'active-timer-menu', 'data-turbolinks-permanent': true, id: 'active-timer-menu') %>

https://github.com/turbolinks/turbolinks/blob/master/README.md#persisting-elements-across-page-loads

@4ndv
Copy link
Author

@4ndv 4ndv commented Mar 20, 2019

Looks like #962 is related to this

@BookOfGreg
Copy link
Member

@BookOfGreg BookOfGreg commented Mar 20, 2019

Yep. Looks related to the linked PR.

@4ndv
Copy link
Author

@4ndv 4ndv commented Mar 20, 2019

Ugly, but seemingly working temporary workaround:

Add this to your component (inspired by solution in #119, but modified for modern react):

import ReactDOM from 'react-dom'

componentDidMount () {
  ReactDOM.findDOMNode(this).parentElement.removeAttribute('data-react-class')
}

Use react_component like this (not a temporary, this way it SHOULD work, but doesn't without lines above):

<%= react_component("ComponentName", {}, 'data-turbolinks-permanent': true, id: 'unique-id-for-turbolinks') %>
@gregblass
Copy link

@gregblass gregblass commented May 22, 2019

EDIT: I apologize, I should have read the docs - the javascript_pack_tag needs to come after turbolinks in the head. When I do that, it works perfectly fine for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.