修复第1章各认证页之间切换会带出上一个页面的报错文案

现象:在注册页填错邀请码提交后(正确显示"邀请码错误,请重新输入"),点击"已有账号?登录"
切到登录页,登录表单顶部会原样带出这条"邀请码错误"提示——用户在登录页什么都还没做,却先看到
一句跟登录毫不相关的报错。反过来,登录密码错误后点"马上注册"也会把"账号或密码错误"带到刚打开
的注册页。

根因:errorText/errorLevel 是 tinode-web.jsx 顶层的一份全局共享状态,不跟当前显示哪个
sidepanel 绑定。Login 组件自己的"切换企业"链接会在跳转前先调用一次 onError() 清空,说明
之前已经意识到这个状态会带着走,但企业码/登录/注册/忘记密码等页面之间的其它跳转都没有做
同样的处理——其中 Register 等好几个视图目前甚至没有拿到 onError 这个 prop,需要在各处
分别补,比较分散。

修复:在 AuthOnboardingView(chapterOneViews 统一走的入口组件)里加一个以 view 为依赖的
useEffect,view 变化时统一调用 onError() 清空全局报错状态,一次性覆盖企业码/登录/注册/
忘记密码等视图之间的所有切换路径(含浏览器前进后退),不用逐个跳转调用点分别处理。

验证:注册页提交错误邀请码复现"邀请码错误,请重新输入"后点击"登录",确认登录页不再带出
该提示;反向验证登录页密码错误后点击"马上注册",确认注册页同样不再带出"账号或密码错误"。

注:umd/index.dev.js 本轮未随此提交一起提交——auth-onboarding-view.jsx 不是按路由懒加载的
独立 chunk,此刻工作区里另有并行 agent 正在改 contact-management-view.jsx / call-panel.jsx
且未提交,重新构建的 index.dev.js 会把它们尚未提交的改动一起编译进同一个产物文件,为避免把
不相关改动混进这次提交,本次只提交源码,构建产物留给后续统一重新构建的提交处理。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Your Name
2026-09-06 15:40:43 +08:00
co-authored by Claude Sonnet 5
parent a71aee9487
commit 605cd12a6e
+20
View File
@@ -825,6 +825,26 @@ export default function AuthOnboardingView({
onLoginRequest, onPersistenceChange, onImRegisterRequest, onError onLoginRequest, onPersistenceChange, onImRegisterRequest, onError
}) { }) {
const tenantName = sessionStorage.getItem('im-tenant-name') || ''; const tenantName = sessionStorage.getItem('im-tenant-name') || '';
// errorText/errorLevel is one flat, top-level (tinode-web.jsx) piece of state shared by every
// view in the whole app -- it's never tied to which sidepanel is showing. Login is the only view
// here that already clears it on its own (its "切换企业" link calls onError() before navigating),
// because it was written knowing it can carry a leftover error INTO the tenant screen. Every other
// transition between these auth views was still missing that: submit a bad invite code on
// Register (errorText='邀请码错误,请重新输入', view stays 'register', shown correctly), then just
// click "已有账号?登录" -- Login mounts and, since it renders the exact same errorText/errorLevel
// props, shows that same registration error as if it were a login failure, with zero user action
// on this new page. Same the other way: a stale "账号或密码错误" from Login is still sitting there
// to greet a fresh Register visit. Fixing every call site that navigates between these views
// (TenantEntry/Login/Register/... several of which don't even receive onError as a prop today)
// would be a lot of scattered one-off edits for the same bug; clearing it centrally whenever the
// resolved `view` itself changes covers all of them (button clicks and browser back/forward alike)
// from the one place they all already funnel through.
React.useEffect(() => {
if (onError) onError();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [view]);
switch (view) { switch (view) {
case 'tenant': return <TenantEntry onTenantResolved={onTenantResolved || (() => {})} />; case 'tenant': return <TenantEntry onTenantResolved={onTenantResolved || (() => {})} />;
case 'login': return <Login tenantName={tenantName} login={login} loginDisabled={loginDisabled} persist={persist} case 'login': return <Login tenantName={tenantName} login={login} loginDisabled={loginDisabled} persist={persist}