@@ -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
0 commit comments