Skip to content

fix(web): restore the last active chat session#1385

Merged
wj-xiao merged 2 commits intosipeed:mainfrom
Alix-007:fix/issue-1373-restore-last-session
Mar 13, 2026
Merged

fix(web): restore the last active chat session#1385
wj-xiao merged 2 commits intosipeed:mainfrom
Alix-007:fix/issue-1373-restore-last-session

Conversation

@Alix-007
Copy link
Copy Markdown
Contributor

@Alix-007 Alix-007 commented Mar 11, 2026

Fixes #1373.

Summary

  • persist the last active chat session id in local storage
  • hydrate that session history when the chat page opens again
  • keep manual session switching on the same loading path

Testing

  • pnpm exec tsc --noEmit
  • pnpm exec eslint src/hooks/use-pico-chat.ts

}))
}, [])

useEffect(() => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hydration effect is not safe under React StrictMode. In development, React runs the effect setup/cleanup/setup sequence on initial mount. The first pass sets the hydratedInitialSessionRef flag and starts the restore request, the cleanup marks it cancelled, and the second pass exits early because the flag is already set. That means the restored messages never get applied, so the feature appears broken locally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted in 16ce1a8. I removed the one-shot hydration gate so the initial restore effect remains safe under React StrictMode, and the restore now only applies if the session and local message revision are still unchanged when the request resolves.

content: m.content,
timestamp: fallbackTime,
}))
const historyMessages = await loadSessionMessages(sessionId)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial restore request is not guarded against later state changes. While loadSessionMessages(storedSessionId) is in flight, the websocket can already reconnect and receive new messages, or the user can switch to another session. When the restore promise resolves, it unconditionally calls setMessages(historyMessages), which can overwrite newer live messages or leave messages out of sync with activeSessionId.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted in 16ce1a8. The initial restore path now captures a message revision before requesting history and skips applying the result if the user switched sessions or any newer messages landed while the request was in flight, so it no longer overwrites live state.

@wj-xiao wj-xiao merged commit d24fccd into sipeed:main Mar 13, 2026
4 checks passed
dj-oyu pushed a commit to dj-oyu/picoclaw that referenced this pull request Mar 14, 2026
…ast-session

fix(web): restore the last active chat session
dj-oyu pushed a commit to dj-oyu/picoclaw that referenced this pull request Mar 16, 2026
…ast-session

fix(web): restore the last active chat session
neotty pushed a commit to neotty/picoclaw that referenced this pull request Mar 17, 2026
…ast-session

fix(web): restore the last active chat session
j0904 pushed a commit to j0904/picoclaw that referenced this pull request Mar 22, 2026
…ast-session

fix(web): restore the last active chat session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]在web对话页面,每次点击对话项目都是默认显示新的对话。希望修改为默认显示上次的对话内容。

2 participants