Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements several improvements to the smart reading interface including editor reset functionality, better conversation state tracking, enhanced error handling for missing conversations, and fixes for SSR hydration mismatches.
- Added
resetEditormethod to NoteEditorPanel for clearing editor state - Enhanced conversation history loading with 404 error recovery and state tracking
- Fixed hydration mismatches in notes pages by deferring token reads to client-side
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/components/note-editor/NoteEditorPanel.tsx | Added resetEditor method to ref interface and implementation to clear all editor state |
| frontend/src/components/ai-agent/AgentChatPanel.tsx | Added savedConversationRef tracking, improved 404 error handling with cache cleanup, and conditional auto-summary prevention |
| frontend/src/app/smart-reading/page.tsx | Updated ref type to include resetEditor, removed obsolete state setters, and added editor reset on PDF close |
| frontend/src/app/notes/page.tsx | Fixed SSR hydration mismatch by deferring token read to useEffect with loading state |
| frontend/src/app/notes/new/page.tsx | Applied same hydration fix as notes page |
| frontend/package-lock.json | Removed peer dependency flags from several packages |
Files not reviewed (1)
- frontend/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)
frontend/src/components/ai-agent/AgentChatPanel.tsx:146
- The
loadConversationHistorycallback usespaperIdon line 128 but doesn't include it in the dependency array. This could lead to stale closure issues where the callback references an outdatedpaperIdvalue. AddpaperIdto the dependency array.
const loadConversationHistory = useCallback(async (convId: number) => {
if (!convId) return;
setIsLoadingHistory(true);
try {
const token = getAccessToken();
if (!token) {
console.warn("未登录,无法加载对话历史");
return;
}
const conversation = await getConversationHistory(token, convId, "reading");
if (conversation.messages && conversation.messages.length > 0) {
const historyMessages: AgentMessage[] = conversation.messages.map((msg) => ({
id: createId(),
role: msg.role,
content: msg.content,
timestamp: new Date(msg.created_at),
}));
setMessages(historyMessages);
savedConversationRef.current = true;
}
} catch (error) {
console.error("加载对话历史失败:", error);
// 后端会在类别不匹配或不存在时返回 404;清理本地缓存以便重新创建对话
const message = error instanceof Error ? error.message : "";
if (message.includes("不存在") || message.toLowerCase().includes("not found")) {
if (paperId) {
localStorage.removeItem(`conversation_${paperId}`);
}
setConversationId(null);
setMessages([
{
id: createId(),
role: "assistant",
content: "对话不存在,已为当前文档重置。可以继续提问,我会新建对话并保存历史。",
timestamp: new Date(),
},
]);
savedConversationRef.current = false;
}
// 其他错误不影响新对话
} finally {
setIsLoadingHistory(false);
}
}, []);
Collaborator
Author
|
these changes have been merged to release, not dev |
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.
No description provided.