From 8bced69828de7cbe2ef4a036c2c9080f5799f4f0 Mon Sep 17 00:00:00 2001 From: Nan Yu Date: Wed, 19 Jan 2022 12:57:44 -0800 Subject: [PATCH] fix: changing the title and body content in quick succession would trigger unsaved changes warning prompt (#2950) changing the title and body content in quick succession would trigger unsaved changes warning prompt --- app/scenes/Document/components/Document.tsx | 17 ++++++++++++++--- shared/i18n/locales/en_US/translation.json | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/scenes/Document/components/Document.tsx b/app/scenes/Document/components/Document.tsx index 02d23b40d..935056f24 100644 --- a/app/scenes/Document/components/Document.tsx +++ b/app/scenes/Document/components/Document.tsx @@ -466,9 +466,20 @@ class DocumentScene extends React.Component { !this.isUploading && !team?.collaborativeEditing } - message={t( - `You have unsaved changes.\nAre you sure you want to discard them?` - )} + message={(location, action) => { + if ( + // a URL replace matching the current document indicates a title change + // no guard is needed for this transition + action === "REPLACE" && + location.pathname === editDocumentUrl(document) + ) { + return true; + } + + return t( + `You have unsaved changes.\nAre you sure you want to discard them?` + ) as string; + }} />