-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Drop jQuery as a dependency #25208
Comments
Actually I'm working on jquery-ujs rewrite to pure JS. My first test is living in https://github.com/simi/jquery-ujs/tree/no-jquery. |
I think @pixeltrix wanted to do this as GSoC project, so I'm pinging him here as well. |
I think I can't attend GSoC, but definitely I'm really interested in this and I would like to finish it. At least I can provide alternative implementation. |
Grabbed assignment for this one. @simi (and others), I'd be happy to review your implementation if you want to see it through. |
I do agree that this would make a lot of sense as a GSoC project, or a first patch for a newcomer, as it's a solid self contained change that's pretty straightforward. We'd be doing a disservice to those trying to find a way to get into OSS by handling this ourselves |
Sounds like a good time to apply our newest label, |
Note: There's no reason that someone looking to work on this needs to do the entire migration as a single PR -- changing one piece of ujs to not rely on jQuery at a time would make sense |
Hey, what form of browser support are you looking for here? I don't mind personally landing a hand. If browser support needs to work for older IE versions than I doubt it'll save much space because of polyfills but it will still be worth our while. |
There is also https://github.com/hauleth/vanilla-ujs |
Don't think that supporting legacy browsers is something we need to have On Wed, Jun 1, 2016 at 2:38 PM, Benjamin Gruenbaum <notifications@github.com
|
Ah, https://github.com/hauleth/vanilla-ujs looks like exactly what we've been searching for. @javan do you want to take a look at that? If we can just adopt that, all the better. |
vanilla-ujs looks pretty solid, and perhaps we can use it as a starting point. I don't like that it exposes some unnecessary globals (I spotted |
@javan I just checked - it only exposes them for debugging they are not actually required. It will trigger a DOM custom event with It is only exposed with https://github.com/hauleth/vanilla-ujs/blob/master/lib/assets/javascripts/vanilla-ujs/csrf.js#L20 - it is not used anywhere sans tests and can be safely removed. IE8 and below are not supported but then again we shouldn't really support legacy browsers. LiteAjax and others can be shared, I think this can be easily build into a single module wrapped in an IIFE - other things aren't using |
@simi vanilla ujs has existed for quite some time. :) |
👍 Additionally, it would be nice to use |
@mhuggins nice. I'm reviewing that also. |
That'd be nice |
@hauleth What do you think about turning vanilla-js into a Rails PR? |
@dhh I know Rails doesn't treat backwards compatibility as an important goal, but only supporting modern browsers will mean maintaining legacy Rails applications is going to be even more challenging. There are still plenty of places where developers are stuck supporting users on legacy browsers. It would be great if the current version of ujs was kept around and officially supported (maybe renamed |
@lucaspiller current implementation lives in https://github.com/rails/jquery-ujs. I think it will be still supported and you'll be able to point manually in gemfile to that. The current approach is to make new default and avoid https://github.com/rails/jquery-ujs. PS:
That's not true IMHO. |
@lucaspiller What @simi said. The current jquery-based approach would still be available as a plugin, but the default would change. |
@dhh I would be pleased. |
One of the main ideas in the philosophy of a software framework is to ease the burden of program developer. Rails does this perfectly nowadays by providing a really useful set of tools and libraries. On the other hand, Ruby on Rails developers often do Javascript code, which in most cases lives in the Rails application itself and I understand the idea behind this issue is to decrease the number of dependencies. However in reality this change means that most developers will do the manual installation of JQuery as the first step after "rails new [app]". So -- combining the statements above with JQuery download stats (http://npm-stat.com/charts.html?package=jquery), the question: Is it really really a good decision? |
I think so. Also you can easily do |
I assumed that vanilla-ujs was meant to be a drop-in replacement for jquery-ujs but it currently only fires two ( |
@liudangyi Right, of course, thanks. |
@jjb Do you have evidence that CoffeeScript is preferred over JS by Rubyists? I for one have come to loathe CoffeeScript, so I'm curious what the basis of your consideration is. |
I do not have evidence. My statement was based on coffeescript syntax and grammar being more similar to ruby than it is to javascript. |
@dhh @rafaelfranca Which approach is better? |
I think @liudangyi's approach will be the best. |
ActionCable had cable.coffee replaced by cable.js for exactly this reason, I'd prefer that CoffeeScript was avoided as a dependency. |
Hello, all. I have finished most of the work now, which is available here. All tests are passed, with some necessary modifications in API. However, I cannot test all the cases, so any reviews or suggestions are welcome. :) |
Please do open a pull request with the changes. On Mon, Aug 1, 2016 at 1:46 AM Dangyi Liu 刘当一 notifications@github.com
|
FYI, rails/jquery-ujs#474 is finished and ready for review |
The vanilla ujs implementation by @liudangyi is now living in https://github.com/rails/rails-ujs I'll ask to get #26836 updated so the users of Yarn can get this in their default package.json file instead of
What do you prefer? |
I'm partial to #1. It's just one compiled file. Seems a little much to distribute as a gem and make it a dependency. I would have it be part of Action View since it's needed as a baseline for those helpers to work. |
But that means that if we need to upgrade that file for security reasons we
|
If there's an update, we can also just release that dist file again for people to copy in. Don't think that should be the blocker. Agree that for people who use a dependency manager, that should be the default. But if we are not committing to that as a requirement at the moment, then I think a single dist file is fine. But I also don't care THAT much. So if you're very passionate about a gem wrapper, then fine by me.
|
The pull request for this: #27113 |
What happened to the github repo? https://github.com/rails/rails-ujs is showing 404 not found...did you decide to revert back to jquery-ujs? |
It was merged into actionview, in rails/rails: https://github.com/rails/rails/tree/master/actionview/app/assets/javascripts |
Given that it has been merged into actionview, does one still need to install it via npm or yarn? I saw some discussion re: a gem for rails-ujs, will that continue to be maintained? For those of us used to working with gems rather than npm or yarn, I'd prefer the gem route rather than having to remember to update via some other method (e.g. npm/yarn). |
@professorNim, you can install it either way. See https://github.com/rails/rails/tree/master/actionview/app/assets/javascripts#readme |
Isn't the Working with Javascript in Rails doc now quite misleading? Almost all of the code relies on jQuery. Is an update to this doc on the core team agenda, or are PR's welcome here? |
Hi, I will repeat here my opinion about the topic. Then it is confusing. Following the tutorials of the Unobtrusive JavaScript you get coffeescript errors (silent error indeed), and it should work out-of-the-box. I'll try to elaborate more my reply:
Then, I think Rails was created with the intention to be the on the easy way. By default everything should be included, so everything (typical) would work out-of-the-box, the easy way. Look i.e. that all objects are included by default. After, any user could freely attune the config to the application. |
* Add jQuery 3.2.1 library (jquery3.2.js) * Update Rails UJS library * Add Rails UJS with File Upload support (rails-ujs-file-upload.js), see rails/jquery-ujs#499 * Add Rails UJS without jQuery dependancy (rails-ujs-no-jquery.js), see rails/rails#25208 * Add Laravel 5.5 providers directive * Add PHP 7.2 in Travis CI builds * Remove HHVM support from Travis CI builds
We should now be able to write our data-remote, data-confirm, XHR wrapping, and the few other hooks we rely on using vanilla JavaScript. Things have progressed well enough for that. This is not a verdict on jQuery. There are still plenty of other reasons for someone to want to use that, but it needn't be part of the default stack any more.
//cc @sstephenson @javan
The text was updated successfully, but these errors were encountered: