Repository navigation
Keep one QueryClient and share the drugs query (WEB-007, WEB-029) - #264
Merged
Merged
Conversation
_app.tsx created a new QueryClient on every render, so the cache was empty after each navigation and the 1 MB+ drugs.json was downloaded again. Keep one client in useState, and drop the second QueryClient and LocalizationProvider that Factsheets.tsx wrapped itself in. The factsheets table and the factsheet pages each had their own query under the same "table-data" key but with different data shapes, which would clash in a shared cache. Both now use one useDrugs() hook (src/utils/drugs.ts) with a 30 minute staleTime; a failed download now throws. Removing the table's rowCount also fixes the pager showing "1-10 of 555" after filtering (WEB-029). The tracker gains WEB-027 to WEB-030 for the issues found while deploying and testing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes WEB-007: the data cache was recreated on every render, so the 1 MB+
drugs.jsondownloaded again on every page change. The change also fixes WEB-029, the factsheets row counter that ignored filters.What changed:
src/pages/_app.tsx: keeps oneQueryClientfor the session (useState(() => new QueryClient())) instead ofnew QueryClient()on every render.src/utils/drugs.ts(new): auseDrugs()hook that loads the drug database. It uses the cache key["drugs"]and treats the data as fresh for 30 minutes, so navigating between pages reuses it.src/components/Factsheets.tsx:useDrugs().ExamplePagewrapper is gone; it added a secondQueryClientand a secondLocalizationProvider, and_app.tsxalready provides both.rowCountis removed (WEB-029). That option is meant for server-side pagination, and it pinned the footer to "1-10 of 555" whatever the filter.src/pages/factsheets/[drug].tsx: usesuseDrugs().["table-data"]key, with different data shapes. With one shared cache, whichever ran first would have broken the other, so both now share the hook.REVIEW-ISSUES.md:Type of change
Checklist
uat(this PR targetsuat, notmain)npx eslint .)npx next buildsucceeds locally (also type-checks).envvalues, or user data includedTest plan
npx eslint .: 0 errors. The 2 warnings were already there.npx jest: all 37 tests pass, including 2 new ones forfetchDrugs.npx next buildsucceeds./factsheetsto/factsheets/lsd, then/, then back to/factsheets, using client-side navigation.drugs.jsondownloaded 3 times on UAT and once on this branch. Both pages rendered their data./factsheets/lsddirectly still renders the full factsheet.Notes for reviewers
🤖 Generated with Claude Code