Skip to content

Commit

Permalink
refactor(core): remove abort event error on init (#9465)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
doodlewind committed Jan 1, 2025
1 parent d97c4b5 commit 8227d68
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
12 changes: 3 additions & 9 deletions packages/frontend/core/src/desktop/pages/root/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
12 changes: 3 additions & 9 deletions packages/frontend/core/src/mobile/pages/root/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
15 changes: 10 additions & 5 deletions packages/frontend/core/src/modules/cloud/entities/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8227d68

Please sign in to comment.