Compatibility with Turbo (next version of Turbolinks)
See original GitHub issueIssue
The next version of Turbolinks, now called Turbo (available for Rails via turbo-rails), is in beta and react-rails
should be updated to be compatible. The new interface is similar to the old one, the events are just called differently.
The relevant events are now called turbo:load
and turbo:before-render
instead of turbolinks:load
and turbolinks:before-render
. A new event script along the following lines should do the trick:
// in react_ujs/src/events/turbo.js
module.exports = {
setup: function(ujs) {
ujs.handleEvent('turbo:load', ujs.handleMount);
ujs.handleEvent('turbo:before-render', ujs.handleUnmount);
},
teardown: function(ujs) {
ujs.removeEvent('turbo:load', ujs.handleMount);
ujs.removeEvent('turbo:before-render', ujs.handleUnmount);
},
}
Along with this some changes to the detection script will be required, but I’m not familiar enough to be able to tell exactly what needs to be added.
Hotfix
I have solved this issue in my app by adding the following two lines to the application.js
script:
// earlier: var ujs = require("react_ujs");
ujs.handleEvent('turbo:load', ujs.handleMount);
ujs.handleEvent('turbo:before-render', ujs.handleUnmount);
For anyone already using Turbo and looking to also use react-rails
, the above is a hotfix until it’s implemented in the package.
Thanks to the contributors for taking a look at this.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:25
- Comments:7
Top GitHub Comments
Another thing to consider is turbo-frame events once that is merged https://github.com/hotwired/turbo/pull/59
At the moment React components that come in via a frame do not mount even with the above hotfix. And as per the above PR there is currently no existing events to tap into.
@phoozle They’ve added
turbo:frame-render
event https://github.com/hotwired/turbo/pull/327 🙂