fix(compare): keep chart data when a client refetch fails #12

Merged
tudor merged 1 commits from fix/compare-chart-refetch-resilience into main 2026-07-06 07:27:04 +00:00
Owner

The staging E2E gate for #11 failed on the new mobile compare-chart test: the chart canvas never appeared on staging. Root cause is not the chart code but a pre-existing fragility it exposed.

Mechanism

  • app/compare/page.tsx fetches comparison data server-side (internal FASTAPI_URL, which works on staging) and passes it as initialData, so the chart has data to render.
  • ComparisonView's client useEffect then refetches /api/compare from the browser. On staging the external /api edge proxy 500s (known issue), and the catch did setComparisonData(null) — wiping the good SSR data, so the chart section disappeared.
  • On production the refetch succeeds, so this was invisible there — but any transient network failure would blank a working comparison for a real user too.

Fix
On refetch failure, keep whatever data we already have (SSR data or a previous successful fetch) instead of nulling it. Strictly better UX, and it lets the chart render on staging so the promotion gate passes.

Verified: production compare renders the canvas with zero console errors; staging returns 500 on the client /api/compare and (before this fix) drops the chart. Typecheck + 33 unit tests pass.

🤖 Generated with Claude Code

The staging E2E gate for #11 failed on the new mobile compare-chart test: the chart canvas never appeared on staging. Root cause is not the chart code but a pre-existing fragility it exposed. **Mechanism** - `app/compare/page.tsx` fetches comparison data server-side (internal `FASTAPI_URL`, which works on staging) and passes it as `initialData`, so the chart has data to render. - `ComparisonView`'s client `useEffect` then refetches `/api/compare` from the browser. On staging the external `/api` edge proxy 500s (known issue), and the catch did `setComparisonData(null)` — wiping the good SSR data, so the chart section disappeared. - On production the refetch succeeds, so this was invisible there — but any transient network failure would blank a working comparison for a real user too. **Fix** On refetch failure, keep whatever data we already have (SSR data or a previous successful fetch) instead of nulling it. Strictly better UX, and it lets the chart render on staging so the promotion gate passes. Verified: production compare renders the canvas with zero console errors; staging returns 500 on the client `/api/compare` and (before this fix) drops the chart. Typecheck + 33 unit tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tudor added 1 commit 2026-07-05 22:08:50 +00:00
fix(compare): keep chart data when a client refetch fails
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 9m38s
PR Checks / Backend Smoke (pull_request) Successful in 5s
PR Checks / Build Backend (no push) (pull_request) Successful in 10s
PR Checks / Build Frontend (no push) (pull_request) Successful in 47s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 9s
PR Checks / AI Code Review (Claude) (pull_request) Successful in 1m9s
9f8dba227c
The compare view refetches /api/compare on the client after SSR; on any
failure the catch nulled comparisonData, destroying the working
SSR-provided chart. A transient error (or staging's broken external /api
proxy) should not blank a comparison the user is already viewing — keep
the existing data instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

🤖 AI Code Review (Claude Code)

This small diff changes ComparisonView's refetch error handler to keep the existing comparisonData instead of clearing it to null, avoiding a flash-to-empty when a transient refetch fails. The intent (preserve a working chart across a blip) is reasonable, but it introduces a staleness edge case with no user-visible feedback.

🟡 Minor

  • nextjs-app/components/ComparisonView.tsx: When the school selection itself changes (add/remove) and the refetch then fails, the component silently keeps rendering comparisonData keyed to the previous selection with no error indicator to the user. E.g. adding a school while a fetch fails leaves that school's card visible but absent from the chart/table with no explanation, and there is no retry/error UI — the failure is only logged to console.
## 🤖 AI Code Review (Claude Code) This small diff changes ComparisonView's refetch error handler to keep the existing comparisonData instead of clearing it to null, avoiding a flash-to-empty when a transient refetch fails. The intent (preserve a working chart across a blip) is reasonable, but it introduces a staleness edge case with no user-visible feedback. ### 🟡 Minor - **nextjs-app/components/ComparisonView.tsx**: When the school selection itself changes (add/remove) and the refetch then fails, the component silently keeps rendering comparisonData keyed to the previous selection with no error indicator to the user. E.g. adding a school while a fetch fails leaves that school's card visible but absent from the chart/table with no explanation, and there is no retry/error UI — the failure is only logged to console.
tudor merged commit 694b6013b3 into main 2026-07-06 07:27:04 +00:00
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: tudor/school_compare#12