@@ -246,6 +246,18 @@ class MentionsInput<
246246 private _scrollSyncFrame : number | null = null
247247 private _autoResizeFrame : number | null = null
248248
249+ private cancelScheduledFrame ( frameKey : '_scrollSyncFrame' | '_autoResizeFrame' ) : void {
250+ const frame = this [ frameKey ]
251+ if (
252+ frame !== null &&
253+ globalThis . window !== undefined &&
254+ typeof globalThis . cancelAnimationFrame === 'function'
255+ ) {
256+ globalThis . cancelAnimationFrame ( frame )
257+ this [ frameKey ] = null
258+ }
259+ }
260+
249261 private getSlotClassName ( slot : keyof MentionsInputClassNames , baseClass : string ) {
250262 const { classNames } = this . props
251263 const extra = classNames ?. [ slot ]
@@ -486,22 +498,8 @@ class MentionsInput<
486498 document . removeEventListener ( 'paste' , this . handlePaste )
487499 document . removeEventListener ( 'scroll' , this . handleDocumentScroll , true )
488500 document . removeEventListener ( 'selectionchange' , this . handleDocumentSelectionChange )
489- if (
490- this . _scrollSyncFrame !== null &&
491- globalThis . window !== undefined &&
492- typeof globalThis . cancelAnimationFrame === 'function'
493- ) {
494- globalThis . cancelAnimationFrame ( this . _scrollSyncFrame )
495- this . _scrollSyncFrame = null
496- }
497- if (
498- this . _autoResizeFrame !== null &&
499- globalThis . window !== undefined &&
500- typeof globalThis . cancelAnimationFrame === 'function'
501- ) {
502- globalThis . cancelAnimationFrame ( this . _autoResizeFrame )
503- this . _autoResizeFrame = null
504- }
501+ this . cancelScheduledFrame ( '_scrollSyncFrame' )
502+ this . cancelScheduledFrame ( '_autoResizeFrame' )
505503 this . _pendingHighlighterRecompute = false
506504 this . _didUnmount = true
507505 }
0 commit comments