mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Context We've been seeing many `NotFoundError: Failed to execute 'removeChild' on 'Node'` and `NotFoundError: Failed to execute 'insertBefore' on 'Node'` events on Sentry which are historically known to be caused by Google Translate in the browser. There's technically no _right way_ to address this unfortunately, but one of the solutions which should address most of these issues is to wrap any dynamic text within a span - we've considered that quite a while back tbh but never took the time to do this until today with the help of Claude. Although just a heads up that it might not necessarily completely eradicate those issues. Also added an eslint rule which should prevent future occurences of this <img width="1264" height="192" alt="image" src="https://github.com/user-attachments/assets/b2c32ea0-45a2-4ccd-82fe-1a859905fc29" />
124 lines
4.1 KiB
TypeScript
124 lines
4.1 KiB
TypeScript
import { useParams } from 'common'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Button,
|
|
Dialog,
|
|
DialogContent,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogSection,
|
|
DialogSectionSeparator,
|
|
DialogTitle,
|
|
} from 'ui'
|
|
|
|
import { InlineLink } from '@/components/ui/InlineLink'
|
|
import { useDatabasePublicationsQuery } from '@/data/database-publications/database-publications-query'
|
|
import { useDatabasePublicationUpdateMutation } from '@/data/database-publications/database-publications-update-mutation'
|
|
import { Entity } from '@/data/table-editor/table-editor-types'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
|
|
export const RealtimeToggleDialog = ({
|
|
table,
|
|
open,
|
|
setOpen,
|
|
}: {
|
|
table: Entity
|
|
open: boolean
|
|
setOpen: (value: boolean) => void
|
|
}) => {
|
|
const track = useTrack()
|
|
const { ref } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
const { data: publications } = useDatabasePublicationsQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
const realtimePublication = (publications ?? []).find(
|
|
(publication) => publication.name === 'supabase_realtime'
|
|
)
|
|
const realtimeEnabledTables = realtimePublication?.tables ?? []
|
|
const isRealtimeEnabled = realtimeEnabledTables.some((t) => t.id === table?.id)
|
|
|
|
const { mutate: updatePublications, isPending: isTogglingRealtime } =
|
|
useDatabasePublicationUpdateMutation({
|
|
onSuccess: () => {
|
|
setOpen(false)
|
|
|
|
track(isRealtimeEnabled ? 'table_realtime_disabled' : 'table_realtime_enabled', {
|
|
method: 'ui',
|
|
schema_name: table.schema,
|
|
table_name: table.name,
|
|
})
|
|
},
|
|
onError: (error) => {
|
|
toast.error(`Failed to toggle realtime for ${table.name}: ${error.message}`)
|
|
},
|
|
})
|
|
|
|
const toggleRealtime = async () => {
|
|
if (!project || !realtimePublication) return
|
|
|
|
const exists = realtimeEnabledTables.some((x) => x.id === table.id)
|
|
const tables = !exists
|
|
? [`${table.schema}.${table.name}`].concat(
|
|
realtimeEnabledTables.map((t) => `${t.schema}.${t.name}`)
|
|
)
|
|
: realtimeEnabledTables.filter((x) => x.id !== table.id).map((x) => `${x.schema}.${x.name}`)
|
|
|
|
track('realtime_toggle_table_clicked', {
|
|
newState: exists ? 'disabled' : 'enabled',
|
|
origin: 'tableGridHeader',
|
|
})
|
|
|
|
updatePublications({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
id: realtimePublication.id,
|
|
tables,
|
|
})
|
|
}
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={setOpen}>
|
|
<DialogContent size="small" aria-describedby={undefined}>
|
|
<DialogHeader>
|
|
<DialogTitle>
|
|
{isRealtimeEnabled ? <span>Disable</span> : <span>Enable</span>}{' '}
|
|
<span>realtime for</span> {table.name}
|
|
</DialogTitle>
|
|
</DialogHeader>
|
|
<DialogSectionSeparator />
|
|
<DialogSection>
|
|
<div className="space-y-2">
|
|
<p className="text-sm">
|
|
Once realtime has been{' '}
|
|
{isRealtimeEnabled ? <span>disabled</span> : <span>enabled</span>}
|
|
<span>, the table will</span> {isRealtimeEnabled ? <span>{'no longer '}</span> : ''}
|
|
<span>broadcast any changes to authorized subscribers.</span>
|
|
</p>
|
|
{!isRealtimeEnabled && (
|
|
<p className="text-sm">
|
|
You may also select which events to broadcast to subscribers on the{' '}
|
|
<InlineLink href={`/project/${ref}/database/publications`}>
|
|
database publications
|
|
</InlineLink>{' '}
|
|
settings.
|
|
</p>
|
|
)}
|
|
</div>
|
|
</DialogSection>
|
|
<DialogFooter>
|
|
<Button disabled={isTogglingRealtime} onClick={() => setOpen(false)}>
|
|
Cancel
|
|
</Button>
|
|
<Button variant="primary" loading={isTogglingRealtime} onClick={toggleRealtime}>
|
|
{isRealtimeEnabled ? <span>Disable</span> : <span>Enable</span>} <span>realtime</span>
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|