Skip to content
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

Merged
merged 5 commits into from
Jan 18, 2019

Conversation

kennyadsl
Copy link
Member

@kennyadsl kennyadsl commented Jan 6, 2019

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, like jquery_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:

//= require jquery
//= require jquery_ujs
//= require spree/backend
//= require_tree .

to

//= require spree/backend
//= require_tree .

which should be legit since jquery and jquery_ujs were already included into spree/backend manifest. (This PR also removes these double requires). In this case, users can just re-add these two requires to their manifest using either rails-ujs or jquery_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 while jquery_ujs accepts different parameters. For more details see:

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.
@kennyadsl kennyadsl self-assigned this Jan 6, 2019
This is now needed since those requires have been removed from
spree/backend manifest and need to be required manually.
@kennyadsl kennyadsl changed the title Replace jquery_ujs with rails-ujs in frontend and admin Replace jquery_ujs with rails-ujs in frontend and backend Jan 6, 2019
Copy link
Contributor

@jacobherrington jacobherrington left a 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 👍

Copy link
Contributor

@aitbw aitbw left a 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 💪 💪 💪

Copy link
Contributor

@ericsaupe ericsaupe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@kennyadsl kennyadsl merged commit 24ad270 into solidusio:master Jan 18, 2019
@kennyadsl kennyadsl deleted the kennyadsl/rails-ujs branch January 18, 2019 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants