fix: 代理开关状态切换页面后不保存 (#183)#185
Conversation
The proxy enable/disable toggle only updated local React state (setForm) without persisting to the Zustand store. Users expected the toggle to take effect immediately (standard UX for switches), but the change was lost when navigating away from the Network panel. Now the toggle immediately syncs the enabled state to: - Local form state (instant visual feedback) - Zustand store (survives page navigation) - Backend via PUT /api/settings/proxy (keeps server config in sync) - Electron main process via electronProxy.setProxy Fixes #183 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe NetworkPanel toggle handler now updates local form state, immediately persists the new proxy config via setProxyConfig, and best-effort syncs the change to the backend API and Electron (both in try/catch, without response validation). ChangesImmediate Proxy Toggle Persistence
Sequence DiagramsequenceDiagram
participant User
participant NetworkPanel
participant ProxyStore
participant BackendAPI
participant Electron
User->>NetworkPanel: Click toggle
NetworkPanel->>NetworkPanel: Compute newForm (toggled enabled)
NetworkPanel->>ProxyStore: setProxyConfig(newForm)
ProxyStore-->>NetworkPanel: Store updated
NetworkPanel->>BackendAPI: PUT /api/settings/proxy (best-effort)
BackendAPI-->>NetworkPanel: Response (ignored/non-blocking)
NetworkPanel->>Electron: electronProxy.setProxy(newForm) (best-effort)
Electron-->>NetworkPanel: Ack (best-effort)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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.
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/components/settings/NetworkPanel.tsx`:
- Around line 122-146: The code is sending inconsistent payloads: it updates the
store with only { enabled: newEnabled } and sends { ...proxyConfig, enabled:
newEnabled } to the backend while sending newForm to Electron, which can discard
uncommitted edits due to the useEffect that mirrors proxyConfig into form. Fix
by treating newForm as the single source of truth: call setProxyConfig(newForm)
(not setProxyConfig({ enabled: newEnabled })), send newForm as the body to
fetch('/api/settings/proxy'), and continue using
electronProxy.setProxy(newForm); keep the existing authHeaders/try-catch logic
so both backend and Electron receive the identical newForm payload.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 72ab9683-ce3a-4054-8153-50f8d274cda8
📒 Files selected for processing (1)
src/components/settings/NetworkPanel.tsx
… sync
Address CodeRabbit review: send identical newForm to all three targets
instead of mixing { enabled }, { ...proxyConfig, enabled }, and newForm.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
问题
设置 → 网络设置 → 代理开关一旦开启后无法关闭。关闭开关后切到别的页面再切回来,开关仍然显示打开状态。
根因
代理开关的 只更新了本地 React state(),没有将 状态持久化到 Zustand store。用户需要手动点击「保存」按钮才会生效,但 toggle 开关的 UX 语义是即时生效的。
修复
修改 toggle 的 处理器,在切换时立即同步 状态到:
所有远程同步均为 best-effort,不会因网络问题阻塞 UI。
Fixes #183
Summary by CodeRabbit