mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem
Studio switched project URLs to the custom domain when the Cloudflare
hostname reported `active`, which already happens at
`4_origin_setup_completed`. At that point the platform services don't
accept requests on the custom domain yet. So URLs Studio handed out,
such as the Storage explorer's **Get URL** links, failed until
activation finished.
## Solution
`useProjectApiUrl` now uses the custom domain only when the
custom-hostname status is `5_services_reconfigured`. Before that it
returns the project's own host. Every Studio surface that builds project
URLs reads this hook, so Storage **Get URL**, the Connect sheet, API
settings, and Edge Functions all follow the same rule.
## How to verify
1. Open a project with the custom domain add-on whose domain is in
`4_origin_setup_completed` (verified, not yet activated). In Storage,
click **Get URL** on a file. The copied URL uses the project's
`supabase.co` host.
2. On a project whose custom domain is in `5_services_reconfigured`
(activated), **Get URL** copies a URL on the custom domain.
3. On a project with no custom domain, **Get URL** copies a URL on the
project's `supabase.co` host, as before.
4. `pnpm exec vitest run
data/config/project-endpoint-query.platform.test.tsx` from `apps/studio`
passes. The status-4 case fails without this change.
## Checks
From `apps/studio`: `tsc --noEmit` (passed); `eslint` and the type-aware
`eslint.type-checks.config.cjs` on the changed files (passed); `vitest
run` on the new test plus `ProjectConnectionPopover.platform.test.tsx`
and `TerminalInstructions.platform.test.tsx` (passed). `oxfmt --check`
on the changed files (passed). Checked the status values against
`packages/api-types` (`/v1/projects/{ref}/custom-hostname`) and against
`CustomDomainConfig.tsx`, which treats status 4 as "ready to activate".
## Checklist
- [x] I have read the [Contributing
Guidelines](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] I have added tests where applicable
- [ ] I have checked that the change works in the preview deployment
## Feedback for Tedd
To ask Tedd for a change to this PR, reply in Tedd's session on
[FE-5306](https://linear.app/supabase/issue/FE-5306/studio-uses-custom-domain-before-domain-is-fully-activated).
Tedd doesn't read comments on this PR.
---------
Co-authored-by: supabase-vercel-tedd[bot] <336548405+supabase-vercel-tedd[bot]@users.noreply.github.com>
95 lines
2.8 KiB
TypeScript
95 lines
2.8 KiB
TypeScript
import { waitFor } from '@testing-library/react'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { useProjectApiUrl } from './project-endpoint-query'
|
|
import { customRenderHook } from '@/tests/lib/custom-render'
|
|
import { addAPIMock } from '@/tests/lib/msw'
|
|
|
|
const mockSettings = () =>
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/settings',
|
|
response: {
|
|
app_config: {
|
|
endpoint: 'default.supabase.co',
|
|
db_schema: 'public',
|
|
storage_endpoint: 'default.supabase.co',
|
|
},
|
|
cloud_provider: 'AWS',
|
|
db_dns_name: 'db.default.supabase.co',
|
|
db_host: 'db.default.supabase.co',
|
|
db_name: 'postgres',
|
|
db_port: 5432,
|
|
db_user: 'postgres',
|
|
inserted_at: '2026-01-01T00:00:00.000Z',
|
|
name: 'Production',
|
|
ref: 'default',
|
|
region: 'us-east-1',
|
|
ssl_enforced: false,
|
|
status: 'ACTIVE_HEALTHY',
|
|
},
|
|
})
|
|
|
|
const mockCustomDomain = (status: '4_origin_setup_completed' | '5_services_reconfigured') => {
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/billing/addons',
|
|
response: {
|
|
selected_addons: [
|
|
{
|
|
type: 'custom_domain',
|
|
variant: {
|
|
identifier: 'cd_default',
|
|
name: 'Custom domain',
|
|
price: 10,
|
|
price_description: 'per month',
|
|
price_interval: 'monthly',
|
|
price_type: 'fixed',
|
|
},
|
|
},
|
|
],
|
|
available_addons: [],
|
|
ref: 'default',
|
|
},
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/v1/projects/:ref/custom-hostname',
|
|
response: {
|
|
status,
|
|
custom_hostname: 'api.example.com',
|
|
data: {
|
|
errors: [],
|
|
messages: [],
|
|
success: true,
|
|
// The hostname already reports `active` before services are reconfigured.
|
|
result: { hostname: 'api.example.com', id: 'hostname-id', status: 'active' },
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
describe('useProjectApiUrl', () => {
|
|
it('keeps the project host until the custom domain finishes activating', async () => {
|
|
mockSettings()
|
|
mockCustomDomain('4_origin_setup_completed')
|
|
|
|
const { result } = customRenderHook(() => useProjectApiUrl({ projectRef: 'default' }))
|
|
|
|
await waitFor(() => expect(result.current.isSuccess).toBe(true))
|
|
expect(result.current.customEndpoint).toBeUndefined()
|
|
expect(result.current.data).toBe('https://default.supabase.co')
|
|
})
|
|
|
|
it('uses the custom domain once services are reconfigured', async () => {
|
|
mockSettings()
|
|
mockCustomDomain('5_services_reconfigured')
|
|
|
|
const { result } = customRenderHook(() => useProjectApiUrl({ projectRef: 'default' }))
|
|
|
|
await waitFor(() => expect(result.current.isSuccess).toBe(true))
|
|
expect(result.current.customEndpoint).toBe('https://api.example.com')
|
|
expect(result.current.data).toBe('https://api.example.com')
|
|
})
|
|
})
|