On fast refresh realtime subscription created multiple time but never closed.
- 0
- Self Hosted
- Realtime
- Web

I'm using realtime subscription in a zustand store like this : ` import { Databases, Query } from "appwrite"; import { create } from "zustand"; import { DATABASE_ID } from "../models/database"; import { PLAYOUT_STATUS_COLLECTION_ID, PlayoutStatus } from "../models/playoutStatus"; import { Client } from "../utils/client";
const databases = new Databases(Client);
export const usePlayoutStatusStore = create<PlayoutStatusState>((set) => ({ [...] subscribeToRealtime: (containerId: string) => { set((state) => { if (state.realtimeSubscription) return state;
const subscription = Client.subscribe(
`databases.${DATABASE_ID}.collections.${PLAYOUT_STATUS_COLLECTION_ID}.documents`,
(response) => {
const events: string[] = response.events;
const updatedStatus = response.payload as PlayoutStatus;
if (updatedStatus.containerId !== containerId) return;
if (events.some((evt) => evt.includes("create") || evt.includes("update"))) {
set({ status: updatedStatus });
}
if (events.some((evt) => evt.includes("delete"))) {
set({ status: null });
}
}
);
return { realtimeSubscription: subscription };
});
}, unsubscribeFromRealtime: () => { set((state) => { if (state.realtimeSubscription) { state.realtimeSubscription(); } return { realtimeSubscription: null }; }); } })); ` but when there multiple refresh in a short time it create multiple subscription for the same client and its impossible to close the old one without making a force restart of the appwrite-realtime via docker restart appwrite-realtime.
so there is orphan connection that can be seen in the dashboard. is there a way to solve this ?
Recommended threads
- Unable to migrate from self hosted to cl...
I'm trying to migrate my project that's currently self hosted running on version 1.6.0. I was able to migrate 3 other projects that had auth, functions, and dat...
- WHITELIST IPS
_APP_CONSOLE_WHITELIST_IPS=my-ip but it's working from any ip.How can make console open just from my ip?
- Can multiple functions exist in one Appw...
Can I add more than one function in the `src/main.js` file of an Appwrite cloud function? What if the different functions depend on two separate events, speci...
