Skip to content

Commit c0d938a

Browse files
committed
Merge remote-tracking branch 'origin' into refactor/shared
2 parents a780760 + 6e0fc5a commit c0d938a

File tree

13 files changed

+82
-18
lines changed

13 files changed

+82
-18
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

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+
713
## [3.1.4] - 2024-04-28
814

915
* Reset Inertia shared data after each RSpec example where `inertia: true` is used. Thanks @coreyaus!

lib/inertia_rails/middleware.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def response
1919
status, headers, body = @app.call(@env)
2020
request = ActionDispatch::Request.new(@env)
2121

22-
# Inertia errors are added to the session via redirect_to
22+
# Inertia errors are added to the session via redirect_to
2323
request.session.delete(:inertia_errors) unless keep_inertia_errors?(status)
2424

2525
status = 303 if inertia_non_post_redirect?(status)
@@ -96,4 +96,3 @@ def copy_xsrf_to_csrf!
9696
end
9797
end
9898
end
99-

lib/inertia_rails/renderer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def initialize(component, controller, request, response, render_method, props: n
2626

2727
def render
2828
if @request.headers['X-Inertia']
29-
@response.set_header('Vary', 'Accept')
29+
@response.set_header('Vary', 'X-Inertia')
3030
@response.set_header('X-Inertia', 'true')
3131
@render_method.call json: page, status: @response.status, content_type: Mime[:json]
3232
else

lib/inertia_rails/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module InertiaRails
2-
VERSION = "3.1.4"
2+
VERSION = "3.2.0"
33
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class InertiaConditionalSharingController < ApplicationController
2+
before_action :conditionally_share_props, only: [:show]
3+
inertia_share normal_shared_prop: 1
4+
5+
def index
6+
render inertia: 'EmptyTestComponent', props: {
7+
index_only_prop: 1,
8+
}
9+
end
10+
11+
def show
12+
render inertia: 'EmptyTestComponent', props: {
13+
show_only_prop: 1,
14+
}
15+
end
16+
17+
protected
18+
19+
def conditionally_share_props
20+
self.class.inertia_share conditionally_shared_show_prop: 1
21+
end
22+
end

spec/dummy/app/controllers/inertia_share_test_controller.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ class InertiaShareTestController < ApplicationController
44
inertia_share do
55
{
66
position: 'center',
7-
number: 29,
7+
number: number,
88
}
99
end
10-
10+
1111
def share
1212
render inertia: 'ShareTestComponent'
1313
end
14+
15+
private
16+
17+
def number
18+
29
19+
end
1420
end

spec/dummy/app/controllers/inertia_test_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,8 @@ def content_type_test
6464
format.xml { render xml: [ 1, 2, 3 ] }
6565
end
6666
end
67+
68+
def redirect_to_share_test
69+
redirect_to share_path
70+
end
6771
end

spec/dummy/config/application.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ class Application < Rails::Application
3434
config.secret_key_base = SecureRandom.hex
3535
end
3636
end
37-

spec/dummy/config/environments/test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
config.cache_store = :null_store
3030

3131
# Raise exceptions instead of rendering exception templates.
32-
config.action_dispatch.show_exceptions = false
32+
config.action_dispatch.show_exceptions = :none
3333

3434
# Disable request forgery protection in test environment.
3535
config.action_controller.allow_forgery_protection = false

spec/dummy/config/routes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
get 'default_component_test' => 'inertia_rails_mimic#default_component_test'
3535
get 'provided_props_test' => 'inertia_rails_mimic#provided_props_test'
3636

37+
post 'redirect_to_share_test' => 'inertia_test#redirect_to_share_test'
3738
inertia 'inertia_route' => 'TestComponent'
3839

3940
get 'merge_shared' => 'inertia_merge_shared#merge_shared'
@@ -46,4 +47,7 @@
4647
get 'initialize_session' => 'inertia_session_continuity_test#initialize_session'
4748
post 'submit_form_to_test_csrf' => 'inertia_session_continuity_test#submit_form_to_test_csrf'
4849
delete 'clear_session' => 'inertia_session_continuity_test#clear_session'
50+
51+
get 'conditional_share_index' => 'inertia_conditional_sharing#index'
52+
get 'conditional_share_show' => 'inertia_conditional_sharing#show'
4953
end

0 commit comments

Comments
 (0)