Fix: initial sync handling
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user