Skip to content

fix(ui): 清理卸载后的延迟状态更新#93

Merged
H-Chris233 merged 1 commit into
Open-Less:mainfrom
H-Chris233:main
Apr 30, 2026
Merged

fix(ui): 清理卸载后的延迟状态更新#93
H-Chris233 merged 1 commit into
Open-Less:mainfrom
H-Chris233:main

Conversation

@H-Chris233
Copy link
Copy Markdown
Collaborator

摘要

Fixes #64

本 PR 按最小改动修复前端部分 setTimeout 未保存 handle,导致组件卸载后仍可能执行状态更新的问题。

此前 AboutSectionqqCopied 闪烁 timeout,以及 Onboarding 中 refresh 延后 timeout,未统一保存并在组件卸载时清理。React 18 strict mode 下可能出现组件卸载后 setState 的控制台警告,长时间使用也存在轻微泄漏风险。

本次改动将相关 timeout handle 改为通过 useRef 保存,并在组件卸载时执行 clearTimeout。重复触发时也会先清理旧 timeout,避免多个延迟回调叠加。

修复 / 新增 / 改进

  • 修复 Settings.tsxAboutSectionqqCopied 闪烁 timeout:

    • 使用 useRef 保存 timeout handle
    • 组件卸载时 clearTimeout
    • 重复点击复制时先清理旧 timeout
  • 修复 Onboarding.tsx 中 refresh 延后 timeout:

    • 使用 useRef 保存 timeout handle
    • 组件卸载时 clearTimeout
  • 保持现有 UI 行为不变:

    • 复制成功提示仍会短暂闪烁
    • Onboarding refresh 延后逻辑仍保留
  • CredentialField 相关 timeout 远端已有 ref / cleanup 处理,本 PR 未重复修改。

兼容

  • 不包含:

    • 不改变设置页业务逻辑。
    • 不改变 Onboarding 流程。
    • 不调整复制提示时长。
    • 不新增依赖。
    • 不做大范围 hooks 重构。
  • 对现有用户 / 本地环境 / 构建流程的影响:

    • 用户可见交互基本不变。
    • 组件卸载后不再保留相关延迟状态更新回调。
    • 可减少 React strict mode 下的卸载后状态更新警告。
    • 构建流程无变化。

测试计划

  • 命令:npm run build

  • 结果:通过

  • 证据路径:本地构建输出

  • 命令:git diff --check

  • 结果:通过

  • 证据路径:本地命令输出

主要改动文件

  • openless-all/app/src/pages/Settings.tsx
  • openless-all/app/src/components/Onboarding.tsx

备注

本 PR 仅处理当前仍缺少 timeout cleanup 的位置。CredentialField 相关 timeout 远端已有 ref / cleanup 处理,因此未在本次最小修复中重复改动。

Store the remaining transient UI timeout handles in refs so Settings About copy feedback and Onboarding delayed permission refresh do not call setState after their components unmount.

Constraint: Issue Open-Less#64 asks for minimal setTimeout handle cleanup without changing UI behavior

Confidence: high

Scope-risk: narrow

Tested: npm run build

Tested: git diff --check
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Sorry @H-Chris233, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@H-Chris233
Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@H-Chris233 H-Chris233 merged commit 9d92500 into Open-Less:main Apr 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: 前端 setTimeout 未保存句柄 — 组件卸载后 setState 警告 / 内存泄漏

1 participant