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 ActionMailer preview loading #3901

Merged
merged 2 commits into from
Jan 28, 2021
Merged

Fix ActionMailer preview loading #3901

merged 2 commits into from
Jan 28, 2021

Conversation

aldesantis
Copy link
Member

@aldesantis aldesantis commented Jan 19, 2021

Description

This fixes #3898, by moving the loading of the app's previews (and our own) to an after_initialize block, which gets rid of the deprecation warning about constant loading during app initialization.

I also managed to write a test that verifies that both the engine's and the app's previews are properly loaded. I had to enable preview loading in Rails.env.test? as well in order for the test to pass, but I think that won't be a problem.

Btw, it seems like we'll be able to get rid of this hack if/when rails/rails#31595 gets merged.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

@aldesantis aldesantis self-assigned this Jan 19, 2021
@jarednorman
Copy link
Member

Is this seeking to resolve #3898?

@PeteTheSadPanda
Copy link

I believe it would as it would push load_previews' descendants call into runtime and out of intializer time which results in autoloading of the Preview classes.

@aldesantis
Copy link
Member Author

@jarednorman @PeteTheSadPanda yep, this solves #3898. It needs some more love — mostly, I want to implement some kind of caching/memoization and give that anonymous module its own place — but I've tested it in a real Solidus store and both Solidus' and the store's previews are loaded correctly.

@PeteTheSadPanda
Copy link

Given how frequently this gets called, I'm not sure caching/memorization is really needed. This call primarily gets called when rendering /rails/previews which itself does some level of caching by short circuiting is descendants are populated, so really you might only be requiring Solidus previews.

I'm not advocating against your proposal which is fine, I'm just stating that if it proves too much a pain it wouldn't be a blocker (to me). I believe (but am not certain) that any subsequent calls to the same file via require_dependency would be cached assuming the constant is still in memory and hasn't been unloaded due to it being changed.

Loading constants during an app's initialization is a deprecated
technique and will be an error in future versions of Rails.

By moving our custom logic for loading Solidus's previews to an
`after_initialize` block, we ensure the preview classes are only
loaded after initialization has completed.
@aldesantis aldesantis marked this pull request as ready for review January 22, 2021 08:59
@aldesantis aldesantis requested a review from a team January 22, 2021 09:11
@aldesantis
Copy link
Member Author

This should be ready for a review!

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.

👍 Thanks Ale!

Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

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

@aldesantis thanks!

@kennyadsl kennyadsl added Needs Backport changelog:solidus_core Changes to the solidus_core gem labels Jan 28, 2021
@kennyadsl kennyadsl added this to the 2.11 milestone Jan 28, 2021
@kennyadsl
Copy link
Member

Failing specs already addressed, merging anyway!

@kennyadsl kennyadsl merged commit 7019610 into solidusio:master Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecation Warning pertaining to Mailer Previews being loaded from an app which loads the Solidus engine
6 participants