From d4f56da6e730fa56910b5a2234bfee6f032172b2 Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Wed, 19 Apr 2023 11:24:55 -0400 Subject: [PATCH] fix: improve local backup detection --- .../src/components/entry-editor/Editor.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/core/src/components/entry-editor/Editor.tsx b/packages/core/src/components/entry-editor/Editor.tsx index 1f011914..0bb95dd0 100644 --- a/packages/core/src/components/entry-editor/Editor.tsx +++ b/packages/core/src/components/entry-editor/Editor.tsx @@ -4,6 +4,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { translate } from 'react-polyglot'; import { connect } from 'react-redux'; import { useNavigate } from 'react-router-dom'; +import isEqual from 'lodash/isEqual'; import { createDraftDuplicateFromEntry, @@ -165,7 +166,12 @@ const Editor: FC> = ({ >(); useEffect(() => { - if (!prevLocalBackup && localBackup) { + if ( + !prevLocalBackup && + localBackup && + (!isEqual(localBackup.entry.data, entryDraft.entry?.data) || + !isEqual(localBackup.entry.meta, entryDraft.entry?.meta)) + ) { const updateLocalBackup = async () => { const confirmLoadBackupBody = await confirm({ title: 'editor.editor.confirmLoadBackupTitle', @@ -184,7 +190,15 @@ const Editor: FC> = ({ } setPrevLocalBackup(localBackup); - }, [deleteBackup, dispatch, localBackup, prevLocalBackup, version]); + }, [ + deleteBackup, + dispatch, + entryDraft.entry?.data, + entryDraft.entry?.meta, + localBackup, + prevLocalBackup, + version, + ]); useEffect(() => { if (hasChanged && entryDraft.entry) {