From 530e12700044a73995fe176a3a266bcb70050c9b Mon Sep 17 00:00:00 2001 From: gbuomprisco Date: Wed, 17 Sep 2025 12:48:42 +0800 Subject: [PATCH] Increment version to 2.14.1 and refactor notifications stream hook - Bumped package version in package.json from 2.14.0 to 2.14.1. - Refactored the `useNotificationsStream` hook to remove unnecessary `useQuery` and streamline the subscription logic for real-time notifications, enhancing performance and clarity. --- package.json | 2 +- .../src/hooks/use-notifications-stream.ts | 45 ++++++++----------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 3a18b0b6c..10da1c2fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-supabase-saas-kit-turbo", - "version": "2.14.0", + "version": "2.14.1", "private": true, "sideEffects": false, "engines": { diff --git a/packages/features/notifications/src/hooks/use-notifications-stream.ts b/packages/features/notifications/src/hooks/use-notifications-stream.ts index 6530716d8..21519ebc1 100644 --- a/packages/features/notifications/src/hooks/use-notifications-stream.ts +++ b/packages/features/notifications/src/hooks/use-notifications-stream.ts @@ -1,7 +1,5 @@ import { useEffect } from 'react'; -import { useQuery } from '@tanstack/react-query'; - import { useSupabase } from '@kit/supabase/hooks/use-supabase'; type Notification = { @@ -20,32 +18,27 @@ export function useNotificationsStream(params: { }) { const client = useSupabase(); - const { data: subscription } = useQuery({ - enabled: params.enabled, - queryKey: ['realtime-notifications', ...params.accountIds], - queryFn: () => { - const channel = client.channel('notifications-channel'); - - return channel - .on( - 'postgres_changes', - { - event: 'INSERT', - schema: 'public', - filter: `account_id=in.(${params.accountIds.join(', ')})`, - table: 'notifications', - }, - (payload) => { - params.onNotifications([payload.new as Notification]); - }, - ) - .subscribe(); - }, - }); - useEffect(() => { + const channel = client.channel('notifications-channel'); + + const subscription = channel + .on( + 'postgres_changes', + { + event: 'INSERT', + schema: 'public', + filter: `account_id=in.(${params.accountIds.join(', ')})`, + table: 'notifications', + }, + (payload) => { + console.log('payload', payload); + params.onNotifications([payload.new as Notification]); + }, + ) + .subscribe(); + return () => { void subscription?.unsubscribe(); }; - }, [subscription]); + }, [client, params]); }