Repository navigation
fix(sse): close the event stream on pagehide and reconnect on bfcache restore - #434
Merged
Merged
Conversation
Contributor
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.
Summary
Pages could hang on loading skeletons for 15s or more after a few full-page navigations over plain HTTP.
The app opens one
EventSourceto/api/sse/streamand never closed it when the page was hidden. Chrome puts the page into the back/forward cache on full-document navigations (address bar, bookmarks, back/forward, the/loginredirects), and the cached page's stream stayed open./api/sse/statusreported 4-5 live clients for a single tab. Over HTTP/1.1 Chrome allows only 6 connections per host, so after about 5 navigations the next page load waited for a connection to free up. HTTPS behind an HTTP/2 proxy hides the problem; plainhttp://host:portaccess does not.Fix
OpenCodeEventStreamregisters window listeners in the browser:pagehidecloses the live connection through the existingdisconnectConnectionOnly(). Subscribers and directory ref counts are kept, and directories are re-queued as pending.pageshowwithpersisted: true(restored from the back/forward cache) calls the existingreconnect(), which resubscribes the pending directories and notifies status like any other reconnect.Type of Change
Checklist
pnpm lint:frontendpasses locallyTests
frontend/src/lib/opencode-event-stream/__tests__/openCodeEventStream.test.ts:pagehidecloses the active connection and does not schedule a reconnect.pageshowwithpersisted: trueopens a new connection carrying the subscribed directories.pageshowwithpersisted: falseopens no extra connection.Validation
pnpm --filter frontend exec vitest run src/lib/opencode-event-stream src/hooks/useSSE.test.tsx: 38 passedpnpm --filter frontend exec tsc --noEmit -p .andpnpm lint:frontend: clean/api/sse/statusclimbed to 4-5 clients and navigations timed out after 15s.Summary by CodeRabbit