Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

recover failed Vercel deploy connections (#48474)

Danny White6b1fc3d11d01
diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectCreationForm.tsx b/apps/studio/components/interfaces/ProjectCreation/ProjectCreationForm.tsx
index 4aee33481c3..5e3ad93b6db 100644
--- a/apps/studio/components/interfaces/ProjectCreation/ProjectCreationForm.tsx
+++ b/apps/studio/components/interfaces/ProjectCreation/ProjectCreationForm.tsx
@@ -150,6 +150,7 @@ export const ProjectCreationForm = ({
const [allProjects, setAllProjects] = useState<OrgProject[] | undefined>(undefined)
const [isComputeCostsConfirmationModalVisible, setIsComputeCostsConfirmationModalVisible] =
useState(false)
+ const [projectCreationError, setProjectCreationError] = useState<string>()
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
@@ -327,6 +328,7 @@ export const ProjectCreationForm = ({
isSuccess: isSuccessNewProject,
} = useProjectCreateMutation({
onSuccess: (res) => {
+ setProjectCreationError(undefined)
track(
'project_creation_simple_version_submitted',
{
@@ -349,6 +351,11 @@ export const ProjectCreationForm = ({
if (surface === 'main') router.push(`/project/${res.ref}`)
},
onError: (error) => {
+ if (isVercelIntegrationFlow) {
+ setProjectCreationError(`Failed to create new project: ${error.message}`)
+ trackFunnelError('project_creation', classifyApiError('project_creation', error), 'form')
+ return
+ }
const toastId = toast.error(`Failed to create new project: ${error.message}`)
trackFunnelError(
'project_creation',
@@ -376,6 +383,7 @@ export const ProjectCreationForm = ({
const onSubmit = async (values: z.infer<typeof FormSchema>) => {
if (!currentOrg) return console.error('Unable to retrieve current organization')
+ setProjectCreationError(undefined)
const {
cloudProvider,
@@ -401,13 +409,27 @@ export const ProjectCreationForm = ({
const customPostgresVersion = highAvailability ? undefined : postgresVersion
if (customPostgresVersion && !customPostgresVersion.match(/1[2-9]\..*/)) {
- return toast.error(
- `Invalid Postgres version, should start with a number between 12-19, a dot and additional characters, i.e. 15.2 or 15.2.0-3`
- )
+ const message =
+ 'Invalid Postgres version, should start with a number between 12-19, a dot and additional characters, i.e. 15.2 or 15.2.0-3'
+ if (isVercelIntegrationFlow) {
+ setProjectCreationError(message)
+ return
+ }
+ return toast.error(message)
}
if (useOrioleDb && !availableOrioleVersion) {
- const toastId = toast.error('No available OrioleDB image found, only Postgres is available')
+ const message = 'No available OrioleDB image found, only Postgres is available'
+ if (isVercelIntegrationFlow) {
+ setProjectCreationError(message)
+ trackFunnelError(
+ 'project_creation',
+ { errorCategory: 'validation', errorReason: 'oriole_unavailable' },
+ 'form'
+ )
+ return
+ }
+ const toastId = toast.error(message)
trackFunnelError(
'project_creation',
{ errorCategory: 'validation', errorReason: 'oriole_unavailable' },
@@ -754,6 +776,13 @@ export const ProjectCreationForm = ({
) : null}
</div>
)}
+ {projectCreationError && (
+ <Panel.Content>
+ <p role="alert" className="text-sm text-destructive">
+ {projectCreationError}
+ </p>
+ </Panel.Content>
+ )}
</>
</Panel>
diff --git a/apps/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx b/apps/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx
index 5092e50ec87..ba81df5aeec 100644
--- a/apps/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx
+++ b/apps/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx
@@ -1,7 +1,10 @@
import { useParams } from 'common'
import Head from 'next/head'
-import { useEffect, useState } from 'react'
-import { toast } from 'sonner'
+import Link from 'next/link'
+import { useCallback, useEffect, useState } from 'react'
+import { Button } from 'ui'
+import { Admonition } from 'ui-patterns/Admonition'
+import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
import { isVercelUrl } from '@/components/interfaces/Integrations/Vercel/VercelIntegration.utils'
import {
@@ -14,7 +17,6 @@ import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-que
import { useIntegrationsQuery } from '@/data/integrations/integrations-query'
import { useIntegrationVercelConnectionsCreateMutation } from '@/data/integrations/integrations-vercel-connections-create-mutation'
import { useVercelProjectsQuery } from '@/data/integrations/integrations-vercel-projects-query'
-import { useOrganizationsQuery } from '@/data/organizations/organizations-query'
import { withAuth } from '@/hooks/misc/withAuth'
import { buildStudioPageTitle } from '@/lib/page-title'
import { useIntegrationInstallationSnapshot } from '@/state/integration-installation'
@@ -30,20 +32,26 @@ const VercelIntegration: NextPageWithLayout = () => {
const snapshot = useIntegrationInstallationSnapshot()
const [newProjectRef, setNewProjectRef] = useState<string>()
+ const [connectionError, setConnectionError] = useState<string>()
+ const [isConnecting, setIsConnecting] = useState(false)
+ const [isConnectionComplete, setIsConnectionComplete] = useState(false)
const { data: integrationData } = useIntegrationsQuery()
const organizationIntegration = integrationData?.find((x) => x.organization.slug === slug)
- const { data: organizationData } = useOrganizationsQuery()
- const organization = organizationData?.find((x) => x.slug === slug)
-
const { data: vercelProjects } = useVercelProjectsQuery(
{ organization_integration_id: organizationIntegration?.id },
{ enabled: organizationIntegration !== undefined }
)
// Wait for the new project to be created before creating the connection
- const { data, isSuccess } = useProjectSettingsV2Query(
+ const {
+ data,
+ isSuccess,
+ isError: isProjectSettingsError,
+ error: projectSettingsError,
+ refetch: refetchProjectSettings,
+ } = useProjectSettingsV2Query(
{ projectRef: newProjectRef },
{
enabled: newProjectRef !== undefined,
@@ -55,55 +63,119 @@ const VercelIntegration: NextPageWithLayout = () => {
}
)
- const { mutateAsync: createConnections } = useIntegrationVercelConnectionsCreateMutation({
- onError(error) {
- toast.error(`Failed to create connection: ${error.message}`)
- },
- })
+ const { mutateAsync: createConnections } = useIntegrationVercelConnectionsCreateMutation()
- useEffect(() => {
- if (!isSuccess) return
-
- const onSuccessFunc = async () => {
- const isReady = (data.service_api_keys ?? []).length > 0
-
- if (!isReady || !organizationIntegration || !foreignProjectId || !newProjectRef) {
- return
- }
-
- const projectDetails = vercelProjects?.find((x) => x.id === foreignProjectId)
-
- try {
- await createConnections({
- organizationIntegrationId: organizationIntegration?.id,
- connection: {
- foreign_project_id: foreignProjectId,
- supabase_project_ref: newProjectRef,
- integration_id: '0',
- metadata: {
- ...projectDetails,
- supabaseConfig: {
- projectEnvVars: {
- write: true,
- },
+ const connectProject = useCallback(async () => {
+ const isReady = (data?.service_api_keys ?? []).length > 0
+
+ if (!isReady || !organizationIntegration || !foreignProjectId || !newProjectRef) {
+ return
+ }
+
+ const projectDetails = vercelProjects?.find((x) => x.id === foreignProjectId)
+ setConnectionError(undefined)
+ setIsConnecting(true)
+
+ try {
+ await createConnections({
+ organizationIntegrationId: organizationIntegration.id,
+ connection: {
+ foreign_project_id: foreignProjectId,
+ supabase_project_ref: newProjectRef,
+ integration_id: '0',
+ metadata: {
+ ...projectDetails,
+ supabaseConfig: {
+ projectEnvVars: {
+ write: true,
},
},
},
- orgSlug: organization?.slug,
- })
- } catch (error) {
- console.error('An error occurred during createConnections:', error)
- return
- }
-
+ },
+ orgSlug: slug,
+ })
snapshot.setLoading(false)
-
+ setIsConnectionComplete(true)
if (next && isVercelUrl(next)) window.location.href = next
+ } catch (error) {
+ const message = error instanceof Error ? error.message : 'An unknown error occurred'
+ setConnectionError(message)
+ } finally {
+ setIsConnecting(false)
+ }
+ }, [
+ createConnections,
+ data?.service_api_keys,
+ foreignProjectId,
+ newProjectRef,
+ next,
+ organizationIntegration,
+ snapshot,
+ slug,
+ vercelProjects,
+ ])
+
+ useEffect(() => {
+ if (isSuccess && !connectionError && !isConnecting && !isConnectionComplete) {
+ void connectProject()
+ }
+ }, [connectProject, connectionError, isConnecting, isConnectionComplete, isSuccess])
+
+ const renderContent = () => {
+ if (newProjectRef === undefined) {
+ return <ProjectCreationForm isVercelIntegrationFlow onCreateSuccess={setNewProjectRef} />
+ }
+
+ if (isProjectSettingsError) {
+ return (
+ <VercelConnectionError
+ projectRef={newProjectRef}
+ message={projectSettingsError?.message ?? 'Unable to check whether the project is ready.'}
+ onRetry={() => void refetchProjectSettings()}
+ />
+ )
}
- onSuccessFunc()
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [data, isSuccess])
+ if (connectionError) {
+ return (
+ <VercelConnectionError
+ projectRef={newProjectRef}
+ message={connectionError}
+ onRetry={() => void connectProject()}
+ />
+ )
+ }
+
+ if (isConnectionComplete) {
+ return (
+ <div className="px-6 pb-6">
+ <div className="flex flex-col gap-3">
+ <Admonition
+ type="success"
+ title="Project connected"
+ description="Your Supabase project is connected to Vercel."
+ />
+ <Button asChild variant="primary" block>
+ <Link href={`/project/${newProjectRef}`}>Open project</Link>
+ </Button>
+ </div>
+ </div>
+ )
+ }
+
+ return (
+ <div className="px-6 pb-6">
+ <div className="space-y-3" role="status">
+ <p className="text-sm text-foreground-light">
+ {isConnecting
+ ? 'Connecting your project to Vercel'
+ : 'Waiting for your project to be ready'}
+ </p>
+ <ShimmeringLoader className="h-2 w-full rounded-full py-0" />
+ </div>
+ </div>
+ )
+ }
return (
<>
@@ -118,10 +190,38 @@ const VercelIntegration: NextPageWithLayout = () => {
footer={<VercelIntegrationFooter />}
widthClassName="max-w-2xl"
>
- <ProjectCreationForm isVercelIntegrationFlow onCreateSuccess={setNewProjectRef} />
+ {renderContent()}
</InterstitialLayout>
</>
)
}
+export function VercelConnectionError({
+ projectRef,
+ message,
+ onRetry,
+}: {
+ projectRef: string
+ message: string
+ onRetry: () => void
+}) {
+ return (
+ <div>
+ <div className="px-6 pb-6">
+ <Admonition
+ type="danger"
+ title="Unable to connect to Vercel"
+ description={`Your Supabase project was still created. Error: ${message}`}
+ />
+ </div>
+ <div className="flex h-12 items-center justify-end gap-x-2 border-t border-default bg-surface-100 px-card">
+ <Button asChild variant="default">
+ <Link href={`/project/${projectRef}`}>Open project</Link>
+ </Button>
+ <Button onClick={onRetry}>Retry connection</Button>
+ </div>
+ </div>
+ )
+}
+
export default withAuth(VercelIntegration)
diff --git a/apps/studio/tests/pages/vercel-deploy-button-new-project.test.tsx b/apps/studio/tests/pages/vercel-deploy-button-new-project.test.tsx
new file mode 100644
index 00000000000..432df5dfcb7
--- /dev/null
+++ b/apps/studio/tests/pages/vercel-deploy-button-new-project.test.tsx
@@ -0,0 +1,32 @@
+import { screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+import { expect, test, vi } from 'vitest'
+
+import { VercelConnectionError } from '@/pages/integrations/vercel/[slug]/deploy-button/new-project'
+import { customRender } from '@/tests/lib/custom-render'
+
+test('shows a recoverable partial-success state without recreating the project', async () => {
+ const user = userEvent.setup()
+ const retry = vi.fn()
+
+ customRender(
+ <VercelConnectionError
+ projectRef="project-ref"
+ message="Connection request failed"
+ onRetry={retry}
+ />
+ )
+
+ const alert = screen.getByRole('alert')
+ expect(alert).toHaveTextContent('Unable to connect to Vercel')
+ expect(alert).toHaveTextContent(
+ 'Your Supabase project was still created. Error: Connection request failed'
+ )
+ expect(screen.getByRole('link', { name: 'Open project' })).toHaveAttribute(
+ 'href',
+ '/project/project-ref'
+ )
+
+ await user.click(screen.getByRole('button', { name: 'Retry connection' }))
+ expect(retry).toHaveBeenCalledOnce()
+})