The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
[FE-4520] fix(studio): hide Realtime setup for published tables (#51152)
Alaister Young09a245d72de9
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx b/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsxindex 555a8dc749f..1c30f3cec67 100644--- a/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx+++ b/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx@@ -184,7 +184,7 @@ const MessagesTable = ({</div><DataGrid- className="data-grid--simple-logs h-full border-t-0! border-b-0!"+ className="data-grid--simple-logs h-full! border-t-0! border-b-0!"rowHeight={40}headerRowHeight={0}columns={ColumnRenderer}diff --git a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeInspector.test.tsx b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeInspector.test.tsxnew file mode 100644index 00000000000..22a606bdb8a--- /dev/null+++ b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeInspector.test.tsx@@ -0,0 +1,182 @@+import { RealtimeInspector } from '.'+import type { PGPublication } from '@supabase/pg-meta'+import { QueryClient } from '@tanstack/react-query'+import { screen, waitFor } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { delay, HttpResponse } from 'msw'+import { beforeEach, describe, expect, test, vi } from 'vitest'++import type { LogData } from './Messages.types'+import type { RealtimeConfig } from './useRealtimeMessages'+import { databasePublicationsKeys } from '@/data/database-publications/keys'+import type { ProjectDetail } from '@/data/projects/project-detail-query'+import { customRender } from '@/tests/lib/custom-render'+import { addAPIMock, type APIErrorBody } from '@/tests/lib/msw'++const realtime = vi.hoisted(() => ({ logData: [] as LogData[] }))++vi.mock('./useRealtimeMessages', () => ({+ useRealtimeMessages: () => ({ logData: realtime.logData, sendMessage: vi.fn() }),+}))+vi.mock('./useRealtimeInspectorShortcuts', () => ({ useRealtimeInspectorShortcuts: vi.fn() }))+vi.mock('@/lib/telemetry/track', () => ({ useTrack: () => vi.fn() }))+vi.mock('./Header', () => ({+ Header: ({+ config,+ onChangeConfig,+ }: {+ config: RealtimeConfig+ onChangeConfig: (config: RealtimeConfig) => void+ }) => (+ <button+ tabIndex={0}+ onClick={() => onChangeConfig({ ...config, channelName: 'test', enabled: true })}+ >+ Join a channel+ </button>+ ),+}))+vi.mock('./MessagesTable', () => ({ default: () => <div>Inspector messages</div> }))+vi.mock('./EmptyRealtime', () => ({+ EmptyRealtime: () => <button tabIndex={0}>Set up realtime for me</button>,+}))+vi.mock('./SendMessageModal', () => ({ SendMessageModal: () => null }))++const PROJECT: ProjectDetail = {+ cloud_provider: 'AWS',+ connectionString: 'postgresql://postgres@localhost:5432/postgres',+ db_host: 'db.default.supabase.co',+ high_availability: false,+ id: 1,+ inserted_at: '2026-01-01T00:00:00.000Z',+ integration_source: null,+ is_branch_enabled: false,+ is_hibernating: false,+ is_physical_backups_enabled: false,+ name: 'Test project',+ organization_id: 1,+ ref: 'default',+ region: 'us-east-1',+ restUrl: 'https://default.supabase.co/rest/v1',+ status: 'ACTIVE_HEALTHY',+ subscription_id: 'subscription-1',+ updated_at: '2026-01-01T00:00:00.000Z',+}++const publication = (+ tables: PGPublication['tables'],+ name = 'supabase_realtime'+): PGPublication => ({+ id: 1,+ name,+ owner: 'postgres',+ publish_insert: true,+ publish_update: true,+ publish_delete: true,+ publish_truncate: true,+ tables,+})++function mockPublications(publications: PGPublication[]) {+ addAPIMock({+ method: 'post',+ path: '/platform/pg-meta/:ref/query',+ response: () => HttpResponse.json<PGPublication[]>(publications),+ })+}++function renderInspector() {+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })+ customRender(<RealtimeInspector />, { queryClient })+ return queryClient+}++async function waitForPublications(queryClient: QueryClient, status = 'success') {+ await waitFor(() =>+ expect(queryClient.getQueryState(databasePublicationsKeys.list('default'))?.status).toBe(status)+ )+}++beforeEach(() => {+ realtime.logData = []+ addAPIMock({ method: 'get', path: '/platform/projects/:ref', response: PROJECT })+})++describe('Realtime Inspector setup guidance', () => {+ test.each([+ ['a published table', [publication([{ id: 1, name: 'books', schema: 'public' }])]],+ ['all tables published', [publication(null)]],+ ])('does not show setup guidance with %s and no messages or channel', async (_, publications) => {+ mockPublications(publications)+ await waitForPublications(renderInspector())++ expect(screen.getByText('Inspector messages')).toBeInTheDocument()+ expect(screen.queryByRole('button', { name: 'Set up realtime for me' })).not.toBeInTheDocument()+ })++ test.each([+ ['no publications', []],+ ['an empty Realtime publication', [publication([])]],+ ['a different publication', [publication(null, 'other_publication')]],+ ])('retains setup guidance with %s', async (_, publications) => {+ mockPublications(publications)+ renderInspector()++ expect(+ await screen.findByRole('button', { name: 'Set up realtime for me' })+ ).toBeInTheDocument()+ expect(screen.queryByText('Inspector messages')).not.toBeInTheDocument()+ })++ test('does not show setup guidance while publications are loading', async () => {+ addAPIMock({+ method: 'post',+ path: '/platform/pg-meta/:ref/query',+ response: async () => {+ await delay('infinite')+ return HttpResponse.json<PGPublication[]>([])+ },+ })+ const queryClient = renderInspector()+ await waitFor(() =>+ expect(queryClient.getQueryState(databasePublicationsKeys.list('default'))?.fetchStatus).toBe(+ 'fetching'+ )+ )++ expect(screen.getByText('Inspector messages')).toBeInTheDocument()+ expect(screen.queryByRole('button', { name: 'Set up realtime for me' })).not.toBeInTheDocument()+ })++ test('does not imply Realtime is unconfigured when publications fail to load', async () => {+ addAPIMock({+ method: 'post',+ path: '/platform/pg-meta/:ref/query',+ response: () => HttpResponse.json<APIErrorBody>({ message: 'Unavailable' }, { status: 500 }),+ })+ await waitForPublications(renderInspector(), 'error')++ expect(screen.getByText('Inspector messages')).toBeInTheDocument()+ expect(screen.queryByRole('button', { name: 'Set up realtime for me' })).not.toBeInTheDocument()+ })++ test('shows messages immediately after joining a broadcast-only channel', async () => {+ mockPublications([publication([])])+ renderInspector()+ await screen.findByRole('button', { name: 'Set up realtime for me' })++ await userEvent.click(screen.getByRole('button', { name: 'Join a channel' }))++ expect(screen.getByText('Inspector messages')).toBeInTheDocument()+ expect(screen.queryByRole('button', { name: 'Set up realtime for me' })).not.toBeInTheDocument()+ })++ test('retains received messages without a channel or published tables', async () => {+ realtime.logData = [{ id: '1', timestamp: 1, message: 'BROADCAST' }]+ mockPublications([])+ await waitForPublications(renderInspector())++ expect(screen.getByText('Inspector messages')).toBeInTheDocument()+ expect(screen.queryByRole('button', { name: 'Set up realtime for me' })).not.toBeInTheDocument()+ })+})diff --git a/apps/studio/components/interfaces/Realtime/Inspector/index.tsx b/apps/studio/components/interfaces/Realtime/Inspector/index.tsxindex 08af2260f63..ab2b33a43a0 100644--- a/apps/studio/components/interfaces/Realtime/Inspector/index.tsx+++ b/apps/studio/components/interfaces/Realtime/Inspector/index.tsx@@ -19,7 +19,7 @@ export const RealtimeInspector = () => {const { data: project } = useSelectedProjectQuery()// Check if realtime publications are available- const { data: publications } = useDatabasePublicationsQuery({+ const { data: publications, isSuccess: isPublicationsSuccess } = useDatabasePublicationsQuery({projectRef: project?.ref,connectionString: project?.connectionString,})@@ -55,10 +55,10 @@ export const RealtimeInspector = () => {const hasChannel = realtimeConfig.channelName.length > 0const isListening = realtimeConfig.enabled- // Once a channel is set, MessagesTable renders its own empty states (including- // the "Broadcast a message" entry point), so sending doesn't depend on a- // message having arrived first. EmptyRealtime is only the pre-channel onboarding.- const showMessagesTable = hasChannel || (logData ?? []).length > 0+ // Only show setup guidance once publications confirm that Postgres Changes+ // is not configured. An empty Inspector session does not imply Realtime is unused.+ const showMessagesTable =+ !isPublicationsSuccess || isRealtimeAvailable || hasChannel || (logData ?? []).length > 0const handleJoinChannel = useCallback(() => {if (!hasChannel) {diff --git a/e2e/studio/utils/realtime-helpers.ts b/e2e/studio/utils/realtime-helpers.tsindex d58dba5397f..20e381f00d4 100644--- a/e2e/studio/utils/realtime-helpers.ts+++ b/e2e/studio/utils/realtime-helpers.ts@@ -3,7 +3,9 @@ import { toUrl } from './to-url.js'export async function navigateToRealtimeInspector(page: Page, ref: string) {await page.goto(toUrl(`/project/${ref}/realtime/inspector`))- await expect(page.locator('text=Join a channel')).toBeVisible({ timeout: 30000 })+ await expect(page.getByRole('button', { name: 'Join a channel' })).toBeVisible({+ timeout: 30000,+ })}export async function joinChannel(page: Page, channelName: string) {