Add external_template_mode configuration option - #115
Merged
Conversation
marcoroth
added a commit
that referenced
this pull request
Aug 8, 2026
Follow up on #115. When a gem ships a `.html.herb` template, it reaches `ReActionView::Template::Handlers::Herb` straight from the railtie. It never passes through `Handlers::ERB`, so nothing is in a position to rescue it. #115 nonetheless forced `validation_mode: :raise` for every external template, including those, which turned what used to be a validation overlay into an uncaught exception on a template the application cannot edit: ```ruby ReActionView.config.validation_mode = :overlay ReActionView.config.external_template_mode = :fallback # /gems/some_gem/app/views/x.html.herb # before: Herb::Engine::CompilationError # after: compiles, with the usual validation overlay ``` The mistake was putting the decision in `Handlers::Herb`, which cannot tell whether its caller will rescue. `validation_mode_for` is gone, and the mode is now passed in by the handler that owns the `rescue`. Related #115
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up on #94.
This pull request adds
config.external_template_modeto control what happens to templates that come from gems rather than from the application itself.Motivation
With
intercept_erbenabled, ReActionView sees every.html.erbtemplate Rails renders, including ones shipped inside gems. #94 stopped compiling those, which fixed #91, but it did so silently. If a gem's templates cannot be compiled by Herb, you never find out.That silence is the objection @joelhawksley raises in marcoroth/herb#1508, where a vendored copy of
primer/view_componentscontains ERB that Herb cannot compile:So rather than a binary "skip or don't", the mode says how loudly to handle the failure:
:fallback(default)ActionView::Template::Handlers::ERB, so the template renders exactly as it would without ReActionView installed.:skip:compilevalidation_modeapplies to them just as it does to your own templates, and nothing is rescued.A gem template Herb cannot handle now renders as before, and says so:
Related marcoroth/herb#1508
Related marcoroth/herb#1362
Related #91