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

Fix dependency on the engines load order when adding paths #65

Merged
merged 1 commit into from
Jan 5, 2022
Merged

Fix dependency on the engines load order when adding paths #65

merged 1 commit into from
Jan 5, 2022

Conversation

waiting-for-dev
Copy link
Contributor

@waiting-for-dev waiting-for-dev commented Jun 15, 2021

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
one. Thenceforth Rails begins messing with the load paths, and it doesn't
take them into account anymore.

References solidusio/solidus_starter_frontend#162

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?")
Copy link
Member

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.

Copy link
Contributor Author

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.
Copy link
Member

@kennyadsl kennyadsl left a 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:

  1. auth views (eg. login) coming from solidus_auth_devise are available
  2. 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!

@waiting-for-dev waiting-for-dev merged commit 4dd0c05 into solidusio:master Jan 5, 2022
@waiting-for-dev waiting-for-dev deleted the waiting-for-dev/fix_paths_depending_on_gem_order branch January 5, 2022 05:10
senemsoy added a commit to TubeDepot/solidus_print_invoice that referenced this pull request May 24, 2023
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.
MassimilianoLattanzio added a commit to sdtechdev/solidus_support that referenced this pull request May 10, 2024
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.
MassimilianoLattanzio added a commit to sdtechdev/solidus_support that referenced this pull request May 10, 2024
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.
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.

4 participants