Repository navigation
fix(storage): don't write the initial value over stored data on mount - #201
Conversation
anurag629
left a comment
There was a problem hiding this comment.
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.
|
Done! |
anurag629
left a comment
There was a problem hiding this comment.
Thanks @prakashNalla, that was the only thing left. Nothing changed in the code or on develop since I tested it, so merging.
What and why
useLocalStoragesetloadedRefin the load effect, so the write effect ran in the same mount pass with the initial value still invalueand wrote it over what was stored.loadedis 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) andnpm run build, on Node v22.23.3npm run build && npx next start, run in headless Chrome:/invoice-generatorwith empty storage: From is empty, number INV0001developthe same steps give an empty From and INV0001 again.{"a":1}in the JSON formatter and pasted a token in the JWT decoder, and after a reload bothcc:history:json-formatterandcc:history:jwt-decoderstill have their entry.No unit test: vitest runs in the
nodeenvironment onlib/**/*.test.tsonly, 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
Checklist
npm run lint && npm run test && npm run buildpasses locallylib/and have a test inlib/__tests__/page.tsx, client component,opengraph-image.tsx, and the bug report dropdown are all done