Missing PostgreSQL indexes caused React dashboard crash with TypeError in production
A production bug in an internal Condo Dashboard triggered a JavaScript TypeError because the /condos/metrics API endpoint was returning null or a single object instead of an array, crashing a React dropdown component. The root cause was duplicate rows in the broker_tokens table, resulting from missing unique database indexes that allowed multiple rows with the same broker_id and token pair. Initial workarounds — a frontend Array.isArray guard and forced API normalization — suppressed the error but left KPI calculations incorrect and the underlying data inconsistency unresolved. The permanent fix involved adding a unique index on broker_tokens, a performance index on condo_metrics, and a foreign key constraint in apps/api/src/db/db.ts to prevent duplicates at the database level. With the schema corrected, the API controller was also updated to reliably return a clean array, restoring accurate dashboard metrics.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in