-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Fix dependency on the engines load order when adding paths #65
Fix dependency on the engines load order when adding paths #65
Conversation
paths['app/controllers'] << "lib/controllers/#{engine}" | ||
paths['app/views'] << "lib/views/#{engine}" | ||
initializer "#{name}_#{engine}_paths", before: :initialize_dependency_mechanism do | ||
if SolidusSupport.send(:"#{engine}_available?") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this if
need to be here (as opposed to wrapping the whole method) because SolidusSupport.send(:"#{engine}_available?")
needs to be evaluated when the initializer block is executed? If yes, maybe it's worth documenting it, at least in the commit message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's it. Outside the initializer
block, we're still at load time execution time, so the frontend might not be available yet. I updated the commit message to make it clearer.
We were adding the view and controller paths at engine loading time. So, E.g., if a frontend engine was present, but we loaded it after the extension depending on `solidus_support` (i.e., the extension went first on the `Gemfile`), paths weren't being loaded. We're adding the paths on an initializer that runs before Rails's [`:initialize_dependency_mechanism`](https://github.com/rails/rails/blob/127dd06df66552dd272eea7832f8bb205cf6fd01/railties/lib/rails/application/bootstrap.rb#L68) one. Thenceforth Rails begins messing with the load paths, and it doesn't take them into account anymore. Keep in mind that the `SolidusSupport.#{engine}_available?` call needs to be placed within the `initializer` context and not wrapping it. The reason is the same as above: don't doing the logic at load time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I validated this PR by using this version of solidus_support
on an existing Solidus (3.0) application and verifying that:
- auth views (eg. login) coming from
solidus_auth_devise
are available - code reload and decorators are still working in development environment:
# bin/rails c
> Spree::Admin::BaseController.ancestors
=> [Spree::Admin::BaseControllerDecorator, Spree::Admin::BaseController, Spree::BaseController, ...]
> reload!
Reloading...
=> true
> Spree::Admin::BaseController.ancestors
=> [Spree::Admin::BaseControllerDecorator, Spree::Admin::BaseController, Spree::BaseController, ...]
Being Spree::Admin::BaseControllerDecorator
present before and after the reload!
call, ensures that they are working.
Thanks!
solidusio/solidus_support#65 causes some solidus gem controllers not to be eager loaded on boot in Rails 6 with the classic autoloader. This is a temporary solution that will allow us to upgrade all our solidus gems to versions that allow Ruby 3. Once we switch over to using Zeitwerk we won't be needing this bump down.
In solidusio#65 and solidusio#71 they changed how the engine i loaded using the Rails initializers. This updates causes some issues when using Rails <6.1 because the initializers are totally different. The solution is to load the extension outside of the initializer block until we use Rails 6.1 or newer version. Ref: solidusio#73.
In solidusio#65 and solidusio#71 they changed how the engine is loaded using the Rails initializers. This updates causes some issues when using Rails < 6.1 because the initializers are totally different. The solution is to load the extension outside of the initializer block until we use Rails 6.1 or newer version. Ref: solidusio#73.
We were adding the view and controller paths at engine loading time. So,
E.g., if a frontend engine was present, but we loaded it after the
extension depending on
solidus_support
(i.e., the extension went firston the
Gemfile
), paths weren't being loaded.We're adding the paths on an initializer that runs before Rails's
:initialize_dependency_mechanism
one. Thenceforth Rails begins messing with the load paths, and it doesn't
take them into account anymore.
References solidusio/solidus_starter_frontend#162