From 360fd6d2cca96fd11f96cd6259289732b26db445 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 11 Oct 2026 12:08:30 +1300 Subject: [PATCH] Add unsubscribe call on SharePage unload --- client/homebrew/pages/sharePage/sharePage.jsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/sharePage/sharePage.jsx b/client/homebrew/pages/sharePage/sharePage.jsx index 4b03cffdf..80d544c3a 100644 --- a/client/homebrew/pages/sharePage/sharePage.jsx +++ b/client/homebrew/pages/sharePage/sharePage.jsx @@ -54,7 +54,15 @@ const SharePage = (props)=>{ fetchThemeBundle(undefined, setThemeBundle, currentBrew.renderer, currentBrew.theme); // listen for changes in the brew version - const eventSource = new EventSource(`/stream/${props.brew.shareId}`); + const eventSource = new EventSource(`/api/stream/${props.brew.shareId}`); + + let subId = ''; + eventSource.addEventListener('subscribe', (evt)=>{ + const messageData = JSON.parse(evt.data); + + subId = messageData.id; + }); + eventSource.addEventListener('brewUpdated', (evt)=>{ const messageData = JSON.parse(evt.data); @@ -64,7 +72,11 @@ const SharePage = (props)=>{ } }); - return ()=>{ + window.addEventListener('beforeunload', async ()=>{ + await request.get(`/api/stream/unsubscribe/${subId}`); + }); + + return async ()=>{ document.removeEventListener('keydown', handleControlKeys); eventSource.close(); };