-
Notifications
You must be signed in to change notification settings - Fork 71
Refactor inertia share to use instance variables #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bknoles
merged 20 commits into
inertiajs:master
from
PedroAugustoRamalhoDuarte:fix-data-sharing
Jun 19, 2024
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
35d01a0
Rewrite "inertia_share" to drop InertiaRails.reset!
ledermann c17171a
Test inertia_share with redirects
ledermann d3f86f4
Add test for exception handler
ledermann ff6833c
merge with origin
PedroAugustoRamalhoDuarte 4dfe6b5
refactor inertia headers for class variable
PedroAugustoRamalhoDuarte 55293f4
:refactor: rewrite multithread spec
PedroAugustoRamalhoDuarte ba50ac4
:refactor: refactor InertiaRails::Controller to use only instance var…
PedroAugustoRamalhoDuarte 0158d32
suppress testing warning
PedroAugustoRamalhoDuarte f0dcd35
make sure inertia initialize shared data for renderer
PedroAugustoRamalhoDuarte 9bbf451
refactor inertia html headers setter
PedroAugustoRamalhoDuarte 6160d38
cleanup test files
PedroAugustoRamalhoDuarte 5da531a
Merge remote-tracking branch 'other/master' into fix-data-sharing
PedroAugustoRamalhoDuarte 4349026
removes old ::InertiaRails.reset! from rspec
PedroAugustoRamalhoDuarte 7c3152a
call shared_data directly without send method
PedroAugustoRamalhoDuarte 077f5ad
conditionally shared data specs
bknoles b7d69cc
Mark as todo (an admittedly contrived) failing spec for conditionally…
PedroAugustoRamalhoDuarte a306898
improves conditional_sharing_spec.rb for edge case documentation
PedroAugustoRamalhoDuarte 6037973
rollback old multithreaded testing
PedroAugustoRamalhoDuarte a9cb801
removes unused methods from InertiaRails::Controller
PedroAugustoRamalhoDuarte c622c7a
refactor shared data method
PedroAugustoRamalhoDuarte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
spec/dummy/app/controllers/inertia_conditional_sharing_controller.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class InertiaConditionalSharingController < ApplicationController | ||
before_action :conditionally_share_props, only: [:show] | ||
inertia_share normal_shared_prop: 1 | ||
|
||
def index | ||
render inertia: 'EmptyTestComponent', props: { | ||
index_only_prop: 1, | ||
} | ||
end | ||
|
||
def show | ||
render inertia: 'EmptyTestComponent', props: { | ||
show_only_prop: 1, | ||
} | ||
end | ||
|
||
protected | ||
|
||
def conditionally_share_props | ||
self.class.inertia_share conditionally_shared_show_prop: 1 | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,3 @@ class Application < Rails::Application | |
config.secret_key_base = SecureRandom.hex | ||
end | ||
end | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
RSpec.describe "conditionally shared data in a controller", type: :request do | ||
context "when there is a before_action inside a inertia_share" do | ||
it "does leak data between requests" do | ||
get conditional_share_index_path, headers: {'X-Inertia' => true} | ||
expect(JSON.parse(response.body)['props'].deep_symbolize_keys).to eq({ | ||
index_only_prop: 1, | ||
normal_shared_prop: 1, | ||
}) | ||
|
||
# NOTE: we actually have to run the show action twice since the new implementation | ||
# sets up a before_action within a before_action to share the data. | ||
# In effect, that means that the shared data isn't rendered until the second time the action is run. | ||
get conditional_share_show_path, headers: {'X-Inertia' => true} | ||
get conditional_share_show_path, headers: {'X-Inertia' => true} | ||
expect(JSON.parse(response.body)['props'].deep_symbolize_keys).to eq({ | ||
normal_shared_prop: 1, | ||
show_only_prop: 1, | ||
conditionally_shared_show_prop: 1, | ||
}) | ||
|
||
get conditional_share_index_path, headers: {'X-Inertia' => true} | ||
expect(JSON.parse(response.body)['props'].deep_symbolize_keys).to eq({ | ||
index_only_prop: 1, | ||
normal_shared_prop: 1, | ||
conditionally_shared_show_prop: 1, | ||
}) | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.