@@ -189,6 +189,19 @@ export default function MultiMarkdownInput(props: Props) {
189189 path,
190190 } = useFrameContext ( ) ;
191191
192+ // We use refs for shiftEnter and onChange to be absolutely
193+ // 100% certain that if either of these functions is changed,
194+ // then the new function is used, even if the components
195+ // implementing our markdown editor mess up somehow and hang on.
196+ const onShiftEnterRef = useRef < any > ( onShiftEnter ) ;
197+ useEffect ( ( ) => {
198+ onShiftEnterRef . current = onShiftEnter ;
199+ } , [ onShiftEnter ] ) ;
200+ const onChangeRef = useRef < any > ( onChange ) ;
201+ useEffect ( ( ) => {
202+ onChangeRef . current = onChange ;
203+ } , [ onChange ] ) ;
204+
192205 const editBar2 = useRef < JSX . Element | undefined > ( undefined ) ;
193206
194207 function getCache ( ) {
@@ -380,7 +393,9 @@ export default function MultiMarkdownInput(props: Props) {
380393 divRef = { editorDivRef }
381394 selectionRef = { selectionRef }
382395 value = { value }
383- onChange = { onChange }
396+ onChange = { ( value ) => {
397+ onChangeRef . current ?.( value ) ;
398+ } }
384399 saveDebounceMs = { saveDebounceMs }
385400 getValueRef = { getValueRef }
386401 project_id = { project_id }
@@ -389,7 +404,9 @@ export default function MultiMarkdownInput(props: Props) {
389404 onUploadStart = { onUploadStart }
390405 onUploadEnd = { onUploadEnd }
391406 enableMentions = { enableMentions }
392- onShiftEnter = { onShiftEnter }
407+ onShiftEnter = { ( value ) => {
408+ onShiftEnterRef . current ?.( value ) ;
409+ } }
393410 placeholder = { placeholder ?? "Type markdown..." }
394411 fontSize = { fontSize }
395412 cmOptions = { cmOptions }
@@ -400,7 +417,7 @@ export default function MultiMarkdownInput(props: Props) {
400417 extraHelp = { extraHelp }
401418 hideHelp = { hideHelp }
402419 onBlur = { ( value ) => {
403- onChange ?.( value ) ;
420+ onChangeRef . current ?.( value ) ;
404421 if ( ! ignoreBlur . current ) {
405422 onBlur ?.( ) ;
406423 }
@@ -463,14 +480,14 @@ export default function MultiMarkdownInput(props: Props) {
463480 getValueRef = { getValueRef }
464481 actions = { {
465482 set_value : ( value ) => {
466- onChange ?.( value ) ;
483+ onChangeRef . current ?.( value ) ;
467484 } ,
468485 shiftEnter : ( value ) => {
469- onChange ?.( value ) ;
470- onShiftEnter ?.( value ) ;
486+ onChangeRef . current ?.( value ) ;
487+ onShiftEnterRef . current ?.( value ) ;
471488 } ,
472489 altEnter : ( value ) => {
473- onChange ?.( value ) ;
490+ onChangeRef . current ?.( value ) ;
474491 setMode ( "markdown" ) ;
475492 } ,
476493 set_cursor_locs : onCursors ,
0 commit comments