Skip to content

Commit ccb8018

Browse files
committed
the previous patch fixed some issues with slate editing, but would randomly result in loss sometimes when multiple people are editing at once, so address that
1 parent eb74334 commit ccb8018

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

src/packages/frontend/editors/slate/editable-markdown.tsx

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const EditableMarkdown: React.FC<Props> = React.memo((props: Props) => {
155155
placeholder,
156156
read_only,
157157
registerEditor,
158-
saveDebounceMs,
158+
saveDebounceMs = SAVE_DEBOUNCE_MS,
159159
selectionRef,
160160
style,
161161
submitMentionsRef,
@@ -257,7 +257,7 @@ export const EditableMarkdown: React.FC<Props> = React.memo((props: Props) => {
257257
// hook up to syncstring if available:
258258
useEffect(() => {
259259
if (actions._syncstring == null) return;
260-
const beforeChange = setSyncstringFromSlate;
260+
const beforeChange = setSyncstringFromSlateNOW;
261261
const change = () => {
262262
setEditorToValue(actions._syncstring.to_str());
263263
};
@@ -496,29 +496,31 @@ export const EditableMarkdown: React.FC<Props> = React.memo((props: Props) => {
496496
}
497497
}, [value]);
498498

499-
const setSyncstringFromSlate = useMemo(() => {
500-
const f = () => {
501-
if (actions.set_value == null) {
502-
// no way to save the value out (e.g., just beginning to test
503-
// using the component).
504-
return;
505-
}
506-
if (!editor.hasUnsavedChanges()) {
507-
// there are no changes to save
508-
return;
509-
}
499+
const setSyncstringFromSlateNOW = () => {
500+
if (actions.set_value == null) {
501+
// no way to save the value out (e.g., just beginning to test
502+
// using the component).
503+
return;
504+
}
505+
if (!editor.hasUnsavedChanges()) {
506+
// there are no changes to save
507+
return;
508+
}
510509

511-
const markdown = editor.getMarkdownValue();
512-
actions.set_value(markdown);
513-
actions.syncstring_commit?.();
510+
const markdown = editor.getMarkdownValue();
511+
actions.set_value(markdown);
512+
actions.syncstring_commit?.();
514513

515-
// Record that the syncstring's value is now equal to ours:
516-
editor.resetHasUnsavedChanges();
517-
};
514+
// Record that the syncstring's value is now equal to ours:
515+
editor.resetHasUnsavedChanges();
516+
};
517+
518+
const setSyncstringFromSlate = useMemo(() => {
518519
if (saveDebounceMs) {
519-
return debounce(f, saveDebounceMs);
520+
return debounce(setSyncstringFromSlateNOW, saveDebounceMs);
520521
} else {
521-
return f;
522+
// this case shouldn't happen
523+
return setSyncstringFromSlateNOW;
522524
}
523525
}, []);
524526

src/packages/frontend/editors/task-editor/desc-editor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export default function DescriptionEditor({
5959
return (
6060
<div>
6161
<MarkdownInput
62+
saveDebounceMs={SAVE_DEBOUNCE_MS}
6263
cacheId={task_id}
6364
value={desc}
6465
onChange={(desc) => {

0 commit comments

Comments
 (0)