-
Notifications
You must be signed in to change notification settings - Fork 754
Webpacker + Turbolinks + ReactRailsUJS = 😞 #899
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
Comments
👀 |
Was last tested in #868 where I fixed a double mount. Edit: I understand what you mean now, yes when I tested that Turbolinks was loaded via sprockets. |
@BookOfGreg Should I try coming up with a solution to avoid relying on Turbolinks being global, or should I expand the README to clarify this possibility? The former is probably more "correct", but will require greater changes. |
In general this gem should avoid making changes or having specific integrations with other gems/packages. How are you supposed to deal with overloading I'd rather not make Turbolinks global to make the detector keep working, if possible lets document what the fix is and then look into something to replace the detector in both Sprockets and Webpack worlds. |
Use setup instructions from reactjs/react-rails#899 to get Turbolinks + webpacker + react-rails to work correctly
Steps to reproduce
Create a new Rails app that uses Webpacker for assets, and
import
s Turbolinks (as opposed to using Sprockets for Turbolinks as seems to be the case for this repo's tests).Run
ReactRailsUJS.detectEvents()
to set up Turbolinks' events.Expected behavior
ReactRailsUJS
shouldmount
andunmount
React components on the corresponding Turbolinks events.Actual behavior
Those events don't get fired.
System configuration
Webpacker: 3.2.0
React-Rails version: 2.4.4
React_UJS version: 2.4.4
The reason this happens is because React-Rails expects Turbolinks to be a global object. If you're using Webpacker, by default everything is local, causing React-Rails to think that Turbolinks is not installed.
(My attempt to solve this via using a
webpack.ProvidePlugin
to turn Turbolinks into a global did not work, becauseTurbolinks.start()
needs to be called before React-Rails, elseTurbolinks.controller
isundefined
.)I'm not sure this can be considered a bug, so instead I'll just share how I solved this. If this is intended, perhaps it can be added to README / Uncyclo? (I can create a PR if desired!)
My solution:
Cheers!
The text was updated successfully, but these errors were encountered: