🐛(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

@@ -204,6 +204,15 @@ test.describe('Doc Editor', () => {
await verifyDocName(page, firstDoc);
await expect(editor.getByText('Hello World Doc 2')).toBeHidden();
await expect(editor.getByText('Hello World Doc 1')).toBeVisible();
await page
.getByRole('button', {
name: 'New doc',
})
.click();
await expect(editor.getByText('Hello World Doc 1')).toBeHidden();
await expect(editor.getByText('Hello World Doc 2')).toBeHidden();
});
test('it saves the doc when we change pages', async ({

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]);
};