Skip to content

fix: WebDAV 配置激活后 isActive 字段未同步,导致自动备份校验失败#21

Merged
lostiv merged 2 commits into
mainfrom
fix/sync
May 12, 2026
Merged

fix: WebDAV 配置激活后 isActive 字段未同步,导致自动备份校验失败#21
lostiv merged 2 commits into
mainfrom
fix/sync

Conversation

@lostiv
Copy link
Copy Markdown
Owner

@lostiv lostiv commented May 12, 2026

No description provided.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d0f82210-5b46-44bf-b69e-73e7f4512d46

📥 Commits

Reviewing files that changed from the base of the PR and between 5f14de8 and 8b0c69d.

📒 Files selected for processing (1)
  • src/store/useAppStore.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/store/useAppStore.ts

📝 Walkthrough

Summary by CodeRabbit

  • Bug修复
    • 优化了 WebDAV 配置的持久化与恢复流程:重建时会恢复每项配置的激活标记,并在引用的配置不存在时将激活项清空,避免错误状态。
    • 调整了切换激活配置的行为:设置激活项时会同步更新所有配置,确保只有选中的配置被标记为激活。

Walkthrough

补水时重建并校验 webdavConfigs 的 isActive 标志;激活操作在一次状态更新中同时设置 activeWebDAVConfig 并在 webdavConfigs 中同步 isActive。

变更清单

WebDAV配置状态同步

层 / 文件 摘要
状态补水中的isActive标志重构
src/store/useAppStore.ts
normalizePersistedState 遍历持久化的 webdavConfigs,为每个配置注入 isActive 布尔值(基于 ID 与 activeWebDAVConfig 的匹配),并在引用 ID 不存在时将 activeWebDAVConfig 规范化为 null
活跃配置更新中的isActive同步
src/store/useAppStore.ts
setActiveWebDAVConfig 动作现在在一次更新中同步修改 webdavConfigs 数组中所有配置的 isActive 状态(匹配的为 true,其他为 false),同时更新 activeWebDAVConfig 字段。

代码审查重点

  1. 状态一致性:补水逻辑与激活逻辑的 isActive 计算是否完全一致。
  2. 空安全:当 webdavConfigsactiveWebDAVConfig 为空/缺失时行为是否明确(返回空数组或 null)。
  3. 原子性与响应性:一次性更新多个字段时 Zustand 的订阅/渲染行为是否满足预期。
  4. 性能:在大量配置时对数组的每次遍历开销及是否需要优化(节流/增量更新)。

可能相关的PR

建议标签

bug, frontend


🎯 2 (Simple) | ⏱️ ~8 分钟

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive PR 描述为空,无法验证其与变更集的相关性。 建议添加 PR 描述,说明问题背景、解决方案和测试验证情况,便于代码审查。
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed PR标题遵循 Conventional Commits 格式 (type: description),清晰描述了 WebDAV 配置的 isActive 字段同步问题。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sync
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/sync

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added bug Something isn't working frontend labels May 12, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/store/useAppStore.ts`:
- Around line 358-360: The persisted webdavConfigs mapping sets per-config
isActive but does not validate or normalize safePersisted.activeWebDAVConfig,
which can leave activeWebDAVConfig pointing at a deleted id; update the
initialization to compute the normalized active id by mapping
safePersisted.webdavConfigs to include isActive and then set activeWebDAVConfig
to the id of the matched active config (or null) in the same atomic step so
state is consistent—use the same variables (safePersisted, webdavConfigs,
activeWebDAVConfig) and ensure activeWebDAVConfig is cleared or replaced when no
config matches.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3669bb56-0d21-4635-8d0b-a497081725bd

📥 Commits

Reviewing files that changed from the base of the PR and between f8f36ca and 5f14de8.

📒 Files selected for processing (1)
  • src/store/useAppStore.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
src/store/**

⚙️ CodeRabbit configuration file

src/store/**: Zustand 状态管理。审查时请关注: 1. 持久化存储(IndexedDB)的数据结构和版本迁移 2. Selector 的细粒度订阅(避免不必要的重渲染) 3. 敏感数据是否被持久化到客户端 4. 状态更新的原子性和一致性

Files:

  • src/store/useAppStore.ts
🔇 Additional comments (1)
src/store/useAppStore.ts (1)

895-898: setActiveWebDAVConfig 的原子更新实现正确

同一次 set 内同步更新 activeWebDAVConfig 与每个配置的 isActive,能有效避免激活状态分裂,方向正确。

As per coding guidelines src/store/**: “状态更新的原子性和一致性”。

Comment thread src/store/useAppStore.ts Outdated
@lostiv lostiv merged commit 2465e7a into main May 12, 2026
1 check passed
@lostiv lostiv deleted the fix/sync branch May 12, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working frontend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant