fix(theme-store): use injected get() to break circular self-reference - #2288
fix(theme-store): use injected get() to break circular self-reference#2288hognek wants to merge 1 commit into
Conversation
Replace the useThemeStore.getState() call inside the create closure with the get() second argument of zustand's create. Eliminates the TS7022 / TS7006 cascade caused by referencing the store within its own initializer. Only the in-closure occurrence changes; module-level getState() calls (outside the creator) keep referencing the store hook directly.
|
👋 Thanks for the PR! This one targets See CONTRIBUTING.md for the branch model. |
PR Summary by QodoFix theme store circular self-reference by using zustand-injected get()
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
Reviewed by step-3.7-flash · Input: 50K · Output: 1.9K · Cached: 126.6K |
Code Review by Qodo
1. No new regression test
|
| } | ||
|
|
||
| export const useThemeStore = create<ThemeStore>((set) => ({ | ||
| export const useThemeStore = create<ThemeStore>((set, get) => ({ |
There was a problem hiding this comment.
1. No new regression test 📜 Skill insight ▣ Testability
This PR fixes a bug in useThemeStore initialization by switching to the injected get() accessor, but it does not add any new test case that would fail prior to the fix and pass after it. Without a regression test, this typecheck/circular-reference issue may be reintroduced unnoticed.
Agent Prompt
## Issue description
The PR is a bug fix but does not include a new regression test that would catch the circular self-reference/type inference failure (TS7022/TS7006) if it reappears.
## Issue Context
The change replaces `useThemeStore.getState()` inside the zustand `create` closure with the injected `get()` to avoid self-referencing the store during initialization.
## Fix Focus Areas
- desktop/src/stores/theme-store.test.ts[1-200]
- desktop/src/stores/theme-store.ts[229-307]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Reviewed. ON-SPEC, arming. Correct fix and the right idiom. getWallpapersBySection called useThemeStore.getState() from INSIDE the store's own initializer, which is a circular self-reference: the module binding is not initialised while create() is still running, so the call depends on module-evaluation order rather than on anything the code controls. Swapping to zustand's injected get() is the standard fix and is semantically identical for callers - same state object, no behaviour change - while removing the cycle. Verified rather than eyeballed: 191 tests across all 16 store suites pass with the change, including restore-theme.test.ts which is the one that would notice if getWallpapersBySection started returning a different shape. No changelog needed (internal correctness fix, no user-visible behaviour change) and doc-gate agrees - it is not red. CI is otherwise clean on this one. Auto-merge armed on green. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe theme store initializer now receives Zustand’s ChangesTheme store state access
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 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 |
Task: t_71a7eb3a
Replace the
useThemeStore.getState()call inside the theme-store create closure with theget()argument injected by zustand'screate. This eliminates the TS7022 / TS7006 cascade caused by referencing the store within its own initializer.Changed:
create<ThemeStore>((set) => ({...}))->create<ThemeStore>((set, get) => ({...}))getWallpapersBySectionnow usesget()instead ofuseThemeStore.getState()Only the in-closure occurrence changes. Module-level
getState()calls in exported helpers (outside the creator) keep referencing the hook directly — they are not circular.Verification:
tsc -b --forceexits 0 (full uncached typecheck, no TS7022/TS7006)vitest run src/stores/theme-store.test.ts src/stores/__tests__/wallpaper.test.ts: 19/19 passSummary by CodeRabbit