From 8227d689534e3e4ab1b97c26fde1b75a788a1e25 Mon Sep 17 00:00:00 2001 From: doodlewind <7312949+doodlewind@users.noreply.github.com> Date: Wed, 1 Jan 2025 01:22:29 +0000 Subject: [PATCH] refactor(core): remove abort event error on init (#9465) Following error always throw on Affine init, which is actually an `Event` from abort controller that can be handled in upstream. ![image](https://github.com/user-attachments/assets/50c25e5e-4a9c-45e0-b756-6b0f47390733) --- .../core/src/desktop/pages/root/index.tsx | 12 +++--------- .../frontend/core/src/mobile/pages/root/index.tsx | 12 +++--------- .../core/src/modules/cloud/entities/server.ts | 15 ++++++++++----- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/packages/frontend/core/src/desktop/pages/root/index.tsx b/packages/frontend/core/src/desktop/pages/root/index.tsx index 05004d446ccca..1f0e0116003a5 100644 --- a/packages/frontend/core/src/desktop/pages/root/index.tsx +++ b/packages/frontend/core/src/desktop/pages/root/index.tsx @@ -19,15 +19,9 @@ export const RootWrapper = () => { const abortController = new AbortController(); defaultServerService.server .waitForConfigRevalidation(abortController.signal) - .then(() => { - setIsServerReady(true); - }) - .catch(error => { - console.error(error); - }); - return () => { - abortController.abort(); - }; + .then(() => setIsServerReady(true)) + .catch(console.error); + return () => abortController.abort(); }, [defaultServerService, isServerReady]); return ( diff --git a/packages/frontend/core/src/mobile/pages/root/index.tsx b/packages/frontend/core/src/mobile/pages/root/index.tsx index 0dccf2bf6bd9d..0f963223117be 100644 --- a/packages/frontend/core/src/mobile/pages/root/index.tsx +++ b/packages/frontend/core/src/mobile/pages/root/index.tsx @@ -17,15 +17,9 @@ export const RootWrapper = () => { const abortController = new AbortController(); defaultServerService.server .waitForConfigRevalidation(abortController.signal) - .then(() => { - setIsServerReady(true); - }) - .catch(error => { - console.error(error); - }); - return () => { - abortController.abort(); - }; + .then(() => setIsServerReady(true)) + .catch(console.error); + return () => abortController.abort(); }, [defaultServerService, isServerReady]); return ( diff --git a/packages/frontend/core/src/modules/cloud/entities/server.ts b/packages/frontend/core/src/modules/cloud/entities/server.ts index 2ffecca2184fe..f8af875be5757 100644 --- a/packages/frontend/core/src/modules/cloud/entities/server.ts +++ b/packages/frontend/core/src/modules/cloud/entities/server.ts @@ -100,11 +100,16 @@ export class Server extends Entity<{ ); async waitForConfigRevalidation(signal?: AbortSignal) { - this.revalidateConfig(); - await this.isConfigRevalidating$.waitFor( - isRevalidating => !isRevalidating, - signal - ); + try { + this.revalidateConfig(); + await this.isConfigRevalidating$.waitFor( + isRevalidating => !isRevalidating, + signal + ); + } catch (error) { + if (error instanceof Event && error.type === 'abort') return; + console.error('Config revalidation failed:', error); + } } override dispose(): void {