diff --git a/app/javascript/chat/util.js b/app/javascript/chat/util.js index f0991fff1..e2f8f5ec4 100644 --- a/app/javascript/chat/util.js +++ b/app/javascript/chat/util.js @@ -53,7 +53,18 @@ export function setupObserver(callback) { const somethingObserver = new IntersectionObserver(callback, { threshold: [0, 1], }); + somethingObserver.observe(sentinel); + + window.addEventListener('beforeunload', () => { + somethingObserver.disconnect(); + }); + + if (typeof instantClick !== 'undefined') { + InstantClick.on('change', () => { + somethingObserver.disconnect(); + }); + } } export function hideMessages(messages, userId) {