Repository navigation
Fix: New sessions will automatically carry over messages from the previous session by default. - #18078
Conversation
…vious session by default.
📝 WalkthroughWalkthroughThe chat page now clears ChangesChat session state
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/src/pages/next-chats/chat/index.tsx`:
- Around line 56-58: Update the session-loading flow around fetchSessionManually
and setCurrentConversation so results from an outdated request cannot restore
the previous conversation after a new session opens. Cancel the prior request
when possible, or track the latest session selection and apply the fetched
conversation only when it still matches that selection; preserve clearing
messages for new sessions.
- Around line 56-58: Replace the `{}` assertion in the new-session reset and the
initial state with a shared empty-conversation factory that returns a fully
valid IClientConversation, including messages: [] and every required field.
Reuse this factory for both the initial state and setCurrentConversation in the
new-session branch so SingleChatBox and MultipleChatBox always receive a valid
conversation.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: bb159d8d-6702-4554-a997-c223946f63ff
📒 Files selected for processing (1)
web/src/pages/next-chats/chat/index.tsx
| } else { | ||
| // New session: clear previous session's messages so they don't leak in. | ||
| setCurrentConversation({} as IClientConversation); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Prevent stale requests from restoring the previous conversation.
If fetchSessionManually is still pending when a new session opens, it can resolve later and execute setCurrentConversation(conversation) at Line 54. The previous session's messages can then reappear. Cancel the previous request or apply the result only when it matches the latest session selection.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/pages/next-chats/chat/index.tsx` around lines 56 - 58, Update the
session-loading flow around fetchSessionManually and setCurrentConversation so
results from an outdated request cannot restore the previous conversation after
a new session opens. Cancel the prior request when possible, or track the latest
session selection and apply the fetched conversation only when it still matches
that selection; preserve clearing messages for new sessions.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Reset to a valid IClientConversation.
IClientConversation requires messages: IMessage[], but this branch assigns {} through a type assertion. SingleChatBox and MultipleChatBox receive this value. Use an empty-conversation factory with messages: [] and all required fields. Apply it to both the initial state at Line 27 and this reset.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/pages/next-chats/chat/index.tsx` around lines 56 - 58, Replace the
`{}` assertion in the new-session reset and the initial state with a shared
empty-conversation factory that returns a fully valid IClientConversation,
including messages: [] and every required field. Reuse this factory for both the
initial state and setCurrentConversation in the new-session branch so
SingleChatBox and MultipleChatBox always receive a valid conversation.
wangq8
left a comment
There was a problem hiding this comment.
Thanks for the fix! The change correctly prevents message leakage from a previous session into a new one.
What this does: When URL params indicate a new session (!conversationId || isNew), setCurrentConversation({} as IClientConversation) clears the stale conversation state before the new session data loads.
Review:
- ✅ The
elsebranch correctly handles the case where we are not loading an existing conversation - ✅
setCurrentConversationis a React state setter with stable reference, so it does not need to be in the dependency array - ✅ No side effects on the existing happy path (
conversationId && !isNew)
One suggestion (non-blocking): Consider wrapping the fetchConversation callback in a useCallback like the handleSessionClick is, to maintain consistency. But this is not required for correctness.
Approve ✅
…vious session by default. (infiniflow#18078)
Summary
Fix: New sessions will automatically carry over messages from the previous session by default.