Skip to content

Conversation

MatissJanis
Copy link
Member

Fixes #5252

@actual-github-bot actual-github-bot bot changed the title Fix switching budget type requiring hard reload to take effect [WIP] Fix switching budget type requiring hard reload to take effect Jun 29, 2025
Copy link

netlify bot commented Jun 29, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 02f4f90
🔍 Latest deploy log https://app.netlify.com/projects/actualbudget/deploys/686160537cade10008677713
😎 Deploy Preview https://deploy-preview-5253.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 project configuration.

Copy link
Contributor

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
20 10.09 MB → 10.09 MB (+227 B) +0.00%
Changeset
File Δ Size
src/components/settings/BudgetTypeSettings.tsx 📈 +227 B (+8.88%) 2.5 kB → 2.72 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

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

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/de.js 134.45 kB 0%
static/js/en-GB.js 6.38 kB 0%
static/js/en.js 121.16 kB 0%
static/js/es.js 70.83 kB 0%
static/js/fr.js 131.54 kB 0%
static/js/nl.js 100.34 kB 0%
static/js/pt-BR.js 124.38 kB 0%
static/js/sv.js 65.13 kB 0%
static/js/th.js 190.63 kB 0%
static/js/uk.js 121.11 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 12.94 kB 0%
static/js/workbox-window.prod.es5.js 5.64 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/ReportRouter.js 820.13 kB 0%
static/js/narrow.js 392.43 kB 0%
static/js/wide.js 115.2 kB 0%
static/js/TransactionList.js 10.92 kB 0%
static/js/useAccountPreviewTransactions.js 3.15 kB 0%

Copy link
Contributor

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.25 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 2.25 MB 0%

@MatissJanis MatissJanis changed the title [WIP] Fix switching budget type requiring hard reload to take effect Fix switching budget type requiring hard reload to take effect Jun 29, 2025
Copy link
Contributor

coderabbitai bot commented Jun 29, 2025

Walkthrough

The BudgetTypeSettings component was updated to handle asynchronous operations when switching budget types. An isLoading state was introduced to manage the loading status during the operation. The onSwitchType handler was refactored into an asynchronous function that sets the loading state, toggles the budget type, sends a reset-budget-cache command to the server, and then resets the loading state. The button used for switching is now a ButtonWithLoading component, which displays a loading indicator based on the isLoading state.

Assessment against linked issues

Objective Addressed Explanation
Prevent page hang and ensure proper feedback when switching budget types (#5252)
Ensure budget type switch triggers server cache reset (#5252)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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 (1)
packages/desktop-client/src/components/settings/BudgetTypeSettings.tsx (1)

18-29: Consider adding error feedback for cache reset failures.

The async implementation correctly manages loading state and prevents race conditions. However, if the reset-budget-cache call fails, users receive no feedback, though the budget type change itself still succeeds.

Consider adding error handling to inform users if the cache reset fails:

 async function onSwitchType() {
   setIsLoading(true);
   try {
     const newBudgetType = budgetType === 'envelope' ? 'tracking' : 'envelope';
     setBudgetType(newBudgetType);

     // Reset the budget cache to ensure the server-side budget system is recalculated
     await send('reset-budget-cache');
+  } catch (error) {
+    // Handle cache reset error while preserving budget type change
+    console.warn('Failed to reset budget cache:', error);
   } finally {
     setIsLoading(false);
   }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 94a76a0 and 02f4f90.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/5253.md is excluded by !**/*.md
📒 Files selected for processing (1)
  • packages/desktop-client/src/components/settings/BudgetTypeSettings.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{ts,tsx}`: Use TypeScript for all code; prefer interfaces over types. Avoi...

**/*.{ts,tsx}: Use TypeScript for all code; prefer interfaces over types.
Avoid enums; use objects or maps instead.
Avoid using any or unknown unless absolutely necessary. Look for type definitions in the codebase instead.
Avoid type assertions with as or !; prefer using satisfies.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/typescript.mdc)

List of files the instruction was applied to:

  • packages/desktop-client/src/components/settings/BudgetTypeSettings.tsx
🧠 Learnings (2)
📓 Common learnings
Learnt from: misu-dev
PR: actualbudget/actual#5167
File: packages/desktop-client/src/components/spreadsheet/useFormat.ts:64-72
Timestamp: 2025-06-16T17:45:40.807Z
Learning: The user misu-dev prefers strict type checking for financial format types in useFormat.ts as a long-term goal, but acknowledges that creating follow-up issues for cleanup should wait until after the current PR is merged, not during the development phase.
Learnt from: tlesicka
PR: actualbudget/actual#3593
File: packages/desktop-client/src/components/sidebar/Sidebar.tsx:112-116
Timestamp: 2024-10-10T02:29:05.655Z
Learning: In `packages/desktop-client/src/components/sidebar/BudgetName.tsx`, the `BudgetName` component consists of three parts: `BudgetName`, `EditBudgetName`, and the Menu. Keeping `EditBudgetName` as a separate component helps maintain cleaner code by separating concerns.
Learnt from: tlesicka
PR: actualbudget/actual#3457
File: packages/desktop-client/e2e/page-models/navigation.js:50-50
Timestamp: 2024-09-25T22:11:14.624Z
Learning: In the e2e tests, the budget name is 'Test Budget', so when navigating to the 'Settings' page, references to the 'More' menu are now replaced with 'Test Budget' to reflect the new placement of the 'Settings' option under the budget name dropdown.
Learnt from: tlesicka
PR: actualbudget/actual#3457
File: packages/desktop-client/e2e/page-models/navigation.js:50-50
Timestamp: 2024-10-08T15:46:15.739Z
Learning: In the e2e tests, the budget name is 'Test Budget', so when navigating to the 'Settings' page, references to the 'More' menu are now replaced with 'Test Budget' to reflect the new placement of the 'Settings' option under the budget name dropdown.
Learnt from: tlesicka
PR: actualbudget/actual#3593
File: packages/desktop-client/src/components/sidebar/BudgetName.tsx:151-165
Timestamp: 2024-10-16T03:46:34.277Z
Learning: In `packages/desktop-client/src/components/sidebar/BudgetName.tsx`, `@media` is not implemented on `<Button>` components at this time.
Learnt from: tlesicka
PR: actualbudget/actual#3593
File: packages/desktop-client/src/components/sidebar/BudgetName.tsx:114-136
Timestamp: 2024-10-16T03:51:04.683Z
Learning: In 'packages/desktop-client/src/components/sidebar/BudgetName.tsx', empty budget names are handled elsewhere, so additional error handling within the 'EditableBudgetName' component is unnecessary.
Learnt from: joel-jeremy
PR: actualbudget/actual#4484
File: packages/desktop-client/src/components/mobile/budget/ExpenseGroup.tsx:0-0
Timestamp: 2025-03-14T15:11:36.220Z
Learning: In the Actual Budget mobile app, the callback functions `onEditCategory` (implemented as `onOpenCategoryMenuModal`) and `onBudgetAction` are already properly memoized with useCallback in the Budget component (packages/desktop-client/src/components/mobile/budget/index.tsx).
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/budget/SidebarGroup.tsx:69-76
Timestamp: 2024-10-13T11:17:59.711Z
Learning: In the `SidebarGroup` component (`packages/desktop-client/src/components/budget/SidebarGroup.tsx`), context menu state management is handled in another file, ensuring that only one context menu is open at a time.
Learnt from: joel-jeremy
PR: actualbudget/actual#4484
File: packages/desktop-client/src/components/mobile/budget/ExpenseGroup.tsx:0-0
Timestamp: 2025-03-14T15:11:36.220Z
Learning: In the Actual Budget app, the callback functions `onEditCategory` and `onBudgetAction` are already properly memoized with useCallback in the Budget component (packages/desktop-client/src/components/mobile/budget/index.tsx).
Learnt from: matt-fidd
PR: actualbudget/actual#3583
File: packages/desktop-client/e2e/budget.mobile.test.js:33-59
Timestamp: 2024-11-12T12:03:19.523Z
Learning: In the `setBudgetAverage` function in `budget.mobile.test.js`, the `spentButton` retrieval is correctly placed inside the loop.
Learnt from: matt-fidd
PR: actualbudget/actual#4181
File: packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx:252-254
Timestamp: 2025-01-18T20:08:55.203Z
Learning: Notification messages in BudgetTable.jsx will be translated in a separate PR to handle all translations together, as there are multiple messages to go through.
packages/desktop-client/src/components/settings/BudgetTypeSettings.tsx (15)
Learnt from: tlesicka
PR: actualbudget/actual#3593
File: packages/desktop-client/src/components/sidebar/Sidebar.tsx:112-116
Timestamp: 2024-10-10T02:29:05.655Z
Learning: In `packages/desktop-client/src/components/sidebar/BudgetName.tsx`, the `BudgetName` component consists of three parts: `BudgetName`, `EditBudgetName`, and the Menu. Keeping `EditBudgetName` as a separate component helps maintain cleaner code by separating concerns.
Learnt from: tlesicka
PR: actualbudget/actual#3593
File: packages/desktop-client/src/components/sidebar/BudgetName.tsx:151-165
Timestamp: 2024-10-16T03:46:34.277Z
Learning: In `packages/desktop-client/src/components/sidebar/BudgetName.tsx`, `@media` is not implemented on `<Button>` components at this time.
Learnt from: tlesicka
PR: actualbudget/actual#3593
File: packages/desktop-client/src/components/sidebar/BudgetName.tsx:114-136
Timestamp: 2024-10-16T03:51:04.683Z
Learning: In 'packages/desktop-client/src/components/sidebar/BudgetName.tsx', empty budget names are handled elsewhere, so additional error handling within the 'EditableBudgetName' component is unnecessary.
Learnt from: tlesicka
PR: actualbudget/actual#3457
File: packages/desktop-client/e2e/page-models/navigation.js:50-50
Timestamp: 2024-09-25T22:11:14.624Z
Learning: In the e2e tests, the budget name is 'Test Budget', so when navigating to the 'Settings' page, references to the 'More' menu are now replaced with 'Test Budget' to reflect the new placement of the 'Settings' option under the budget name dropdown.
Learnt from: tlesicka
PR: actualbudget/actual#3457
File: packages/desktop-client/e2e/page-models/navigation.js:50-50
Timestamp: 2024-10-08T15:46:15.739Z
Learning: In the e2e tests, the budget name is 'Test Budget', so when navigating to the 'Settings' page, references to the 'More' menu are now replaced with 'Test Budget' to reflect the new placement of the 'Settings' option under the budget name dropdown.
Learnt from: csenel
PR: actualbudget/actual#3810
File: packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx:150-161
Timestamp: 2024-11-09T20:18:28.468Z
Learning: In `packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx`, prefer to keep the implementation of checks consistent with similar patterns elsewhere in the codebase, even if alternative implementations are more concise.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/budget/SidebarGroup.tsx:69-76
Timestamp: 2024-10-13T11:17:59.711Z
Learning: In the `SidebarGroup` component (`packages/desktop-client/src/components/budget/SidebarGroup.tsx`), context menu state management is handled in another file, ensuring that only one context menu is open at a time.
Learnt from: joel-jeremy
PR: actualbudget/actual#4484
File: packages/desktop-client/src/components/mobile/budget/ExpenseGroup.tsx:0-0
Timestamp: 2025-03-14T15:11:36.220Z
Learning: In the Actual Budget app, the callback functions `onEditCategory` and `onBudgetAction` are already properly memoized with useCallback in the Budget component (packages/desktop-client/src/components/mobile/budget/index.tsx).
Learnt from: joel-jeremy
PR: actualbudget/actual#4484
File: packages/desktop-client/src/components/mobile/budget/ExpenseGroup.tsx:0-0
Timestamp: 2025-03-14T15:11:36.220Z
Learning: In the Actual Budget mobile app, the callback functions `onEditCategory` (implemented as `onOpenCategoryMenuModal`) and `onBudgetAction` are already properly memoized with useCallback in the Budget component (packages/desktop-client/src/components/mobile/budget/index.tsx).
Learnt from: tlesicka
PR: actualbudget/actual#3593
File: packages/desktop-client/src/components/sidebar/BudgetName.tsx:64-64
Timestamp: 2024-10-07T11:45:10.127Z
Learning: In `packages/desktop-client/src/components/sidebar/BudgetName.tsx`, when `useMetadataPref('budgetName')` returns `undefined`, the code handles it appropriately without the need to assign a default value to `budgetName`.
Learnt from: joel-jeremy
PR: actualbudget/actual#3685
File: packages/loot-core/src/client/data-hooks/transactions.ts:32-88
Timestamp: 2024-10-22T02:08:48.162Z
Learning: In the React `useTransactions` hook defined in `packages/loot-core/src/client/data-hooks/transactions.ts`, changes to `options` (e.g., `options.pageCount`) should be applied on the next query without adding them to the `useEffect` dependency array, to avoid unnecessary rerenders when options change.
Learnt from: MatissJanis
PR: actualbudget/actual#0
File: :0-0
Timestamp: 2025-02-11T18:44:28.613Z
Learning: The Button2 component is deprecated. Use @actual-app/components/button instead.
Learnt from: matt-fidd
PR: actualbudget/actual#3840
File: packages/loot-core/src/server/budget/template-notes.ts:12-12
Timestamp: 2025-01-17T12:11:23.669Z
Learning: In server-side code or non-React contexts where React hooks cannot be used, prefer using `import { t } from 'i18next'` and directly using `t(string)` for translations, instead of using react-i18next hooks or other approaches.
Learnt from: jfdoming
PR: actualbudget/actual#3402
File: packages/desktop-client/src/components/accounts/Account.tsx:8-8
Timestamp: 2024-09-27T14:15:46.637Z
Learning: In the `AllTransactions` component of `Account.tsx`, the `useLayoutEffect` hook is appropriately used to dispatch an action that closes splits for parent transactions when `prependTransactions` changes, ensuring this occurs synchronously before the component is painted.
Learnt from: lelemm
PR: actualbudget/actual#3309
File: packages/desktop-client/src/components/ColumnWidthContext.jsx:17-17
Timestamp: 2024-10-25T18:30:24.287Z
Learning: In `packages/desktop-client/src/components/ColumnWidthContext.jsx`, replacing `useState` with `useRef` for `positionAccumulator` causes the resize action to become unpredictable. Therefore, it's preferable to keep using `useState` for `positionAccumulator` in this context.
🔇 Additional comments (5)
packages/desktop-client/src/components/settings/BudgetTypeSettings.tsx (5)

1-1: LGTM: Import addition is appropriate.

Adding useState import is correct for the new loading state management.


4-4: LGTM: Component upgrade enhances UX.

Switching from Button to ButtonWithLoading provides better user feedback during the async operation.


7-8: LGTM: Server communication import is necessary.

The send import is required for the new cache reset functionality.


16-16: LGTM: Loading state initialization is correct.

Starting with false is appropriate for the loading state.


34-40: LGTM: Button component integration is correct.

The ButtonWithLoading usage with isLoading prop properly displays loading state during the async operation while preserving the existing button text logic.

@MatissJanis MatissJanis merged commit e5c84d4 into master Jun 29, 2025
23 of 24 checks passed
@MatissJanis MatissJanis deleted the matiss/fix-5252 branch June 29, 2025 16:43
passabilities added a commit to passabilities/actual-budget that referenced this pull request Jul 8, 2025
…raph

* actual/master: (113 commits)
  Customize tags colors (actualbudget#5032)
  Run rules on transactions created by a transfer. (actualbudget#5279)
  add notes to scheduled transactions table (actualbudget#5290)
  💬 Added Discord link to the help menu for discoverability (actualbudget#5286)
  Fixes actualbudget#5278: Applied PrivacyFilter to balance graph display (and added conditionality whether user is hovering on the graph) (actualbudget#5281)
  add some basic linting rules for translation consistency (actualbudget#5212)
  Update contributor points calculation logic (actualbudget#5169)
  feat(currency): add currency setting and format (actualbudget#5167)
  Move remaining `.d.ts` files to `.ts` (actualbudget#5208)
  use correct running balance when adding a new transaction (actualbudget#5207)
  Fix rule templating on date causing crash (actualbudget#5259)
  Fixes actualbudget#5228 - has tag(s) filter now takes values when pressing Enter (actualbudget#5263)
  correctly ignore hidden categories when using "Set Average Budget" (actualbudget#5239)
  Mobile running balance (actualbudget#5219)
  🔖 (25.7.1) (actualbudget#5272)
  fix (actualbudget#5270)
  🔖 (25.7.0) (actualbudget#5260)
  Fixes actualbudget#5238 last synced button text not visible on light theme. (actualbudget#5241)
  fix: Tracking budget income budget fields missing in mobile view  (actualbudget#5251)
  Fix switching budget type requiring hard reload to take effect (actualbudget#5253)
  ...
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.

[Bug]: switching budget types operation hangs up
2 participants