Skip to content

Conversation

@salmanasiddiqui
Copy link

@salmanasiddiqui salmanasiddiqui commented Nov 9, 2024

What? Why?

Fixes #215

The steps to reproduce are described in the above linked issue.

I was thinking that to fix this issue I will have to check config.eager_load but after_initialize works fine in both cases.

How was it tested?

Created a new rails app locally, followed the steps in the linked issue to reproduce error. Then updated the gem with the change in this PR. That fixed the issue.

I am thinking on how to write a test for this, any help or suggestion would be greatly appreciated. As this depends on how rails app is initialized its kinda hard to test this in isolation. It might be good to have a build step where gruf-demo is checked out and we test this in that?

@salmanasiddiqui salmanasiddiqui marked this pull request as ready for review November 9, 2024 20:20
@salmanasiddiqui
Copy link
Author

@splittingred 👋🏽 can you give this small fix a look?

class Railtie < ::Rails::Railtie
initializer 'gruf.initializer' do |app|
config.before_configuration do
config.after_initialize do
Copy link
Member

Choose a reason for hiding this comment

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

Rails is pretty finicky with initialization order changes between versions. @salmanasiddiqui - I think we're probably going to need to see some proof of life here that this change doesn't break Rails 7.0, 7.1, 7.2, and 8.0 installations.

Copy link

Choose a reason for hiding this comment

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

I think eager load paths are frozen at the point of after_initialize so you won't be able to mutate it

Copy link
Author

Choose a reason for hiding this comment

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

thanks for reviewing this, Im trying to figure if there is a good way to test this railtie. Any suggestions or relevant resources will be greatly appreciated

@zzak - after_initialize is used by gruf-rspec aswell, and I have tested this with Rails 7.1, it updated the autoloader correctly.
https://github.com/bigcommerce/gruf-rspec/blob/main/lib/gruf/rspec/railtie.rb#L25

Copy link

Choose a reason for hiding this comment

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

Have you tried EAGER_LOAD=true?

Copy link
Author

Choose a reason for hiding this comment

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

yes, I did

@phoffer
Copy link

phoffer commented Jul 10, 2025

We are working to make a Rails 6.1 app Zeitwerk compatible, and we're running into the same issue as #215 with controllers_path being configured, and then encountering the Zeitwerk conflict. This patch does fix it for us as well.

Is there any chance this PR can get some movement again?

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.

Gruf.controllers_path config breaks integration with Rails

4 participants