Skip to content

When using turbolinks, unmount components just before loading the new page #85

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

Merged
merged 1 commit into from
Sep 10, 2014
Merged

When using turbolinks, unmount components just before loading the new page #85

merged 1 commit into from
Sep 10, 2014

Conversation

rmosolgo
Copy link
Member

@rmosolgo rmosolgo commented Sep 5, 2014

I'm migrating my project to React & Turbolinks. I have a non-optimized page which exposed this issue.

I think the react_ujs unmounts components sooner than it has to. It unmounts on page:before-change, but I think it could wait until page:receive.

Here's the difference it made for me. In the GIF below, the chart & list of times is a React component. The "stations" link is another page that takes a long time to load.

page:before-change

Notice the blank state while it waits for the page from the server.

earlier_unload

page:receive

The components are left around til the new page gets here.

later_unload

What do you think? Is there a downside to this?

@rmosolgo
Copy link
Member Author

rmosolgo commented Sep 5, 2014

Another point for this issue:

If you use Turbolinks.visit (and consequently, redirect_via_turbolinks_to on the server), the before-change event is never fired (since a link is never clicked). Since before-change isn't fired, componentWillUnmount hooks aren't executed. My flux changeHandlers are still attached!

However, receive is fired by Turbolinks.visit, so this patch should solve that issue, too.

@zpao
Copy link
Member

zpao commented Sep 7, 2014

I don't know anything about Turbolinks events, but those gifs are pretty convincing. I assume receive is still before the content is actually replaced? cc @meleyal who's done some of our work there.

Also, #69 just went in so you'll need to rebase.

@rmosolgo
Copy link
Member Author

rmosolgo commented Sep 8, 2014

Yes, thats right -- from the turbolinks readme:

  • page:receive the page has been fetched from the server, but not yet parsed

Ok, rebased, looks good locally!

@meleyal
Copy link
Contributor

meleyal commented Sep 9, 2014

Tested locally and this looks good

zpao added a commit that referenced this pull request Sep 10, 2014
When using turbolinks, unmount components just before loading the new page
@zpao zpao merged commit 45ca4ad into reactjs:master Sep 10, 2014
@zpao
Copy link
Member

zpao commented Sep 10, 2014

👍 thanks!

@rmosolgo rmosolgo deleted the later-turbolinks-unmount branch September 10, 2014 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants