mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
fix(studio): guard branches and read-replicas queries against non-array 200 bodies (#50347)
## 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 <noreply@anthropic.com> Co-authored-by: Ali Waseem <waseema393@gmail.com>
This commit is contained in:
2 files changed
+5
-3
No files matched your search
@@ -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<ReturnType<typeof getBranches>>
|
||||
|
||||
@@ -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<ReturnType<typeof getReadReplicas>>
|
||||
|
||||
Reference in new issue
Block a user