🐛(frontend) switch to other provider

When we redirect from a doc to another, the components
are not unmounted and states are not reset.
We now destroy the provider if we see that
the provider is not bind to the current doc.
This commit is contained in:
Anthony LC
2025-01-13 16:40:21 +01:00
committed by Anthony LC
parent 23e6b508f8
commit c7e543d459
2 changed files with 16 additions and 2 deletions

View File

@@ -27,9 +27,14 @@ export const useCollaboration = (room?: string, initialContent?: Base64) => {
setBroadcastProvider,
]);
/**
* Destroy the provider when the component is unmounted
*/
useEffect(() => {
return () => {
destroyProvider();
if (room) {
destroyProvider();
}
};
}, [destroyProvider]);
}, [destroyProvider, room]);
};