From 453139780b7c45ed7ddd00cd5dbee01f28f3cb2e Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 13 Apr 2026 07:59:16 +0200 Subject: [PATCH] Fix: initial sync handling --- client/boot.ts | 5 +++++ client/client.ts | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/client/boot.ts b/client/boot.ts index 465ae97e..0f7fe20e 100644 --- a/client/boot.ts +++ b/client/boot.ts @@ -326,6 +326,11 @@ async function cachedFetch(path: string): Promise { 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( diff --git a/client/client.ts b/client/client.ts index b4170894..08e162d6 100644 --- a/client/client.ts +++ b/client/client.ts @@ -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": {