Skip to content

fix(renderer): synchronize miniapp settings state and respect region filter#13166

Merged
DeJeune merged 1 commit intoCherryHQ:mainfrom
nanimore:fix/minapp-settings-sync
Mar 3, 2026
Merged

fix(renderer): synchronize miniapp settings state and respect region filter#13166
DeJeune merged 1 commit intoCherryHQ:mainfrom
nanimore:fix/minapp-settings-sync

Conversation

@nanimore
Copy link
Copy Markdown
Contributor

@nanimore nanimore commented Mar 3, 2026

What this PR does

Before this PR:

  • Mini Program settings were not synchronized with the global Redux store in real-time. Changes to "Mini Program Region" (e.g., from Auto to China) did not reflect immediately in the visible/disabled lists.
  • The "Reset" button bypassed region-based filtering logic, causing restricted apps (like Zhipu, Doubao, etc.) to appear temporarily and then "disappear" after reopening the settings window.
  • Core synchronization logic lacked clear documentation for local maintainers.

After this PR:

  • Added a useEffect hook in MiniAppSettings.tsx to synchronize local state with the useMinapps

    hook whenever the underlying store data or region settings change.

  • Refactored handleResetMinApps to respect the current region's filtering rules, ensuring UI consistency.

  • Updated relevant code comments to Chinese as requested for better local team understanding.

Visual Evidence (Bug Demonstration)

Before Clicking "Reset" (Restricted apps hidden):

20260303155923

After Clicking "Reset" (Ghost apps appear):
20260303155953

Note: After the fix, Clicking "Reset" will correctly maintain the region filter, and the list will remain consistent as shown in Picture 1.

Why we need it and why it was done in this way

Users in different regions (CN vs. Global) expect a consistent experience. The prior implementation had a disconnect between the persistent data layer and the configuration UI. By enforcing state synchronization at the component level, we eliminate "ghost" icons and ensure the settings UI always matches the actual application state.

Checklist

  • PR: The PR description is expressive enough and will help future contributors

  • Code: Write code that humans can understand and Keep it simple

  • Self-review: I have reviewed my own code

Release note

fix(renderer): synchronize mini program settings state and enforce region-based filtering consistency.

@EurFelux EurFelux requested a review from GeorgeDong32 March 3, 2026 08:29
Copy link
Copy Markdown
Collaborator

@DeJeune DeJeune left a comment

Choose a reason for hiding this comment

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

Clean, focused fix for the mini app settings region sync issue.

What works well:

  • The useEffect correctly syncs local component state when the store data (e.g., region) changes, eliminating the stale-state problem.
  • handleResetMinApps now respects region filtering (minapps instead of allMinApps), preventing "ghost" apps from appearing after reset.
  • The store-level write (updateMinapps(allMinApps)) still preserves all apps correctly since the useMinapps hook handles region-aware merging internally.

Minor notes (non-blocking):

  • The useEffect duplicates the useState initializers on first mount — harmless but could be skipped with a ref guard if desired.

LGTM — approving.

Comment on lines +57 to +60
// 当 store 数据变化时(例如切换地区)同步本地状态
useEffect(() => {
setVisibleMiniApps(minapps)
setDisabledMiniApps(disabled || [])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: The useEffect also runs on initial mount, duplicating the work already done by the useState initializers on lines 52–53. This is harmless since React batches the updates, but if you wanted to be explicit you could skip the first render with a ref guard. Not blocking — just a note.

Comment on lines 63 to 66
const handleResetMinApps = useCallback(() => {
setVisibleMiniApps(allMinApps)
// 仅重置为当前地区可见的应用,以避免混淆
setVisibleMiniApps(minapps)
setDisabledMiniApps([])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Observation: handleResetMinApps now sets local state to minapps (region-filtered) but still dispatches updateMinapps(allMinApps) to the store (all apps). This is actually correct — the store preserves all apps, and the useEffect above will re-sync local state to the region-filtered view after the store updates. Just confirming this asymmetry is intentional and works as expected.

Copy link
Copy Markdown
Collaborator

@GeorgeDong32 GeorgeDong32 left a comment

Choose a reason for hiding this comment

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

LGTM! This PR correctly fixes the MiniApp settings state synchronization issue. The useEffect hook properly syncs local state with Redux store when region changes, and the handleResetMinApps fix respects region filtering. Clean, minimal changes following the project architecture.

@DeJeune DeJeune merged commit 15e2025 into CherryHQ:main Mar 3, 2026
11 checks passed
Comment on lines +58 to +61
useEffect(() => {
setVisibleMiniApps(minapps)
setDisabledMiniApps(disabled || [])
}, [minapps, disabled])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

是否可以总是使用store state作为SSOT,而不使用组件本地状态+useEffect同步?

@kangfenmao kangfenmao mentioned this pull request Mar 3, 2026
4 tasks
DeJeune added a commit that referenced this pull request Mar 4, 2026
### What this PR does

This is a release PR for **Cherry Studio v1.7.23**.

**Changes included:**
- Bump version from 1.7.22 to 1.7.23
- Update release notes with user-facing bug fixes

### Release Notes

<!--LANG:en-->
Cherry Studio 1.7.23 - Bug Fixes

🐛 Bug Fixes
- [Selection] Fix app crash on Windows when closing action window
- [MiniApp] Fix settings state synchronization and region filter
consistency
- [Plugin Browser] Make detail modal text selectable and improve search
experience
- [Tools] Fix approval card not showing for builtin and provider tools

### Included Commits

- fix(Selection): prevent Windows crash when closing transparent action
window (#13177)
- fix(renderer): synchronize miniapp settings state and respect region
filter (#13166)
- fix: improve plugin browser UX with three small fixes (#13153)
- fix: show approval card for builtin and provider tools (#13154)
- fix: support esc to close modal (#13159)
- fix: open external editor in new window instead of reusing existing
one (#13160)
- fix: render directory Select options with optionRender (#13152)
- refactor: replace static pnpm patch with postinstall script for
claude-agent-sdk (#13139)
- feat: add dev-only message data inspection button (#13142)
- docs: add review workflow to CLAUDE.md (#13145)
- chore(deps): upgrade @uiw/codemirror packages to 4.25.7 (#13149)
- fix(ci): skip CI on PR body/title edits, only re-run on base branch
changes (#13150)

### Review Checklist

- [ ] Review generated release notes in `electron-builder.yml`
- [ ] Verify version bump in `package.json`
- [ ] CI passes
- [ ] Merge to trigger release build

### Release note

```release-note
Cherry Studio 1.7.23 - Bug Fixes

🐛 Bug Fixes
- [Selection] Fix app crash on Windows when closing action window
- [MiniApp] Fix settings state synchronization and region filter consistency
- [Plugin Browser] Make detail modal text selectable and improve search experience
- [Tools] Fix approval card not showing for builtin and provider tools
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: suyao <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants