mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 18:35:07 +03:00
Fixes a batch of production Studio crashes from Sentry (all caught by the global error boundary). Most are missing array/null guards where an endpoint typed as an array — or with a nested array field — returned a non-array body in production; a few are one-off render crashes. Resolves FE-3748. ## Issues fixed | Sentry | Error | Fix | | --- | --- | --- | | [J7R](https://supabase.sentry.io/issues/7492997940/) | Maximum update depth exceeded | Disable RadialBar animation in disk-cooldown countdown | | [JR5](https://supabase.sentry.io/issues/7548484681/) | resourceWarnings.find is not a function | Guard in ResourceExhaustionWarningBanner | | [JCJ](https://supabase.sentry.io/issues/7506024989/) | resourceWarnings.find is not a function | Guard in ProjectLayout + normalize query | | [K1Y](https://supabase.sentry.io/issues/7584792331/) | snippet.name on undefined | Optional-chain SQL editor download filename | | [B3K](https://supabase.sentry.io/issues/7141649636/) | pagination.count on undefined | Guard pagination in projects infinite query | | [JVP](https://supabase.sentry.io/issues/7560437621/) | schemas.some / extensions.find | Coerce pg-meta lists to arrays in useInstalledIntegrations | | [JR2](https://supabase.sentry.io/issues/7548339272/) | extensions.find is not a function | (same fix as JVP) | | [JQR](https://supabase.sentry.io/issues/7547163939/) | lints.filter is not a function | Normalize project lints query | | [JR3](https://supabase.sentry.io/issues/7548433501/) | entitlements.find is not a function | Guard call sites + normalize entitlements query | | [JQS](https://supabase.sentry.io/issues/7547557098/) | selected_addons.find is not a function | Normalize addons query arrays | <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved stability across several Studio screens by handling missing or unexpected data more safely. * Downloads now use a fallback name when a snippet name isn’t available. * Project, entitlement, schema, addon, warning, and extension views are less likely to break when data is missing or not in the expected format. * Pagination and countdown visuals now behave more consistently, with reduced chance of runtime errors or animation-related glitches. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import type { components } from 'api-types'
|
|
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import { organizationKeys } from '@/data/organizations/keys'
|
|
import { EMPTY_ARR } from '@/lib/void'
|
|
import { UseCustomQueryOptions } from '@/types'
|
|
import { ResponseError } from '@/types/base'
|
|
|
|
export type FeatureKey =
|
|
components['schemas']['ListEntitlementsResponse']['entitlements'][number]['feature']['key']
|
|
|
|
export type EntitlementsVariables = {
|
|
slug: string
|
|
}
|
|
|
|
export type EntitlementConfig =
|
|
components['schemas']['ListEntitlementsResponse']['entitlements'][0]['config']
|
|
export type Entitlement = components['schemas']['ListEntitlementsResponse']['entitlements'][0]
|
|
export type EntitlementType = Entitlement['type']
|
|
|
|
export async function getEntitlements(
|
|
{ slug }: EntitlementsVariables,
|
|
signal?: AbortSignal,
|
|
headers?: HeadersInit
|
|
) {
|
|
if (!slug) throw new Error('slug is required')
|
|
|
|
const { data, error } = await get('/platform/organizations/{slug}/entitlements', {
|
|
params: { path: { slug } },
|
|
signal,
|
|
...(headers && { headers }),
|
|
})
|
|
if (error) handleError(error)
|
|
|
|
return {
|
|
...data,
|
|
entitlements: Array.isArray(data?.entitlements) ? data.entitlements : EMPTY_ARR,
|
|
}
|
|
}
|
|
|
|
export type EntitlementsData = Awaited<ReturnType<typeof getEntitlements>>
|
|
export type EntitlementsError = ResponseError
|
|
|
|
/**
|
|
* Helper to check a specific entitlement for an organization
|
|
* For client-side components, please using useCheckEntitlements hook instead
|
|
*/
|
|
export async function checkEntitlement(
|
|
slug: string,
|
|
featureKey: string,
|
|
signal?: AbortSignal,
|
|
headers?: HeadersInit
|
|
): Promise<{ hasAccess: boolean; entitlement?: Entitlement }> {
|
|
const entitlements = await getEntitlements({ slug }, signal, headers)
|
|
|
|
const entitlement = entitlements.entitlements.find((e) => e.feature.key === (featureKey as any))
|
|
|
|
return {
|
|
hasAccess: entitlement?.hasAccess ?? false,
|
|
entitlement,
|
|
}
|
|
}
|
|
|
|
export const useEntitlementsQuery = <TData = EntitlementsData>(
|
|
{ slug }: EntitlementsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<EntitlementsData, EntitlementsError, TData> = {}
|
|
) => {
|
|
return useQuery<EntitlementsData, EntitlementsError, TData>({
|
|
queryKey: organizationKeys.entitlements(slug),
|
|
queryFn: ({ signal }) => getEntitlements({ slug }, signal),
|
|
enabled: enabled && typeof slug !== 'undefined',
|
|
...options,
|
|
staleTime: 30 * 60 * 1000,
|
|
})
|
|
}
|