diff --git a/app/scenes/Document/components/Document.tsx b/app/scenes/Document/components/Document.tsx index a4dea7a5d9..35d9e996a3 100644 --- a/app/scenes/Document/components/Document.tsx +++ b/app/scenes/Document/components/Document.tsx @@ -30,6 +30,7 @@ import { useLocationSidebarContext } from "~/hooks/useLocationSidebarContext"; import useMobile from "~/hooks/useMobile"; import useStores from "~/hooks/useStores"; import isTextInput from "~/utils/isTextInput"; +import Logger from "~/utils/Logger"; import { client } from "~/utils/ApiClient"; import { emojiToUrl } from "~/utils/emoji"; import { documentHistoryPath, documentEditPath } from "~/utils/routeHelpers"; @@ -324,28 +325,28 @@ function DocumentScene({ const hasUnsyncedChanges = !readOnly && documentContext.hasUnsyncedChanges; + const warnUnsyncedChanges = () => { + Logger.warn("Leaving document with unsynced changes", { + documentId: document.id, + hasLocalPersistence: documentContext.hasLocalPersistence, + }); + }; + const handleBlockNavigation = () => { - if (hasUnsyncedChanges) { - return documentContext.hasLocalPersistence - ? t( - `Your changes haven’t synced yet, they are saved on this device.\nAre you sure you want to leave?` - ) - : t( - `Your changes haven’t synced yet and will be lost.\nAre you sure you want to leave?` - ); - } if (isUploading && !isEditorDirty) { return t( `Images are still uploading.\nAre you sure you want to discard them?` ); } + if (hasUnsyncedChanges) { + warnUnsyncedChanges(); + } return true; }; - const handleUnload = (event: BeforeUnloadEvent) => { + const handleUnload = () => { if (hasUnsyncedChanges) { - event.preventDefault(); - event.returnValue = ""; + warnUnsyncedChanges(); } }; diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 88c246f8ce..156d3a3942 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -928,8 +928,6 @@ "Edits you make will sync once you’re online": "Edits you make will sync once you’re online", "Offline": "Offline", "Document restored": "Document restored", - "Your changes haven’t synced yet, they are saved on this device.\nAre you sure you want to leave?": "Your changes haven’t synced yet, they are saved on this device.\nAre you sure you want to leave?", - "Your changes haven’t synced yet and will be lost.\nAre you sure you want to leave?": "Your changes haven’t synced yet and will be lost.\nAre you sure you want to leave?", "Images are still uploading.\nAre you sure you want to discard them?": "Images are still uploading.\nAre you sure you want to discard them?", "{{ count }} comment": "{{ count }} comment", "{{ count }} comment_plural": "{{ count }} comments",