Conversation
仅在首次会话解析期间阻塞路由树,后台会话刷新保持登录页及本地表单状态挂载。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
故障现象
在
/ctrl/login填写邮箱、手机号、密码、确认密码或姓名等登录/注册表单内容后,切换到其他浏览器标签页或窗口,再返回登录页时,尚未提交的内容会被清空,登录/注册模式等组件本地状态也可能恢复初始值。该问题可在 Chrome、Edge 和 Firefox 中稳定复现。DevTools Network 开启 Preserve log 后可看到返回页面时出现两次
/api/auth/get-session,随后再次请求/api/auth/signup-status,但没有新的/ctrl/loginDocument 请求:浏览器没有重新加载页面,而是应用内部卸载并重新挂载了登录页。根因
Better Auth 默认在页面重新可见时刷新 session。未登录状态下,刷新过程会短暂再次进入
isPending;根路由原先只要看到isPending就用全屏 loading 替换整个<Outlet />。因此登录页被卸载,保存在组件useState中的未提交表单内容随组件销毁而丢失;重新挂载时又触发了/api/auth/signup-status。修复方式
isPending,也保持当前路由子树挂载localStorage/sessionStorage验证
bun test web/src/__tests__/initial-session-loading.test.tsx:3 pass / 0 failweb/下执行bun x vite build:通过bun run precheck:format、import-sort、server/web TypeScript、lint 通过;后端测试在 Windows + Bun 1.4.0 下为 8028 pass / 94 fail,失败集中于/bin/sh、symlink、Windows 路径及级联用例,与本次前端改动无关风险与回滚
改动仅调整 session 后台 revalidation 时的加载展示策略,不改变认证请求、会话刷新或权限判断。回滚本提交即可恢复原行为。
🤖 Generated with Claude Code