railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.89k stars 2.26k forks source link

Define jQuery object in separate file to support esbuild #3571

Closed wayc closed 1 year ago

wayc commented 1 year ago

Background

During our migration from webpacker to esbuild, our apps using rails_admin began to fail during builds, along with Chrome showing a jQuery is not defined error in the Console:

image

We traced the root cause to the order of these actions in src/rails_admin/base.js:

The jquery-ui modules are imported before window.$ is defined, causing the above issues.

To add support for esbuild and to avoid issues with async and hoisting, we suggest importing and initialising jQuery together.

Changes

coveralls commented 1 year ago

Coverage Status

Coverage remained the same at 95.814% when pulling de2b36116b1a7c5087cecd70a430d0ae17dc4e0c on wayc:master into 6d2eece3e3fb9bb1291a53fa29579b62716636c5 on railsadminteam:master.

rjaus commented 1 year ago

Nice work. Are these the only changes you made to get rails_admin running with esbuild? I'm struggling to get it to work.

wayc commented 1 year ago

Nice work. Are these the only changes you made to get rails_admin running with esbuild? I'm struggling to get it to work.

@rjaus Hi there 👋

Yes, the changes in this PR allowed esbuild to build successfully. However, our migration from webpacker to esbuild took some effort. If you're in a similar situation, you can try creating a new separate Rails project on esbuild: rails new demo-rails -j esbuild and implementing rails_admin. Then you can diff between your new and existing projects to identify areas to change.

It looks like a few test suites are failing here—I'll sort them out soon.

wayc commented 1 year ago

@mshibuya @pcai

Thank you so much for resolving the failing JRuby tests in https://github.com/railsadminteam/rails_admin/pull/3574

I've marked this PR (on jQuery initialisation) as ready to review and would love to hear your thoughts.

Zeneixe commented 1 year ago

Hello, any updates on this?

mshibuya commented 1 year ago

Confirmed to work, thanks!