Files
supabase/apps/studio/components/interfaces/Settings/API/DataApiProjectUrlCard.tsx
Alaister Young 7e9badc6b8 chore(studio): migrate useStaticEffectEvent to React 19 useEffectEvent (#46415)
Studio is on `react@^19.2.6`, and `useEffectEvent` shipped stable in
React 19.2 with the same signature as the userland polyfill. This drops
the local hook in `apps/studio` and `apps/www` in favor of the built-in.

**Removed:**
- `apps/studio/hooks/useStaticEffectEvent.ts`
- `apps/www/hooks/useStaticEffectEvent.ts`
- `.claude/skills/use-static-effect-event/` — skill is obsolete

**Changed:**
- 26 call sites: dropped the `useStaticEffectEvent` import, added
`useEffectEvent` to the existing `react` import, renamed call sites
- `.claude/CLAUDE.md`: `apps/studio` row updated React 18 → React 19
- `.claude/skills/vercel-composition-patterns/SKILL.md`: removed stale
"Studio uses React 18, skip these patterns" warning

## To test

- `pnpm typecheck --filter=studio` — passes locally
- `pnpm typecheck --filter=www` — passes locally
- `grep -rn "useStaticEffectEvent"` returns nothing outside
`node_modules`
- Smoke-test areas that use the hook: schema visualizer edges
(intersection check), spreadsheet import, sign-in/CLI login flows, side
panels with unsaved-changes prompts

**Out of scope:** pre-existing Tailwind lint warning on
`DefaultEdge.tsx:141` (`outline` + `outline-1` conflict) — unrelated to
this migration

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Refactor**
* Internal event handling migrated to React’s built-in event hooks
across the Studio app; no user-facing changes.

* **Documentation**
* Clarified React 19 compatibility and noted Studio now targets React
19.
  * Removed obsolete documentation for a deprecated internal hook.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46415?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-05-28 23:30:42 +08:00

107 lines
3.9 KiB
TypeScript

import { useParams } from 'common'
import { AlertCircle } from 'lucide-react'
import { parseAsString, useQueryState } from 'nuqs'
import { useEffect, useEffectEvent } from 'react'
import { Alert, AlertTitle } from 'ui'
import {
PageSection,
PageSectionAside,
PageSectionContent,
PageSectionDescription,
PageSectionMeta,
PageSectionSummary,
PageSectionTitle,
} from 'ui-patterns'
import { Input } from 'ui-patterns/DataInputs/Input'
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
import { getApiEndpoint } from '@/components/interfaces/Integrations/DataApi/DataApi.utils'
import { DatabaseSelector } from '@/components/ui/DatabaseSelector'
import { useProjectApiUrl } from '@/data/config/project-endpoint-query'
import { useLoadBalancersQuery } from '@/data/read-replicas/load-balancers-query'
import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { useDatabaseSelectorStateSnapshot } from '@/state/database-selector'
export const DataApiProjectUrlCard = () => {
const { isPending: isLoading } = useSelectedProjectQuery()
const { ref: projectRef } = useParams()
const state = useDatabaseSelectorStateSnapshot()
const [querySource, setQuerySource] = useQueryState('source', parseAsString)
const { data: resolvedEndpoint } = useProjectApiUrl({ projectRef })
const {
data: databases,
isError,
isPending: isLoadingDatabases,
} = useReadReplicasQuery({ projectRef })
const { data: loadBalancers } = useLoadBalancersQuery({ projectRef })
const syncSelectedDb = useEffectEvent(() => {
if (querySource && querySource !== state.selectedDatabaseId) {
state.setSelectedDatabaseId(querySource)
}
})
useEffect(() => {
syncSelectedDb()
// eslint-disable-next-line react-hooks/exhaustive-deps -- useEffectEvent fn intentionally not a dep (eslint-plugin-react-hooks v5 doesn't recognize stable useEffectEvent yet)
}, [querySource, projectRef])
const selectedDatabase = databases?.find((db) => db.identifier === state.selectedDatabaseId)
const loadBalancerSelected = state.selectedDatabaseId === 'load-balancer'
const replicaSelected = selectedDatabase?.identifier !== projectRef
const endpoint = getApiEndpoint({
selectedDatabaseId: state.selectedDatabaseId,
projectRef,
resolvedEndpoint,
loadBalancers,
selectedDatabase,
})
return (
<PageSection className="first:pt-0">
<PageSectionMeta>
<PageSectionSummary>
<PageSectionTitle>API URL</PageSectionTitle>
<PageSectionDescription>
{loadBalancerSelected
? 'RESTful endpoint for querying and managing your databases through your load balancer'
: replicaSelected
? 'RESTful endpoint for querying your read replica'
: 'RESTful endpoint for querying and managing your database'}
</PageSectionDescription>
</PageSectionSummary>
<PageSectionAside>
<DatabaseSelector
additionalOptions={
(loadBalancers ?? []).length > 0
? [{ id: 'load-balancer', name: 'API Load Balancer' }]
: []
}
onSelectId={() => {
setQuerySource(null)
}}
/>
</PageSectionAside>
</PageSectionMeta>
<PageSectionContent>
{isLoading || isLoadingDatabases ? (
<div className="space-y-2">
<ShimmeringLoader />
<ShimmeringLoader className="w-3/4" delayIndex={1} />
</div>
) : isError ? (
<Alert variant="destructive">
<AlertCircle size={16} />
<AlertTitle>Failed to retrieve project URL</AlertTitle>
</Alert>
) : (
<Input copy readOnly className="font-mono" value={endpoint} />
)}
</PageSectionContent>
</PageSection>
)
}