fix: multi device syncing issue#31
Merged
Merged
Conversation
旧实现完全用客户端 Date.now() 作为同步决策依据,存在两个致命问题: 1. 拉取-编辑竞态:B 设备拉取期间用户先开始编辑,本地 updatedAt 被 打上"新于远程"的时间戳,导致拉到的远程版本被识别为过时不覆盖; 接着 debounce 推送时反过来覆盖远程,A 设备的修改被静默吞掉。 2. 没有任何并发校验:从不查远程是否被别人改过,直接 last-write-wins, 谁后保存谁赢,与真正的时间先后无关。 引入 GitHub Gist 的服务端 updated_at 作为权威基线 remoteUpdatedAt, 配合两条不变量: - settings.updatedAt > settings.remoteUpdatedAt ⇔ 本地有未推送修改 - remote.updated_at > settings.remoteUpdatedAt ⇔ 远程被其他设备改过 主要改动: - types/setting.type.ts: 新增 remoteUpdatedAt 字段 - hooks/useSettings.ts: 用服务端时间戳决策合并;冲突时远程优先并 toast 警告;导出 patchSettings(不自增 updatedAt);updateSettings 改为 max(Date.now(), prev+1) 单调递增以抗时钟漂移 - hooks/useGistSync.ts: 推送前 await refetch() 校验远程是否被改过, 若被改则放弃推送让拉取流程接管;推送成功后用 GitHub 返回的 updated_at 写回 remoteUpdatedAt;移除 isFirstMount 跳过;修复 candi_tab_settings.json 拼写错误 - context/settings.context.ts & components/SettingProvider.tsx: 暴露 patchSettings - partials/Setting/OAuth/index.tsx: 创建/切换 gist 流程改用 patchSettings 写入 remoteUpdatedAt,避免切换 gist 后反向用本地内容 覆盖远程;去掉重复的 updateSettings 调用 - locales/*.json: 5 种语言的冲突提示翻译 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
🎉 This PR is included in version 1.9.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
No description provided.