Skip to content

fix(theme-store): use injected get() to break circular self-reference - #2288

Open
hognek wants to merge 1 commit into
jaylfc:masterfrom
hognek:feat/theme-store-get-fix2
Open

fix(theme-store): use injected get() to break circular self-reference#2288
hognek wants to merge 1 commit into
jaylfc:masterfrom
hognek:feat/theme-store-get-fix2

Conversation

@hognek

@hognek hognek commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Task: t_71a7eb3a

Replace the useThemeStore.getState() call inside the theme-store create closure with the get() argument injected by zustand's create. This eliminates the TS7022 / TS7006 cascade caused by referencing the store within its own initializer.

Changed:

  • create<ThemeStore>((set) => ({...})) -> create<ThemeStore>((set, get) => ({...}))
  • getWallpapersBySection now uses get() instead of useThemeStore.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 --force exits 0 (full uncached typecheck, no TS7022/TS7006)
  • vitest run src/stores/theme-store.test.ts src/stores/__tests__/wallpaper.test.ts: 19/19 pass

Summary by CodeRabbit

  • Refactor
    • Improved theme state handling when generating wallpaper sections.
    • No visible changes to the user experience.

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.
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

👋 Thanks for the PR! This one targets master, which is our
stable branch (it's what live installs track). Please retarget it to
dev — click Edit next to the PR title and change the base
branch dropdown from master to dev. Your commits and any review
carry over, nothing is lost.

See CONTRIBUTING.md for the branch model.

@gitar-bot

gitar-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

Important

You are using the Gitar free plan. Upgrade to unlock code review, CI analysis, auto-apply, custom automations, and more.

Gitar

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix theme store circular self-reference by using zustand-injected get()

🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Use zustand’s injected get() inside the store initializer to avoid self-referencing the store.
• Eliminate TS7022/TS7006 typecheck failures without changing external helper patterns.
Diagram

graph TD
  UI["Theme consumers"] --> Hook["useThemeStore"] --> Init["create<ThemeStore>(...) initializer"]
  Init --> GetFn["injected get()"] --> Selector["getWallpapersBySection()"] --> Data["WALLPAPERS"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Move derived logic to a pure helper taking state as an argument
  • ➕ Keeps store initializer free of any intra-store reads
  • ➕ Makes derivations easier to unit test in isolation
  • ➖ Adds indirection and may duplicate state-shape typing at call sites
  • ➖ Doesn’t address other potential circular reads if added later
2. Define store creator with an explicit `StateCreator` type alias
  • ➕ Can reduce inference cascades in more complex stores
  • ➕ Makes the intended set/get API explicit in types
  • ➖ More boilerplate for a single call-site issue
  • ➖ Doesn’t change the underlying circular reference risk if getState() is still used inside initializer

Recommendation: Keep the PR’s approach. Using zustand’s injected get() is the idiomatic fix for avoiding circular self-references during store initialization, and it minimizes surface-area change while directly addressing the TS7022/TS7006 cascade.

Files changed (1) +2 / -2

Bug fix (1) +2 / -2
theme-store.tsUse zustand-injected 'get()' inside store initializer +2/-2

Use zustand-injected 'get()' inside store initializer

• Updates the zustand 'create' initializer signature to accept 'get' and switches 'getWallpapersBySection' to read state via 'get()' rather than 'useThemeStore.getState()'. This prevents referencing the store hook within its own initialization and avoids the resulting TypeScript inference/error cascade.

desktop/src/stores/theme-store.ts

@kilo-code-bot

kilo-code-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • desktop/src/stores/theme-store.ts

Reviewed by step-3.7-flash · Input: 50K · Output: 1.9K · Cached: 126.6K

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📜 Skill insights (1)

Context used
✅ Compliance rules (platform): 35 rules

Grey Divider


Remediation recommended

1. No new regression test 📜 Skill insight ▣ Testability
Description
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.
Code

desktop/src/stores/theme-store.ts[229]

+export const useThemeStore = create<ThemeStore>((set, get) => ({
Relevance

●● Moderate

Tests are frequently accepted when suggested, but no clear precedent enforcing new regression test
for every bugfix.

PR-#1542
PR-#507

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 2185285 requires that bug-fix PRs add at least one regression test. The diff shows
only the fix in desktop/src/stores/theme-store.ts (switching the create closure to accept get
and using get() in getWallpapersBySection) with no accompanying test change in the provided PR
diff.

desktop/src/stores/theme-store.ts[229-229]
desktop/src/stores/theme-store.ts[305-307]
Skill: taos-development-skill

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

}

export const useThemeStore = create<ThemeStore>((set) => ({
export const useThemeStore = create<ThemeStore>((set, get) => ({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

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

@jaylfc

jaylfc commented Aug 4, 2026

Copy link
Copy Markdown
Owner

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.

@jaylfc
jaylfc enabled auto-merge (squash) August 4, 2026 10:54
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1ce9316c-e2c7-4310-9973-73e8785e6cf2

📥 Commits

Reviewing files that changed from the base of the PR and between 6099c5d and 1743609.

📒 Files selected for processing (1)
  • desktop/src/stores/theme-store.ts

📝 Walkthrough

Walkthrough

The theme store initializer now receives Zustand’s get accessor. Wallpaper-section generation uses this accessor to read current store state.

Changes

Theme store state access

Layer / File(s) Summary
Use initializer-scoped state access
desktop/src/stores/theme-store.ts
The store initializer accepts get. getWallpapersBySection uses get() instead of useThemeStore.getState().

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: jaylfc

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the theme-store change and the use of the injected get() function to remove the circular self-reference.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

2 participants