inertia_rails 3.5.0 → 3.6.0
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 +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +11 -6
- data/lib/inertia_rails/configuration.rb +3 -0
- data/lib/inertia_rails/controller.rb +8 -3
- data/lib/inertia_rails/defer_prop.rb +21 -0
- data/lib/inertia_rails/ignore_on_first_load_prop.rb +6 -0
- data/lib/inertia_rails/inertia_rails.rb +16 -0
- data/lib/inertia_rails/lazy_prop.rb +5 -1
- data/lib/inertia_rails/merge_prop.rb +14 -0
- data/lib/inertia_rails/middleware.rb +7 -2
- data/lib/inertia_rails/optional_prop.rb +6 -0
- data/lib/inertia_rails/renderer.rb +38 -6
- data/lib/inertia_rails/version.rb +1 -1
- data/lib/inertia_rails.rb +2 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1703f19fcb6d8f3d2c580e6e7bd80ff999cda8f55f72f7ea915001279577386c
|
4
|
+
data.tar.gz: d5ff27be81328583e03aa7eb4473f1a4a966139993a3d856c54c0b6ae447b122
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cdd9eebf261e555bc09d237272852c4c59cf08618462f5deb5aaa314e09538e121a8c116e989c9c66632f38d2bcf14617d0d0f6ca9f5fe152e7b646a5a652f3
|
7
|
+
data.tar.gz: 4fea8b1605262d6d80ccec45fe68368b9f62ae4cd96cca7768b58b0b65e5a690877216f6f10f7d4e93915cbba8003b4635b99ea4b3af3f2100bceda8c572cd73
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,17 @@ 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.6.0] - 2024-12-13
|
8
|
+
|
9
|
+
Support for the v2.0 Inertia.js release! It's a minor bump because there are no breaking changes!
|
10
|
+
|
11
|
+
Kudos to @skryukov and @PedroAugustoRamalhoDuarte for driving the features in this release!
|
12
|
+
|
13
|
+
* InertiaRails.defer for deferred props
|
14
|
+
* History encryption
|
15
|
+
* InertiaRails.merge for merge props
|
16
|
+
* InertiaRails.optional props (replaces lazy props in v2.0, InertiaRails.lazy now has a deprecation warning)
|
17
|
+
|
7
18
|
## [3.5.0] - 2024-11-29
|
8
19
|
|
9
20
|
* Add Algolia search for docs (#151, @skryukov)
|
data/README.md
CHANGED
@@ -188,15 +188,12 @@ end
|
|
188
188
|
}
|
189
189
|
```
|
190
190
|
|
191
|
-
###
|
191
|
+
### Optional Props
|
192
192
|
|
193
|
-
On the
|
193
|
+
On the frontend, Inertia supports the concept of "partial reloads" where only the props requested are returned by the server. Sometimes, you may want to use this flow to avoid processing a particularly slow prop on the initial load. In this case, you can use Optional props. Optional props aren't evaluated unless they're specifically requested by name in a partial reload.
|
194
194
|
|
195
195
|
```ruby
|
196
|
-
inertia_share some_data: InertiaRails.
|
197
|
-
|
198
|
-
# Using a Ruby block syntax
|
199
|
-
inertia_share some_data: InertiaRails.lazy { some_very_slow_method }
|
196
|
+
inertia_share some_data: InertiaRails.optional { some_very_slow_method }
|
200
197
|
```
|
201
198
|
|
202
199
|
### Routing
|
@@ -269,6 +266,14 @@ end
|
|
269
266
|
|
270
267
|
__Default__: `false`
|
271
268
|
|
269
|
+
#### `encrypt_history`
|
270
|
+
|
271
|
+
When enabled, you instruct Inertia to encrypt your app's history, it uses
|
272
|
+
the browser's built-in [`crypto` api](https://developer.mozilla.org/en-US/docs/Web/API/Crypto)
|
273
|
+
to encrypt the current page's data before pushing it to the history state.
|
274
|
+
|
275
|
+
__Default__: `false`
|
276
|
+
|
272
277
|
#### `ssr_enabled` _(experimental)_
|
273
278
|
|
274
279
|
Whether to use a JavaScript server to pre-render your JavaScript pages,
|
@@ -123,7 +123,7 @@ module InertiaRails
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def redirect_to(options = {}, response_options = {})
|
126
|
-
|
126
|
+
capture_inertia_session_options(response_options)
|
127
127
|
super
|
128
128
|
end
|
129
129
|
|
@@ -155,8 +155,10 @@ module InertiaRails
|
|
155
155
|
head :conflict
|
156
156
|
end
|
157
157
|
|
158
|
-
def
|
159
|
-
|
158
|
+
def capture_inertia_session_options(options)
|
159
|
+
return unless (inertia = options[:inertia])
|
160
|
+
|
161
|
+
if (inertia_errors = inertia[:errors])
|
160
162
|
if inertia_errors.respond_to?(:to_hash)
|
161
163
|
session[:inertia_errors] = inertia_errors.to_hash
|
162
164
|
else
|
@@ -165,7 +167,10 @@ module InertiaRails
|
|
165
167
|
)
|
166
168
|
session[:inertia_errors] = inertia_errors
|
167
169
|
end
|
170
|
+
|
168
171
|
end
|
172
|
+
|
173
|
+
session[:inertia_clear_history] = inertia[:clear_history] if inertia[:clear_history]
|
169
174
|
end
|
170
175
|
end
|
171
176
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InertiaRails
|
4
|
+
class DeferProp < IgnoreOnFirstLoadProp
|
5
|
+
DEFAULT_GROUP = 'default'
|
6
|
+
|
7
|
+
attr_reader :group
|
8
|
+
|
9
|
+
def initialize(group: nil, merge: nil, &block)
|
10
|
+
super(&block)
|
11
|
+
|
12
|
+
@group = group || DEFAULT_GROUP
|
13
|
+
@merge = merge
|
14
|
+
@block = block
|
15
|
+
end
|
16
|
+
|
17
|
+
def merge?
|
18
|
+
@merge
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'inertia_rails/base_prop'
|
2
|
+
require 'inertia_rails/ignore_on_first_load_prop'
|
2
3
|
require 'inertia_rails/always_prop'
|
3
4
|
require 'inertia_rails/lazy_prop'
|
5
|
+
require 'inertia_rails/optional_prop'
|
6
|
+
require 'inertia_rails/defer_prop'
|
7
|
+
require 'inertia_rails/merge_prop'
|
4
8
|
require 'inertia_rails/configuration'
|
5
9
|
|
6
10
|
module InertiaRails
|
@@ -19,8 +23,20 @@ module InertiaRails
|
|
19
23
|
LazyProp.new(value, &block)
|
20
24
|
end
|
21
25
|
|
26
|
+
def optional(&block)
|
27
|
+
OptionalProp.new(&block)
|
28
|
+
end
|
29
|
+
|
22
30
|
def always(&block)
|
23
31
|
AlwaysProp.new(&block)
|
24
32
|
end
|
33
|
+
|
34
|
+
def merge(&block)
|
35
|
+
MergeProp.new(&block)
|
36
|
+
end
|
37
|
+
|
38
|
+
def defer(group: nil, merge: nil, &block)
|
39
|
+
DeferProp.new(group: group, merge: merge, &block)
|
40
|
+
end
|
25
41
|
end
|
26
42
|
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module InertiaRails
|
4
|
-
class LazyProp <
|
4
|
+
class LazyProp < IgnoreOnFirstLoadProp
|
5
5
|
def initialize(value = nil, &block)
|
6
6
|
raise ArgumentError, 'You must provide either a value or a block, not both' if value && block
|
7
7
|
|
8
|
+
InertiaRails.deprecator.warn(
|
9
|
+
'`lazy` is deprecated and will be removed in InertiaRails 4.0, use `optional` instead.'
|
10
|
+
)
|
11
|
+
|
8
12
|
@value = value
|
9
13
|
@block = block
|
10
14
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module InertiaRails
|
2
4
|
class Middleware
|
3
5
|
def initialize(app)
|
@@ -20,7 +22,10 @@ module InertiaRails
|
|
20
22
|
request = ActionDispatch::Request.new(@env)
|
21
23
|
|
22
24
|
# Inertia errors are added to the session via redirect_to
|
23
|
-
|
25
|
+
unless keep_inertia_session_options?(status)
|
26
|
+
request.session.delete(:inertia_errors)
|
27
|
+
request.session.delete(:inertia_clear_history)
|
28
|
+
end
|
24
29
|
|
25
30
|
status = 303 if inertia_non_post_redirect?(status)
|
26
31
|
|
@@ -29,7 +34,7 @@ module InertiaRails
|
|
29
34
|
|
30
35
|
private
|
31
36
|
|
32
|
-
def
|
37
|
+
def keep_inertia_session_options?(status)
|
33
38
|
redirect_status?(status) || stale_inertia_request?
|
34
39
|
end
|
35
40
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'json'
|
5
|
-
require_relative
|
5
|
+
require_relative 'inertia_rails'
|
6
6
|
|
7
7
|
module InertiaRails
|
8
8
|
class Renderer
|
@@ -15,9 +15,11 @@ module InertiaRails
|
|
15
15
|
:controller,
|
16
16
|
:props,
|
17
17
|
:view_data,
|
18
|
+
:encrypt_history,
|
19
|
+
:clear_history
|
18
20
|
)
|
19
21
|
|
20
|
-
def initialize(component, controller, request, response, render_method, props: nil, view_data: nil, deep_merge: nil)
|
22
|
+
def initialize(component, controller, request, response, render_method, props: nil, view_data: nil, deep_merge: nil, encrypt_history: nil, clear_history: nil)
|
21
23
|
@controller = controller
|
22
24
|
@configuration = controller.__send__(:inertia_configuration)
|
23
25
|
@component = resolve_component(component)
|
@@ -27,6 +29,8 @@ module InertiaRails
|
|
27
29
|
@props = props || controller.__send__(:inertia_view_assigns)
|
28
30
|
@view_data = view_data || {}
|
29
31
|
@deep_merge = !deep_merge.nil? ? deep_merge : configuration.deep_merge_shared_data
|
32
|
+
@encrypt_history = !encrypt_history.nil? ? encrypt_history : configuration.encrypt_history
|
33
|
+
@clear_history = clear_history || controller.session[:inertia_clear_history] || false
|
30
34
|
end
|
31
35
|
|
32
36
|
def render
|
@@ -96,12 +100,22 @@ module InertiaRails
|
|
96
100
|
end
|
97
101
|
|
98
102
|
def page
|
99
|
-
{
|
103
|
+
default_page = {
|
100
104
|
component: component,
|
101
105
|
props: computed_props,
|
102
106
|
url: @request.original_fullpath,
|
103
107
|
version: configuration.version,
|
108
|
+
encryptHistory: encrypt_history,
|
109
|
+
clearHistory: clear_history,
|
104
110
|
}
|
111
|
+
|
112
|
+
deferred_props = deferred_props_keys
|
113
|
+
default_page[:deferredProps] = deferred_props if deferred_props.present?
|
114
|
+
|
115
|
+
merge_props = merge_props_keys
|
116
|
+
default_page[:mergeProps] = merge_props if merge_props.present?
|
117
|
+
|
118
|
+
default_page
|
105
119
|
end
|
106
120
|
|
107
121
|
def deep_transform_props(props, parent_path = [], &block)
|
@@ -120,8 +134,26 @@ module InertiaRails
|
|
120
134
|
end
|
121
135
|
end
|
122
136
|
|
137
|
+
def deferred_props_keys
|
138
|
+
return if rendering_partial_component?
|
139
|
+
|
140
|
+
@props.each_with_object({}) do |(key, prop), result|
|
141
|
+
(result[prop.group] ||= []) << key if prop.is_a?(DeferProp)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def merge_props_keys
|
146
|
+
@props.each_with_object([]) do |(key, prop), result|
|
147
|
+
result << key if prop.try(:merge?) && reset_keys.exclude?(key)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
123
151
|
def partial_keys
|
124
|
-
(@request.headers['X-Inertia-Partial-Data'] || '').split(',').compact
|
152
|
+
@partial_keys ||= (@request.headers['X-Inertia-Partial-Data'] || '').split(',').compact
|
153
|
+
end
|
154
|
+
|
155
|
+
def reset_keys
|
156
|
+
(@request.headers['X-Inertia-Reset'] || '').split(',').compact.map(&:to_sym)
|
125
157
|
end
|
126
158
|
|
127
159
|
def partial_except_keys
|
@@ -147,8 +179,8 @@ module InertiaRails
|
|
147
179
|
return false if excluded_by_except_partial_keys?(path_with_prefixes)
|
148
180
|
end
|
149
181
|
|
150
|
-
# Precedence: Evaluate
|
151
|
-
return false if prop.is_a?(
|
182
|
+
# Precedence: Evaluate IgnoreOnFirstLoadProp only after partial keys have been checked
|
183
|
+
return false if prop.is_a?(IgnoreOnFirstLoadProp) && !rendering_partial_component?
|
152
184
|
|
153
185
|
true
|
154
186
|
end
|
data/lib/inertia_rails.rb
CHANGED
@@ -16,6 +16,8 @@ ActionController::Renderers.add :inertia do |component, options|
|
|
16
16
|
props: options[:props],
|
17
17
|
view_data: options[:view_data],
|
18
18
|
deep_merge: options[:deep_merge],
|
19
|
+
encrypt_history: options[:encrypt_history],
|
20
|
+
clear_history: options[:clear_history],
|
19
21
|
).render
|
20
22
|
end
|
21
23
|
|
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.
|
4
|
+
version: 3.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Knoles
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-
|
13
|
+
date: 2024-12-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|
@@ -218,14 +218,18 @@ files:
|
|
218
218
|
- lib/inertia_rails/base_prop.rb
|
219
219
|
- lib/inertia_rails/configuration.rb
|
220
220
|
- lib/inertia_rails/controller.rb
|
221
|
+
- lib/inertia_rails/defer_prop.rb
|
221
222
|
- lib/inertia_rails/engine.rb
|
222
223
|
- lib/inertia_rails/generators/controller_template_base.rb
|
223
224
|
- lib/inertia_rails/generators/helper.rb
|
224
225
|
- lib/inertia_rails/generators/scaffold_template_base.rb
|
225
226
|
- lib/inertia_rails/helper.rb
|
227
|
+
- lib/inertia_rails/ignore_on_first_load_prop.rb
|
226
228
|
- lib/inertia_rails/inertia_rails.rb
|
227
229
|
- lib/inertia_rails/lazy_prop.rb
|
230
|
+
- lib/inertia_rails/merge_prop.rb
|
228
231
|
- lib/inertia_rails/middleware.rb
|
232
|
+
- lib/inertia_rails/optional_prop.rb
|
229
233
|
- lib/inertia_rails/renderer.rb
|
230
234
|
- lib/inertia_rails/rspec.rb
|
231
235
|
- lib/inertia_rails/version.rb
|