Closed snaptopixel closed 3 years ago
Hey @snaptopixel this has been discussed before in #37 .
The TL;DR is that changing the .erb
layout file requires a full page refresh. To reliably trigger that, we would need the client side library to send up which template it was using on every request. If that change were made on the client side library, then we could handle dynamic root templates in inertia_rails
pretty easily.
I don't believe that's in the plans for inertia.js
. It seems to be a core assumption of the client side library that a single root template is used for Inertia across the app.
FWIW, there is a suggested workaround from the Laravel repo: https://github.com/inertiajs/inertia-laravel/issues/114
...which is to treat the "main" app separately from the non-standard layout app (in this case the share page) and use regular anchor tags instead of <InertiaLink />
s when linking between them. In that case, you could set the Inertia layout dynamically in a before_action
in your share page controller. Keep in mind that the configuration is stored per-thread and not per-request, so you might need to reset the layout configuration in an after_action
callback or commit to specifying it in every controller. I haven't tried this myself, but it seems like it should work.
Unfortunately, I don't believe we can build that workaround into the Rails library because it relies on the user writing their frontend templates in a specific and perhaps non-obvious way.
Thanks for the quick reply @bknoles, much appreciated! That does make sense about the core assumption. Looks like Inertia does support triggering a full page reload via: inertia_location index_path
based on the docs here maybe that would be relevant?
Yea, under the hood that method just sends a 409 Conflict
header so that Inertia.js knows to trigger a full page refresh:
https://github.com/inertiajs/inertia-rails/blob/master/lib/inertia_rails/controller.rb#L39
We'd do the same thing here if we could detect that the "layout on the page that the request was made from" is different than the "layout specified in receiving controller action." The trick is that we can't detect the original layout file.
I'm going to close this issue, but if you think of or use any kind of workaround, please post it here. We'd love to support this feature if it's possible to do so.
We would like to be able to switch layout erb files, imagine a share page with meta tags etc. It would be great if you could pass the desired layout to
render inertia
or use the default when necessary