Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when accessing status of empty newChats array #2610

Closed
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
24 changes: 12 additions & 12 deletions packages/semi-ui/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,19 @@ class Chat extends BaseComponent<ChatProps, ChatState> {
const { wheelScroll } = this.state;
let shouldScroll = false;
if (newChats !== oldChats) {
if (Array.isArray(newChats) && Array.isArray(oldChats)) {
const newLastChat = newChats[newChats.length - 1];
const oldLastChat = oldChats[oldChats.length - 1];
if (newChats.length > oldChats.length) {
if (oldChats.length === 0 || newLastChat.id !== oldLastChat.id) {
shouldScroll = true;
}
} else if (newChats.length === oldChats.length && newChats.length &&
(newLastChat.status !== 'complete' || newLastChat.status !== oldLastChat.status)
) {
shouldScroll = true;
}
if (Array.isArray(newChats) && Array.isArray(oldChats)) {
const newLastChat = newChats[newChats.length - 1];
const oldLastChat = oldChats[oldChats.length - 1];
if (newChats.length > oldChats.length) {
if (oldChats.length === 0 || newLastChat.id !== oldLastChat.id) {
shouldScroll = true;
}
} else if (newChats.length === oldChats.length && newChats.length > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

我理解改动的区别如下
image
我理解两者的效果是一致的?
或者可以提供一个复现的 demo 展示下修改前后的区别吗?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry I'm using version 2.68.4, it looks like this issue has been fixed in the new version, it was an oversight on my part not to notice, I'll switch off this pr

if (newLastChat.status !== 'complete' || newLastChat.status !== oldLastChat.status) {
shouldScroll = true;
}
}
}
}
if (newHints !== cacheHints) {
if (newHints.length > cacheHints.length) {
Expand Down
Loading