diff --git a/apps/stage-tamagotchi/src/renderer/components/ChatHistory.vue b/apps/stage-tamagotchi/src/renderer/components/ChatHistory.vue index 57915eabf..69a4b29af 100644 --- a/apps/stage-tamagotchi/src/renderer/components/ChatHistory.vue +++ b/apps/stage-tamagotchi/src/renderer/components/ChatHistory.vue @@ -3,7 +3,7 @@ import { MarkdownRenderer } from '@proj-airi/stage-ui/components' import { useChatStore } from '@proj-airi/stage-ui/stores/chat' import { useBroadcastChannel } from '@vueuse/core' import { storeToRefs } from 'pinia' -import { nextTick, ref, watch } from 'vue' +import { ref, watch } from 'vue' import { useI18n } from 'vue-i18n' const chatHistoryRef = ref() @@ -31,25 +31,30 @@ watch(presentEvent, (ev) => { } }) +function scrollToBottom() { + requestAnimationFrame(() => { + requestAnimationFrame(() => { + if (!chatHistoryRef.value) + return + + chatHistoryRef.value.scrollTop = chatHistoryRef.value.scrollHeight + }) + }) +} + onBeforeMessageComposed(async () => { // Scroll down to the new sent message - nextTick().then(() => { - if (!chatHistoryRef.value) - return - - chatHistoryRef.value.scrollTop = chatHistoryRef.value.scrollHeight - }) + await scrollToBottom() }) onTokenLiteral(async () => { // Scroll down to the new responding message - nextTick().then(() => { - if (!chatHistoryRef.value) - return - - chatHistoryRef.value.scrollTop = chatHistoryRef.value.scrollHeight - }) + await scrollToBottom() }) + +watch(sending, () => { + scrollToBottom() +}, { flush: 'post' })