Skip to content

fix(storage): don't write the initial value over stored data on mount - #201

Merged
anurag629 merged 1 commit into
codercops:developfrom
prakashNalla:fix/126-use-local-storage-mount-write
Oct 19, 2026
Merged

anurag629 merged 1 commit into
codercops:developfrom
prakashNalla:fix/126-use-local-storage-mount-write

Conversation

@prakashNalla

@prakashNalla prakashNalla commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What and why

useLocalStorage set loadedRef in the load effect, so the write effect ran in the same mount pass with the initial value still in value and wrote it over what was stored. loaded is now state, set together with the stored value, so the first write happens on the render that already has the stored value. The invoice tool's seed effect now finds the saved sender and invoices after a reload.

Closes #126

How I tested this

  • npm run lint (no new warnings), npm run test (16 files / 354 tests pass) and npm run build, on Node v22.23.3
  • Manual reload steps on npm run build && npx next start, run in headless Chrome:
    1. /invoice-generator with empty storage: From is empty, number INV0001
    2. Typed "Jane" as the sender name and clicked Save
    3. Reloaded: From shows Jane and the number is INV0002. On develop the same steps give an empty From and INV0001 again.
  • JSON and JWT history still persist: formatted {"a":1} in the JSON formatter and pasted a token in the JWT decoder, and after a reload both cc:history:json-formatter and cc:history:jwt-decoder still have their entry.

No unit test: vitest runs in the node environment on lib/**/*.test.ts only, and there's no DOM or React testing library in the repo to render a hook.

AI assistance

Claude helped me understand the problem

Type of change

  • Bug fix
  • New tool or feature
  • Tests
  • Refactor or cleanup
  • Docs

Checklist

  • I was assigned the linked issue
  • npm run lint && npm run test && npm run build passes locally
  • Logic changes live in lib/ and have a test in lib/__tests__/
  • For a bug fix: the new test fails without my change
  • No analytics, trackers, or calls that send user data off-device
  • Works in both light and dark themes (if UI changed)
  • Inputs have labels and it works with the keyboard alone (if UI changed)
  • New tool: registry entry, page.tsx, client component, opengraph-image.tsx, and the bug report dropdown are all done

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @prakashNalla, the fix works. I built this branch merged onto current develop and ran your reload steps in headless Chrome: Jane and INV0002 come back after the reload, while develop shows an empty From and INV0001. I also logged every localStorage write during the reload. develop writes [] and the default sender first and the saved values after that, this branch only writes the saved values. JSON and JWT history survive a reload too, and lint, all 354 tests and the build pass. You're right that the tests can't render a hook yet, so the manual steps are fine here.

The only thing left is the "AI assistance" section. It's empty, which is why the description check is red. Fill it in (or say you didn't use any) and I'll merge.

@prakashNalla

Copy link
Copy Markdown
Contributor Author

Done!

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @prakashNalla, that was the only thing left. Nothing changed in the code or on develop since I tested it, so merging.

@anurag629 anurag629 added the hacktoberfest-accepted PR counts for Hacktoberfest label Oct 19, 2026
@anurag629
anurag629 merged commit 7c72124 into codercops:develop Oct 19, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest-accepted PR counts for Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep the saved sender and next invoice number after a reload

2 participants