fix(copilot): persist thinking blocks on page refresh#3194
fix(copilot): persist thinking blocks on page refresh#3194waleedlatif1 wants to merge 1 commit intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryThis PR fixes the loss of thinking blocks and in-progress copilot messages during page refresh/close. It uses
Confidence Score: 5/5Safe to merge — no blocking issues found; all changes are focused bug fixes The sendBeacon approach is the correct browser-native pattern for page-unload persistence. The beforeunload handler is synchronous, wrapped in a no-throw try/catch, and only fires when there is an active streaming message. flushStreamingUpdates correctly drains the RAF queue before persisting, ensuring thinking blocks are captured. The abortMessage path correctly suppresses the continue option and preserves the active stream on unload. The pl-6 to pl-8 change is a simple, safe cosmetic fix. No P0 or P1 issues were identified. No files require special attention Important Files Changed
Sequence DiagramsequenceDiagram
participant Browser
participant CopilotStore
participant Server as Server (update-messages)
Note over Browser,CopilotStore: User refreshes or closes tab while streaming
Browser->>CopilotStore: beforeunload fires
CopilotStore->>CopilotStore: _isPageUnloading = true
alt isSendingMessage && currentChat
CopilotStore->>CopilotStore: flushStreamingUpdates(setState)
Note over CopilotStore: Drains RAF-batched contentBlocks into store
CopilotStore->>Server: navigator.sendBeacon(blob)
Note over Server: Browser queues beacon — delivered after teardown
end
Note over Browser,CopilotStore: abortMessage() called (e.g. via cleanup on unmount)
CopilotStore->>CopilotStore: isPageUnloading() === true
CopilotStore->>CopilotStore: suppressContinueOption = true
CopilotStore->>CopilotStore: flushStreamingUpdates(set) — no-op if already flushed
CopilotStore->>CopilotStore: Preserve activeStream in sessionStorage
Note over CopilotStore: Stream can be resumed after page reload
CopilotStore->>Server: navigator.sendBeacon(blob)
Note over Server: Persists thinking blocks + partial content
Reviews (2): Last reviewed commit: "fix(copilot): persist thinking blocks on..." | Re-trigger Greptile |
| <Streamdown | ||
| components={{ | ||
| h2: ({ children, ...props }) => | ||
| h2: ({ children }: any) => |
There was a problem hiding this comment.
Using any type violates TypeScript conventions - consider using proper types from Streamdown's component prop types
| h2: ({ children }: any) => | |
| h2: ({ children }: { children?: React.ReactNode }) => |
Context Used: Context from dashboard - TypeScript conventions and type safety (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
- Use navigator.sendBeacon in beforeunload handler to reliably persist in-progress messages (including thinking blocks) during page teardown - Flush batched streaming updates before beacon persistence - Fall back to sendBeacon in abortMessage when page is unloading - Fix double-digit ordered list clipping in thinking block (pl-6 → pl-8)
87e50be to
031866e
Compare
Summary
navigator.sendBeaconinbeforeunloadto persist in-progress messages (including thinking blocks) during page refresh/closeabortMessageuses beacon instead of fire-and-forget fetch when page is unloadingpl-6→pl-8)Type of Change
Testing
Tested manually
Checklist