Skip to content

fix(medications): restore lint to 0 errors via useQuery refactor of API-endpoint dialog#144

Merged
MBombeck merged 1 commit intomainfrom
fix/v141-h6-medications-lint
May 8, 2026
Merged

fix(medications): restore lint to 0 errors via useQuery refactor of API-endpoint dialog#144
MBombeck merged 1 commit intomainfrom
fix/v141-h6-medications-lint

Conversation

@MBombeck
Copy link
Copy Markdown
Owner

@MBombeck MBombeck commented May 8, 2026

Summary

The medications page's "API endpoint" dialog ran its initial status load through a useCallback + useEffect pair. Inside the callback, setLoadingStatus(true) fired synchronously before the first await, which the strict react-hooks/set-state-in-effect rule flags as a cascading-render risk. That was the last remaining ESLint error on main (1 error baseline since the v1.3.x cycle — the v1.4 settings monolith carried three more, all cleared by the A2-content extraction in #143).

This PR converts the dialog to TanStack Query — same fetch shape, but the effect disappears entirely.

What changed

  • enabled / activeTokenCount / loadingStatus now derive from a useQuery({ queryKey: ["medication-api-endpoint", id], … }).
  • The "Reload status" menu item calls refetch().
  • After a successful toggle PUT, the response is written back through queryClient.setQueryData so the UI updates in place without a second GET.
  • Status-fetch errors flow through the same callout that toggle errors do (displayMsg = msg ?? statusError.message).
  • gcTime: 0 + removeQueries on close keep the cache from leaking the active-token count between successive openings of the dialog.

No user-visible change. Same network calls, same UX.

Quality gates

  • pnpm typecheck — clean
  • pnpm test — 658/658 pass (no test removed/skipped)
  • pnpm lint0 errors (12 warnings, all pre-existing unused-var hints)
  • pnpm exec prettier --check — clean

🤖 Generated with Claude Code

The dialog's "load endpoint status" effect was triggering a
react-hooks/set-state-in-effect lint error: setLoadingStatus(true)
fired synchronously inside an effect, which the rule flags as a
cascading-render risk.

Convert the imperative useCallback + useEffect pair to a single
useQuery — same fetch shape, but loading/data state now lives in
TanStack Query and the effect goes away. The "Reload status" menu
item calls refetch(); the toggle path uses queryClient.setQueryData
to keep the displayed state in sync after a PUT, so users still see
the new active-token count without a second roundtrip. Errors from
the GET render through the same callout that toggle errors do.

No user-visible change. Restores lint to 0 errors on main.

Co-Authored-By: Marc-André Bombeck <mbombeck@gmail.com>
@MBombeck MBombeck merged commit 6bb0055 into main May 8, 2026
5 checks passed
@MBombeck MBombeck deleted the fix/v141-h6-medications-lint branch May 8, 2026 13:40
MBombeck added a commit that referenced this pull request May 8, 2026
Production at healthlog.bombeck.io has been 503-ing since the v1.4.1
deploys started landing on apps-01 (Coolify). The container boots —
Next.js prints "Ready" and the pg-boss workers run — but never
accepts HTTP on :3000, so the Docker healthcheck fails and Traefik
takes the upstream out of rotation. A manual restart, a Coolify
force-rebuild, and a docker-compose pin to the GHCR :1.4.0 multi-arch
image all failed to bring the site back up — Coolify rebuilds the
image from main HEAD on every deploy regardless of the compose
directives.

This commit resets the working tree to commit 21bd46d (v1.4.0
release). Same content that's been running for self-hosters since
yesterday's tag-and-release. The next Coolify deploy will build
from this tree and produce a healthy container.

The v1.4.1 work is NOT lost:
  - PRs #144, #145, #137, #146, #147, #148, #149, #150 remain in
    git history.
  - Their commits are still tagged (`v1.4.1`), still on the GHCR
    multi-arch image (`ghcr.io/mbombeck/healthlog:1.4.1`), still in
    the GitHub Release notes.
  - Self-hosters who have already pulled the v1.4.1 image keep it.
  - Local development continues from main HEAD with the v1.4.1
    code — the regression only surfaced under the Coolify build
    flow.

Re-applying v1.4.1 to production will need a separate cycle to
reproduce the runtime failure under the Coolify build path. That
work is tracked in docs/ops/v141-followup-issues.md (added back
when the tree is reapplied) and the deploy gating in
.github/workflows/e2e.yml will catch this class of bug going
forward.

No DB migration. No env-var change. No API contract change.
Co-Authored-By: Marc-André Bombeck <mbombeck@gmail.com>
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