You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Food search: backend errors shown as 'No foods found'; stale responses overwrite results #5
User-reported: manual food logging search shows "no results" when it should show the closest result.
frontend/src/components/FoodSearchInput.jsx (~L437-465, ~L607): the catch swallows every error (404/5xx/network/CORS) into setResults([]); showDropdown stays true from an earlier search, so the "No foods found. Try a different search term" branch renders for failures too. No AbortController/request-id, so a slow older response can overwrite the current query's results.
Backend: supabase/functions/search-food/index.ts (~L73-77) turns a USDA 429 / DEMO_KEY rate limit into a generic 500 (falls back to DEMO_KEY when USDA_API_KEY unset, ~L21). Same in food-details/index.ts (~L17).
Fix:
Add an error state; on failure show "Search unavailable, try again" (distinct from empty results). Show "No foods found" only after a 200 with empty foods.
Ignore stale responses (AbortController via axios signal, or query-id ref).
In search-food and food-details, map USDA 429 → 503 with detail: "Food database rate-limited, try again shortly"; log a warning when falling back to DEMO_KEY.
Existing FoodSearchInput tests must pass; add tests for error state and stale-response guard.
CI: PR run 35947466034 success (Frontend Tests pass); main run 35947588843 success (Frontend Tests, Security Scan, both deploys green).
Diff matches handoff: AbortSignal passed to api.get + request-id stale guard; canceled requests set no error; distinct "Search unavailable, try again" panel; search-food/food-details map USDA 429 -> 503 + DEMO_KEY warning; +4 tests.
Deviations reconciled (decided on Krish's behalf, fit scope, no plan change):
Error panel gated on error && !loading && query.length>=2 instead of showDropdown || error -> accepted; equivalent since showDropdown only true on success. Known nit: error panel ignores click-outside; acceptable (clears on next keystroke).
Duplicate "Add manually" onClick -> shared handleAddManually -> accepted; pure dedupe, no behavior change.
Docs: troubleshooting note for 503/"Search unavailable" on branch krish/docs-food-search-503.
Card: Done.
Activity
KrishP147 commentedon Sep 24, 2026
Verified post-merge (d093fb2, PR #14).
error && !loading && query.length>=2instead ofshowDropdown || error-> accepted; equivalent since showDropdown only true on success. Known nit: error panel ignores click-outside; acceptable (clears on next keystroke).handleAddManually-> accepted; pure dedupe, no behavior change.Card: Done.
docs: troubleshooting entry for food-search 503 (#17)