feat: add workbox-window and improve event stream cleanup

Add workbox-window dependency to bun.lock and web package.json
Cancel and release the stream reader on disconnect to avoid leaks
This commit is contained in:
Bohdan Triapitsyn
2026-01-22 12:30:33 +02:00
parent d97181bcd2
commit d4f1d8abbf
3 changed files with 11 additions and 3 deletions
+1
View File
@@ -303,6 +303,7 @@
"typescript-eslint": "^8.39.1",
"vite": "^7.1.2",
"vite-plugin-pwa": "^1.0.3",
"workbox-window": "^7.4.0",
},
},
},
+2 -1
View File
@@ -85,7 +85,8 @@
"typescript": "~5.8.3",
"typescript-eslint": "^8.39.1",
"vite": "^7.1.2",
"vite-plugin-pwa": "^1.0.3"
"vite-plugin-pwa": "^1.0.3",
"workbox-window": "^7.4.0"
},
"files": [
"dist",
+8 -2
View File
@@ -1339,6 +1339,7 @@ const startGlobalEventWatcher = async () => {
while (!signal.aborted) {
attempt += 1;
let upstream;
let reader;
try {
const url = buildOpenCodeUrl('/global/event', '');
upstream = await fetch(url, {
@@ -1357,7 +1358,7 @@ const startGlobalEventWatcher = async () => {
console.log('[PushWatcher] connected');
const decoder = new TextDecoder();
const reader = upstream.body.getReader();
reader = upstream.body.getReader();
let buffer = '';
while (!signal.aborted) {
@@ -1383,7 +1384,12 @@ const startGlobalEventWatcher = async () => {
console.warn('[PushWatcher] disconnected', error?.message ?? error);
} finally {
try {
upstream?.body?.cancel?.();
if (reader) {
await reader.cancel();
reader.releaseLock();
} else if (upstream?.body && !upstream.body.locked) {
await upstream.body.cancel();
}
} catch {
// ignore
}