From c7e543d45931c72fa2ad6fd85c4fe159372394b0 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Mon, 13 Jan 2025 16:40:21 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(frontend)=20switch=20to=20other=20?= =?UTF-8?q?provider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../apps/e2e/__tests__/app-impress/doc-editor.spec.ts | 9 +++++++++ .../docs/doc-management/hooks/useCollaboration.tsx | 9 +++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts index aaf1e6b7..8dba8dab 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts @@ -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 ({ diff --git a/src/frontend/apps/impress/src/features/docs/doc-management/hooks/useCollaboration.tsx b/src/frontend/apps/impress/src/features/docs/doc-management/hooks/useCollaboration.tsx index 848ccd00..14f3b715 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-management/hooks/useCollaboration.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-management/hooks/useCollaboration.tsx @@ -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]); };