Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/views/chats/conversations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
and on return-to-visible. It needs to wrap the <turbo-cable-stream-source>
that `turbo_stream_from` renders so it can observe its `connected`
attribute as the heartbeat. %>

<%# The OTHER inbox-staleness case, distinct from a missed broadcast: 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.
The reconciler above can't help (it only fires on reconnect / visibility,
not on a restore visit). `turbo-cache-control: no-cache` makes the inbox
uncacheable, so a restore visit re-fetches from the network and is always
fresh — on the web AND in Hotwire Native, whose back-pop issues a Turbo
`.restore` visit that honors this. Requires the host layout to
`yield :head` (the Rails convention); harmless no-op otherwise.
https://turbo.hotwired.dev/handbook/building#opting-out-of-caching %>
<% content_for :head do %>
<meta name="turbo-cache-control" content="no-cache">
<% end %>
<%= chats_styles %>
<div data-controller="chats--refresh-inbox">
<%= turbo_stream_from chats_current_messager, :chats_inbox %>
Expand Down
1 change: 1 addition & 0 deletions test/dummy/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<%# No javascript_importmap_tags: the suite asserts engine pins via
Rails.application.importmap directly; rendering the tags would need
propshaft digests for every pinned file in the dummy. %>
<%= yield :head %>
</head>
<body>
<%= yield %>
Expand Down
12 changes: 12 additions & 0 deletions test/integration/conversations_flow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ class ConversationsFlowTest < ActionDispatch::IntegrationTest
assert_select "[data-controller='chats--refresh-inbox'] turbo-cable-stream-source"
end

test "the inbox opts out of Turbo caching so back-navigation re-fetches it fresh" do
login_as @alice
get "/messages"

# The reconciler heals a MISSED live broadcast on an open page; it does NOT
# heal a STALE RESTORED snapshot. A Turbo restoration visit (browser back /
# Hotwire Native stack pop) serves the inbox snapshot cached before the
# latest activity, with no GET. no-cache makes the inbox uncacheable, so a
# restore visit re-fetches from the network and is always fresh.
assert_select "head meta[name='turbo-cache-control'][content='no-cache']", count: 1
end

test "the inbox hides blocked direct threads" do
block_pair!(@alice, @bob)
login_as @alice
Expand Down
Loading