🐛(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:
@@ -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 ({
|
||||
|
||||
@@ -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]);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user