Skip to content

Commit babcd59

Browse files
authored
fix(ui): save nested richtext inside inlineBlock (#12773)
Removing the `setTimeout` not only doesn't break any tests, but it also fixes the linked issue. The long comment above the if statement was added in #5460 and explains why the if statement is necessary GIVEN the existence of the `setTimeout`, but the `setTimeout` was introduced [earlier because the button apparently didn't work](#1414). It seems to work now without the `setTimeout`, because otherwise the tests wouldn't even pass. I also tested it manually, and it works fine. Fixes #12687
1 parent ac19b78 commit babcd59

File tree

1 file changed

+2
-23
lines changed

1 file changed

+2
-23
lines changed

packages/ui/src/forms/useField/index.tsx

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,31 +96,10 @@ export const useField = <TValue,>(options?: Options): FieldType<TValue> => {
9696
})
9797

9898
if (!disableModifyingForm) {
99-
if (typeof setModified === 'function') {
100-
// Only update setModified to true if the form is not already set to modified. Otherwise the following could happen:
101-
// 1. Text field: someone types in it in an unmodified form
102-
// 2. After setTimeout triggers setModified(true): form is set to modified. Save Button becomes available. Good!
103-
// 3. Type something in text field
104-
// 4. Click on save button before setTimeout in useField has finished (so setModified(true) has not been run yet)
105-
// 5. Form is saved, setModified(false) is set in the Form/index.tsx `submit` function, "saved successfully" toast appears
106-
// 6. setModified(true) inside the timeout is run, form is set to modified again, even though it was already saved and thus set to unmodified. Bad! This should have happened before the form is saved. Now the form should be unmodified and stay that way
107-
// until a NEW change happens. Due to this, the "Leave without saving" modal appears even though it should not when leaving the page fast immediately after saving the document.
108-
// This is only an issue for forms which have already been set to modified true, as that causes the save button to be enabled. If we prevent this setTimeout to be run
109-
// for already-modified forms first place (which is unnecessary), we can avoid this issue. As for unmodified forms, this race issue will not happen, because you cannot click the save button faster
110-
// than the timeout in useField is run. That's because the save button won't even be enabled for clicking until the setTimeout in useField has run.
111-
// This fixes e2e test flakes, as e2e tests were often so fast that they were saving the form before the timeout in useField has run.
112-
// Specifically, this fixes the 'should not warn about unsaved changes when navigating to lexical editor with blocks node and then leaving the page after making a change and saving' lexical e2e test.
113-
if (modified === false) {
114-
// Update modified state after field value comes back
115-
// to avoid cursor jump caused by state value / DOM mismatch
116-
setTimeout(() => {
117-
setModified(true)
118-
}, 10)
119-
}
120-
}
99+
setModified(true)
121100
}
122101
},
123-
[setModified, path, dispatchField, disableFormData, hasRows, modified],
102+
[setModified, path, dispatchField, disableFormData, hasRows],
124103
)
125104

126105
// Store result from hook as ref

0 commit comments

Comments
 (0)