Open francescob opened 4 days ago
try
Rails.application.routes_reloader.try(:execute_unless_loaded)
before
config.middleware.use(JsRoutes::Middleware)
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)
ok, looks like need to find best way to fix this (looks like similar to https://github.com/heartcombo/devise/issues/5705 )
Maybe adding application.reload_routes_unless_loaded
in beginning of https://github.com/railsware/js-routes/blob/9bedb7f20a0d125189f8bcd9883d7c21314b47e3/lib/js_routes/instance.rb#L25-L27 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
...
yes, that fixed it. I'm creating a pull request
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