Skip to content

修复 Style 页保存失败后的状态回滚#331

Merged
H-Chris233 merged 1 commit into
Open-Less:betafrom
H-Chris233:fix/issue-313-style-save-feedback
May 7, 2026
Merged

修复 Style 页保存失败后的状态回滚#331
H-Chris233 merged 1 commit into
Open-Less:betafrom
H-Chris233:fix/issue-313-style-save-feedback

Conversation

@H-Chris233
Copy link
Copy Markdown
Collaborator

@H-Chris233 H-Chris233 commented May 7, 2026

User description

概述

  • 修复 Style 页默认风格、单项启停、整体启用三条写入路径的 IPC 失败处理
  • 保存失败时回滚到点击前的本地 prefs,并在对应卡片/总开关旁展示后端错误信息
  • 增加手写回归测试覆盖 setSettings reject 时的 optimistic state 回滚

验证

  • cd openless-all/app && npx tsx src/lib/stylePrefs.test.ts
  • cd openless-all/app && npm run build
  • git diff --check

Closes #313


PR Type

Bug fix, Tests


Description

  • Add rollback on IPC save failure

    • Three write ops now restore previous state on error
  • Show inline error next to controls

    • Error message from backend displayed at toggle/card
  • Extract reusable save-and-rollback module

    • New stylePrefs.ts with persist and rollback helpers
  • Add unit test for save failure paths

    • Covers optimistic update rollback on rejection

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"]
Loading

File Walkthrough

Relevant files
Enhancement
5 files
en.ts
Add save failure error message key                                             
+1/-0     
ja.ts
Add save failure error message key                                             
+1/-0     
ko.ts
Add save failure error message key                                             
+1/-0     
zh-CN.ts
Add save failure error message key                                             
+1/-0     
zh-TW.ts
Add save failure error message key                                             
+1/-0     
Tests
1 files
stylePrefs.test.ts
Add unit tests for save failure rollback                                 
+103/-0 
Bug fix
2 files
stylePrefs.ts
Implement save-and-rollback utility and rollback functions
+70/-0   
Style.tsx
Add error handling and rollback to Style page writes         
+62/-8   

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment thread openless-all/app/src/lib/stylePrefs.ts Outdated
await persist();
return true;
} catch (error) {
setPrefs(previousPrefs);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

已改为按失败操作定向回滚:单项风格失败只恢复该模式,默认风格失败只恢复 defaultMode,整体开关失败仅在当前 enabledModes 仍等于本次 optimistic 值时才恢复。新增重叠保存回归测试,避免慢失败覆盖后续成功编辑。

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

PR Reviewer Guide 🔍

(Review updated until commit f67e906)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

313 - PR Code Verified

Compliant requirements:

  • Add try/catch to onPickDefault(), onToggleEnabled() and onMasterToggle() so that IPC save failures are caught.
  • On failure, roll back local state to the previous preferences.
  • Display an inline error message next to the affected control.
  • Provide at least one test that covers the setSettings rejection path and confirms the UI rolls back correctly.

Requires further human verification:

  • Visual check: confirmation that the inline error appears at the correct location and disappears after a subsequent successful save may need manual browser testing.
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

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
@H-Chris233 H-Chris233 force-pushed the fix/issue-313-style-save-feedback branch from 49719ef to f67e906 Compare May 7, 2026 14:01
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Persistent review updated to latest commit f67e906

@H-Chris233 H-Chris233 merged commit fc24d37 into Open-Less:beta May 7, 2026
5 checks passed
@H-Chris233 H-Chris233 deleted the fix/issue-313-style-save-feedback branch May 9, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ui][bug] Style 页 3 个写操作失败无回滚无反馈 — UI 与后端可能不一致

1 participant