fix: recover feature install SSE on tab visibility change

This commit is contained in:
SnapOtter
2026-06-05 21:45:32 +08:00
parent fbc70272dd
commit 2b92109aee
+20
View File
@@ -147,6 +147,26 @@ export const useFeaturesStore = create<FeaturesState>((set, get) => {
}
};
if (typeof document !== "undefined") {
document.addEventListener("visibilitychange", () => {
if (document.visibilityState !== "visible") return;
const activeIds = Object.keys(get().installing);
if (activeIds.length === 0) return;
for (const bundleId of activeIds) {
const es = esRefs[bundleId];
if (es && es.readyState === EventSource.OPEN) continue;
if (es) {
es.close();
delete esRefs[bundleId];
}
if (!pollRefs[bundleId]) {
startPolling(bundleId);
}
}
});
}
return {
bundles: [],
loaded: false,