Skip to content

Commit c73f6c7

Browse files
authored
fix(ui): autosave and preventLeaveWithoutSaving interfering with fetching form-state reliably (#8434)
Removes the setModified call from Autosave logic and updates the `preventLeaveWithoutSaving` logic in Document info to actually disable if autosave is enabled (previously it always resolved to true) Fixes #8072
1 parent 5c2e39e commit c73f6c7

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

packages/next/src/views/Edit/Default/index.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,19 @@ export const DefaultEditView: React.FC = () => {
113113

114114
const isLockingEnabled = lockDocumentsProp !== false
115115

116-
const preventLeaveWithoutSaving =
117-
(!(collectionConfig?.versions?.drafts && collectionConfig?.versions?.drafts?.autosave) ||
118-
!(globalConfig?.versions?.drafts && globalConfig?.versions?.drafts?.autosave)) &&
119-
!disableLeaveWithoutSaving
116+
let preventLeaveWithoutSaving = true
117+
118+
if (collectionConfig) {
119+
preventLeaveWithoutSaving = !(
120+
collectionConfig?.versions?.drafts && collectionConfig?.versions?.drafts?.autosave
121+
)
122+
} else if (globalConfig) {
123+
preventLeaveWithoutSaving = !(
124+
globalConfig?.versions?.drafts && globalConfig?.versions?.drafts?.autosave
125+
)
126+
} else if (typeof disableLeaveWithoutSaving !== 'undefined') {
127+
preventLeaveWithoutSaving = !disableLeaveWithoutSaving
128+
}
120129

121130
const [isReadOnlyForIncomingUser, setIsReadOnlyForIncomingUser] = useState(false)
122131
const [showTakeOverModal, setShowTakeOverModal] = useState(false)

packages/ui/src/elements/Autosave/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const Autosave: React.FC<Props> = ({
4747
} = useConfig()
4848
const { docConfig, getVersions, versions } = useDocumentInfo()
4949
const { reportUpdate } = useDocumentEvents()
50-
const { dispatchFields, setModified, setSubmitted } = useForm()
50+
const { dispatchFields, setSubmitted } = useForm()
5151
const submitted = useFormSubmitted()
5252
const versionsConfig = docConfig?.versions
5353

@@ -149,7 +149,7 @@ export const Autosave: React.FC<Props> = ({
149149
entitySlug,
150150
updatedAt: newDate.toISOString(),
151151
})
152-
setModified(false)
152+
153153
void getVersions()
154154
} else {
155155
return res.json()
@@ -247,7 +247,6 @@ export const Autosave: React.FC<Props> = ({
247247
reportUpdate,
248248
serverURL,
249249
setSubmitted,
250-
setModified,
251250
versionsConfig?.drafts,
252251
debouncedFields,
253252
submitted,

0 commit comments

Comments
 (0)