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: react-markdown crash on code highlighting - threads switching do not take effect sometime #4216

Merged
merged 1 commit into from
Dec 4, 2024
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
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"react-icons": "^4.12.0",
"react-markdown": "^9.0.1",
"react-toastify": "^9.1.3",
"rehype-highlight": "^6.0.0",
"rehype-highlight": "^7.0.1",
"rehype-highlight-code-lines": "^1.0.4",
"rehype-katex": "^7.0.1",
"rehype-raw": "^7.0.0",
Expand Down
10 changes: 6 additions & 4 deletions web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,33 @@
import EmptyThread from './EmptyThread'

import { getCurrentChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom'
import { activeThreadAtom } from '@/helpers/atoms/Thread.atom'

const ChatConfigurator = memo(() => {
const messages = useAtomValue(getCurrentChatMessagesAtom)
const currentThread = useAtomValue(activeThreadAtom)

Check warning on line 21 in web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

20-21 lines are not covered with tests

const [current, setCurrent] = useState<ThreadMessage[]>([])
const loadModelError = useAtomValue(loadModelErrorAtom)

Check warning on line 24 in web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

23-24 lines are not covered with tests

const isMessagesIdentificial = (

Check warning on line 26 in web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

26 line is not covered with tests
arr1: ThreadMessage[],
arr2: ThreadMessage[]
): boolean => {
if (arr1.length !== arr2.length) return false
return arr1.every((item, index) => item.id === arr2[index].id)

Check warning on line 31 in web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

30-31 lines are not covered with tests
}

useEffect(() => {
if (

Check warning on line 35 in web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

34-35 lines are not covered with tests
messages?.length !== current?.length ||
!isMessagesIdentificial(messages, current)
!isMessagesIdentificial(messages, current) ||
messages.some((e) => e.thread_id !== currentThread?.id)

Check warning on line 37 in web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

37 line is not covered with tests
) {
setCurrent(messages)

Check warning on line 39 in web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

39 line is not covered with tests
}
}, [messages, current, loadModelError])
}, [messages, current, loadModelError, currentThread])

if (!messages.length) return <EmptyThread />

Check warning on line 43 in web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

43 line is not covered with tests
return (
<div className="flex h-full w-full flex-col">
<ChatBody loadModelError={loadModelError} messages={current} />
Expand All @@ -55,10 +57,10 @@
loadModelError?: string
}) => {
// The scrollable element for your list
const parentRef = useRef(null)

Check warning on line 60 in web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

60 line is not covered with tests

const count = useMemo(
() => (messages?.length ?? 0) + (loadModelError ? 1 : 0),

Check warning on line 63 in web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

62-63 lines are not covered with tests
[messages, loadModelError]
)

Expand Down Expand Up @@ -119,7 +121,7 @@
>
{items.map((virtualRow) => (
<div
key={virtualRow.key}
key={messages[virtualRow.index]?.id}
data-index={virtualRow.index}
ref={virtualizer.measureElement}
>
Expand Down
Loading