Skip to content

Commit 187e45f

Browse files
committed
refactor: re-introduce inertia_headers helper for backwards compat
Also, rename it to `inertia_ssr_head`, which is a better description.
1 parent 005de89 commit 187e45f

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ inertia 'about' => 'AboutComponent'
191191

192192
Enable SSR via the config settings for `ssr_enabled` and `ssr_url`.
193193

194-
When using SSR, don't forget to add `<%= inertia_headers %>` to the `<head>` of your `application.html.erb`.
194+
When using SSR, don't forget to add `<%= inertia_ssr_head %>` to the `<head>` of your `application.html.erb`.
195195

196196
## Configuration
197197

lib/inertia_rails.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@
2121

2222
module InertiaRails
2323
class Error < StandardError; end
24+
25+
def self.deprecator # :nodoc:
26+
@deprecator ||= ActiveSupport::Deprecation.new
27+
end
2428
end

lib/inertia_rails/controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
require_relative "inertia_rails"
2+
require_relative "helper"
23

34
module InertiaRails
45
module Controller
56
extend ActiveSupport::Concern
67

78
included do
9+
helper ::InertiaRails::Helper
10+
811
after_action do
912
cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
1013
end

lib/inertia_rails/helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require_relative 'inertia_rails'
2+
3+
module InertiaRails::Helper
4+
def inertia_ssr_head
5+
controller.instance_variable_get("@_inertia_ssr_head")
6+
end
7+
8+
def inertia_headers
9+
InertiaRails.deprecator.warn(
10+
"`inertia_headers` is deprecated and will be removed in InertiaRails 4.0, use `inertia_ssr_head` instead."
11+
)
12+
inertia_ssr_head
13+
end
14+
end

lib/inertia_rails/renderer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def render_ssr
4141
uri = URI("#{configuration.ssr_url}/render")
4242
res = JSON.parse(Net::HTTP.post(uri, page.to_json, 'Content-Type' => 'application/json').body)
4343

44-
locals = view_data.merge(page: page, inertia_ssr_head: res['head'].join.html_safe)
45-
@render_method.call html: res['body'].html_safe, layout: layout, locals: locals
44+
controller.instance_variable_set("@_inertia_ssr_head", res['head'].join.html_safe)
45+
@render_method.call html: res['body'].html_safe, layout: layout, locals: view_data.merge(page: page)
4646
end
4747

4848
def layout
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<%= local_assigns[:inertia_ssr_head] %>
1+
<%= inertia_ssr_head %>
22
<%= yield %>
33
<%= local_assigns.except(:page, :inertia_ssr_head).to_json.html_safe %>

0 commit comments

Comments
 (0)