[PR #6884] [MERGED] Add default values to useCategories destructuring to prevent undefined crashes #25409

Closed
opened 2026-04-16 18:34:56 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/actualbudget/actual/pull/6884
Author: @Copilot
Created: 2/6/2026
Status: Merged
Merged: 2/6/2026
Merged by: @joel-jeremy

Base: react-query-categories-2Head: copilot/sub-pr-6882


📝 Commits (2)

  • 6dc8014 Initial plan
  • a712a35 Add missing defaults to all useCategories usages

📊 Changes

12 files changed (+28 additions, -26 deletions)

View changed files

📝 packages/desktop-client/src/components/ManageRules.tsx (+1 -3)
📝 packages/desktop-client/src/components/budget/index.tsx (+2 -3)
📝 packages/desktop-client/src/components/mobile/budget/BudgetPage.tsx (+9 -5)
📝 packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsx (+2 -3)
📝 packages/desktop-client/src/components/modals/CloseAccountModal.tsx (+4 -1)
📝 packages/desktop-client/src/components/modals/ConfirmCategoryDeleteModal.tsx (+4 -1)
📝 packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.tsx (+1 -3)
📝 packages/desktop-client/src/components/reports/graphs/BarGraph.tsx (+1 -1)
📝 packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx (+1 -1)
📝 packages/desktop-client/src/components/reports/graphs/LineGraph.tsx (+1 -1)
📝 packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsx (+1 -1)
📝 packages/desktop-client/src/components/rules/Value.tsx (+1 -3)

📄 Description

When useCategories() returns undefined during react-query loading, destructuring { list, grouped } throws TypeError before any guard clauses execute.

Changes

Added default values to all useCategories() destructuring patterns:

// Before - crashes on mount when data is undefined
const { data: { list: categories, grouped: categoryGroups } } = useCategories();

// After - safe with empty arrays during loading
const { 
  data: { list: categories, grouped: categoryGroups } = { list: [], grouped: [] }
} = useCategories();

Files Modified

  • Mobile components: BudgetPage.tsx (3 instances)
  • Modals: ConfirmCategoryDeleteModal, CloseAccountModal, ImportTransactionsModal, CategoryGroupMenuModal
  • Budget/Rules: budget/index.tsx, rules/Value.tsx, ManageRules.tsx
  • Reports graphs: BarGraph, LineGraph, StackedBarGraph, DonutGraph

Pattern matches existing correct usage in useOverspentCategories.ts and MobileRulesPage.tsx.


Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/actualbudget/actual/pull/6884 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 2/6/2026 **Status:** ✅ Merged **Merged:** 2/6/2026 **Merged by:** [@joel-jeremy](https://github.com/joel-jeremy) **Base:** `react-query-categories-2` ← **Head:** `copilot/sub-pr-6882` --- ### 📝 Commits (2) - [`6dc8014`](https://github.com/actualbudget/actual/commit/6dc80147d684509de0c4a1173f4ae2a1429f37b3) Initial plan - [`a712a35`](https://github.com/actualbudget/actual/commit/a712a351f6e1659c814818307b0e75f20bf434cd) Add missing defaults to all useCategories usages ### 📊 Changes **12 files changed** (+28 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `packages/desktop-client/src/components/ManageRules.tsx` (+1 -3) 📝 `packages/desktop-client/src/components/budget/index.tsx` (+2 -3) 📝 `packages/desktop-client/src/components/mobile/budget/BudgetPage.tsx` (+9 -5) 📝 `packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsx` (+2 -3) 📝 `packages/desktop-client/src/components/modals/CloseAccountModal.tsx` (+4 -1) 📝 `packages/desktop-client/src/components/modals/ConfirmCategoryDeleteModal.tsx` (+4 -1) 📝 `packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.tsx` (+1 -3) 📝 `packages/desktop-client/src/components/reports/graphs/BarGraph.tsx` (+1 -1) 📝 `packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx` (+1 -1) 📝 `packages/desktop-client/src/components/reports/graphs/LineGraph.tsx` (+1 -1) 📝 `packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsx` (+1 -1) 📝 `packages/desktop-client/src/components/rules/Value.tsx` (+1 -3) </details> ### 📄 Description When `useCategories()` returns `undefined` during react-query loading, destructuring `{ list, grouped }` throws `TypeError` before any guard clauses execute. ## Changes Added default values to all `useCategories()` destructuring patterns: ```typescript // Before - crashes on mount when data is undefined const { data: { list: categories, grouped: categoryGroups } } = useCategories(); // After - safe with empty arrays during loading const { data: { list: categories, grouped: categoryGroups } = { list: [], grouped: [] } } = useCategories(); ``` ## Files Modified - **Mobile components**: BudgetPage.tsx (3 instances) - **Modals**: ConfirmCategoryDeleteModal, CloseAccountModal, ImportTransactionsModal, CategoryGroupMenuModal - **Budget/Rules**: budget/index.tsx, rules/Value.tsx, ManageRules.tsx - **Reports graphs**: BarGraph, LineGraph, StackedBarGraph, DonutGraph Pattern matches existing correct usage in useOverspentCategories.ts and MobileRulesPage.tsx. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/actualbudget/actual/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-16 18:34:56 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#25409