-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Replace jquery_ujs with rails-ujs in frontend and backend #3027
Conversation
This page allows changing memo via an ajax call and this behavior should be tested.
rails-ujs has a different api handling ajax events than jquery_ujs. The former passes all the event information into the event.detail object while the latter accept different parameters. For more details see: - https://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html#rails-ujs-event-handlers - https://github.com/rails/jquery-ujs/wiki/ajax
Starting from version 5.1, Rails already includes a built-in unobtrusive scripting adapter, named rails-ujs. This library does not depend anymore on jQuery and we should start adopting it.
It's already included in spree/backend/all.js that is generated by the install command and injected into apps. Having those same requires in both places is not creating issues since sprockets is smart enough to understand that and add them once: https://github.com/rails/sprockets#require By doing this way we can let users choose which ujs they want to use since they can just change the value in the spree/backend/all.js that we are injecting in their application.
This is now needed since those requires have been removed from spree/backend manifest and need to be required manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me! Thanks @kennyadsl 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job as usual @kennyadsl 💪 💪 💪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Why swtiching to rails-ujs?
Starting from version 5.1, Rails already includes a built-in unobtrusive scripting adapter, named
rails-ujs
. This library does not depend anymore on jQuery, likejquery_ujs
and we should start adopting it.This PR switches Solidus to this new library to second what Rails does, still allowing users to change it in their own app manifests if needed.
Backward compatibility
Backward compatibility should be respected since existing stores manifests files are not changed, so when users upgrade to newer version of Solidus they should still use what they was previously doing.
The only breaking scenario could be when stores changed the provided
backend
manifest from:to
which should be legit since
jquery
andjquery_ujs
were already included intospree/backend
manifest. (This PR also removes these double requires). In this case, users can just re-add these two requires to their manifest using eitherrails-ujs
orjquery_ujs
.Differences between rails-ujs and jquery_ujs
The only difference in the API is related to how ajax event are handled:
rails-ujs
passes all the event information into the event.detail object whilejquery_ujs
accepts different parameters. For more details see:1b20df7