From 62fe0fca4a5a5e5e2c90d7978308539bd96b67df Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Mon, 14 Sep 2026 19:16:41 +0000 Subject: [PATCH] fix(studio): guard branches and read-replicas queries against non-array 200 bodies (#50347) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - `getBranches()` (`apps/studio/data/branches/branches-query.ts`) and `getReadReplicas()` (`apps/studio/data/read-replicas/replicas-query.ts`) cast the raw API response body to an array with no runtime check. - When the endpoint returns a defined-but-non-array 200 body, the `?? []` fallback in each consumer doesn't catch it (the value isn't nullish), and the first `.find`/`.filter` call throws, crashing the whole page via `globalErrorBoundary`. - This is the same known class of bug already fixed elsewhere in the codebase (e.g. `apps/studio/data/lint/lint-query.ts`, and the `api-keys`/`oauthApps`/`secrets` fetchers) — applies the same `Array.isArray(data) ? data : EMPTY_ARR` guard. ## Evidence (Sentry, past week) - [SUPABASE-APP-KA2](https://supabase.sentry.io/issues/7722780387/) — `(m??[]).find is not a function` in `ActivityStats.tsx` (`branchesData.find`), full-page crash on `/dashboard/project/[ref]`. - [SUPABASE-APP-KAE](https://supabase.sentry.io/issues/7729679561/) — `u.filter is not a function` in `AWSPrivateLinkForm.tsx` (`databases.filter`), full-page crash on `/project/[ref]/settings/integrations`. ## Test plan - [ ] Existing query hook tests still pass - [ ] Manually verified `Array.isArray` guard mirrors the established `lint-query.ts` pattern 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01RUrmUfMBpPqkgerh9onNTM --- _Generated by [Claude Code](https://claude.ai/code/session_01RUrmUfMBpPqkgerh9onNTM)_ --------- Co-authored-by: Claude Co-authored-by: Ali Waseem --- apps/studio/data/branches/branches-query.ts | 5 +++-- apps/studio/data/read-replicas/replicas-query.ts | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/studio/data/branches/branches-query.ts b/apps/studio/data/branches/branches-query.ts index 40a573a31d0..0f195c6321e 100644 --- a/apps/studio/data/branches/branches-query.ts +++ b/apps/studio/data/branches/branches-query.ts @@ -4,6 +4,7 @@ import { branchKeys } from './keys' import type { components } from '@/data/api' import { get, handleError } from '@/data/fetchers' import { IS_PLATFORM } from '@/lib/constants' +import { EMPTY_ARR } from '@/lib/void' import type { ResponseError, UseCustomQueryOptions } from '@/types' export type BranchesVariables = { @@ -22,13 +23,13 @@ export async function getBranches({ projectRef }: BranchesVariables, signal?: Ab if (error) { if ((error as ResponseError).message === 'Preview branching is not enabled for this project.') { - return [] + return EMPTY_ARR } else { handleError(error) } } - return data + return Array.isArray(data) ? data : EMPTY_ARR } export type BranchesData = Awaited> diff --git a/apps/studio/data/read-replicas/replicas-query.ts b/apps/studio/data/read-replicas/replicas-query.ts index f9e951f4158..20c32966d22 100644 --- a/apps/studio/data/read-replicas/replicas-query.ts +++ b/apps/studio/data/read-replicas/replicas-query.ts @@ -7,6 +7,7 @@ import type { components } from '@/data/api' import { get, handleError } from '@/data/fetchers' import { useLocalStorageQuery } from '@/hooks/misc/useLocalStorage' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' +import { EMPTY_ARR } from '@/lib/void' import type { ResponseError, UseCustomQueryOptions } from '@/types' /** @@ -47,7 +48,7 @@ export async function getReadReplicas( }) if (error) handleError(error) - return data + return Array.isArray(data) ? data : EMPTY_ARR } export type ReadReplicasData = Awaited>