Skip to content

A local-first personal finance app

Fix editing notes/account on mobile after a split rule (#9254)

Junaid Khancc368d10c6df
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx
index 7c2ba6b8e3..f666b07e88 100644
--- a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx
+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx
@@ -3,6 +3,7 @@ import {
memo,
useCallback,
useEffect,
+ useLayoutEffect,
useMemo,
useRef,
useState,
@@ -81,7 +82,10 @@ import {
} from '#components/mobile/MobileForms';
import { getPrettyPayee } from '#components/mobile/utils';
import { MobilePageHeader, Page } from '#components/Page';
-import { propagateRuleChangeToSubtransactions } from '#components/transactions/applyRulesToTransaction';
+import {
+ propagateRuleChangeToSubtransactions,
+ transactionForRulesFromList,
+} from '#components/transactions/applyRulesToTransaction';
import {
getClearedFieldNames,
shouldApplyRuleChange,
@@ -1612,6 +1616,10 @@ function TransactionEditUnconnected({
const [fetchedTransactions, setFetchedTransactions] = useState<
TransactionEntity[]
>([]);
+ const transactionsRef = useRef(transactions);
+ useLayoutEffect(() => {
+ transactionsRef.current = transactions;
+ }, [transactions]);
const isAdding = useRef(false);
const isDeleted = useRef(false);
const [learnCategories = 'true'] = useSyncedPref('learn-categories');
@@ -1749,10 +1757,19 @@ function TransactionEditUnconnected({
newTransaction.id,
);
+ // Mobile keeps splits as a flat parent+children list. Group them
+ // before rules-run so an already-applied split rule sees existing
+ // children (same as desktop). Otherwise re-running the rule creates
+ // new child ids and later parent edits (notes/account) fail (#9189).
+ const transactionForRules = transactionForRulesFromList(
+ transactionsRef.current,
+ newTransaction,
+ );
+
const afterRules = await send('rules-run', {
- transaction: newTransaction,
+ transaction: transactionForRules,
});
- const diff = getChangedValues(newTransaction, afterRules);
+ const diff = getChangedValues(transactionForRules, afterRules);
if (diff) {
Object.keys(diff).forEach(key => {
@@ -1767,7 +1784,7 @@ function TransactionEditUnconnected({
(updatedField === 'payee' ||
shouldApplyRuleChange(
field,
- newTransaction[field],
+ Reflect.get(transactionForRules, field),
diff[field],
))
) {
@@ -1776,8 +1793,12 @@ function TransactionEditUnconnected({
}
});
+ const parentForPropagate: TransactionEntity = {
+ ...transactionForRules,
+ ...newTransaction,
+ };
const subtransactions = propagateRuleChangeToSubtransactions(
- newTransaction,
+ parentForPropagate,
diff.subtransactions,
updatedField,
clearedFields.current,
@@ -1785,6 +1806,18 @@ function TransactionEditUnconnected({
if (subtransactions) {
newTransaction.subtransactions = subtransactions;
changedFields.add('subtransactions');
+ } else if (
+ diff.subtransactions &&
+ (updatedField === 'payee' ||
+ shouldApplyRuleChange(
+ 'subtransactions',
+ transactionForRules.subtransactions,
+ diff.subtransactions,
+ ))
+ ) {
+ // First time a split rule converts this row into a parent.
+ newTransaction.subtransactions = diff.subtransactions;
+ changedFields.add('subtransactions');
}
}
}
@@ -1804,6 +1837,37 @@ function TransactionEditUnconnected({
for (const field of changedFields) {
(merged as Record<string, unknown>)[field] = newTransaction[field];
}
+
+ // When editing a split parent without a fresh subtransactions payload
+ // from rules, re-attach the latest children so updateTransaction keeps
+ // the existing split structure.
+ if (
+ !merged.subtransactions &&
+ (merged.is_parent || latestTransaction.is_parent)
+ ) {
+ const children = prevTransactions.filter(
+ t => t.is_child && t.parent_id === merged.id,
+ );
+ merged.subtransactions = children;
+ merged.is_parent = true;
+
+ const updated = updateTransaction(prevTransactions, merged).data;
+ // updateTransaction → makeChild clears child.error; restore any that
+ // were already on the flat list so split-error UI stays correct.
+ const childErrors = new Map(
+ children
+ .filter(c => c.error != null)
+ .map(c => [c.id, c.error!] as const),
+ );
+ if (childErrors.size === 0) {
+ return updated;
+ }
+ return updated.map(t => {
+ const error = childErrors.get(t.id);
+ return error !== undefined ? { ...t, error } : t;
+ });
+ }
+
return updateTransaction(prevTransactions, merged).data;
});
diff --git a/packages/desktop-client/src/components/transactions/applyRulesToTransaction.test.ts b/packages/desktop-client/src/components/transactions/applyRulesToTransaction.test.ts
index c559573d5a..9788fb14a1 100644
--- a/packages/desktop-client/src/components/transactions/applyRulesToTransaction.test.ts
+++ b/packages/desktop-client/src/components/transactions/applyRulesToTransaction.test.ts
@@ -1,6 +1,9 @@
import type { TransactionEntity } from '@actual-app/core/types/models';
-import { applyRulesToTransaction } from './applyRulesToTransaction';
+import {
+ applyRulesToTransaction,
+ transactionForRulesFromList,
+} from './applyRulesToTransaction';
import { trackClearedField } from './table/utils';
const baseTransaction: TransactionEntity = {
@@ -154,6 +157,64 @@ describe('applyRulesToTransaction', () => {
});
});
+describe('transactionForRulesFromList', () => {
+ it('returns a non-split transaction unchanged', () => {
+ const transaction = { ...baseTransaction };
+ expect(transactionForRulesFromList([transaction], transaction)).toEqual(
+ transaction,
+ );
+ });
+
+ it('groups a split parent with its children from a flat list', () => {
+ const parent: TransactionEntity = {
+ ...baseTransaction,
+ is_parent: true,
+ category: undefined,
+ };
+ const child1: TransactionEntity = {
+ id: 'sub-1',
+ account: 'account-1',
+ amount: -600,
+ date: '2026-10-01',
+ is_child: true,
+ parent_id: parent.id,
+ };
+ const child2: TransactionEntity = {
+ id: 'sub-2',
+ account: 'account-1',
+ amount: -400,
+ date: '2026-10-01',
+ is_child: true,
+ parent_id: parent.id,
+ };
+
+ const grouped = transactionForRulesFromList(
+ [parent, child1, child2],
+ parent,
+ );
+
+ expect(grouped.is_parent).toBe(true);
+ expect(grouped.subtransactions).toEqual([child1, child2]);
+ expect(grouped.id).toBe(parent.id);
+ });
+
+ it('groups by parent_id even if is_parent is missing on the row', () => {
+ const parent: TransactionEntity = { ...baseTransaction };
+ const child: TransactionEntity = {
+ id: 'sub-1',
+ account: 'account-1',
+ amount: -1000,
+ date: '2026-10-01',
+ is_child: true,
+ parent_id: parent.id,
+ };
+
+ const grouped = transactionForRulesFromList([parent, child], parent);
+
+ expect(grouped.subtransactions).toEqual([child]);
+ });
+});
+
describe('trackClearedField', () => {
it('marks a field cleared when its value is empty and unmarks it when set', () => {
const clearedFields = new Map<TransactionEntity['id'], Set<string>>();
diff --git a/packages/desktop-client/src/components/transactions/applyRulesToTransaction.ts b/packages/desktop-client/src/components/transactions/applyRulesToTransaction.ts
index 905cb0ff9c..497eaa895b 100644
--- a/packages/desktop-client/src/components/transactions/applyRulesToTransaction.ts
+++ b/packages/desktop-client/src/components/transactions/applyRulesToTransaction.ts
@@ -1,3 +1,4 @@
+import { groupTransaction } from '@actual-app/core/shared/transactions';
import { getChangedValues } from '@actual-app/core/shared/util';
import type { TransactionEntity } from '@actual-app/core/types/models';
@@ -8,6 +9,28 @@ import {
} from './table/utils';
import type { ClearedFieldsByTransaction } from './table/utils';
+/**
+ * Builds the transaction shape expected by `rules-run` from a flat list
+ * (parent followed by children), matching how the desktop table groups
+ * splits before applying rules.
+ *
+ * Mobile keeps splits ungrouped in state. Re-running a split rule against a
+ * parent without its children recreates new child ids and corrupts later
+ * edits (notes/account) — see #9189.
+ */
+export function transactionForRulesFromList(
+ transactions: readonly TransactionEntity[],
+ transaction: TransactionEntity,
+): TransactionEntity {
+ const children = transactions.filter(
+ t => t.is_child && t.parent_id === transaction.id,
+ );
+ if (transaction.is_parent || children.length > 0) {
+ return groupTransaction([transaction, ...children]);
+ }
+ return transaction;
+}
+
/**
* Merges the result of a rules run back into a transaction that is being
* entered, respecting the user's manual input.
diff --git a/upcoming-release-notes/9189.md b/upcoming-release-notes/9189.md
new file mode 100644
index 0000000000..74218f698f
--- /dev/null
+++ b/upcoming-release-notes/9189.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [junaidkhan80121]
+---
+
+Fix editing notes or account on mobile after a split rule runs, which previously triggered an internal error.