Updated markdown libraries and fixed breaking changes and type issues
Summary:
This PR updates the markdown-related libraries (react-markdown, remark-gfm, and remark-math) and addresses the resulting breaking changes caused by the upgrades. Fixes #414.
Changes:
-
Inline vs Block Code Handling:
- The
inlineprop is no longer passed byreact-markdown(v9.x+). We now determine whether a code block is inline by checking for the absence of aclassNameattribute. - Added a fallback class
"inline-code"for inline code blocks to maintain consistent styling.
- The
-
Safe Access to
childrenProp:- Added safety checks to ensure that
childrenis defined, is an array, and handled correctly (e.g., checkingchildren.lengthor replacing its first element). This avoids potential runtime errors wherechildrencould be null or undefined. - Adjusted the handling of
childrenand other props to conform to strict type checking, ensuring that we account for possible null or undefined values in rendering components.
- Added safety checks to ensure that
-
Special Character Handling:
- Retained logic to replace occurrences of
▍with a pulse animation for custom rendering, ensuring compatibility with the updatedreact-markdownbehavior. - Safeguarded this replacement logic by first checking that
children[0]exists and is a string.
- Retained logic to replace occurrences of
Affected Files:
components/stocks/message.tsx: Fixed handling of inline vs block code and added null checks forchildren.components/chat-message.tsx(although unused): Applied similar fixes to handle breaking changes fromreact-markdownand ensure type safety so that build would not fail since this file is included.
Testing:
- Successfully built the project after applying changes.
- Verified correct rendering of both inline and block code snippets in user and bot messages.
Someone is attempting to deploy a commit to the Uncurated Tests Team on Vercel.
A member of the Team first needs to authorize it.
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
| Package | New capabilities | Transitives | Size | Publisher |
|---|---|---|---|---|
| npm/[email protected] | Transitive: environment | +80 |
2.61 MB | wooorm |
| npm/[email protected] | Transitive: environment | +67 |
2.34 MB | wooorm |
| npm/[email protected] | Transitive: environment, filesystem, shell | +55 |
6 MB | wooorm |
🚮 Removed packages: npm/[email protected]), npm/[email protected]), npm/[email protected])
Should be resolved by implementation of Streamdown