Skip to content

Conversation

joel-jeremy
Copy link
Contributor

@joel-jeremy joel-jeremy commented Jan 10, 2025

@actual-github-bot actual-github-bot bot changed the title [Redux Toolkit Migration] prefsSlice [WIP] [Redux Toolkit Migration] prefsSlice Jan 10, 2025
Copy link

netlify bot commented Jan 10, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 6a8610e
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67d12f5ca0783d000866002f
😎 Deploy Preview https://deploy-preview-4127.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Jan 10, 2025

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
18 8.45 MB → 8.45 MB (+190 B) +0.00%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/client/prefs/prefsSlice.ts 🆕 +2.71 kB 0 B → 2.71 kB
src/hooks/useSyncedPref.ts 📈 +25 B (+7.42%) 337 B → 362 B
src/hooks/useGlobalPref.ts 📈 +31 B (+7.31%) 424 B → 455 B
src/hooks/useSyncedPrefs.ts 📈 +21 B (+7.24%) 290 B → 311 B
src/hooks/useMetadataPref.ts 📈 +25 B (+7.06%) 354 B → 379 B
home/runner/work/actual/actual/packages/loot-core/src/client/modals/modalsSlice.ts 📈 +33 B (+1.59%) 2.03 kB → 2.06 kB
src/index.tsx 📈 +16 B (+1.47%) 1.07 kB → 1.08 kB
src/browser-preload.browser.js 📈 +11 B (+0.24%) 4.41 kB → 4.42 kB
home/runner/work/actual/actual/packages/loot-core/src/client/budgets/budgetsSlice.ts 📉 -61 B (-0.52%) 11.37 kB → 11.31 kB
home/runner/work/actual/actual/packages/loot-core/src/client/store/index.ts 📉 -16 B (-0.98%) 1.59 kB → 1.58 kB
home/runner/work/actual/actual/packages/loot-core/src/client/reducers/index.ts 📉 -19 B (-33.33%) 57 B → 38 B
home/runner/work/actual/actual/packages/loot-core/src/client/constants.ts 📉 -176 B (-62.86%) 280 B → 104 B
home/runner/work/actual/actual/packages/loot-core/src/client/actions/prefs.ts 🔥 -1.64 kB (-100%) 1.64 kB → 0 B
home/runner/work/actual/actual/packages/loot-core/src/client/reducers/prefs.ts 🔥 -793 B (-100%) 793 B → 0 B
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 5.42 MB → 5.42 MB (+190 B) +0.00%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/en-GB.js 96.19 kB 0%
static/js/de.js 120.56 kB 0%
static/js/es.js 59.63 kB 0%
static/js/nl.js 102.82 kB 0%
static/js/fr.js 119.83 kB 0%
static/js/en.js 108.48 kB 0%
static/js/pt-BR.js 110.17 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/uk.js 110.45 kB 0%
static/js/useAccountPreviewTransactions.js 1.69 kB 0%
static/js/AppliedFilters.js 10.87 kB 0%
static/js/wide.js 103.31 kB 0%
static/js/narrow.js 372.02 kB 0%
static/js/ReportRouter.js 1.59 MB 0%

Copy link
Contributor

github-actions bot commented Jan 10, 2025

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 2.57 MB → 2.57 MB (+15 B) +0.00%
Changeset
File Δ Size
packages/loot-core/src/server/preferences/app.ts 📈 +102 B (+2.61%) 3.82 kB → 3.92 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
kcab.worker.js 2.57 MB → 2.57 MB (+15 B) +0.00%

Smaller

No assets were smaller

Unchanged

No assets were unchanged

@joel-jeremy joel-jeremy force-pushed the redux-toolkit-prefs-slice branch from c33712b to 0ae8b6d Compare January 11, 2025 00:03
@joel-jeremy joel-jeremy changed the base branch from master to redux-toolkit-notifications-slice January 13, 2025 16:59
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-notifications-slice branch from 200b0fc to 2384069 Compare January 13, 2025 23:03
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-prefs-slice branch from 5cbdb7d to 582138a Compare January 13, 2025 23:04
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-notifications-slice branch from 2384069 to 5e0cf64 Compare January 13, 2025 23:11
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-prefs-slice branch from 582138a to f0e15a2 Compare January 13, 2025 23:12
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-notifications-slice branch from 5e0cf64 to 67df0f6 Compare January 13, 2025 23:25
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-prefs-slice branch from f0e15a2 to 1e4d9a1 Compare January 13, 2025 23:26
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-notifications-slice branch from 67df0f6 to 3de3bba Compare January 14, 2025 08:18
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-prefs-slice branch from 1e4d9a1 to af70553 Compare January 14, 2025 08:19
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-notifications-slice branch from 3de3bba to b648b01 Compare January 14, 2025 16:45
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-prefs-slice branch from af70553 to 389b7ae Compare January 14, 2025 16:45
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-notifications-slice branch 2 times, most recently from 6c28206 to 49c15a1 Compare January 14, 2025 17:15
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-prefs-slice branch from 389b7ae to a42f2b3 Compare January 14, 2025 17:16
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-notifications-slice branch from 49c15a1 to 532232b Compare January 14, 2025 17:54
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-prefs-slice branch from a42f2b3 to 43b6e4e Compare January 14, 2025 17:57
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-notifications-slice branch from 532232b to e1dacf3 Compare January 14, 2025 18:10
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-prefs-slice branch from 43b6e4e to 29faba1 Compare January 14, 2025 18:10
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-notifications-slice branch from e1dacf3 to b58a227 Compare January 17, 2025 17:44
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-prefs-slice branch from 29faba1 to 63a022d Compare January 17, 2025 17:46
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-notifications-slice branch from b58a227 to 28c5c8f Compare January 17, 2025 19:23
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-prefs-slice branch from 63a022d to 65641d0 Compare January 17, 2025 19:23
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-notifications-slice branch from 28c5c8f to 86bbe73 Compare January 20, 2025 07:11
@joel-jeremy joel-jeremy force-pushed the redux-toolkit-prefs-slice branch from d6b3604 to 6a8610e Compare March 12, 2025 06:53
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
packages/loot-core/src/client/prefs/prefsSlice.ts (4)

1-4: Avoid ignoring restricted imports in loot-core.
The file explicitly disables the no-restricted-imports lint rule for @actual-app/web, suggesting this is unintentional. To prevent issues when reorganizing the codebase, consider removing or refactoring this import rather than disabling the lint rule.


29-63: Refine conditional check using optional chaining.
In line 36, the code checks both prefs && prefs.id. This can be simplified using optional chaining, which also reduces potential null/undefined checks.

Example fix:

-if (prefs && prefs.id && !currentPrefs) {
+if (prefs?.id && !currentPrefs) {
  dispatch(closeModal());
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 36-36: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


76-89: Ensure handling of null or undefined fields in global prefs.
In previous feedback, type errors arose when certain fields like maxMonths or language returned null from the API. If GlobalPrefs strictly requires non-null types, consider providing default values or performing a shape transformation before dispatching.

Would you like help implementing fallback logic?


158-170: Consider adding tests for new thunks and reducers.
Although these actions and reducers look correct, thorough test coverage can help prevent regressions. You may want to add unit tests or integration tests verifying each new thunk and merge reducer’s behavior under various scenarios.

Would you like me to open a new issue or draft example tests for each action?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d6b3604 and 6a8610e.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4127.md is excluded by !**/*.md
📒 Files selected for processing (25)
  • packages/desktop-client/src/browser-preload.browser.js (1 hunks)
  • packages/desktop-client/src/components/App.tsx (1 hunks)
  • packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx (1 hunks)
  • packages/desktop-client/src/components/settings/index.tsx (1 hunks)
  • packages/desktop-client/src/global-events.ts (1 hunks)
  • packages/desktop-client/src/hooks/useGlobalPref.ts (2 hunks)
  • packages/desktop-client/src/hooks/useMetadataPref.ts (2 hunks)
  • packages/desktop-client/src/hooks/useSyncedPref.ts (2 hunks)
  • packages/desktop-client/src/hooks/useSyncedPrefs.ts (2 hunks)
  • packages/desktop-client/src/index.tsx (2 hunks)
  • packages/desktop-electron/index.ts (1 hunks)
  • packages/loot-core/src/client/actions/index.ts (0 hunks)
  • packages/loot-core/src/client/actions/prefs.ts (0 hunks)
  • packages/loot-core/src/client/actions/user.ts (1 hunks)
  • packages/loot-core/src/client/app/appSlice.ts (1 hunks)
  • packages/loot-core/src/client/budgets/budgetsSlice.ts (1 hunks)
  • packages/loot-core/src/client/prefs/prefsSlice.ts (1 hunks)
  • packages/loot-core/src/client/reducers/index.ts (0 hunks)
  • packages/loot-core/src/client/reducers/prefs.ts (0 hunks)
  • packages/loot-core/src/client/shared-listeners.ts (1 hunks)
  • packages/loot-core/src/client/state-types/index.d.ts (1 hunks)
  • packages/loot-core/src/client/state-types/prefs.d.ts (0 hunks)
  • packages/loot-core/src/client/store/index.ts (3 hunks)
  • packages/loot-core/src/client/store/mock.ts (2 hunks)
  • packages/loot-core/src/server/preferences/app.ts (5 hunks)
💤 Files with no reviewable changes (5)
  • packages/loot-core/src/client/reducers/index.ts
  • packages/loot-core/src/client/actions/index.ts
  • packages/loot-core/src/client/state-types/prefs.d.ts
  • packages/loot-core/src/client/actions/prefs.ts
  • packages/loot-core/src/client/reducers/prefs.ts
🚧 Files skipped from review as they are similar to previous changes (19)
  • packages/loot-core/src/client/store/mock.ts
  • packages/loot-core/src/client/app/appSlice.ts
  • packages/desktop-client/src/hooks/useSyncedPref.ts
  • packages/desktop-client/src/components/App.tsx
  • packages/loot-core/src/client/budgets/budgetsSlice.ts
  • packages/desktop-client/src/index.tsx
  • packages/desktop-client/src/components/settings/index.tsx
  • packages/desktop-client/src/global-events.ts
  • packages/loot-core/src/client/shared-listeners.ts
  • packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx
  • packages/loot-core/src/client/state-types/index.d.ts
  • packages/loot-core/src/server/preferences/app.ts
  • packages/desktop-client/src/browser-preload.browser.js
  • packages/loot-core/src/client/store/index.ts
  • packages/desktop-client/src/hooks/useGlobalPref.ts
  • packages/loot-core/src/client/actions/user.ts
  • packages/desktop-client/src/hooks/useMetadataPref.ts
  • packages/desktop-client/src/hooks/useSyncedPrefs.ts
  • packages/desktop-electron/index.ts
🧰 Additional context used
🧠 Learnings (1)
packages/loot-core/src/client/prefs/prefsSlice.ts (1)
Learnt from: MatissJanis
PR: actualbudget/actual#3544
File: packages/loot-core/src/client/state-types/prefs.d.ts:13-18
Timestamp: 2024-11-10T16:45:31.225Z
Learning: When action types like `SetPrefsAction` are updated with new properties, ensure that reducers are correctly handling these properties before suggesting a potential issue.
🪛 Biome (1.9.4)
packages/loot-core/src/client/prefs/prefsSlice.ts

[error] 36-36: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Analyze
  • GitHub Check: Wait for Netlify build to finish
🔇 Additional comments (3)
packages/loot-core/src/client/prefs/prefsSlice.ts (3)

96-106: Validate onSaveGlobalPrefs callback usage.
The onSaveGlobalPrefs callback is optional. Ensure calling code checks for any errors thrown during the saveGlobalPrefs process, and confirm that expected side-effects in the callback run only after a successful save.


112-125: Confirm concurrency safety when saving multiple synced prefs.
The loop concurrently sends multiple preferences/save requests. While this is likely fine, confirm the backend can handle simultaneous updates without partial saves, or add error handling if a single request fails.


137-156: Looks good!
The reducers are cleanly defined, allowing atomic merges of preferences. This approach ensures that local, global, and synced prefs remain distinct, minimizing potential overwrites.

@joel-jeremy joel-jeremy requested a review from lelemm March 13, 2025 04:56
Copy link
Contributor

@lelemm lelemm left a comment

Choose a reason for hiding this comment

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

All good :)

@joel-jeremy joel-jeremy merged commit 47c0d39 into master Mar 14, 2025
21 checks passed
@joel-jeremy joel-jeremy deleted the redux-toolkit-prefs-slice branch March 14, 2025 13:35
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.

2 participants