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 @@ -86,15 +86,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();