Fix: initial sync handling

This commit is contained in:
Zef Hemel
2026-04-13 07:59:16 +02:00
parent 82868f7992
commit 453139780b
2 changed files with 14 additions and 0 deletions
+5
View File
@@ -326,6 +326,11 @@ async function cachedFetch(path: string): Promise<string> {
throw offlineError;
}
}
if (response.status === 404) {
// File doesn't exist yet (e.g., CONFIG.md before first sync)
// Return empty string without caching, so next boot re-fetches
return "";
}
if (response.type === "opaqueredirect") {
// We received an opaque redirect, there's little sensible we can do than unregister service workers and reload
console.log(
+9
View File
@@ -880,10 +880,19 @@ export class Client {
async handleServiceWorkerMessage(message: ServiceWorkerSourceMessage) {
switch (message.type) {
case "space-sync-complete": {
const isFirstSync = !this.fullSyncCompleted;
this.fullSyncCompleted = true;
// Trigger version-bump reindex if needed (must happen here, not in a plug,
// because the plug may not be loaded yet when the first sync completes)
void this.objectIndex.ensureFullIndex(this.space);
if (isFirstSync && message.operations > 0) {
// First sync pulled new content — reload the current page
// (it may have been empty because the file didn't exist locally yet)
void this.reloadEditor();
// Re-evaluate CONFIG and space scripts now that sync has pulled them
void this.clientSystem.reloadState();
}
break;
}
case "online-status": {