railsadminteam / rails_admin

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

Support for turbo-rails 2.x gem #3661

Closed ArturT closed 9 months ago

ArturT commented 11 months ago

Turbo 8 has been released in the turbo-rails gem 2.0.0.pre.beta.1.

Turbo 8 has a few cool features and I wanted to test this with the Rails app but the rails_admin depends on turbo-rails < 2 (see spec.add_dependency 'turbo-rails', '~> 1.0' in rails_admin.gemspec).

Reproduction steps

I updated the rails_admin.gemspec file to:

# rails_admin.gemspec
spec.add_dependency 'turbo-rails', ['>= 1.0', '< 3']

I was able to run the Rails app with rails_admin and the latest turbo-rails. I'm using turbo-rails directly from github because they did some fix (the bug prevented to start my Rails app fix: https://github.com/hotwired/turbo-rails/pull/523 ) that has not been released to rubygems yet.

# my rails app
# Gemfile
gem 'turbo-rails', github: 'hotwired/turbo-rails', ref: '4eb4e928e30be8cd537af8073f98b80ddea4a578'

Describe the bug

When it comes to rails_admin. While I'm using Turbo 8 (turbo-rails 2.x gem) I found an issue. When I visit the http://localhost:3000/admin/user In the search bar I type a user name and click on Refresh button then nothing happens. I get the error in the Chrome console:

RangeError: Maximum call stack size exceeded

Screenshot 2023-12-08 at 17 25 47 Screenshot 2023-12-08 at 17 25 59

Workaround

In order to keep using rails_admin and the latest turbo-rails 2.x I disabled Turbo in the rails_admin dashboard.

I added:

// app/assets/javascripts/rails_admin/custom/ui.js
window.Turbo.session.drive = false

Now I can search records in the rails_admin panel. I hope this workaround can be helpful for someone looking for a temporary solution to use both rails_admin and turbo-rails 2.x in your Rails app.

Expected behavior rails_admin works with the turbo-rails 2.x gem.

Additional context

turbo.source.js:2557 RangeError: Maximum call stack size exceeded
    at uuid (turbo.source.js:363:1)
    at fetch (turbo.source.js:490:1)
    at fetch (turbo.source.js:493:1)
    at fetch (turbo.source.js:493:1)
    at fetch (turbo.source.js:493:1)
    at fetch (turbo.source.js:493:1)
    at fetch (turbo.source.js:493:1)
    at fetch (turbo.source.js:493:1)
    at fetch (turbo.source.js:493:1)
    at fetch (turbo.source.js:493:1)
formSubmissionErrored @ turbo.source.js:2557
requestErrored @ turbo.source.js:892
perform @ turbo.source.js:617
await in perform (async)
start @ turbo.source.js:825
submitForm @ turbo.source.js:2489
formSubmitted @ turbo.source.js:3913
submitBubbled @ turbo.source.js:1067

Let me know if there is something I could help to bring turbo-rails 2.x to rails_admin. Thanks.

bb commented 9 months ago

I tried reproducing the above issue with shakapacker/webpack, but I had no issues (also tried searching my users).

I think it works for me because with npm packages, a package can have a different version than the main project when required as an indirect dependency. While my app uses turbo-rails 8.x (located directly in node_modules/@hotwired/), rails_admin uses version 7.x which is in node_modules/rails_admin/node_modules/@hotwired/)

The versions:

So, as long as you're using the client scripts via yarn/npm instead of the sprockets you should be fine.

ArturT commented 9 months ago

I use the sprockets gem, the terser gem, and the importmap-rails gem.

mshibuya commented 9 months ago

The originally reported issue seems to be fixed by https://github.com/hotwired/turbo/pull/1077.

ArturT commented 9 months ago

The originally reported issue seems to be fixed by hotwired/turbo#1077.

Yes. I confirm updating the turbo-rails gem fixes the issue. Thank you.