Skip to content
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

Refactor inertia share to use instance variables #111

Merged
merged 20 commits into from
Jun 19, 2024

Conversation

PedroAugustoRamalhoDuarte
Copy link
Contributor

@PedroAugustoRamalhoDuarte PedroAugustoRamalhoDuarte commented Apr 11, 2024

Goal

This PR refactors how inertia_share is storage inside the request lifecycle.

Solution

The solution was to sticky with default rails conventions, using only instance variable to storage inertia_share data and using inertia_share as a wrapper to rails before_action

Future improves

  • Maybe we can support easly only, expect features from before_action.

ledermann and others added 5 commits June 28, 2021 06:43
Move code to InertiaRails::Controller and use `class_attribute`
to manage definitions without affecting parent controller.

This avoids resetting shared data (`InertiaRails.reset!`) on
every request. Instead, the shared data is defined at class loading.

This change is thread-safe by design, so the multi-threading-test
is removed.
@buhrmi
Copy link
Contributor

buhrmi commented Apr 11, 2024

wow that was fast

@PedroAugustoRamalhoDuarte
Copy link
Contributor Author

@bknoles i see the problem with class_attribute and i refactor with this idea in mind: #108 (comment).

Basically using instance attributes and before_action, the CI is passing, but i think we need some more tests

lib/inertia_rails/controller.rb Outdated Show resolved Hide resolved
lib/inertia_rails/controller.rb Outdated Show resolved Hide resolved
@PedroAugustoRamalhoDuarte PedroAugustoRamalhoDuarte changed the title [Draft] ♻️ Refactor inertia share Refactor inertia share to use instance variables Apr 28, 2024
@PedroAugustoRamalhoDuarte PedroAugustoRamalhoDuarte marked this pull request as ready for review April 28, 2024 13:08
@bknoles
Copy link
Collaborator

bknoles commented Apr 29, 2024

Want to review the code a bit more, but, as I mentioned in #115 , I'm leaning towards merging this!

@PedroAugustoRamalhoDuarte
Copy link
Contributor Author

The tests that are failling in CI are bit flaky, i dont know if is a error in the test code or in the new controller implementation i can check better in this friday

@waliffcordeiro
Copy link

Great addition! Refactoring to stick with default Rails conventions by using instance variables to store inertia_share data and using inertia_share as a wrapper for before_action improves the clarity and maintainability of the code. Future enhancements, like supporting only and except features from before_action, would also be beneficial and add more flexibility. Good job!

Copy link
Collaborator

@bknoles bknoles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! I asked for a couple small changes plus to revert the multithreaded spec back to its original state (so we aren't changing the implementation and the spec at the same time).

Once we get those hammered out I'll get this merged in! Thanks for the good work and the patience + persistence!

spec/inertia/conditional_sharing_spec.rb Outdated Show resolved Hide resolved
lib/inertia_rails/controller.rb Outdated Show resolved Hide resolved
lib/inertia_rails/controller.rb Outdated Show resolved Hide resolved
lib/inertia_rails/inertia_rails.rb Show resolved Hide resolved
spec/inertia/sharing_spec.rb Outdated Show resolved Hide resolved
spec/inertia/ssr_spec.rb Show resolved Hide resolved
@bknoles
Copy link
Collaborator

bknoles commented May 31, 2024

Great addition! Refactoring to stick with default Rails conventions by using instance variables to store inertia_share data and using inertia_share as a wrapper for before_action improves the clarity and maintainability of the code. Future enhancements, like supporting only and except features from before_action, would also be beneficial and add more flexibility. Good job!

Team support! I like it! 😀

Copy link
Collaborator

@bknoles bknoles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At long last, a merge! Thanks for sticking with it!

@bknoles bknoles merged commit 6c76a33 into inertiajs:master Jun 19, 2024
9 checks passed
@bknoles
Copy link
Collaborator

bknoles commented Jun 19, 2024

Released as part of 3.2.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants