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:
@@ -303,6 +303,7 @@
|
|||||||
"typescript-eslint": "^8.39.1",
|
"typescript-eslint": "^8.39.1",
|
||||||
"vite": "^7.1.2",
|
"vite": "^7.1.2",
|
||||||
"vite-plugin-pwa": "^1.0.3",
|
"vite-plugin-pwa": "^1.0.3",
|
||||||
|
"workbox-window": "^7.4.0",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -85,7 +85,8 @@
|
|||||||
"typescript": "~5.8.3",
|
"typescript": "~5.8.3",
|
||||||
"typescript-eslint": "^8.39.1",
|
"typescript-eslint": "^8.39.1",
|
||||||
"vite": "^7.1.2",
|
"vite": "^7.1.2",
|
||||||
"vite-plugin-pwa": "^1.0.3"
|
"vite-plugin-pwa": "^1.0.3",
|
||||||
|
"workbox-window": "^7.4.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
|
|||||||
@@ -1339,6 +1339,7 @@ const startGlobalEventWatcher = async () => {
|
|||||||
while (!signal.aborted) {
|
while (!signal.aborted) {
|
||||||
attempt += 1;
|
attempt += 1;
|
||||||
let upstream;
|
let upstream;
|
||||||
|
let reader;
|
||||||
try {
|
try {
|
||||||
const url = buildOpenCodeUrl('/global/event', '');
|
const url = buildOpenCodeUrl('/global/event', '');
|
||||||
upstream = await fetch(url, {
|
upstream = await fetch(url, {
|
||||||
@@ -1357,7 +1358,7 @@ const startGlobalEventWatcher = async () => {
|
|||||||
console.log('[PushWatcher] connected');
|
console.log('[PushWatcher] connected');
|
||||||
|
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
const reader = upstream.body.getReader();
|
reader = upstream.body.getReader();
|
||||||
let buffer = '';
|
let buffer = '';
|
||||||
|
|
||||||
while (!signal.aborted) {
|
while (!signal.aborted) {
|
||||||
@@ -1383,7 +1384,12 @@ const startGlobalEventWatcher = async () => {
|
|||||||
console.warn('[PushWatcher] disconnected', error?.message ?? error);
|
console.warn('[PushWatcher] disconnected', error?.message ?? error);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
upstream?.body?.cancel?.();
|
if (reader) {
|
||||||
|
await reader.cancel();
|
||||||
|
reader.releaseLock();
|
||||||
|
} else if (upstream?.body && !upstream.body.locked) {
|
||||||
|
await upstream.body.cancel();
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user