React-rails: detectEvents() results in Turbolinks is not defined

Created on 21 Jun 2017  路  5Comments  路  Source: reactjs/react-rails

Help us help you! Please choose one:

  • [ ] My app crashes with react-rails, so I've included the stack trace and the exact steps which make it crash.
  • [x] My app doesn't crash, but I'm getting unexpected behavior. So, I've described the unexpected behavior and suggested a new behavior.
  • [ ] I'm trying to use react-rails with another library, but I'm having trouble. I've described my JavaScript management setup (eg, Sprockets, Webpack...), how I'm trying to use this other library, and why it's not working.
  • [ ] I have another issue to discuss.

I've tried this in a large react-rails app that I've been trying to upgrade to 2.0 as well as a fresh app, neither of which includes turbolinks. I was attempting to debug why ReactRailsUJS.mountComponents() doesn't seem to be running automatically, which is what led me to attempt to call ReactRailsUJS.detectEvents(). I do not see any errors in the console when my page loads, only after calling detectEvents().

> ReactRailsUJS.detectEvents()
detect.js?5263:12 Uncaught ReferenceError: Turbolinks is not defined
    at module.exports (eval at <anonymous> (application.js:3324), <anonymous>:12:5)
    at Object.detectEvents (eval at <anonymous> (application.js:3313), <anonymous>:114:5)
    at <anonymous>:1:15
bug

Most helpful comment

It looks like _this_ line is causing the error, right?

https://github.com/reactjs/react-rails/blob/b39860b69b4c0eb5612169df0c5d8208e7d598dd/react_ujs/src/events/detect.js#L12

Maybe the file should be update to something like

if (typeof Turbolinks !== "undefined" && ...)

?

All 5 comments

Same issue here, can it be used without Turbolinks? Our app extensively use react-router, that conflicts with Turbolinks, would go for disabling the latter, but breaks page loading. We're calling mountComponents() manually as well, but nothing happens
Thanks

It looks like _this_ line is causing the error, right?

https://github.com/reactjs/react-rails/blob/b39860b69b4c0eb5612169df0c5d8208e7d598dd/react_ujs/src/events/detect.js#L12

Maybe the file should be update to something like

if (typeof Turbolinks !== "undefined" && ...)

?

Can we make a PR on this? @reactjs

@rmosolgo Can you give me permission on NPM please?
Not sure what you need to grant me publish, but my account is: https://www.npmjs.com/~bookofgreg

I'll push this out as part of 2.3.1 I think.

Thanks.

Very cool :) I added you as a collaborator, I think that should do it! https://www.npmjs.com/package/react_ujs

Was this page helpful?
0 / 5 - 0 ratings