From 64db9a59f4501e1c8b129ceebca06b808fc4407b Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 5 Jan 2026 23:58:54 +0100 Subject: [PATCH] Fix null context crash in tracking budget mode (#6538) * Initial plan * Fix fatal error by adding default values to TrackingBudgetContext The TrackingBudgetContext was initialized with null, causing a fatal error when components tried to destructure properties like currentMonth. This fix adds proper default values and type definitions, matching the pattern used in EnvelopeBudgetContext. Co-authored-by: MatissJanis <886567+MatissJanis@users.noreply.github.com> * Add release notes for issue #6538 Co-authored-by: MatissJanis <886567+MatissJanis@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MatissJanis <886567+MatissJanis@users.noreply.github.com> --- .../budget/tracking/TrackingBudgetContext.tsx | 33 ++++++++++++++----- upcoming-release-notes/6538.md | 6 ++++ 2 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 upcoming-release-notes/6538.md diff --git a/packages/desktop-client/src/components/budget/tracking/TrackingBudgetContext.tsx b/packages/desktop-client/src/components/budget/tracking/TrackingBudgetContext.tsx index 33666ed258..d6c126455d 100644 --- a/packages/desktop-client/src/components/budget/tracking/TrackingBudgetContext.tsx +++ b/packages/desktop-client/src/components/budget/tracking/TrackingBudgetContext.tsx @@ -1,14 +1,31 @@ -// @ts-strict-ignore import React, { type ReactNode, createContext, useContext } from 'react'; import * as monthUtils from 'loot-core/shared/months'; -const Context = createContext(null); - -type TrackingBudgetProviderProps = { +type TrackingBudgetContextDefinition = { summaryCollapsed: boolean; - onBudgetAction: (month: string, action: string, arg: unknown) => void; + onBudgetAction: (month: string, action: string, arg?: unknown) => void; onToggleSummaryCollapse: () => void; + currentMonth: string; +}; + +const TrackingBudgetContext = createContext({ + summaryCollapsed: false, + onBudgetAction: () => { + throw new Error('Unitialised context method called: onBudgetAction'); + }, + onToggleSummaryCollapse: () => { + throw new Error( + 'Unitialised context method called: onToggleSummaryCollapse', + ); + }, + currentMonth: 'unknown', +}); + +type TrackingBudgetProviderProps = Omit< + TrackingBudgetContextDefinition, + 'currentMonth' +> & { children: ReactNode; }; export function TrackingBudgetProvider({ @@ -20,7 +37,7 @@ export function TrackingBudgetProvider({ const currentMonth = monthUtils.currentMonth(); return ( - {children} - + ); } export function useTrackingBudget() { - return useContext(Context); + return useContext(TrackingBudgetContext); } diff --git a/upcoming-release-notes/6538.md b/upcoming-release-notes/6538.md new file mode 100644 index 0000000000..80d5757f2e --- /dev/null +++ b/upcoming-release-notes/6538.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [copilot] +--- + +Fix fatal error on budget page load when using tracking budget type