Skip to content

v1.16.18: Fix a JSON import's transaction edits not showing until a reload - #41

Open
gitluis wants to merge 2 commits into
fix-read-as-reload-duplicatesfrom
fix-json-import-edits-not-applied
Open

gitluis wants to merge 2 commits into
fix-read-as-reload-duplicatesfrom
fix-json-import-edits-not-applied

Conversation

@gitluis

@gitluis gitluis commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #40 (fix-read-as-reload-duplicates). Merge order: #16, #17, #19, #20, #21, #24–#38, #39–#50, then #10, then #23.
Uses earlier fixes' code: DataCleanup._unedited() (#24) and txFlags() (#31). It doesn't need #40's code.

Summary

Settings → Data & reset → Import JSON saved the file's transaction edits (txOverrides), but every screen kept the old descriptions, categories, types, flags and notes. A transaction the file had no edit for kept its old edit too.

Now every loaded transaction is rebuilt right after the import, the same way an import of the CSVs with those edits would build it.

Cause

  • importJsonFile() (ui.js) replaced State.txOverrides and rebuilt nothing. _applyImportedSettings() re-applied flag rules and transfer keywords only when those keys changed. Its comment said edits apply "once the page reloads".
  • A reload didn't always fix it. The autosave wrote the transactions as they were on screen. A boot from finlens-state.json (loadStateFromFile() → reconstituteTx()) takes the category and type from the saved transaction when the edit has none. So an old edit's category stayed wherever the imported file had no edit for that transaction. Only a boot from IndexedDB rebuilt them from the CSV rows. Seen on the parent: case 2's first check fails for F, which keeps "Travel".
  • Master has the same gap in importJsonFile(), but no button calls it there: the Import JSON button came in v1.16.0. Checked by calling it directly on origin/master (e8e18e7): the edit (description FROM BACKUP, a note) is saved, and the transaction still shows UBER TRIP with no note.

What changed

  • applyImportedEdits(before) (ui.js, new). It rebuilds each loaded transaction:
  • What that gives:
  • before is the edits map from before the import. _unedited() needs it only for a transaction from a ≤v1.16.0 state file, which doesn't record its CSV category and type.
  • _applyImportedSettings(changed, before) is now async:
    • With new edits, it runs the rebuild. The rebuild already uses the imported flag rules and transfer keywords, so applyTxRulesToAll() and reapplyTransferKeywords() don't also run: they would repeat work the rebuild has done.
    • Without new edits, it does what it did before.
  • importJsonFile():
    • its reader callback is now async;
    • it keeps a copy of the edits from before the import;
    • edits moved by IdMigration.adoptOverrides() count as changed edits.
  • Plan links: no change needed. They're read from State.txOverrides, so they already showed at once on the parent too. The test checks they still do.
  • Version: v1.16.18 in CHANGELOG (dated 2026-11-02), footer, README (both places), Settings → General, and CLAUDE.md §1. CLAUDE.md also updated: §9, §20 and "Last updated".

Not verified

  • A real file picked in Edge or Chrome. The test sets the real #dcImportFile input through Playwright.
  • Edits with a singular category field. reconstituteTx() ignores it, as a reload does; mkTx() reads it. Today's drawer writes categories. I didn't check whether any saved data still holds category. Not changed here.
  • Card rows from a ≤v1.16.0 state file without an IndexedDB row. Their own Category and Type can't be recovered. Same limit as Clear transaction edits; the test compares checking and savings only in case 4.
  • Phone layouts (desktop only, by decision).
Automated checks: earlier run, not re-run · a2063c8

Moved unchanged from this PR's "Test results" comment on 2026-11-04; not re-run, so not in the new table format. Originally a description section titled "How it was tested".

Light checks, by Luis's call to save usage: on this branch's final commit a2063c8 (chained on #40) only boot.js, race.js and this PR's own tests ran. Headless Chromium at 1280×900 against samples/, with the pinned CDN libraries served from npm; each script ran as NODE_PATH=$(npm root -g) node <script> <repo> <outdir>.

Script Result on a2063c8
boot.js 257 transactions, 24 views, 0 errors
race.js 24 views, 0 errors
test-json-import-edits.js (new in this PR) 29/29
test-json-export.js (#29's, with this PR's edit) 31/31

Full set, once, on the top of the stack (#23, 819e809: every PR below it merged in): every base suite and every fix test from #24 to #50, plus #10's and #23's, each in its final variant. All pass: test-clarity.js 55/55, test-insights.js 137/137, test-finances.js 126/126, test-plan.js 127/127, boot.js 257 transactions and 0 errors, race.js 0 errors; #24–#38's tests (clear-edits 48/48, rebuild-folder 57/57, partial-import 47/47, json-import 28/28, new-browser-copy 10/10, json-export 31/31, plan-links 60/60, rule-flags 67/67, drawer-flags 36/36, start-balance 193/193, ai-summary-period 78/78, account-names 40/40, account-order 32/32, drawer-focus 167/167, cleanup 21/21); #39–#50's tests (drawer-fields 45/45, read-as 52/52, json-import-edits 29/29, overlapping-exports 46/46, override-balance 160/160, card-override 277/277, ai-summary-trend 91/91, transfer-user-type 39/39, untransfer-category 27/27, recategorize 55/55, retype-transfer 135/135, minor-fixes 34/34); test-dbtab.js 73/73, test-save-status.js 64/64, test-master-port.js 16/16. Three scripts needed a test-only change on that run, listed in #23 and in the PRs they belong to; the app code wasn't changed.

  • No phone checks (desktop only).

Measured before the chain

The numbers below are the PR author's, on the commit before it was chained (built on the old #38 tip ecfcab2, v1.16.15, or on the fix below it there; version numbers renumbered to the chain's).

Headless Chromium, desktop 1280×900, with the harness's fake folder. Suites ran one at a time.

  • test-json-import-edits.js (new). The export is made in one browser with six edits:

    • A: description, category and notes;
    • B: type changed to transfer;
    • C: Bill ticked;
    • G: subscription unticked against a rule;
    • D: notes and a bucket link;
    • E: description of a transfer leg.

    A second browser has other edits (A changed differently; F, a row the file has no edit for) and imports the file through the real file input.

    • Reference: a fresh browser that imports the JSON first, then the CSVs.
    • Parent (bug-1 commit 17cc713): 15/29 passed. Failures: A–G keep their old values, F keeps "Travel", the Transactions list and drawer show the old values, a reload from the state file still shows F as "Travel", and cases 4 and 5 differ from the reference. The passes: setup, links, the IndexedDB boot, the exports without edits (case 3), and no-console-error checks.
    • This branch (b4a87e6): 29/29 passed.
    • Cases:
      1. Each edited field at once: memory, the Transactions list, the drawer, and links in both drawers. Every transaction against the reference.
      2. The autosave, a page reload and a boot from IndexedDB agree with the reference.
      3. 1.0 and 1.1 exports without edits, and the same export again, change nothing.
      4. A v1.16.0 state file with IndexedDB empty.
      5. Edits, flag rules and transfer keywords all change in one import (this browser had an extra keyword that made the rent rows transfers, and no rule).
  • test-read-as.js (from the bug-1 PR): 52/52 passed on b4a87e6.

  • run-tip.sh 15 on b4a87e6: every suite passed except one check, which had to change:

    • test-clarity 55/55, test-insights 137/137, test-finances 126/126, test-plan 127/127.
    • boot: 257 transactions, 0 errors.
    • race: 8 errors, all renderImportLog (expected on this base until v1.10.5: fix Import Logs throwing when the view is left before it loads #18's fix is in the stack; none from this change).
    • test-clear-edits 47/47, test-rebuild-folder 57/57, test-partial-import 47/47, test-json-import 28/28, test-new-browser-copy 10/10.
    • test-plan-links 60/60, test-rule-flags 67/67, test-drawer-flags 36/36, test-start-balance 193/193, test-ai-summary-period 78/78.
    • test-account-names 40/40, test-account-order 32/32, test-drawer-focus 167/167, test-cleanup 21/21.
    • test-json-export 30/31 as written. The failing check is "Import, no reload: transaction edits wait for a reload, as before", which asserted the bug.
  • Suite changed: test-json-export.js (harness copy). That check now depends on whether the fix is present:

    • with applyImportedEdits(), it expects the edit to show at once ("transaction edits show at once (v1.16.18)");
    • without it, it keeps the old check, so the bug-1 branch still runs it.
    • After the change: 31/31 on b4a87e6 and 31/31 on 17cc713.
How to reproduce the bug

Run this on the base branch, fix-read-as-reload-duplicates (#40). Master's code has the same gap, but no button reaches it there, so it can't be reproduced from master's screens.

  1. Do the Setup from the testing steps below, but check out fix-read-as-reload-duplicates instead of fix-json-import-edits-not-applied. Use a scratch folder with the samples only.
  2. Make the backup (state A) and export it, then make the later changes (state B), exactly as written below.
  3. Go to Settings → Data & reset → Import JSON… and pick the export.
  4. Click OK on Imported successfully.
  5. Don't reload. Open Transactions and search for rows A, B, C, D and F.
  6. Optional: wait 5 seconds, press F5 (click Reconnect folder if asked), and search for F again.

What goes wrong:

  • Every row keeps its state-B values: A still shows Changed later and later note, not Airport ride and backup note; B is not a transfer; D has no lunch note.
  • F keeps Travel instead of going back to Groceries, and still shows Travel after the reload.
Manual QA steps

Setup

  1. git checkout fix-json-import-edits-not-applied.
  2. Copy the three CSVs from samples/ to a new scratch folder. Don't use your real folder: Import JSON replaces your edits and the autosave rewrites finlens-state.json.
  3. Open an Edge InPrivate window (Ctrl+Shift+N) and open index.html.
  4. Click Pick your CSV folder, choose the scratch folder and allow access.
  5. Set the date range to All time (calendar icon in the app bar).
  6. Make a budget to link to: Plan → Budget → Use starter budget.

Make the backup (state A). On Transactions, use Search description or notes to find each row, click it, change it, and click Save changes:

  • A: the newest UBER TRIP (Oct 20, −$10.62). Description Airport ride, Category Transport, Notes backup note.
  • B: the newest PUEBLO SUPERMARKET 0412. Type Transfer.
  • C: the newest LUMA ELECTRIC BILL PAY. Tick Bill (untick it if it's already ticked; note which).
  • D: the newest CHIPOTLE 2410. Notes lunch, and Link to a budget, bucket or debt → Budget → pick one.

Then Settings → Data & reset → Export JSON. Keep the downloaded finlens-export-YYYYMMDD.json.

Change things after the backup (state B).

  • Open A again. Change Description to Changed later, Notes to later note. Save.
  • Open B again. Set Type back to Expense. Save.
  • Open C again. Flip Bill back. Save.
  • Open D again. Clear Notes. Save.
  • F: the newest WHOLE FOODS MKT. Set Category to Travel. Save. (The backup has no edit for this row.)

1. Import JSON applies the backup's edits at once (main fix)

  1. Settings → Data & reset → Import JSON… → pick the export.
  2. Click OK on Imported successfully.
  3. Don't reload. Open Transactions and search for each row.

Expected:

  • A shows Airport ride, tag Transport, and the note backup note under the description.
  • B is a transfer again: it's listed under the Transfers pill, with category Transfer out.
  • C's Bill flag is as in the backup (the Flags column).
  • D shows the note lunch. Opening it shows the budget link.
  • F is back to its CSV category Groceries (the backup has no edit for it).

Before this fix: every row kept its state-B values until a reload, and F kept Travel even after one.

2. The drawer shows the imported values

  1. Open A, B and C in turn.

Expected:

  • The drawer fields match test 1: A's Description is Airport ride, B's Type is Transfer, C's Bill box matches the backup.

3. Reload from the folder agrees

  1. Wait 5 seconds (the autosave), or click Save now in Settings → Import.
  2. Press F5. Click Reconnect folder if asked.
  3. Check A, B, C, D and F again.

Expected:

  • Same as test 1 for every row. F is still Groceries, not Travel.

4. A fresh browser agrees

  1. Close the InPrivate window.
  2. Open a new InPrivate window, open index.html, pick the same scratch folder.
  3. Check A, B, C, D and F.

Expected:

  • Same as test 1.
  • F12 → Console shows no red errors.

5. An import without edits changes nothing

  1. Note A's and F's current state on Transactions.
  2. Make a JSON file with no edits: open the export in a text editor, delete the whole "txOverrides": { … }, block, save as no-edits.json.
  3. Settings → Data & reset → Import JSON… → pick no-edits.json.
  4. Check A and F.
  5. Import the original export again.

Expected:

  • Step 4: A and F are unchanged (a file without txOverrides keeps your edits).
  • Step 5: nothing changes, since the edits are the same as now.

6. Edits, flag rules and keywords in one import

  1. On Transactions, scroll to Transaction rules. In When description contains, type LIBERTY INTERNET, Flag as Bill, click Add rule.
  2. On Transfers, under Transfer keywords, type rent in Add keyword and click Add. The RENT PAYMENT PALM COURT APTS rows become transfers.
  3. Settings → Data & reset → Import JSON… → pick the original export (it has neither the rule nor the keyword).
  4. Check the RENT and LIBERTY INTERNET rows on Transactions, and the rule list.

Expected:

  • The rent keyword is gone and the RENT rows are expenses again (not under the Transfers pill).
  • The LIBERTY INTERNET rule is gone, and those rows' Bill flag is back to what it was before step 1.
  • A–D still show the backup's edits.

7. Regression: plan links and other settings

  1. On Transactions, open D. Check Link to a budget, bucket or debt.
  2. Check Settings → Accounts (names and order) and Settings → General → Theme.

Expected:

  • D is still linked to the same budget.
  • Names, order and theme are as they were when you exported.

Please check before merging

  • Export JSON, change a few transactions (description, category, a flag, a note, a link), Import JSON, and check they're back at once, without reloading.
  • Check a transaction you edited after the export: it should go back to its CSV values, since the file has no edit for it. Agree with that: the import replaces all edits, as it always did in storage.
  • Import an old export without edits and check nothing changes on Transactions.
  • Agree that with new edits, the rebuild applies the imported flag rules and transfer keywords, instead of their own steps.
  • Manual QA passed in Edge/Chrome with a real folder

https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft


Generated by Claude Code

…16.18)

Settings -> Data & reset -> Import JSON saved the file's transaction edits
(txOverrides) but left the loaded transactions as they were: every screen
kept the old descriptions, categories, types, flags and notes, and a
transaction the file had no edit for kept its old edit. A reload didn't
always fix it: the autosave wrote the transactions as shown, and a boot from
finlens-state.json keeps a saved category and type where the edit has none.
master has the same gap in importJsonFile(), but no button calls it there
(Import JSON came in v1.16.0).

- applyImportedEdits() (ui.js): with new edits, every loaded transaction is
  rebuilt from its CSV values (DataCleanup._unedited(), as Clear transaction
  edits does) with its imported edit on top (reconstituteTx()), then
  detectTransfers() runs: what an import of the CSVs makes with these edits.
  Flags an edit doesn't set follow the rules now in State (txFlags()).
- _applyImportedSettings() is async and runs it when txOverrides changed;
  that rebuild also covers new flag rules and transfer keywords, so their own
  steps run only without new edits. Edits moved by adoptOverrides() count.
- Plan links already showed at once (read from txOverrides); unchanged.
- An export without edits (1.0, 1.1) changes no transaction.
- Version bumped to v1.16.18 (CHANGELOG, footer, README, Settings,
  CLAUDE.md); CLAUDE.md §9 and §20 updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft
@gitluis gitluis added the bug Something isn't working label Nov 3, 2026 — with Claude
@gitluis gitluis added this to the Clarity stack (v1.12.0 → v1.18.1) milestone Nov 3, 2026 — with Claude
… into fix-json-import-edits-not-applied

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Z8iBUZo6LRYpLthSp2PRi

# Conflicts:
#	CLAUDE.md
#	js/ui.js
#	js/views-settings.js

gitluis commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Dark theme taken out of the stack (Luis, 2026-11-04). #17 is light only for now: no ◐ toggle, no Light / Dark / Match system setting, no dark tokens. It comes back later in its own PR. #17's change was merged forward into this branch (no force push).


🤖 Generated with Claude Code

https://claude.ai/code/session_013Z8iBUZo6LRYpLthSp2PRi


Generated by Claude Code

@gitluis gitluis changed the title v1.16.18: fix a JSON import's transaction edits not showing until a reload v1.16.18: Fix a JSON import's transaction edits not showing until a reload Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants