Make sync requests not blow up when service worker is not activated

This commit is contained in:
Zef Hemel
2026-03-13 14:54:01 +01:00
parent 6d52350640
commit fc2228be1a
2 changed files with 28 additions and 4 deletions
+6
View File
@@ -55,6 +55,12 @@ export function cleanModePlugins(client: Client) {
// Propagate click event from checkbox
void client.dispatchClickEvent(clickEvent);
},
onStateChange: (pos, endPos, _oldState, newState) => {
client.editorView.dispatch({
changes: { from: pos, to: endPos, insert: newState },
});
},
client,
}),
listBulletPlugin(),
tablePlugin(client),
+22 -4
View File
@@ -7,12 +7,30 @@ export function syncSyscalls(client: Client): SysCallMapping {
"sync.hasInitialSyncCompleted": (): boolean => {
return client.fullSyncCompleted;
},
"sync.performFileSync": (_ctx, path: string): Promise<void> => {
void client.postServiceWorkerMessage({ type: "perform-file-sync", path });
"sync.performFileSync": async (_ctx, path: string): Promise<void> => {
try {
await client.postServiceWorkerMessage({
type: "perform-file-sync",
path,
});
} catch (e: any) {
console.warn(
"No service worker available, so sync is inactive",
e.message,
);
return;
}
return waitForServiceWorkerActivation(path);
},
"sync.performSpaceSync": (): Promise<number> => {
void client.postServiceWorkerMessage({ type: "perform-space-sync" });
"sync.performSpaceSync": async (): Promise<number> => {
try {
await client.postServiceWorkerMessage({
type: "perform-space-sync",
});
} catch (e: any) {
console.warn("No service worker available, so sync is inactive", e);
return 0;
}
return waitForServiceWorkerActivation();
},
};