Skip to content

Keep the inbox fresh on back-navigation (turbo-cache-control)#3

Open
rameerez wants to merge 1 commit into
mainfrom
feat/inbox-no-cache-on-restore
Open

Keep the inbox fresh on back-navigation (turbo-cache-control)#3
rameerez wants to merge 1 commit into
mainfrom
feat/inbox-no-cache-on-restore

Conversation

@rameerez

@rameerez rameerez commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Follow-up to #2. That PR added chats--refresh-inbox, which heals a missed live broadcast on a page that stays open. This closes the other inbox-staleness case it can't touch.

The gap

A Turbo restoration visit — browser back / Hotwire Native stack pop — serves the inbox's cached snapshot with no GET. Open a chat from a profile, send a message, tap back → the snapshot cached before the chat existed comes back and the new conversation is missing until you navigate away and return. Pull-to-refresh is commonly disabled on the native inbox tab, so there's no manual escape. (Reported + reproduced end-to-end in a downstream host app.)

The chats--refresh-inbox controller can't help: it fires on cable reconnect / return-to-visible, not on a restore visit.

Fix

turbo-cache-control: no-cache on the inbox → Turbo never stores the snapshot → a restore visit re-fetches from the network and is always fresh.

Verified it reaches Hotwire Native, not just web:

  • native back-pop issues a Turbo .restore visit (Session.visitableViewWillAppear),
  • bundled turbo.js marks a no-cache page isCacheable == false, so the restore visit finds no cached snapshot and falls through to a network fetch.

Requires the host layout to yield :head (the Rails convention); harmless no-op otherwise. The dummy layout now yields :head so the suite can assert the meta renders.

Complementary to #2: missed live broadcast (controller) + stale restored snapshot (this). Both axes of inbox freshness now covered.

Companion to chats--refresh-inbox. That controller heals a MISSED live
broadcast on a page that stays OPEN; it does nothing for the other
inbox-staleness case: a Turbo RESTORATION visit (browser back / Hotwire
Native stack pop) serves the inbox's cached snapshot with no GET. Open a
chat from a profile, send a message, tap back — the snapshot cached
before the chat existed returns and the new conversation is missing until
you navigate away and return (pull-to-refresh is commonly disabled on the
native inbox tab).

`turbo-cache-control: no-cache` makes the inbox uncacheable, so a restore
visit re-fetches from the network — fresh on web AND in Hotwire Native
(back-pop issues a Turbo `.restore` visit that honors it; bundled turbo.js
marks a no-cache page isCacheable=false, so restore falls through to a
network fetch). Requires the host layout to `yield :head`; harmless no-op
otherwise. The dummy layout now yields :head so the suite can assert it.
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.

1 participant