fix: persist RPC download secret across client restarts#189
Conversation
The RPC download secret (aria2 --rpc-secret) was excluded from Zustand persistence, causing it to disappear after every client restart in client-only and web-only modes. - Include secret in Zustand partialize to persist to IndexedDB - Restore secret in mergePersistedState hydration logic - Initialize hasStoredSecret from persisted secret on mount Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR updates the RPC download secret handling to persist across application restarts. The store now includes ChangesRPC Secret Persistence
Possibly related PRs
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/store/useAppStore.ts (1)
558-570: ⚡ Quick winAdd a round-trip regression test for
rpcDownloadConfig.secret.This fix depends on both normalization and
partializestaying in sync. A small store test that persists and rehydratesrpcDownloadConfig.secretwould make the web/local-only restart path much harder to regress again.Also applies to: 1542-1547
🤖 Prompt for 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. In `@src/store/useAppStore.ts` around lines 558 - 570, Add a round-trip regression test that verifies rpcDownloadConfig.secret is persisted and rehydrated unchanged: create a test that sets useAppStore().rpcDownloadConfig.secret to a non-empty string, forces the store to persist (or serializes via the same persistence/partialize logic used in the app), then rehydrate/deserialize into a fresh store instance and assert the secret value matches; ensure the test covers both normalization logic in the rpcDownloadConfig initializer (the object returned in the IIFE) and the persistence partialize/rehydration path so future changes to rpcDownloadConfig or partialize (also present in the other occurrence) will break the test if they diverge.
🤖 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.
Nitpick comments:
In `@src/store/useAppStore.ts`:
- Around line 558-570: Add a round-trip regression test that verifies
rpcDownloadConfig.secret is persisted and rehydrated unchanged: create a test
that sets useAppStore().rpcDownloadConfig.secret to a non-empty string, forces
the store to persist (or serializes via the same persistence/partialize logic
used in the app), then rehydrate/deserialize into a fresh store instance and
assert the secret value matches; ensure the test covers both normalization logic
in the rpcDownloadConfig initializer (the object returned in the IIFE) and the
persistence partialize/rehydration path so future changes to rpcDownloadConfig
or partialize (also present in the other occurrence) will break the test if they
diverge.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ff11ed5a-5d58-4e5c-8d21-f2aaba6783b8
📒 Files selected for processing (2)
src/components/settings/NetworkPanel.tsxsrc/store/useAppStore.ts
Problem
Settings → Network → Remote Download 中的密钥(aria2
--rpc-secret)在重启客户端后消失。根因: Zustand store 的
partialize明确排除了secret字段,mergePersistedState也未恢复它,导致密钥仅存在于内存中,重启即丢失。Fix
将
secret纳入 Zustand 持久化(IndexedDB),确保重启后恢复:useAppStore.ts—partialize包含secret;mergePersistedState恢复secretNetworkPanel.tsx—hasStoredSecret从持久化的secret初始化各模式验证
🤖 Generated with Claude Code
Summary by CodeRabbit