Skip to content

Commit 39131ab

Browse files
committed
Add inertia_rendering? method and set instance variable in renderer
We are introducing a new method `inertia_rendering?` in the `InertiaRails` helper to check if the controller is currently rendering an Inertia response. This allow a view to conditionally render something based on this option i.e. the layout may include the `inertia` pack based on this.
1 parent c8f36c6 commit 39131ab

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

lib/inertia_rails/helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ def inertia_headers
1111
)
1212
inertia_ssr_head
1313
end
14+
15+
def inertia_rendering?
16+
controller.instance_variable_get("@_inertia_rendering")
17+
end
1418
end

lib/inertia_rails/renderer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def initialize(component, controller, request, response, render_method, props: n
3737
@deep_merge = deep_merge.nil? ? configuration.deep_merge_shared_data : deep_merge
3838
@encrypt_history = encrypt_history.nil? ? configuration.encrypt_history : encrypt_history
3939
@clear_history = clear_history || controller.session[:inertia_clear_history] || false
40+
@controller.instance_variable_set('@_inertia_rendering', true)
4041
end
4142

4243
def render

0 commit comments

Comments
 (0)