{
  "id": 4911958,
  "title": "Fixing the “D.map is not a function” crash by tightening DB indexes and normalizing the API payload",
  "url": "https://urgent.news/2026/09/01/fixing-the-d-map-is-not-a-function-crash-by-tightening-db-indexes-and",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-01T18:02:05.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/zaerohell/fixing-the-dmap-is-not-a-function-crash-by-tightening-db-indexes-and-normalizing-the-api-payload-1bno"
  },
  "original_language": "en",
  "account": "The Condo Dashboard began experiencing a runtime error: TypeError: D.map is not a function. The error occurred in the React selector component when the dropdown was empty and the component crashed. The API call responsible for populating the dropdown (GET /api/condos/metrics) was supposed to return an array of objects with id and name properties, but under certain conditions, it returned null or a single object instead. This inconsistency caused the .map call to fail, breaking the component. The root cause was discovered to be duplicate rows in the broker_tokens table, which resulted from missing unique indexes on several tables. These duplicates caused the query to return malformed results, leading to the error. Initially, the front-end attempted to mitigate the issue by checking if the data was an array before processing it. However, this only temporarily silenced the error, as the API continued to return the incorrect data shape, leading to duplicate entries in downstream calculations. The KPI numbers in the dashboard remained inaccurate. To resolve the issue, a two-pronged approach was implemented. First, proper indexes were added to the database to prevent duplicate broker token rows and enforce referential integrity. Second, the metrics endpoint was refactored to guarantee an array output, even if the result was empty. This ensured the front-end received the correct data format, effectively fixing the crash and restoring accurate KPI calculations. Additionally, a small guard was left in the CondoSelector component to handle any future API misbehavior.",
  "summary": "Fixing the “D.map is not a function” crash by tightening DB indexes and normalizing the API payload TL;DR: I added missing PostgreSQL indexes in apps/api/src/db/db.ts and forced the /condos/metrics endpoint to always return an array. The change stopped the runtime TypeError: D.map is not a function in the React selector and restored correct KPI calculations. The Problem Our internal “Condo…",
  "key_points": [
    "Duplicate rows in brokertokens table caused malformed API responses",
    "Indexes added to prevent duplicate rows and enforce referential integrity",
    "Metrics endpoint refactored to guarantee array output, fixing crash"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}