修复 Style 页保存失败后的状态回滚#331
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 49719efbaa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await persist(); | ||
| return true; | ||
| } catch (error) { | ||
| setPrefs(previousPrefs); |
There was a problem hiding this comment.
Preserve newer style edits when an earlier save fails
When two Style-page saves overlap, this unconditional rollback restores the entire snapshot captured before the failed request. For example, if disabling one style fails slowly after the user already toggled another style successfully, the late catch replaces the UI prefs with the state from before both clicks, so the UI no longer reflects the backend and a later full setSettings save can overwrite the successful edit. Consider rolling back only if the current state still matches this request's optimistic nextPrefs, or reverting only the field changed by the failed request.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
已改为按失败操作定向回滚:单项风格失败只恢复该模式,默认风格失败只恢复 defaultMode,整体开关失败仅在当前 enabledModes 仍等于本次 optimistic 值时才恢复。新增重叠保存回归测试,避免慢失败覆盖后续成功编辑。
PR Reviewer Guide 🔍(Review updated until commit f67e906)Here are some key observations to aid the review process:
|
Style page writes previously updated local UI state before awaiting IPC, so rejected handlers left the page showing values that were never persisted. The change keeps the optimistic update, but centralizes rollback to the previous preferences and surfaces the backend error inline near the failing control. Constraint: Issue Open-Less#313 asks for minimal frontend-only handling; backend handlers remain unchanged.\nRejected: Global toast framework | outside the issue scope and heavier than an inline page error.\nConfidence: high\nScope-risk: narrow\nTested: cd openless-all/app && npx tsx src/lib/stylePrefs.test.ts\nTested: cd openless-all/app && npm run build\nTested: git diff --check\nRelated: Open-Less#313
49719ef to
f67e906
Compare
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Persistent review updated to latest commit f67e906 |
User description
概述
验证
cd openless-all/app && npx tsx src/lib/stylePrefs.test.tscd openless-all/app && npm run buildgit diff --checkCloses #313
PR Type
Bug fix, Tests
Description
Add rollback on IPC save failure
Show inline error next to controls
Extract reusable save-and-rollback module
Add unit test for save failure paths
Diagram Walkthrough
flowchart LR A["User action"] --> B["Optimistic UI update"] B --> C["IPC persist call"] C --> D{"Success?"} D -->|Yes| E["Keep updated state"] D -->|No| F["Rollback to previous state"] F --> G["Show inline error"]File Walkthrough
5 files
Add save failure error message keyAdd save failure error message keyAdd save failure error message keyAdd save failure error message keyAdd save failure error message key1 files
Add unit tests for save failure rollback2 files
Implement save-and-rollback utility and rollback functionsAdd error handling and rollback to Style page writes