Closed
Conversation
This removes the fetch event listener that was added in c345484 to address stale content when launching/resuming the PWA. The fix was well-intentioned but ineffective for two reasons: 1. The service worker fetch handler only runs when an actual navigation occurs (cold start, manual refresh, link click). It does NOT run when a tab or PWA is resumed from memory - which is the primary scenario where users see stale content. When you switch back to a backgrounded tab, the page is already loaded in memory; no fetch happens. 2. Even when a fetch does occur, the `cache: 'no-cache'` option is redundant. The server already responds with `Cache-Control: max-age=0, private, must-revalidate` headers, which tells browsers to always revalidate before using cached HTML. The service worker was duplicating what the server headers already ensure. The actual stale content problem stems from WebSocket disconnection when tabs are backgrounded - Turbo Stream broadcasts are missed, and when the user returns, they see the in-memory page state from before. Solving this properly requires JavaScript that detects visibility changes and triggers a refresh after extended background time (similar to the existing frame_reloader_controller pattern). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Member
Author
|
Looking a bit more into this, it seems the behaviour this was attempting to fix was a very specific cold start of the Safari PWA. That means that 1 would apply, and a |
Member
Author
|
Yes, confirmed this seems to be a specific Safari bug, and this works around it. Ahhhh. Safari! ✊🏻 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This removes the fetch event listener that was added to address stale content when launching/resuming the PWA. I think the fix was ineffective for two reasons:
The service worker
fetchhandler only runs when an actual navigation occurs (cold start, manual refresh, link click). It does not run when a tab or PWA is resumed from memory, which is the primary scenario where users see stale content. When you switch back to a backgrounded tab, the page is already loaded in memory; no fetch happens.Even when a fetch does occur, the
cache: 'no-cache'option is redundant. The server already responds withCache-Control: max-age=0, private, must-revalidateheaders, which tells browsers to always revalidate before using cached HTML. The service worker was duplicating what the server headers already ensure.The actual stale content problem stems from
WebSocketdisconnection when tabs are backgrounded - Turbo Stream broadcasts are missed, and when the user returns, they see the in-memory page state from before. Solving this properly requires JavaScript that detects visibility changes and triggers a refresh after extended background time (similar to the existingframe_reloader_controllerpattern).