inertia_rails 3.1.3 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/push.yml +7 -13
- data/CHANGELOG.md +11 -0
- data/Gemfile +3 -0
- data/inertia_rails.gemspec +0 -1
- data/lib/inertia_rails/controller.rb +34 -8
- data/lib/inertia_rails/inertia_rails.rb +0 -54
- data/lib/inertia_rails/middleware.rb +1 -4
- data/lib/inertia_rails/renderer.rb +4 -6
- data/lib/inertia_rails/version.rb +1 -1
- metadata +3 -24
- data/Appraisals +0 -19
- data/gemfiles/rails_5.1.gemfile +0 -7
- data/gemfiles/rails_5.2.gemfile +0 -7
- data/gemfiles/rails_6.0.gemfile +0 -7
- data/gemfiles/rails_6.1.gemfile +0 -7
- data/gemfiles/rails_7.0.gemfile +0 -7
- data/lib/inertia_rails/helper.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76a7152d32edba5a140ed16b25efe25a6766a7d53c955f39f6b5efb2b5fc0d12
|
4
|
+
data.tar.gz: c1dc0d2bf09b2f3c71e4729a26dc6c24c78dc0fe4c5b8d09484bacee18543953
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70ff7787dd839a58c652ffe5fa402be2baa2036ea54b86b2b033ecaf2062304a4f5e8433316eea192ab25009d6c5e8b1cf45dfeba71dc6f8775b361cb3055f50
|
7
|
+
data.tar.gz: 9e9072c293cd62385df9e8be3f464c7b688acc665ad4ce40daea5fd29c0414c18ba5c9f72967edfc3c7963974867d2791486e78714cea98ac212c64f38144ccb
|
data/.github/workflows/push.yml
CHANGED
@@ -7,17 +7,14 @@ jobs:
|
|
7
7
|
strategy:
|
8
8
|
fail-fast: false
|
9
9
|
matrix:
|
10
|
-
ruby: [
|
11
|
-
rails: ['
|
12
|
-
exclude:
|
13
|
-
- rails: '7.0'
|
14
|
-
ruby: 2.6
|
10
|
+
ruby: ['3.1', '3.2', '3.3']
|
11
|
+
rails: ['6.1', '7.0', '7.1']
|
15
12
|
|
16
13
|
runs-on: ubuntu-latest
|
17
14
|
name: Test against Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
|
18
15
|
|
19
16
|
steps:
|
20
|
-
- uses: actions/checkout@
|
17
|
+
- uses: actions/checkout@v4
|
21
18
|
|
22
19
|
- name: Setup System
|
23
20
|
run: sudo apt-get install libsqlite3-dev
|
@@ -26,14 +23,11 @@ jobs:
|
|
26
23
|
uses: ruby/setup-ruby@v1
|
27
24
|
with:
|
28
25
|
ruby-version: ${{ matrix.ruby }}
|
29
|
-
|
30
|
-
- name: Install gems
|
26
|
+
bundler-cache: true
|
31
27
|
env:
|
32
|
-
|
33
|
-
run: |
|
34
|
-
export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/rails_${MATRIX_RAILS_VERSION}.gemfile"
|
35
|
-
gem install bundler
|
36
|
-
bundle install --jobs 4 --retry 3
|
28
|
+
RAILS_VERSION: ${{ matrix.rails }}
|
37
29
|
|
38
30
|
- name: Run tests
|
39
31
|
run: bundle exec rake
|
32
|
+
env:
|
33
|
+
RAILS_VERSION: ${{ matrix.rails }}
|
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.2.0] - 2024-06-19
|
8
|
+
|
9
|
+
* Refactor the internals of shared Inertia data to use controller instance variables instead of module level variables that run a higher risk of being leaked between requests. Big thanks to @ledermann for the initial work many years ago and to @PedroAugustoRamalhoDuarte for finishing it up!
|
10
|
+
* Change the Inertia response to set the `Vary` header to `X-Inertia` instead of `Accept`, Thanks @osbre!
|
11
|
+
* Always set the `XSRF-TOKEN` in an `after_action` request instead of only on non-Inertia requests. This fixes a bug where logging out (and resetting the session) via Inertia would create a CSRF token mismatch on a subsequent Inertia request (until you manually hard refreshed the page). Thanks @jordanhiltunen!
|
12
|
+
|
13
|
+
## [3.1.4] - 2024-04-28
|
14
|
+
|
15
|
+
* Reset Inertia shared data after each RSpec example where `inertia: true` is used. Thanks @coreyaus!
|
16
|
+
* Update Github Actions workflows to use currently supported Ruby/Rails versions. Thanks @PedroAugustoRamalhoDuarte!
|
17
|
+
|
7
18
|
## [3.1.3] - 2023-11-03
|
8
19
|
|
9
20
|
* Depend on railties instead of rails so that applications which only use pieces of Rails can avoid a full Rails installation. Thanks @BenMorganMY!
|
data/Gemfile
CHANGED
data/inertia_rails.gemspec
CHANGED
@@ -32,7 +32,6 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency "rspec-rails", "~> 4.0"
|
33
33
|
spec.add_development_dependency "rails-controller-testing"
|
34
34
|
spec.add_development_dependency "sqlite3"
|
35
|
-
spec.add_development_dependency "appraisal"
|
36
35
|
spec.add_development_dependency "responders"
|
37
36
|
spec.add_development_dependency "debug"
|
38
37
|
end
|
@@ -1,27 +1,37 @@
|
|
1
1
|
require_relative "inertia_rails"
|
2
|
-
require_relative "helper"
|
3
2
|
|
4
3
|
module InertiaRails
|
5
4
|
module Controller
|
6
5
|
extend ActiveSupport::Concern
|
7
6
|
|
8
7
|
included do
|
8
|
+
helper_method :inertia_headers
|
9
|
+
|
9
10
|
before_action do
|
10
|
-
|
11
|
-
|
11
|
+
error_sharing = proc do
|
12
|
+
# :inertia_errors are deleted from the session by the middleware
|
13
|
+
if @_request && session[:inertia_errors].present?
|
14
|
+
{ errors: session[:inertia_errors] }
|
15
|
+
else
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
@_inertia_shared_plain_data ||= {}
|
21
|
+
@_inertia_shared_blocks ||= [error_sharing]
|
22
|
+
@_inertia_html_headers ||= []
|
12
23
|
end
|
13
|
-
helper ::InertiaRails::Helper
|
14
24
|
|
15
25
|
after_action do
|
16
|
-
cookies['XSRF-TOKEN'] = form_authenticity_token unless
|
26
|
+
cookies['XSRF-TOKEN'] = form_authenticity_token unless !protect_against_forgery?
|
17
27
|
end
|
18
28
|
end
|
19
29
|
|
20
30
|
module ClassMethods
|
21
|
-
def inertia_share(
|
31
|
+
def inertia_share(hash = nil, &block)
|
22
32
|
before_action do
|
23
|
-
|
24
|
-
|
33
|
+
@_inertia_shared_plain_data = @_inertia_shared_plain_data.merge(hash) if hash
|
34
|
+
@_inertia_shared_blocks = @_inertia_shared_blocks + [block] if block_given?
|
25
35
|
end
|
26
36
|
end
|
27
37
|
|
@@ -33,6 +43,14 @@ module InertiaRails
|
|
33
43
|
end
|
34
44
|
end
|
35
45
|
|
46
|
+
def inertia_headers
|
47
|
+
@_inertia_html_headers.join.html_safe
|
48
|
+
end
|
49
|
+
|
50
|
+
def inertia_headers=(value)
|
51
|
+
@_inertia_html_headers = value
|
52
|
+
end
|
53
|
+
|
36
54
|
def default_render
|
37
55
|
if InertiaRails.default_render?
|
38
56
|
render(inertia: true)
|
@@ -41,6 +59,10 @@ module InertiaRails
|
|
41
59
|
end
|
42
60
|
end
|
43
61
|
|
62
|
+
def shared_data
|
63
|
+
(@_inertia_shared_plain_data || {}).merge(evaluated_blocks)
|
64
|
+
end
|
65
|
+
|
44
66
|
def redirect_to(options = {}, response_options = {})
|
45
67
|
capture_inertia_errors(response_options)
|
46
68
|
super(options, response_options)
|
@@ -80,5 +102,9 @@ module InertiaRails
|
|
80
102
|
session[:inertia_errors] = inertia_errors
|
81
103
|
end
|
82
104
|
end
|
105
|
+
|
106
|
+
def evaluated_blocks
|
107
|
+
(@_inertia_shared_blocks || []).map { |block| instance_exec(&block) }.reduce(&:merge) || {}
|
108
|
+
end
|
83
109
|
end
|
84
110
|
end
|
@@ -3,20 +3,10 @@ require 'active_support/core_ext/module/attribute_accessors_per_thread'
|
|
3
3
|
require 'inertia_rails/lazy'
|
4
4
|
|
5
5
|
module InertiaRails
|
6
|
-
thread_mattr_accessor :threadsafe_shared_plain_data
|
7
|
-
thread_mattr_accessor :threadsafe_shared_blocks
|
8
|
-
thread_mattr_accessor :threadsafe_html_headers
|
9
|
-
|
10
6
|
def self.configure
|
11
7
|
yield(Configuration)
|
12
8
|
end
|
13
9
|
|
14
|
-
# "Getters"
|
15
|
-
def self.shared_data(controller)
|
16
|
-
shared_plain_data.
|
17
|
-
merge!(evaluated_blocks(controller, shared_blocks))
|
18
|
-
end
|
19
|
-
|
20
10
|
def self.version
|
21
11
|
Configuration.evaluated_version
|
22
12
|
end
|
@@ -35,35 +25,12 @@ module InertiaRails
|
|
35
25
|
|
36
26
|
def self.default_render?
|
37
27
|
Configuration.default_render
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.html_headers
|
41
|
-
self.threadsafe_html_headers || []
|
42
28
|
end
|
43
29
|
|
44
30
|
def self.deep_merge_shared_data?
|
45
31
|
Configuration.deep_merge_shared_data
|
46
32
|
end
|
47
33
|
|
48
|
-
# "Setters"
|
49
|
-
def self.share(**args)
|
50
|
-
self.shared_plain_data = self.shared_plain_data.merge(args)
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.share_block(block)
|
54
|
-
self.shared_blocks = self.shared_blocks + [block]
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.html_headers=(headers)
|
58
|
-
self.threadsafe_html_headers = headers
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.reset!
|
62
|
-
self.shared_plain_data = {}
|
63
|
-
self.shared_blocks = []
|
64
|
-
self.html_headers = []
|
65
|
-
end
|
66
|
-
|
67
34
|
def self.lazy(value = nil, &block)
|
68
35
|
InertiaRails::Lazy.new(value, &block)
|
69
36
|
end
|
@@ -82,25 +49,4 @@ module InertiaRails
|
|
82
49
|
self.version.respond_to?(:call) ? self.version.call : self.version
|
83
50
|
end
|
84
51
|
end
|
85
|
-
|
86
|
-
# Getters and setters to provide default values for the threadsafe attributes
|
87
|
-
def self.shared_plain_data
|
88
|
-
self.threadsafe_shared_plain_data || {}
|
89
|
-
end
|
90
|
-
|
91
|
-
def self.shared_plain_data=(val)
|
92
|
-
self.threadsafe_shared_plain_data = val
|
93
|
-
end
|
94
|
-
|
95
|
-
def self.shared_blocks
|
96
|
-
self.threadsafe_shared_blocks || []
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.shared_blocks=(val)
|
100
|
-
self.threadsafe_shared_blocks = val
|
101
|
-
end
|
102
|
-
|
103
|
-
def self.evaluated_blocks(controller, blocks)
|
104
|
-
blocks.flat_map { |block| controller.instance_exec(&block) }.reduce(&:merge) || {}
|
105
|
-
end
|
106
52
|
end
|
@@ -7,8 +7,6 @@ module InertiaRails
|
|
7
7
|
def call(env)
|
8
8
|
InertiaRailsRequest.new(@app, env)
|
9
9
|
.response
|
10
|
-
ensure
|
11
|
-
::InertiaRails.reset!
|
12
10
|
end
|
13
11
|
|
14
12
|
class InertiaRailsRequest
|
@@ -22,7 +20,7 @@ module InertiaRails
|
|
22
20
|
status, headers, body = @app.call(@env)
|
23
21
|
request = ActionDispatch::Request.new(@env)
|
24
22
|
|
25
|
-
# Inertia errors are added to the session via redirect_to
|
23
|
+
# Inertia errors are added to the session via redirect_to
|
26
24
|
request.session.delete(:inertia_errors) unless keep_inertia_errors?(status)
|
27
25
|
|
28
26
|
status = 303 if inertia_non_post_redirect?(status)
|
@@ -97,4 +95,3 @@ module InertiaRails
|
|
97
95
|
end
|
98
96
|
end
|
99
97
|
end
|
100
|
-
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'json'
|
3
1
|
require_relative "inertia_rails"
|
4
2
|
|
5
3
|
module InertiaRails
|
@@ -19,7 +17,7 @@ module InertiaRails
|
|
19
17
|
|
20
18
|
def render
|
21
19
|
if @request.headers['X-Inertia']
|
22
|
-
@response.set_header('Vary', '
|
20
|
+
@response.set_header('Vary', 'X-Inertia')
|
23
21
|
@response.set_header('X-Inertia', 'true')
|
24
22
|
@render_method.call json: page, status: @response.status, content_type: Mime[:json]
|
25
23
|
else
|
@@ -33,8 +31,8 @@ module InertiaRails
|
|
33
31
|
def render_ssr
|
34
32
|
uri = URI("#{::InertiaRails.ssr_url}/render")
|
35
33
|
res = JSON.parse(Net::HTTP.post(uri, page.to_json, 'Content-Type' => 'application/json').body)
|
36
|
-
|
37
|
-
|
34
|
+
|
35
|
+
@controller.inertia_headers = res['head']
|
38
36
|
@render_method.call html: res['body'].html_safe, layout: layout, locals: (view_data).merge({page: page})
|
39
37
|
end
|
40
38
|
|
@@ -48,7 +46,7 @@ module InertiaRails
|
|
48
46
|
#
|
49
47
|
# Functionally, this permits using either string or symbol keys in the controller. Since the results
|
50
48
|
# is cast to json, we should treat string/symbol keys as identical.
|
51
|
-
_props =
|
49
|
+
_props = @controller.shared_data.merge.deep_symbolize_keys.send(prop_merge_method, @props.deep_symbolize_keys).select do |key, prop|
|
52
50
|
if rendering_partial_component?
|
53
51
|
key.in? partial_keys
|
54
52
|
else
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Knoles
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2024-06-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|
@@ -96,20 +96,6 @@ dependencies:
|
|
96
96
|
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
|
-
- !ruby/object:Gem::Dependency
|
100
|
-
name: appraisal
|
101
|
-
requirement: !ruby/object:Gem::Requirement
|
102
|
-
requirements:
|
103
|
-
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
version: '0'
|
106
|
-
type: :development
|
107
|
-
prerelease: false
|
108
|
-
version_requirements: !ruby/object:Gem::Requirement
|
109
|
-
requirements:
|
110
|
-
- - ">="
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: '0'
|
113
99
|
- !ruby/object:Gem::Dependency
|
114
100
|
name: responders
|
115
101
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,7 +136,6 @@ files:
|
|
150
136
|
- ".github/workflows/push.yml"
|
151
137
|
- ".gitignore"
|
152
138
|
- ".rspec"
|
153
|
-
- Appraisals
|
154
139
|
- CHANGELOG.md
|
155
140
|
- CODE_OF_CONDUCT.md
|
156
141
|
- Gemfile
|
@@ -161,11 +146,6 @@ files:
|
|
161
146
|
- app/views/inertia.html.erb
|
162
147
|
- bin/console
|
163
148
|
- bin/setup
|
164
|
-
- gemfiles/rails_5.1.gemfile
|
165
|
-
- gemfiles/rails_5.2.gemfile
|
166
|
-
- gemfiles/rails_6.0.gemfile
|
167
|
-
- gemfiles/rails_6.1.gemfile
|
168
|
-
- gemfiles/rails_7.0.gemfile
|
169
149
|
- inertia_rails.gemspec
|
170
150
|
- lib/generators/inertia_rails/install/controller.rb
|
171
151
|
- lib/generators/inertia_rails/install/react/InertiaExample.jsx
|
@@ -178,7 +158,6 @@ files:
|
|
178
158
|
- lib/inertia_rails.rb
|
179
159
|
- lib/inertia_rails/controller.rb
|
180
160
|
- lib/inertia_rails/engine.rb
|
181
|
-
- lib/inertia_rails/helper.rb
|
182
161
|
- lib/inertia_rails/inertia_rails.rb
|
183
162
|
- lib/inertia_rails/lazy.rb
|
184
163
|
- lib/inertia_rails/middleware.rb
|
@@ -214,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
193
|
- !ruby/object:Gem::Version
|
215
194
|
version: '0'
|
216
195
|
requirements: []
|
217
|
-
rubygems_version: 3.
|
196
|
+
rubygems_version: 3.5.10
|
218
197
|
signing_key:
|
219
198
|
specification_version: 4
|
220
199
|
summary: Inertia adapter for Rails
|
data/Appraisals
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
appraise "rails-7.0" do
|
2
|
-
gem "rails", "~> 7.0"
|
3
|
-
end
|
4
|
-
|
5
|
-
appraise "rails-6.1" do
|
6
|
-
gem "rails", "~> 6.1.0"
|
7
|
-
end
|
8
|
-
|
9
|
-
appraise "rails-6.0" do
|
10
|
-
gem "rails", "~> 6.0.3", '>= 6.0.3.2'
|
11
|
-
end
|
12
|
-
|
13
|
-
appraise "rails-5.2" do
|
14
|
-
gem "rails", "~> 5.2.4", '>= 5.2.4.3'
|
15
|
-
end
|
16
|
-
|
17
|
-
appraise "rails-5.1" do
|
18
|
-
gem "rails", "~> 5.1.7"
|
19
|
-
end
|
data/gemfiles/rails_5.1.gemfile
DELETED
data/gemfiles/rails_5.2.gemfile
DELETED
data/gemfiles/rails_6.0.gemfile
DELETED
data/gemfiles/rails_6.1.gemfile
DELETED
data/gemfiles/rails_7.0.gemfile
DELETED