fix: react-markdown crash on code highlighting - threads switching do not take effect sometime #4216
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe Your Changes
This PR addresses an issue where ReactMarkdown could crash due to unsupported languages in code highlighting. This has been resolved in the newer version of the dependency.
Also fixed the issue where switching between new threads (very shorts) would not take effect
Fixes Issues
Changes made
The changes in the
git diff
are as follows:package.json
Update:rehype-highlight
package was updated from^6.0.0
to^7.0.1
in the project's dependencies.index.tsx
Code Modifications:Import Changes:
import { activeThreadAtom } from '@/helpers/atoms/Thread.atom'
.State and Effect Hook Adjustments:
currentThread
usinguseAtomValue
to get the value ofactiveThreadAtom
.useEffect
dependency and logic to includecurrentThread
. This ensures thatsetCurrent
is called if any message'sthread_id
does not matchcurrentThread?.id
.Virtual Row Key Adjustment:
virtualRow
fromvirtualRow.key
tomessages[virtualRow.index]?.id
. This provides a more consistent and relevant key based on the message ID.These changes aim to improve thread handling and ensure correct rendering of chat messages in the component.