Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(login): 登录错误页重连期间不再锁住「跳过登录」 (#6010)
Dashb312fb94d595
diff --git a/apps/desktop/src/renderer/components/login/LoginPage.tsx b/apps/desktop/src/renderer/components/login/LoginPage.tsxindex ff0fdfc06a..3b7f8a899a 100644--- a/apps/desktop/src/renderer/components/login/LoginPage.tsx+++ b/apps/desktop/src/renderer/components/login/LoginPage.tsx@@ -186,9 +186,14 @@ export function LoginPage({* 未勾选时先弹协议弹窗,同意后才进主界面。调用方一律用* `requireConsent(..., { deferConsentPersist: true })` 包裹:同意记录由**本函数*** 在会话切过去之后落,不能由 requireConsent 提前落(竞态原因见那里的注释)。+ *+ * 这里**不看 isLoading**:error 步的逃生入口在「返回 / 重试」请求进行中也必须可用,+ * 否则登录服务连不上时每点一次就把用户锁到超时。main 的 enter-local 会推进+ * loginFlowEpoch,在途登录动作迟到时以 AUTH_FLOW_SUPERSEDED 作废,不会回写状态。+ * 面板内入口仍由按钮 disabled 与协议门的 busy 复验挡住 in-flight。*/const openLocalMode = async () => {- if (isLoading || localModePendingRef.current || !enterLocalMode) return;+ if (localModePendingRef.current || !enterLocalMode) return;markLocalModeTransition(true);try {// 必须走 AuthContext.enterLocalMode():它调同一条 IPC,并用返回值立刻改@@ -234,6 +239,8 @@ export function LoginPage({stamp: ConsentStamp;// true = 同意时不在弹窗回调里落同意记录,由 action 自己落(见 requireConsent)deferConsentPersist: boolean;+ // true = 续接复验不看 in-flight(见 requireConsent)+ allowDuringLoginRequest: boolean;} | null>(null);/* 把「用户明示同意《隐私政策》」这个事实落到 main。@@ -261,8 +268,15 @@ export function LoginPage({* 会当场发出 device_login),等 enter-local 完成再广播 allowed:false 已经晚了。* 于是「未登录态不上报」这条承诺在正式包上会被破一个窗口。让 openLocalMode* 先切会话、再落同意即可关掉这个窗口(此时 allowed 恒为 false)。+ * @param options.allowDuringLoginRequest+ * true = 登录请求进行中也可过门续接。只有 error 步逃生入口用它:进入未登录状态+ * 不是登录派发,「in-flight 时不追加并发派发」那条复验不适用;照常复验的话,+ * 用户在重试转圈时点「跳过登录」并同意协议,动作会被静默丢弃。*/- const requireConsent = (action: () => void, options?: { deferConsentPersist?: boolean }) => {+ const requireConsent = (+ action: () => void,+ options?: { deferConsentPersist?: boolean; allowDuringLoginRequest?: boolean },+ ) => {/* 会话切换进行中一律不接新的过门动作(codex 审查 P1 第二条,#907)。`auth:enter-local` 的 handler 要 await waitForSessionInvalidation() 与teardownAuthAccountBoundary(),这是一个真实可观测的窗口;窗口里 isLoading@@ -274,6 +288,7 @@ export function LoginPage({杜绝了 persist 与派发 —— 会话都在切了,任何登录动作本来就该作废。 */if (localModePendingRef.current) return;const deferConsentPersist = options?.deferConsentPersist === true;+ const allowDuringLoginRequest = options?.allowDuringLoginRequest === true;if (consentAccepted) {if (!deferConsentPersist) persistPrivacyConsent();action();@@ -281,8 +296,13 @@ export function LoginPage({}pendingConsentAction.current = {action,- stamp: makeConsentStamp(loginState?.step, isLoading, loginState?.step === 'completed'),+ stamp: makeConsentStamp(+ loginState?.step,+ allowDuringLoginRequest ? false : isLoading,+ loginState?.step === 'completed',+ ),deferConsentPersist,+ allowDuringLoginRequest,};setConsentDialogOpen(true);};@@ -299,7 +319,11 @@ export function LoginPage({if (!pending?.deferConsentPersist) persistPrivacyConsent();if (!pending) return;// 复验:弹窗期间 auth 状态被异步推进(登录完成/步骤切换/in-flight)则丢弃动作- const current = makeConsentStamp(loginState?.step, isLoading, loginState?.step === 'completed');+ const current = makeConsentStamp(+ loginState?.step,+ pending.allowDuringLoginRequest ? false : isLoading,+ loginState?.step === 'completed',+ );if (canResumePendingConsent(pending.stamp, current)) pending.action();};const dismissConsent = () => {@@ -335,6 +359,8 @@ export function LoginPage({}, [reportLoginPanelMounted, reportLoginPanelUnmounted]);// 「跳过登录」常驻入口在面板内(identifier 视图 SKIP_ENTRY 文字链);footer 仅保留// error 步的逃生入口——登录服务不可用时用户仍能进入本地模式(既有产品保证)。+ // 「返回 / 重试」都要重新连登录服务,连不上时会一直等到超时;逃生入口不随这次+ // 等待禁用,否则用户每点一次返回就被锁在这一屏。const showLocalModeFooter =!isAddAccount && loginState?.step === 'error' && !credentialStoreFailed;// 面板底部预留恒取全流程最大值(footer 124;协议行 48 被其覆盖):step 切换时@@ -1395,9 +1421,14 @@ export function LoginPage({<buttondata-testid="login-local-mode"type="button"- disabled={localModePending || isLoading}+ disabled={localModePending}// error 步逃生入口与面板内文字按钮同口径:过协议门(2026-07-29 拍板)- onClick={() => requireConsent(() => void openLocalMode(), { deferConsentPersist: true })}+ onClick={() =>+ requireConsent(() => void openLocalMode(), {+ deferConsentPersist: true,+ allowDuringLoginRequest: true,+ })+ }aria-describedby="login-local-mode-description"className="select-none rounded-full border border-[var(--border-default)] bg-[var(--surface-elevated)] px-6 py-2.5 text-13 font-medium text-[var(--text-primary)] transition-colors hover:bg-[var(--surface-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring-soft)] disabled:cursor-not-allowed disabled:opacity-60"style={{ minHeight: 40 }}diff --git a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.browserRedirect.test.tsx b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.browserRedirect.test.tsxindex 6853e4eb46..4b339336f4 100644--- a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.browserRedirect.test.tsx+++ b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.browserRedirect.test.tsx@@ -145,7 +145,10 @@ describe('LoginPage browser redirect waiting state', () => {expect(screen.queryByRole('button', { name: 'sidebar.accountSwitcher.title' })).toBeNull();});- it('disables local entry while a login request is pending', () => {+ // Back and Retry both reconnect to the login service. Disabling the escape+ // entry for that wait trapped users on this screen whenever the service was+ // unreachable, so it only follows the local-session switch itself.+ it('keeps the error-step local entry available while a login request is pending', () => {loginHook.value = {isLoading: true,errorCode: null,@@ -158,6 +161,6 @@ describe('LoginPage browser redirect waiting state', () => {expect((screen.getByRole('button', { name: 'login.localModeEntry' }) as HTMLButtonElement).disabled,- ).toBe(true);+ ).toBe(false);});});diff --git a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.consent.test.tsx b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.consent.test.tsxindex bf1a17922d..5dbbdd8790 100644--- a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.consent.test.tsx+++ b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.consent.test.tsx@@ -404,6 +404,35 @@ describe('consent guard(未勾选拦截个人登录链路)', () => {expect(screen.getByTestId('login-local-mode')).toBeTruthy();});+ /* 「返回 / 重试」都要重新连登录服务,连不上时会一直等到超时。逃生入口若随这次+ 等待禁用,用户每点一次返回就被锁在 error 屏(0.1.104 实测:点返回 → 请稍候 →+ 超时 → 留在原地,期间跳过登录也点不了)。 */+ it('error 步重连登录服务期间逃生入口仍可用;同意后不因 in-flight 被丢弃', async () => {+ mount(errorState, { errorCode: 'NETWORK_ERROR', isLoading: true });+ const escape = screen.getByTestId('login-local-mode') as HTMLButtonElement;+ expect(escape.disabled).toBe(false);+ await act(async () => {+ fireEvent.click(escape);+ });+ expect(screen.getByTestId('login-consent-dialog')).toBeTruthy();+ await act(async () => {+ fireEvent.click(screen.getByTestId('login-consent-agree'));+ });+ expect(enterLocalMode).toHaveBeenCalledTimes(1);+ expect(enterLocalMode.mock.invocationCallOrder[0]).toBeLessThan(+ acceptPrivacyConsent.mock.invocationCallOrder[0],+ );+ });++ it('面板内「跳过登录」在登录请求进行中仍禁用(只放开 error 步逃生入口)', async () => {+ mount(await identifierState('providers:cn-social'), { isLoading: true });+ const entry = screen.getByTestId('login-skip-entry') as HTMLButtonElement;+ expect(entry.disabled).toBe(true);+ fireEvent.click(entry);+ expect(screen.queryByTestId('login-consent-dialog')).toBeNull();+ expect(enterLocalMode).not.toHaveBeenCalled();+ });+it('旧游客圆钮入口已删除(圆钮行不再渲染 login-social-guest)', async () => {mount(await identifierState('providers:cn-social'));expect(screen.queryByTestId('login-social-guest')).toBeNull();diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.mdindex c8191c887d..f59d45283d 100644--- a/docs/design-rules/DESIGN.md+++ b/docs/design-rules/DESIGN.md@@ -1992,7 +1992,7 @@ and media position (`ui/media-scrubber`, seconds in/out). Native media controls| `binding` | 身份未绑 membership,补绑 phone / email(`codeRequested` 两子态;**无重发钮**,桌面 harness 锁定) | `LoginInput` / `LoginSkinPhoneInput` → `LoginInput`(center) + `LoginPrimaryButton` || `account-deletion`(状态浮层) | 账号删除**状态展示**(发起流程在 Settings 的 `AccountDeletionSection`;登录页仅在存在删除回执时以**根层浮层气泡**展示 status,非主状态机 step;详见下方「注销状态浮层气泡」) | `AccountDeletionStatusPanel`(**登录皮容器外**的根层浮层,非面板内) || `browser-redirect` | 社交 / SSO 跳浏览器验证,等待回调 | `LoginLoadingRing` + Desktop `LoginBackButton`(`cancel-browser`;Mobile 保留原取消入口)+ `LoginTitleBlock` |-| `completed` / `error` | 登录成功 / 失败(含 browser 回调终态页);`error` 步桌面另有面板下方 footer 的「跳过登录」**逃生入口**(登录服务不可用时仍能进未登录状态,与面板内入口同口径**过协议门**——2026-07-29 拍板) | 成功无面板(进主界面);error = `LoginBackButton`(仅桌面,复用 reset;普通登录与添加账号均重新加载登录入口)+ `LoginTitleBlock` + `LoginPrimaryButton`(重试)+ `LoginErrorText` + footer「跳过登录」按钮(桌面);browser 回调页 `oauthResultPage`(系统浏览器独立 HTML,main 侧内联常量,色值与 `--login-callback-*` token 同源——renderer CSS var 不可达,改值需两处同步) |+| `completed` / `error` | 登录成功 / 失败(含 browser 回调终态页);`error` 步桌面另有面板下方 footer 的「跳过登录」**逃生入口**(登录服务不可用时仍能进未登录状态,与面板内入口同口径**过协议门**——2026-07-29 拍板;返回 / 重试重新连接登录服务期间**不禁用**,只在切换到未登录状态的过程中禁用) | 成功无面板(进主界面);error = `LoginBackButton`(仅桌面,复用 reset;普通登录与添加账号均重新加载登录入口)+ `LoginTitleBlock` + `LoginPrimaryButton`(重试)+ `LoginErrorText` + footer「跳过登录」按钮(桌面);browser 回调页 `oauthResultPage`(系统浏览器独立 HTML,main 侧内联常量,色值与 `--login-callback-*` token 同源——renderer CSS var 不可达,改值需两处同步) |**~~配置错误屏同样承载「跳过登录」逃生入口(移动端)~~〔已作废 2026-07-28:手机端整体剥离,配置错误屏无该入口〕**:`getMobileConfigIssues()` 命中(如 auth base URL 非法)时面板切到 config 提示态,该面板内仍渲染同一个 `LoginSkipLoginLink`(同槽 @(0,430)、同 handler、同 in-flight 门)——跳过登录不发任何网络请求,配置坏掉时恰恰最需要这个入口。