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

[NO-TICKET] Fix preview mailers index #9869

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adessy
Copy link
Contributor

@adessy adessy commented Dec 20, 2024

The list of preview mailers at localhost:4000/rails/mailers was broken because the newly introduced PreviewMailer interfered with the lazy loading of mailer previews.

Here's how ActionMailer::Preview determines the list of previews:

def all
  load_previews if descendants.empty?
  descendants
end

def load_previews
  if preview_path
    Dir["#{preview_path}/**/*_preview.rb"].sort.each { |file| require_dependency file }
  end
end

The load_previews method is only triggered if descendants is empty. However, since PreviewMailer was defined in an autoloaded path and is a subclass of ActionMailer::Preview, it was loaded too early and short-circuited the loading of the other mailer previews.

The fix consists of moving the PreviewMailer class to the same folder as the other mailer previews. The downside is that now it needs to be required explicitly in the previewers that use it.

Changelog

Technical

  • Fix preview mailers index

The list of preview mailers at `localhost:4000/rails/mailers` was broken because the newly introduced `PreviewMailer` interfered with the lazy loading of mailer previews.

Here's how `ActionMailer::Preview` determines the list of previews:
```ruby
def all
  load_previews if descendants.empty?
  descendants
end

def load_previews
  if preview_path
    Dir["#{preview_path}/**/*_preview.rb"].sort.each { |file| require_dependency file }
  end
end
```

The `load_previews` method is only triggered if `descendants` is empty. However, since `PreviewMailer` was defined in an autoloaded path and is a subclass of `ActionMailer::Preview`, it was loaded too early and short-circuited the loading of the other mailer previews.

The fix consists of moving the `PreviewMailer` class to the same folder as the other mailer previews. The downside is that now it needs to be required explicitly in the previewers that use it.
@adessy adessy requested a review from jamesspeake December 20, 2024 10:34
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.

1 participant