Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/renderer/src/components/ChatView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted, watch, computed } from 'vue'
import { ref, onMounted, onUnmounted, watch, computed, nextTick } from 'vue'
import MessageList from './message/MessageList.vue'
import ChatInput from './ChatInput.vue'
import { useRoute } from 'vue-router'
Expand Down Expand Up @@ -67,6 +67,12 @@ onMounted(async () => {

window.electron.ipcRenderer.on(STREAM_EVENTS.END, (_, msg) => {
chatStore.handleStreamEnd(msg)
// 当用户没有主动向上滚动时才自动滚动到底部
nextTick(() => {
if (messageList.value && !messageList.value.aboveThreshold) {
scrollToBottom(false)
}
})
Comment on lines +71 to +75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Bug: aboveThreshold is a Ref — need .value to read it.

As written, the condition always treats the ref object as truthy, preventing auto-scroll.

-    nextTick(() => {
-      if (messageList.value && !messageList.value.aboveThreshold) {
-        scrollToBottom(false)
-      }
-    })
+    nextTick(() => {
+      if (messageList.value && !messageList.value.aboveThreshold?.value) {
+        scrollToBottom(false)
+      }
+    })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
nextTick(() => {
if (messageList.value && !messageList.value.aboveThreshold) {
scrollToBottom(false)
}
})
nextTick(() => {
if (messageList.value && !messageList.value.aboveThreshold?.value) {
scrollToBottom(false)
}
})
🤖 Prompt for AI Agents
In src/renderer/src/components/ChatView.vue around lines 71–75, the code checks
messageList.value.aboveThreshold but aboveThreshold itself is a Ref, so the
current condition always treats the ref object as truthy and prevents
auto-scroll; update the condition to read the inner value (e.g. verify
messageList.value exists and use messageList.value.aboveThreshold.value) and
keep the null/undefined guard (for example: if (messageList.value &&
!messageList.value.aboveThreshold.value) scrollToBottom(false)); ensure you also
defensively check that aboveThreshold exists before accessing .value.

setTimeout(() => {
chatInput.value?.restoreFocus()
}, 200)
Expand Down
18 changes: 11 additions & 7 deletions src/renderer/src/components/message/MessageList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
variant="outline"
size="icon"
class="w-8 h-8 shrink-0 rounded-lg relative z-10"
@click="scrollToBottom"
@click="() => scrollToBottom(true)"
>
<Icon icon="lucide:arrow-down" class="w-5 h-5 text-muted-foreground" />
</Button>
Expand Down Expand Up @@ -278,12 +278,14 @@ const handleCopyImage = async (
}
}

const scrollToBottom = () => {
const scrollToBottom = (smooth = false) => {
nextTick(() => {
scrollAnchor.value?.scrollIntoView({
behavior: 'instant',
block: 'end'
})
if (scrollAnchor.value) {
scrollAnchor.value.scrollIntoView({
behavior: smooth ? 'smooth' : 'instant',
block: 'end'
})
}
})
}

Expand Down Expand Up @@ -328,7 +330,9 @@ onMounted(() => {
() => {
const lastMessage = props.messages[props.messages.length - 1]
if (lastMessage?.status === 'pending' && !aboveThreshold.value) {
scrollToBottom()
nextTick(() => {
scrollToBottom()
})
}
}
)
Expand Down