fix(chat): keep the current session in the URL as ?c=
Independent Staging Quality Gate / validate (push) Has been cancelled
Independent Staging Quality Gate / publish (push) Has been cancelled

Refresh, back, and login return were dropping the open conversation because selection lived only in React state.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jesse_Chen
2026-09-01 20:42:21 +08:00
co-authored by Cursor
parent 48174a3cc5
commit 924f420202
8 changed files with 502 additions and 7 deletions
+16
View File
@@ -7134,3 +7134,19 @@
- 相关记录:无
- 复发自:无
- 修复版本:待发布
## BUG-465 | 会话选择只活在内存里,刷新、后退和登录回跳都会丢掉当前对话
- 状态:resolved
- 首次发现:2026-09-01
- 最近更新:2026-09-01
- 影响面:首页 `activeSessionId`、浏览器历史、`redirectToLogin` 后的登录回跳
- 用户现象:无论当前在哪个对话,刷新后回到最近一条;会话间切换后按后退会直接离开站点;登录过期后再登回来落在空白首页,对不上刚才那条对话。
- 触发条件:在侧边栏点开非默认会话后刷新;连续切换几个会话后按浏览器后退;带着 `?c=` 会话地址遇到 401 被送去登录。
- 根因:`activeSessionId` 只存在 React state。地址栏没有会话痕迹,登录页的 `successPath` 也只允许回到 `/``/admin`
- 修复:合法会话 id 写入 `?c=`。用户主动切换、新建、打开校正时 `pushState`;删除/归档当前会话或伪造 id 时 `replaceState`。默认选中和生成恢复不写 URL。`popstate` 复用 `selectSession` 且不再二次 push。401 把当前 `?c=` 暂存 sessionStorage,登录落回 `/` 后启动逻辑读回并清暂存。登录页零改动。
- 验证:合同测试锁启动读参、默认不写 URL、popstate 不二次 push、删除清死链、401 暂存、首页不用 `useSearchParams``./node_modules/.bin/tsc --noEmit`、前端测试与 `next build``/` `○ Static` 必须通过。
- 防复发:首页不得为读 query 引入 `useSearchParams` 或服务端 `searchParams`,以免 `/` 从 Static 退化。不得给登录页加开放重定向 `next` 参数。默认选中不得 `pushState`
- 相关记录:BUG-464
- 复发自:无
- 修复版本:待发布