Skip to content

Commit

Permalink
fix: only restore local changes if the upstream doc has not been modi…
Browse files Browse the repository at this point in the history
…fied
  • Loading branch information
nextchamp-saqib committed Jan 23, 2025
1 parent 99ad410 commit 6d1a77a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions frontend/src2/helpers/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,13 @@ export default function useDocumentResource<T extends object>(
})
// on creation, restore the doc from local storage, if exists
if (storage.value && storage.value.doc) {
resource.doc = storage.value.doc
resource.originalDoc = storage.value.originalDoc
const isStale =
new Date(resource.doc.modified).getTime() > new Date(storage.value.doc.modified).getTime()

if (!isStale) {
resource.doc = storage.value.doc
resource.originalDoc = storage.value.originalDoc
}
}
// watch for changes in doc and save it to local storage
watchDebounced(
Expand Down

0 comments on commit 6d1a77a

Please sign in to comment.