diff --git a/web/chat/edit-text-message.react.js b/web/chat/edit-text-message.react.js --- a/web/chat/edit-text-message.react.js +++ b/web/chat/edit-text-message.react.js @@ -102,15 +102,28 @@ }); }, [background, updatePosition]); + const preventCloseTab = React.useCallback( + event => { + if (!isMessageEdited) { + return event; + } + event.preventDefault(); + return (event.returnValue = ''); + }, + [isMessageEdited], + ); + useEffect(() => { if (!background) { return () => {}; } window.addEventListener('resize', updateDimensions); + window.addEventListener('beforeunload', preventCloseTab); return () => { window.removeEventListener('resize', updateDimensions); + window.removeEventListener('beforeunload', preventCloseTab); }; - }, [background, updateDimensions]); + }, [background, preventCloseTab, updateDimensions]); useEffect(() => { updateDimensions();