-
Notifications
You must be signed in to change notification settings - Fork 64
Determine whether a view template is being rendered by the inertia
custom renderer
#208
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
Comments
inertia
custom rendererinertia
custom renderer
Hey @Andy9822! Sounds like a great addition, I'd also add a view helper i.e. def inertia_rendering?
controller.instance_variable_get("@_inertia_rendering")
end |
cool cool cool! will give it a try later today also, great presentation about Inertia the other day, congratz! I enjoyed a lot talking with you afterwards 😄 |
I'm not so familiar with open source and contributing to projects, so sorry for silly questions or things, but I could find a way to assign anyone as reviewer to the PR I opened addressing this here: #209 how should I formally proceed in these situations? |
One other option you might consider for the use case that prompted this feature: Inertia respects the Rails layout configured by the controller, so you could create a separate layout for Inertia based controllers, even per action if you are migrating one route at a time. Here's an example of that from the test suite. (I say might consider because the specifics of your application.html.erb could certainly mean it's cleaner to conditionally add the inertia javascript via Either way, this is a nice addition to the library! Thanks for the contribution @Andy9822 ! |
I noticed that Inertia sets an instance variable
@_inertia_ssr_head
during SSR rendering:inertia-rails/lib/inertia_rails/helper.rb
Line 5 in c8f36c6
We're planning to gradually migrate our Rails application to use Inertia, and I need a way to detect in our
application.html.erb
layout whether the current request is being rendered through Inertia. This would help us conditionally include the appropriate JavaScript packs.Currently, there doesn't seem to be a way to detect if we're in an Inertia rendering context from the application layout (I may be wrong here, but so far I didn't find anything I could use).
Would it be acceptable if I submit a PR that adds an instance variable (e.g.,
@_inertia_rendering
) in theRenderer
class?inertia-rails/lib/inertia_rails/renderer.rb
Lines 7 to 8 in c8f36c6
This would allow us to conditionally include assets in our layout like:
The text was updated successfully, but these errors were encountered: