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

using the middleware with rails 8 breaks rails routes generation #319

Closed
francescob opened this issue Nov 11, 2024 · 6 comments
Closed

using the middleware with rails 8 breaks rails routes generation #319

francescob opened this issue Nov 11, 2024 · 6 comments

Comments

@francescob
Copy link
Contributor

I've upgraded my application to rails 8 and now the line
config.middleware.use(JsRoutes::Middleware)

in development.rb causes the rails routes to be empty. Removing the line the application works as normal

@le0pard
Copy link
Member

le0pard commented Nov 11, 2024

try

Rails.application.routes_reloader.try(:execute_unless_loaded)

before

config.middleware.use(JsRoutes::Middleware)

@francescob
Copy link
Contributor Author

francescob commented Nov 11, 2024

thanks for the super quick reply, unfortunately that line leads to the app failing to boot with the following error:

/home/francesco/.asdf/installs/ruby/3.3.4/lib64/ruby/gems/3.3.0/gems/railties-8.0.0/lib/rails/engine.rb:602:in unshift: can't modify frozen Array: [] (FrozenError)

@le0pard
Copy link
Member

le0pard commented Nov 11, 2024

ok, looks like need to find best way to fix this (looks like similar to heartcombo/devise#5705 )

@le0pard
Copy link
Member

le0pard commented Nov 11, 2024

Maybe adding application.reload_routes_unless_loaded in beginning of

def generate
# Ensure routes are loaded. If they're not, load them.
application = T.unsafe(self.application)
may fix problem. Are you able to test @francescob (create fork and modify it) ?

so it will be

     def generate
      # Ensure routes are loaded. If they're not, load them.
      application = T.unsafe(self.application)
      if named_routes.empty?
        if application.respond_to?(:reload_routes_unless_loaded, true)
          application.reload_routes_unless_loaded
        elsif application.respond_to?(:reload_routes!, true)
          application.reload_routes!
        end
      end
      ...

@francescob
Copy link
Contributor Author

yes, that fixed it. I'm creating a pull request

@bogdan
Copy link
Collaborator

bogdan commented Nov 16, 2024

Fixed in 2.3.0

@bogdan bogdan closed this as completed Nov 16, 2024
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

No branches or pull requests

3 participants