Skip to content

React component doesn't work with jquery3 #762

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
1 of 4 tasks
ghost opened this issue Aug 6, 2017 · 8 comments
Closed
1 of 4 tasks

React component doesn't work with jquery3 #762

ghost opened this issue Aug 6, 2017 · 8 comments

Comments

@ghost
Copy link

ghost commented Aug 6, 2017

  • My app crashes with react-rails, so I've included the stack trace and the exact steps which make it crash.
  • 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.

When I replace jquery (which makes everything work fine) with jquery3 (https://github.com/rails/jquery-rails#installation), my React component is included in the final HTML, however, I can't see it in the browser itself. Also, no errors are displayed in the JS console.

application.js.coffee:

#= require jquery3
#= require jquery_ujs
#= require react
#= require react_ujs
#= require_tree ./components

➙ Screencast showing the issue

@rmosolgo
Copy link
Member

Hi! thanks for sharing that screencast. Looking at the jQuery 3 upgrade guide, it looks like there were several changes to event handlers.

I guess we should

Maybe our usage there needs to be updated!

@Deekor
Copy link

Deekor commented Sep 8, 2017

My react component won't render if I have any version of jQuery required in my applications.js

I tried

  • //= require jquery
  • //= require jquery2
  • //= require jquery3

My component would only show if I didnt have a require for jQuery. I am seeing no errors in my console.

@Deekor
Copy link

Deekor commented Sep 8, 2017

Looks like if I move the jQuery require below //= require components it works.

@BookOfGreg
Copy link
Member

@Deekor I have just documented that observation in https://github.com/reactjs/react-rails/wiki/Troubleshooting , thanks!
May do some work to check how the detector is working with the variety of jQuery versions.

@BookOfGreg
Copy link
Member

From @duckworth at #742 (comment)

Ran into this as well and it was due to jquery3 removing .on("ready", fn) that react_ujs is binding to.
https://jquery.com/upgrade-guide/3.0/#breaking-change-on-quot-ready-quot-fn-removed

The problem is likely to be with this:
https://github.com/reactjs/react-rails/blob/master/react_ujs/src/events/detect.js#L22

BookOfGreg added a commit that referenced this issue Feb 5, 2018
fix(#762): ensure react is mounted in Jquery3
@BookOfGreg
Copy link
Member

Could someone confirm it's fixed in the pre-release of the gem?
https://rubygems.org/gems/react-rails/versions/2.4.4.pre
Also there's a npm tag of "pre" for the UJS too for those using webpack.

@duckworth
Copy link

I just tested with 2.4.4 and can confirm that I no longer need to manually call ReactRailsUJS.mountComponents()

Thanks!

@BookOfGreg
Copy link
Member

Thanks all for the help with this one 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants