fix dem bugs

This commit is contained in:
JCEEE
2026-09-15 09:05:13 +01:00
parent f9fa99f5ff
commit 29d50985df
8 changed files with 181 additions and 121 deletions
+13 -3
View File
@@ -203,8 +203,11 @@ class FamStore {
this.bonusTemplates = bonusTemplatesRes;
this.rewards = rewardsRes;
this.seasons = seasonsRes;
// A completed resync proves the pipe is healthy again.
this.connectionDown = false;
} catch (e) {
console.error('FamStore.resync failed:', e);
if (!this.destroyed) this.connectionDown = true;
} finally {
this.resyncing = false;
}
@@ -228,7 +231,10 @@ class FamStore {
.then((unsub) => {
this.connWatchers.push(unsub);
})
.catch(() => {});
.catch(() => {
// We never even got the connect signal — surface it.
if (!this.destroyed) this.connectionDown = true;
});
const onDisc = pb.realtime.onDisconnect;
pb.realtime.onDisconnect = (active: string[]) => {
try {
@@ -238,9 +244,10 @@ class FamStore {
if (active.length > 0 && !this.destroyed) this.connectionDown = true;
};
// Browser-level: sleep/wake and offline/online can kill SSE without the
// SDK noticing promptly — resync when the network/tab comes back.
// SDK noticing promptly. Don't touch the flag here — resync() sets it
// from the actual outcome (clearing it early is what left the dot
// green while the console showed errors).
const onOnline = () => {
this.connectionDown = false;
this.resync().catch(() => {});
};
const onVisible = () => {
@@ -284,6 +291,9 @@ class FamStore {
})
.catch((err: Error) => {
console.error(`[famStore] subscribe failed for ${collection}:`, err);
// A failed subscribe IS the outage the console shows while
// the dot stayed green — flag it; PB_CONNECT/resync clears it.
if (!this.destroyed) this.connectionDown = true;
});
});