Skip to content

Commit a153301

Browse files
committed
refactor: remove global for inertia ssr head
1 parent 20e9671 commit a153301

File tree

5 files changed

+5
-24
lines changed

5 files changed

+5
-24
lines changed

lib/inertia_rails/controller.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require_relative "inertia_rails"
2-
require_relative "helper"
32

43
module InertiaRails
54
module Controller
@@ -10,7 +9,6 @@ module Controller
109
# :inertia_errors are deleted from the session by the middleware
1110
InertiaRails.share(errors: session[:inertia_errors]) if session[:inertia_errors].present?
1211
end
13-
helper ::InertiaRails::Helper
1412

1513
after_action do
1614
cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?

lib/inertia_rails/helper.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

lib/inertia_rails/inertia_rails.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
module InertiaRails
77
thread_mattr_accessor :threadsafe_shared_plain_data
88
thread_mattr_accessor :threadsafe_shared_blocks
9-
thread_mattr_accessor :threadsafe_html_headers
109

1110
CONFIGURATION = Configuration.default
1211

@@ -24,10 +23,6 @@ def self.shared_data(controller)
2423
merge!(evaluated_blocks(controller, shared_blocks))
2524
end
2625

27-
def self.html_headers
28-
self.threadsafe_html_headers || []
29-
end
30-
3126
# "Setters"
3227
def self.share(**args)
3328
self.shared_plain_data = self.shared_plain_data.merge(args)
@@ -37,14 +32,9 @@ def self.share_block(block)
3732
self.shared_blocks = self.shared_blocks + [block]
3833
end
3934

40-
def self.html_headers=(headers)
41-
self.threadsafe_html_headers = headers
42-
end
43-
4435
def self.reset!
4536
self.shared_plain_data = {}
4637
self.shared_blocks = []
47-
self.html_headers = []
4838
end
4939

5040
def self.lazy(value = nil, &block)

lib/inertia_rails/renderer.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def render
3434
def render_ssr
3535
uri = URI("#{configuration.ssr_url}/render")
3636
res = JSON.parse(Net::HTTP.post(uri, page.to_json, 'Content-Type' => 'application/json').body)
37-
38-
::InertiaRails.html_headers = res['head']
39-
@render_method.call html: res['body'].html_safe, layout: layout, locals: (view_data).merge({page: page})
37+
38+
locals = view_data.merge(page: page, inertia_ssr_head: res['head'].join.html_safe)
39+
@render_method.call html: res['body'].html_safe, layout: layout, locals: locals
4040
end
4141

4242
def layout
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<%= inertia_headers %>
1+
<%= local_assigns[:inertia_ssr_head] %>
22
<%= yield %>
3-
<%= local_assigns.except(:page).to_json.html_safe %>
3+
<%= local_assigns.except(:page, :inertia_ssr_head).to_json.html_safe %>

0 commit comments

Comments
 (0)