inertia_rails 3.12.0 → 3.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95b5901a42397a1ae01678a1101d5d21a6a2f2f33c6afb413a2fbca48f04e064
4
- data.tar.gz: a4d04ff25ce45b4392e5ad5c5153530446f83256e2b00452999da0c920751416
3
+ metadata.gz: a3bde9e557a4d5b76450d4f019ae8461b40a0eb2fda2984d8d5cb32fa58d769c
4
+ data.tar.gz: d662136e29e4f72957a6677a74b1c6c29086e8e32056023e5b51fb4b5e70b976
5
5
  SHA512:
6
- metadata.gz: 222ebe8277d96856c05c9d712ad0d0e33cea995e7195dada790cf6423e3ad9f16b970c555c9889a1d7eb9082ad9045ca73a00bc95116fc93912f429fc1ded50f
7
- data.tar.gz: f859bfb3d498ae8bc2c146e5bd8d9be8cadb65a6f3a51135c89bd1f3e86c83007f2602b9e6b115179e7f294dc663e3c96ce9073890511b478689ddf99156e1b9
6
+ metadata.gz: 86753985c32f435b2967144c8b88e22984d1999fd0e528ac862d9b2dcc081545d52841d54b984d8184cb7774681576aa03ce244b09016a79b0110067b1d69d7e
7
+ data.tar.gz: 22197c8fc07a0f2d25402f04ab9988b3a572bd7c713ef8a391bf95bdb680bfac5a03c65c19796671d7172f921d1fdc900cc9f4f3d41420702e556a1a820a3942
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [3.12.1] - 2025-11-09
8
+
9
+ * Fix scroll props and deferred props for shared data (@bknoles)
10
+ * Deprecate the probably-no-actually-used-anywhere public readers on InertiaRails::Renderer (@bknoles)
11
+
7
12
  ## [3.12.0] - 2025-11-08
8
13
 
9
14
  * Docs updates (@leenyburger, @skryukov, @bn-l)
@@ -6,15 +6,15 @@ require_relative 'inertia_rails'
6
6
 
7
7
  module InertiaRails
8
8
  class Renderer
9
- attr_reader(
10
- :component,
11
- :configuration,
12
- :controller,
13
- :props,
14
- :view_data,
15
- :encrypt_history,
16
- :clear_history
17
- )
9
+ %i[component configuration controller props view_data encrypt_history
10
+ clear_history].each do |method_name|
11
+ define_method(method_name) do
12
+ InertiaRails.deprecator.warn(
13
+ "[DEPRECATION] Accessing `InertiaRails::Renderer##{method_name}` is deprecated and will be removed in v4.0"
14
+ )
15
+ instance_variable_get("@#{method_name}")
16
+ end
17
+ end
18
18
 
19
19
  def initialize(component, controller, request, response, render_method, **options)
20
20
  if component.is_a?(Hash) && options.key?(:props)
@@ -24,15 +24,20 @@ module InertiaRails
24
24
 
25
25
  @controller = controller
26
26
  @configuration = controller.__send__(:inertia_configuration)
27
- @component = resolve_component(component)
28
27
  @request = request
29
28
  @response = response
30
29
  @render_method = render_method
31
- @props = options.fetch(:props, component.is_a?(Hash) ? component : controller.__send__(:inertia_view_assigns))
32
30
  @view_data = options.fetch(:view_data, {})
33
- @deep_merge = options.fetch(:deep_merge, configuration.deep_merge_shared_data)
34
- @encrypt_history = options.fetch(:encrypt_history, configuration.encrypt_history)
31
+ @encrypt_history = options.fetch(:encrypt_history, @configuration.encrypt_history)
35
32
  @clear_history = options.fetch(:clear_history, controller.session[:inertia_clear_history] || false)
33
+
34
+ deep_merge = options.fetch(:deep_merge, @configuration.deep_merge_shared_data)
35
+ passed_props = options.fetch(:props,
36
+ component.is_a?(Hash) ? component : @controller.__send__(:inertia_view_assigns))
37
+ @props = merge_props(shared_data, passed_props, deep_merge)
38
+
39
+ @component = resolve_component(component)
40
+
36
41
  @controller.instance_variable_set('@_inertia_rendering', true)
37
42
  controller.inertia_meta.add(options[:meta]) if options[:meta]
38
43
  end
@@ -48,32 +53,32 @@ module InertiaRails
48
53
  @render_method.call json: page.to_json, status: @response.status, content_type: Mime[:json]
49
54
  else
50
55
  begin
51
- return render_ssr if configuration.ssr_enabled
56
+ return render_ssr if @configuration.ssr_enabled
52
57
  rescue StandardError
53
58
  nil
54
59
  end
55
- controller.instance_variable_set('@_inertia_page', page)
56
- @render_method.call template: 'inertia', layout: layout, locals: view_data.merge(page: page)
60
+ @controller.instance_variable_set('@_inertia_page', page)
61
+ @render_method.call template: 'inertia', layout: layout, locals: @view_data.merge(page: page)
57
62
  end
58
63
  end
59
64
 
60
65
  private
61
66
 
62
67
  def render_ssr
63
- uri = URI("#{configuration.ssr_url}/render")
68
+ uri = URI("#{@configuration.ssr_url}/render")
64
69
  res = JSON.parse(Net::HTTP.post(uri, page.to_json, 'Content-Type' => 'application/json').body)
65
70
 
66
- controller.instance_variable_set('@_inertia_ssr_head', res['head'].join.html_safe)
67
- @render_method.call html: res['body'].html_safe, layout: layout, locals: view_data.merge(page: page)
71
+ @controller.instance_variable_set('@_inertia_ssr_head', res['head'].join.html_safe)
72
+ @render_method.call html: res['body'].html_safe, layout: layout, locals: @view_data.merge(page: page)
68
73
  end
69
74
 
70
75
  def layout
71
- layout = configuration.layout
76
+ layout = @configuration.layout
72
77
  layout.nil? || layout
73
78
  end
74
79
 
75
80
  def shared_data
76
- controller.__send__(:inertia_shared_data)
81
+ @controller.__send__(:inertia_shared_data)
77
82
  end
78
83
 
79
84
  # Cast props to symbol keyed hash before merging so that we have a consistent data structure and
@@ -81,8 +86,8 @@ module InertiaRails
81
86
  #
82
87
  # Functionally, this permits using either string or symbol keys in the controller. Since the results
83
88
  # is cast to json, we should treat string/symbol keys as identical.
84
- def merge_props(shared_props, props)
85
- if @deep_merge
89
+ def merge_props(shared_props, props, deep_merge)
90
+ if deep_merge
86
91
  shared_props.deep_symbolize_keys.deep_merge!(props.deep_symbolize_keys)
87
92
  else
88
93
  shared_props.symbolize_keys.merge(props.symbolize_keys)
@@ -91,16 +96,15 @@ module InertiaRails
91
96
 
92
97
  def computed_props
93
98
  # rubocop:disable Style/MultilineBlockChain
94
- merge_props(shared_data, props)
95
- .then do |merged_props| # Always keep errors in the props
99
+ @props
100
+ .tap do |merged_props| # Always keep errors in the props
96
101
  if merged_props.key?(:errors) && !merged_props[:errors].is_a?(BaseProp)
97
102
  errors = merged_props[:errors]
98
103
  merged_props[:errors] = InertiaRails.always { errors }
99
104
  end
100
- merged_props
101
105
  end
102
106
  .then { |props| deep_transform_props(props) } # Internal hydration/filtering
103
- .then { |props| configuration.prop_transformer(props: props) } # Apply user-defined prop transformer
107
+ .then { |props| @configuration.prop_transformer(props: props) } # Apply user-defined prop transformer
104
108
  .tap do |props| # Add meta tags last (never transformed)
105
109
  props[:_inertia_meta] = meta_tags if meta_tags.present?
106
110
  end
@@ -111,12 +115,12 @@ module InertiaRails
111
115
  return @page if defined?(@page)
112
116
 
113
117
  @page = {
114
- component: component,
118
+ component: @component,
115
119
  props: computed_props,
116
120
  url: @request.original_fullpath,
117
- version: configuration.version,
118
- encryptHistory: encrypt_history,
119
- clearHistory: clear_history,
121
+ version: @configuration.version,
122
+ encryptHistory: @encrypt_history,
123
+ clearHistory: @clear_history,
120
124
  }
121
125
 
122
126
  deferred_props = deferred_props_keys
@@ -138,9 +142,9 @@ module InertiaRails
138
142
  transformed_props[key] =
139
143
  case prop
140
144
  when BaseProp
141
- prop.call(controller)
145
+ prop.call(@controller)
142
146
  when Proc
143
- controller.instance_exec(&prop)
147
+ @controller.instance_exec(&prop)
144
148
  else
145
149
  prop
146
150
  end
@@ -248,12 +252,12 @@ module InertiaRails
248
252
  end
249
253
 
250
254
  def rendering_partial_component?
251
- @request.headers['X-Inertia-Partial-Component'] == component
255
+ @request.headers['X-Inertia-Partial-Component'] == @component
252
256
  end
253
257
 
254
258
  def resolve_component(component)
255
259
  if component == true || component.is_a?(Hash)
256
- configuration.component_path_resolver(path: controller.controller_path, action: controller.action_name)
260
+ @configuration.component_path_resolver(path: @controller.controller_path, action: @controller.action_name)
257
261
  else
258
262
  component
259
263
  end
@@ -289,7 +293,7 @@ module InertiaRails
289
293
  end
290
294
 
291
295
  def meta_tags
292
- controller.inertia_meta.meta_tags
296
+ @controller.inertia_meta.meta_tags
293
297
  end
294
298
  end
295
299
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InertiaRails
4
- VERSION = '3.12.0'
4
+ VERSION = '3.12.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inertia_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.12.0
4
+ version: 3.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Knoles
@@ -9,7 +9,7 @@ authors:
9
9
  - Eugene Granovsky
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-11-08 00:00:00.000000000 Z
12
+ date: 2025-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties