这是indexloc提供的服务,不要输入任何密码
Skip to content

🏄‍♂️ fix: Handle SSE Stream Edge Case #8556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 19, 2025
Merged

Conversation

danny-avila
Copy link
Owner

Summary

I refactored the draft auto-save and restore logic to use dedicated utility functions, ensured proper draft encoding/decoding, and fixed a blank page issue when an SSE stream is cancelled before a response is received.

  • Moved encodeBase64, decodeBase64, and clearDraft into a new drafts.ts utility file for modularity and reuse
  • Updated useAutoSave hook to utilize the new draft utility functions, reducing redundant code and improving reliability
  • Implemented setDraft and getDraft helpers; all draft-related logic and storage centralized for clarity
  • Fixed getDraft to always decode stored draft values before returning them to avoid showing invalid base64 data in the input field
  • Handled a specific edge case in useEventHandlers where stream cancellation before any response would previously result in a blank conversation page, now preventing navigation and properly restoring any previous or empty draft state
  • Ensured conversation message state and draft input retain consistency in interrupted or failed conversations

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (code quality improvement, no behavior change)
  • Documentation update (added or improved inline comments)

Testing

I manually tested the following scenarios in the LibreChat UI:

  • Draft auto-saving and restoration when navigating between conversations and after refresh
  • Cancelling a streaming response before any content arrives: confirmed the page does not go blank and past drafts/messages persist or reset as expected
  • Draft text consistently appears decoded in the input field after reloads or navigation
  • All storage relevant to draft content is encoded/decoded appropriately

Test Configuration:

  • Latest LibreChat main branch
  • Chrome browser
  • Tested both new and existing conversations with and without SSE response interruptions

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works (manual verification for edge cases)
  • Local unit tests pass with my changes

@danny-avila danny-avila merged commit 4c754c1 into dev Jul 19, 2025
6 checks passed
@danny-avila danny-avila deleted the fix/abort-before-conn branch July 19, 2025 17:44
segyepark pushed a commit to segyepark/LibreChat that referenced this pull request Jul 21, 2025
* refactor: Move draft-related utilities to a new `drafts.ts` file

* refactor: auto-save draft logic to use new get/set functions

* fix: Ensure `getDraft` properly decodes stored draft values

* fix: Handle edge case where stream is cancelled before any response, which creates a blank page
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