Skip to content

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

Stop re-rendering UI if live mode is off (#48188)

Joshen Lim31878cabf688
diff --git a/apps/studio/pages/project/[ref]/observability/connections.tsx b/apps/studio/pages/project/[ref]/observability/connections.tsx
index c8c5c5ed58e..da80b8b844f 100644
--- a/apps/studio/pages/project/[ref]/observability/connections.tsx
+++ b/apps/studio/pages/project/[ref]/observability/connections.tsx
@@ -25,7 +25,11 @@ export const DatabaseConnections: NextPageWithLayout = () => {
const [live, setLive] = useState(true)
const [now, setNow] = useState(() => dayjs.utc())
- const { data, isPending: isLoadingActivity } = useDatabaseActivityQuery(
+ const {
+ data,
+ isPending: isLoadingActivity,
+ refetch: refetchActivity,
+ } = useDatabaseActivityQuery(
{
projectRef: project?.ref,
connectionString: project?.connectionString,
@@ -51,9 +55,10 @@ export const DatabaseConnections: NextPageWithLayout = () => {
// [Joshen] Just to trigger a UI re-render for the duration to be "live"
useEffect(() => {
+ if (!live) return
const interval = setInterval(() => setNow(dayjs.utc()), 1000)
return () => clearInterval(interval)
- }, [])
+ }, [live])
return (
<ReportPadding className="gap-y-12">
@@ -77,7 +82,14 @@ export const DatabaseConnections: NextPageWithLayout = () => {
<div className="flex items-center gap-x-2">
<Button
variant={live ? 'default' : 'primary'}
- onClick={() => setLive((prev) => !prev)}
+ onClick={() => {
+ const nextLive = !live
+ setLive(nextLive)
+ if (nextLive) {
+ setNow(dayjs.utc())
+ refetchActivity()
+ }
+ }}
icon={live ? <Pause /> : <Play />}
>
{live ? 'Pause' : 'Live'}