@@ -110,7 +110,8 @@ import {
110110 onMounted ,
111111 nextTick ,
112112 getCurrentInstance ,
113- useSlots
113+ useSlots ,
114+ onBeforeUnmount
114115} from ' vue'
115116import {
116117 createCommandNotFound ,
@@ -298,6 +299,12 @@ const vueCommandHistoryEntryComponentRefs = ref(null)
298299const vueCommandHistoryRef = ref (null )
299300const vueCommandRef = ref (null )
300301
302+ // Keep a global resizeObserver instance to disconnect it at onBeforeUnmount
303+ const resizeObserver = new ResizeObserver (() => {
304+ // TODO: Only scroll to bottom if user scrolled to bottom before
305+ vueCommandHistoryRef .value .scrollTop = vueCommandHistoryRef .value .scrollHeight
306+ })
307+
301308// A local copy to allow the absence of properties
302309const local = reactive ({
303310 cursorPosition: props .cursorPosition ,
@@ -511,6 +518,9 @@ watch(() => props.query, query => {
511518 // Cursor position gets updated in query component
512519})
513520
521+ onBeforeUnmount (() => {
522+ resizeObserver .disconnect ()
523+ })
514524onMounted (() => {
515525 // Binds given event listeners and calls them with the terminals references
516526 // and exposed properties
@@ -520,20 +530,16 @@ onMounted(() => {
520530 }
521531
522532 // Scroll to bottom if history changes
523- const resizeObsever = new ResizeObserver (() => {
524- // TODO: Only scroll to bottom if user scrolled to bottom before
525- vueCommandHistoryRef .value .scrollTop = vueCommandHistoryRef .value .scrollHeight
526- })
527533 for (const vueCommandHistoryEntry of vueCommandHistoryRef .value .children ) {
528- resizeObsever .observe (vueCommandHistoryEntry)
534+ resizeObserver .observe (vueCommandHistoryEntry)
529535 }
530536 // If history changes, unobserve all history entries and observe again
531537 watch (local .history , async () => {
532538 await nextTick ()
533539
534- resizeObsever .disconnect ()
540+ resizeObserver .disconnect ()
535541 for (const vueCommandHistoryEntry of vueCommandHistoryRef .value .children ) {
536- resizeObsever .observe (vueCommandHistoryEntry)
542+ resizeObserver .observe (vueCommandHistoryEntry)
537543 }
538544 })
539545})
0 commit comments