Fix Save Draft always showing Unsaved after save
The snapshot was set from buildSiteContentForSave(form) which runs normalizeSiteContentForAdmin and rebuilds study objects, producing a JSON string that never matched the raw form state. isDirty therefore stayed true permanently after every save. Fix by capturing JSON.stringify(form) before the fetch and using that as the snapshot, so isDirty correctly clears on success. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+2
-1
@@ -1468,6 +1468,7 @@ export default function AdminPage({ content, onSave, onLogout }: Props) {
|
|||||||
|
|
||||||
async function handleSaveDraft() {
|
async function handleSaveDraft() {
|
||||||
const payload = buildSiteContentForSave(form)
|
const payload = buildSiteContentForSave(form)
|
||||||
|
const formSnapshot = JSON.stringify(form)
|
||||||
setStatus('saving')
|
setStatus('saving')
|
||||||
setErrorMsg('')
|
setErrorMsg('')
|
||||||
try {
|
try {
|
||||||
@@ -1482,7 +1483,7 @@ export default function AdminPage({ content, onSave, onLogout }: Props) {
|
|||||||
}
|
}
|
||||||
const data = await res.json() as { updatedAt?: string }
|
const data = await res.json() as { updatedAt?: string }
|
||||||
setPublishState(prev => ({ ...prev, draftUpdatedAt: data.updatedAt ?? new Date().toISOString() }))
|
setPublishState(prev => ({ ...prev, draftUpdatedAt: data.updatedAt ?? new Date().toISOString() }))
|
||||||
setLastSavedSnapshot(JSON.stringify(payload))
|
setLastSavedSnapshot(formSnapshot)
|
||||||
clearAutosaveDraft()
|
clearAutosaveDraft()
|
||||||
setStatus('saved')
|
setStatus('saved')
|
||||||
if (saveStatusTimeoutRef.current !== null) {
|
if (saveStatusTimeoutRef.current !== null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user