Skip to content

Commit 0852502

Browse files
authored
Do not enable debug tools for lib templates (#45)
## Problem statement When using `reactionview` with the `intercept_erb` and `debug` options, one can get warnings for templates that are outside one's control. Here's an example with the [Avo ](https://github.com/avo-hq/avo) dashboard in one of my apps: <img width="2726" height="1776" alt="CleanShot 2025-10-10 at 15 37 01@2x" src="https://github.com/user-attachments/assets/0b4905ce-c338-4254-af1d-e84b06764418" /> The problem has also been described in #43 ## Proposed solution The proposed change here only allows debug for "local" templates, i.e. templates rendered from the main app `app/views` directory. ## Potential shortcomings The solution proposed only works for templates inside `"#{Rails.root}/app/views"`. It means that should an app use local engines, the engine templates will not benefit from ReActionView debug tools. One potential solution would be to add a new configuration item that would basically be an allow-list for other template paths within the app. Resolves #43
1 parent 02289fc commit 0852502

File tree

1 file changed

+8
-1
lines changed
  • lib/reactionview/template/handlers

1 file changed

+8
-1
lines changed

lib/reactionview/template/handlers/herb.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Herb < ActionView::Template::Handlers::ERB
1111
def call(template, source)
1212
visitors = []
1313

14-
if ::ReActionView.config.debug_mode_enabled?
14+
if ::ReActionView.config.debug_mode_enabled? && local_template?(template)
1515
visitors << ::Herb::Engine::DebugVisitor.new(
1616
file_path: template.identifier,
1717
project_path: Rails.root.to_s
@@ -37,8 +37,15 @@ def layout_template?(template)
3737
template.identifier.include?("/layouts/")
3838
end
3939

40+
def local_template?(template)
41+
return true unless template.respond_to?(:identifier) && template.identifier
42+
43+
template.identifier.start_with?("#{Rails.root}/app/views")
44+
end
45+
4046
def reactionview_dev_tools_markup(template)
4147
return nil unless layout_template?(template) && ::ReActionView.config.debug_mode_enabled?
48+
return nil unless local_template?(template)
4249

4350
<<~HTML
4451
<meta name="herb-debug-mode" content="true">

0 commit comments

Comments
 (0)