Skip to content

Keep one QueryClient and share the drugs query (WEB-007, WEB-029) - #264

Merged
LunaUrsa merged 2 commits into
uatfrom
fix/WEB-007-query-client
Nov 8, 2026
Merged

LunaUrsa merged 2 commits into
uatfrom
fix/WEB-007-query-client

Conversation

@LunaUrsa

@LunaUrsa LunaUrsa commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes WEB-007: the data cache was recreated on every render, so the 1 MB+ drugs.json downloaded 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 one QueryClient for the session (useState(() => new QueryClient())) instead of new QueryClient() on every render.
  • src/utils/drugs.ts (new): a useDrugs() 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.
    • A failed download now throws, so the table shows its error banner instead of trying to parse an error page.
    • The table's refresh button still forces a new download.
  • src/components/Factsheets.tsx:
    • Uses useDrugs().
    • The ExamplePage wrapper is gone; it added a second QueryClient and a second LocalizationProvider, and _app.tsx already provides both.
    • rowCount is 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: uses useDrugs().
    • The table and this page each had their own query under the same ["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.
    • WEB-010 will move this page to build-time data later.
  • REVIEW-ISSUES.md:
    • WEB-007 and WEB-029 are marked fixed.
    • New issues found while deploying and testing: WEB-027 (both Drone servers build every push), WEB-028 (the shared deployer gives up after about 60 s) and WEB-030 (expanding a factsheet row keeps the browser busy).
    • Notes added to WEB-014 (where the UAT compose file lives) and WEB-026 (current audit counts).

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor / chore
  • Other (describe above)

Checklist

  • Branch is up to date with uat (this PR targets uat, not main)
  • Lint passes (npx eslint .)
  • npx next build succeeds locally (also type-checks)
  • No secrets, .env values, or user data included

Test plan

  • Automated checks:
    • npx eslint .: 0 errors. The 2 warnings were already there.
    • npx jest: all 37 tests pass, including 2 new ones for fetchDrugs.
    • npx next build succeeds.
  • Browser check: a local production build in Chrome, compared with UAT.
    • Downloads while navigating: I went from /factsheets to /factsheets/lsd, then /, then back to /factsheets, using client-side navigation. drugs.json downloaded 3 times on UAT and once on this branch. Both pages rendered their data.
    • Row counter: with "mdma" in the name filter, the footer goes from "1-10 of 555" to "1-1 of 1". UAT and production still show "1-10 of 555".
    • Other pages: opening /factsheets/lsd directly still renders the full factsheet.
    • Refresh button: "Refresh Data" downloads the list again.
    • The console showed no errors.

Notes for reviewers

  • A full page reload still downloads the list once, as before, because each page load starts with an empty cache. Only client-side navigation reuses it.

🤖 Generated with Claude Code

LunaUrsa and others added 2 commits November 8, 2026 13:57
_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>
@LunaUrsa
LunaUrsa merged commit 89b51d0 into uat Nov 8, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant