Repository navigation
[AI] Mobile transaction updates field-level merging - #8196
Conversation
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
👋 Hello contributor! We would love to review your PR! Before we can do that, please make sure:
A quick note on volume: please get one PR reviewed and merged before opening several more. A stack of simultaneous, similar PRs from one author is reviewed slowly, and low-effort, untested, or undisclosed-AI PRs may be closed without a detailed review. We do this to reduce the TOIL the core contributor team has to go through for each PR and to allow for speedy reviews and merges. For more information, please see our Contributing Guide. |
📝 WalkthroughWalkthroughThe PR fixes a race condition in the mobile transaction editor where auto-fill rule updates could overwrite in-flight transaction changes. It introduces ChangesTransaction state concurrency fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx (1)
1820-1848:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftDon't merge
subtransactionsas a stale whole-array snapshot.This still loses concurrent split edits.
newTransaction.subtransactionsis built before the functional state update, so if a child split changes while the rule run is in flight, Line 1846 copies the stale child objects ontomerged.updateTransaction(...)then treats that array asoriginalSubtransactions, so the later parent update can wipe the child’s newer fields. Merge only the affected child field(s) ontolatestTransaction.subtransactionsinside the updater instead of assigning the stale array wholesale.💡 Suggested direction
- const merged = { ...latestTransaction }; - for (const field of changedFields) { - (merged as Record<string, unknown>)[field] = newTransaction[field]; - } + const merged = { ...latestTransaction }; + for (const field of changedFields) { + if ( + field === 'subtransactions' && + latestTransaction.is_parent && + latestTransaction.subtransactions && + newTransaction.subtransactions + ) { + merged.subtransactions = latestTransaction.subtransactions.map( + latestSubtransaction => { + const nextSubtransaction = newTransaction.subtransactions?.find( + subtransaction => subtransaction.id === latestSubtransaction.id, + ); + + if (!nextSubtransaction) { + return latestSubtransaction; + } + + return { + ...latestSubtransaction, + [updatedField]: nextSubtransaction[updatedField], + }; + }, + ); + continue; + } + + (merged as Record<string, unknown>)[field] = newTransaction[field]; + }Based on
packages/loot-core/src/shared/transactions.ts:260-298,updateTransaction(...)rebases parent updates fromtransaction.subtransactionswhenever that property is present.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx` around lines 1820 - 1848, The updater is copying the pre-built newTransaction.subtransactions array (which may be stale) onto merged, risking lost concurrent child edits; instead, inside the setTransactions functional updater where you find latestTransaction, handle the 'subtransactions' case specially: for each changed child index/field present in newTransaction.subtransactions, merge only those specific child fields onto latestTransaction.subtransactions[index] (preserving other properties and other children's newer values) before calling updateTransaction; keep the per-field loop for changedFields but replace the wholesale assignment of newTransaction.subtransactions with a targeted per-child merge into merged.subtransactions so updateTransaction receives a rebased array rather than a stale snapshot.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@upcoming-release-notes/8196.md`:
- Line 6: Replace the hedged release-note heading "Attempt to fix entered amount
being lost sometimes when tapping the Nearby payee chip before field loses
focus" with a definitive, concise statement of the shipped behavior; for example
use "Fixed an issue where an entered amount could be lost when tapping Nearby
before the amount field lost focus" (locate the original string in
upcoming-release-notes/8196.md and update it accordingly).
---
Outside diff comments:
In
`@packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx`:
- Around line 1820-1848: The updater is copying the pre-built
newTransaction.subtransactions array (which may be stale) onto merged, risking
lost concurrent child edits; instead, inside the setTransactions functional
updater where you find latestTransaction, handle the 'subtransactions' case
specially: for each changed child index/field present in
newTransaction.subtransactions, merge only those specific child fields onto
latestTransaction.subtransactions[index] (preserving other properties and other
children's newer values) before calling updateTransaction; keep the per-field
loop for changedFields but replace the wholesale assignment of
newTransaction.subtransactions with a targeted per-child merge into
merged.subtransactions so updateTransaction receives a rebased array rather than
a stale snapshot.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: abd0b271-37dc-4f1b-80a6-89afb83f7aca
📒 Files selected for processing (2)
packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsxupcoming-release-notes/8196.md
…earby payee chip before field loses focus
…earby payee chip before field loses focus (actualbudget#8196) Co-authored-by: Matiss Janis Aboltins <[email protected]>
Description
I haven't been able to reproduce the issue reported in #6706 (comment). I thought maybe there might be some kind of race condition on updating the transaction that I didn't quite grok.
Claude (Fable 5) concurs that is likely two concurrent updates (e.g. the blur committing the typed amount, and the Nearby tap setting the payee) each replacing the entire transaction from a stale copy, so whichever landed last erased the other's field.
Claude Code (Fable 5) helped work through the potential issue and the fix.
Related issue(s)
Issue reported on #6706 (comment)
Testing
Reproducing the issue has not been possible for me, but I've manually tested this locally and don't see it adding additional issues. 😅
Checklist
Bundle Stats
View detailed bundle stats
desktop-client
Total
Changeset
src/components/mobile/transactions/TransactionEdit.tsxView detailed bundle breakdown
Added
No assets were added
Removed
No assets were removed
Bigger
Smaller
No assets were smaller
Unchanged
loot-core
Total
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
api
Total
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
cli
Total
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
crdt
Total
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