Skip to content

fix: 回前台重连去抖,避免一次切前台触发两轮同步 - #242

Open
CorrectRoadH wants to merge 1 commit into
haierkeys:masterfrom
CorrectRoadH:upstream/fix/resume-reconnect-debounce
Open

fix: 回前台重连去抖,避免一次切前台触发两轮同步#242
CorrectRoadH wants to merge 1 commit into
haierkeys:masterfrom
CorrectRoadH:upstream/fix/resume-reconnect-debounce

Conversation

@CorrectRoadH

Copy link
Copy Markdown
Contributor

问题

手机回到前台时,onWindowFocusonVisibilityChange各调一次 triggerReconnect()。而每次重连成功(auth → StartHandle)都会无条件发起一轮同步,也就是一次全库扫描。

修复

把两个入口合并到 scheduleResumeReconnect():1s 去抖,且只在 !isConnected() 时才真的重连。一次切前台 = 一次重连 = 一轮同步。定时器在 stop() 里一并清理。

注:重连后「是否该立刻全库扫描」本身还值得再加个节流(比如距上次成功同步不足 N 分钟就跳过扫描、只补发 pending 变更),涉及同步策略取舍,没有放进这个 PR。

已跑 tsc -noEmit -skipLibCheck 通过。

🤖 Generated with Claude Code

https://claude.ai/code/session_01T2QYrNjmd1hNqgzWyR4jFZ

手机回到前台时 focus 和 visibilitychange 会各调一次 triggerReconnect,
每次重连成功都会发起一轮全库扫描同步。

合并为 1s 去抖,且只在连接确实已断开时才重连。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T2QYrNjmd1hNqgzWyR4jFZ
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.

1 participant