question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compatibility with Turbo (next version of Turbolinks)

See original GitHub issue

Issue

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:open
  • Created 3 years ago
  • Reactions:25
  • Comments:7

github_iconTop GitHub Comments

3reactions
phoozlecommented, Mar 3, 2021

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.

1reaction
100terrescommented, Sep 14, 2021

Another thing to consider is turbo-frame events once that is merged hotwired/turbo#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 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Turbolinks Compatibility
A collection of tutorials for how to get your favorite javascript libraries, plug-ins, and snippets working with Turbolinks. · Initialization bound to the...
Read more >
How to Upgrade from Turbolinks to Hotwire & Turbo - YouTube
Check out https://gorails.com for Pro episodes and more!▻ SaaS business template for Ruby on Rails with built-in features like Payments, ...
Read more >
How to Upgrade to Turbolinks 5 (Example) - GoRails
The turbolinks/compatibility.coffee file doesn't ship with the gem unfortunately (at least not right now). You'll have to copy it into your ...
Read more >
Developers - Compatibility with Turbo (next version of Turbolinks) -
Coming soon: A brand new website interface for an even better experience!
Read more >
Using Hotwire Turbo in Rails with legacy JavaScript
Update : since Turbo version 7.2.0, explicitly enabling Turbo Frames using data-turbo: true is not needed any more. We can use Turbo Frames...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found