:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(frontend): harden useEventListener guard against non-callable addEventListener (#59398)
posthog[bot]348b785b5682
diff --git a/frontend/src/lib/hooks/useEventListener.ts b/frontend/src/lib/hooks/useEventListener.tsindex bfbc0faf590f..9bcb0e0da60d 100644--- a/frontend/src/lib/hooks/useEventListener.ts+++ b/frontend/src/lib/hooks/useEventListener.ts@@ -47,7 +47,7 @@ export function useEventListener(useEffect(() => {// Make sure element supports addEventListener- if (!element?.addEventListener) {+ if (typeof element?.addEventListener !== 'function') {console.warn(`Could not start listening to ${eventName} on ${!element ? element : ((element as Element)?.localName ?? 'window')@@ -61,7 +61,9 @@ export function useEventListener(element.addEventListener(eventName, eventListener)// Remove event listener on cleanupreturn () => {- element?.removeEventListener(eventName, eventListener)+ if (typeof element?.removeEventListener === 'function') {+ element.removeEventListener(eventName, eventListener)+ }}},