mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 15:14:56 -04:00
fix(redux): avoid state mutation in history redux
When updating the data of a note in the redux, the old state element gets manipulated and will be dispatched again into the state. Redux is not optimized for external state-mutations and has some weird side-effects in that case and sometimes throws an error. This commit fixes the problem by using a clone of the entry. Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
84ee805c56
commit
f16b3c0fe6
1 changed files with 5 additions and 4 deletions
|
@ -43,10 +43,11 @@ export const useUpdateLocalHistoryEntry = (): void => {
|
||||||
if (entry.origin === HistoryEntryOrigin.REMOTE) {
|
if (entry.origin === HistoryEntryOrigin.REMOTE) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
entry.title = currentNoteTitle
|
const updatedEntry = { ...entry }
|
||||||
entry.tags = currentNoteTags
|
updatedEntry.title = currentNoteTitle
|
||||||
entry.lastVisitedAt = new Date().toISOString()
|
updatedEntry.tags = currentNoteTags
|
||||||
updateLocalHistoryEntry(id, entry)
|
updatedEntry.lastVisitedAt = new Date().toISOString()
|
||||||
|
updateLocalHistoryEntry(id, updatedEntry)
|
||||||
lastNoteTitle.current = currentNoteTitle
|
lastNoteTitle.current = currentNoteTitle
|
||||||
lastNoteTags.current = currentNoteTags
|
lastNoteTags.current = currentNoteTags
|
||||||
}, [id, userExists, currentNoteTitle, currentNoteTags])
|
}, [id, userExists, currentNoteTitle, currentNoteTags])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue