Skip to content

Commit fc2228b

Browse files
committed
Make sync requests not blow up when service worker is not activated
1 parent 6d52350 commit fc2228b

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

client/codemirror/clean.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ export function cleanModePlugins(client: Client) {
5555
// Propagate click event from checkbox
5656
void client.dispatchClickEvent(clickEvent);
5757
},
58+
onStateChange: (pos, endPos, _oldState, newState) => {
59+
client.editorView.dispatch({
60+
changes: { from: pos, to: endPos, insert: newState },
61+
});
62+
},
63+
client,
5864
}),
5965
listBulletPlugin(),
6066
tablePlugin(client),

client/plugos/syscalls/sync.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,30 @@ export function syncSyscalls(client: Client): SysCallMapping {
77
"sync.hasInitialSyncCompleted": (): boolean => {
88
return client.fullSyncCompleted;
99
},
10-
"sync.performFileSync": (_ctx, path: string): Promise<void> => {
11-
void client.postServiceWorkerMessage({ type: "perform-file-sync", path });
10+
"sync.performFileSync": async (_ctx, path: string): Promise<void> => {
11+
try {
12+
await client.postServiceWorkerMessage({
13+
type: "perform-file-sync",
14+
path,
15+
});
16+
} catch (e: any) {
17+
console.warn(
18+
"No service worker available, so sync is inactive",
19+
e.message,
20+
);
21+
return;
22+
}
1223
return waitForServiceWorkerActivation(path);
1324
},
14-
"sync.performSpaceSync": (): Promise<number> => {
15-
void client.postServiceWorkerMessage({ type: "perform-space-sync" });
25+
"sync.performSpaceSync": async (): Promise<number> => {
26+
try {
27+
await client.postServiceWorkerMessage({
28+
type: "perform-space-sync",
29+
});
30+
} catch (e: any) {
31+
console.warn("No service worker available, so sync is inactive", e);
32+
return 0;
33+
}
1634
return waitForServiceWorkerActivation();
1735
},
1836
};

0 commit comments

Comments
 (0)