inertiajs / inertia-rails

The Rails adapter for Inertia.js.
https://inertia-rails.dev/
MIT License
574 stars 45 forks source link

`Vary` header should be included in all Inertia responses #124

Closed ariel-codes closed 1 month ago

ariel-codes commented 4 months ago

Hi! I've stumbled upon a very specific error when an Inertia page is served from the browser cache:

  1. First, HTML page is accessed, response is cached
  2. Then, a partial reload on the same URL, expecting a Inertia JSON response (with X-Inertia header)
  3. Inertia gets served first HTML, errors and shows response inside a modal

Taking a look at the InertiaRails::Renderer, it seems that the Vary header that would prevent this from happening is only added for subsequent X-Inertia Inertia responses – and so the browser still uses the first response for all cache hits.

I'm testing a monkey-patch fix on my app and could open a PR if this is the correct diagnosis.

bknoles commented 1 month ago

Thanks for the report @ariel-codes !