Skip to content

Enhanced turbolinks support #962

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

Closed

Conversation

joshleblanc
Copy link

Summary

This does 2 things.

The first is move the mounting to turbolinks:before-render, since that's the earliest event where the user sees content on the page. When it was set to load only, the user wouldn't see any react components until the network request finished, rather than seeing them on the cached page. This fixes #960

The second caches rendered components. If you pass an existing component to ReactDOM, it will update the currently mounted component with the passed component, rather than replacing it.
This allows the data-turbolinks-permanent attribute to work correct. When the cached page is displayed and react_ujs mounts the existing component, it won't destroy the cached component.

This lets you do things like have react components in your layout that aren't affected by page changes, like a navigation component, or search popup.

An example where the navbar/appbar is permanent, but the main page is not:

mk2aly1ba2

@joshleblanc
Copy link
Author

I can't get the tests to run locally, so I can't debug why some of the tests aren't passing.

I'm running into a lot of node-pre-gyp ERR! stack Error: Failed to execute. The bundle exec appraisal install doesn't finish either, because it's looking for a bundler under version 2. Not sure if it's related.

I'll squash all these commits once I figure it out.

@BookOfGreg
Copy link
Member

Hi @HorizonShadow ,
First I'd like to say it's been a while since I was last able to help out here so I'd understand if you're not interested in helping this particular PR through anymore.
I do want to say this looks both valuable and useful to those using Turbolinks so I'd like to help.
I managed to correct the entire test suite for react-rails, basically it was a cascade of old dependencies, JS packages get made and deprecated every week it feels like so keeping up is a hell of a treadmill!
Now that that's fine you should be able to merge master back into your branch and see it cleanly.

If you're still getting gyp related issues, that's a common NodeJS issue that happens for a whole variety of reasons, rm -rf the node_modules (And the ones in test/dummy_apps) usually goes some way to helping.
The other is becuase of the complex support structure of this gem, bundler is stuck at 1.x while we support rails 4.2 still. You may have to gem uninstall bundler and gem install bundler -v 1.17.3

Hopefully this will get us going again. I pulled your branch in locally and their tests now pass on my machine!

@BookOfGreg
Copy link
Member

The one with tests #978 was merged into 2.6.0
This branch can now be removed. Thank you for contributing to the gem!

@joshleblanc joshleblanc deleted the enhanced-turbolinks-support branch July 28, 2019 12:33
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.

Components aren't mounted on turbolinks cache
2 participants