fix(venue-crowd): always detach load listeners, gate only the callback

Codex preflight: superseded loads left canplaythrough/error listeners
attached to the persistent video elements — unbounded growth over a
session.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
byrongamatos
2026-07-12 21:09:00 +02:00
co-authored by Claude Fable 5
parent 663e8ff4a1
commit 9d8fda6d46
+5 -1
View File
@@ -216,10 +216,14 @@
const gen = _stopGen;
let settled = false;
const settle = (ok) => {
if (settled || token !== video._fbCrowdToken || gen !== _stopGen) return;
if (settled) return;
settled = true;
// Cleanup must run even for superseded loads or stale listeners
// accumulate on the two persistent elements; only the callback
// is gated on still being the current load.
video.removeEventListener('canplaythrough', onReady);
video.removeEventListener('error', onError);
if (token !== video._fbCrowdToken || gen !== _stopGen) return;
cb(ok);
};
const onReady = () => settle(true);