-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New option to disable rendering of user message markdown #2726
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
base: main
Are you sure you want to change the base?
New option to disable rendering of user message markdown #2726
Conversation
|
|
||
| const videoExtensions = ['.mp4', '.webm', '.mov', '.avi', '.ogv', '.m4v']; | ||
| const isVideo = videoExtensions.some(ext => | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to include this to pass the linter checks.
| isLoading | ||
| } = useApi<IThread>( | ||
| id ? (isSharedRoute ? `/project/share/${id}` : `/project/thread/${id}`) : null, | ||
| id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to include this to pass the linter checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 issues found across 12 files
Prompt for AI agents (all 4 issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="frontend/src/components/chat/Messages/Message/Content/index.tsx">
<violation number="1" location="frontend/src/components/chat/Messages/Message/Content/index.tsx:19">
P1: The new `renderMarkdown` prop is not included in the `memo` comparison function. When `renderMarkdown` changes, the component won't re-render because the custom comparison function doesn't check this prop. Add `prevProps.renderMarkdown === nextProps.renderMarkdown &&` to the comparison function.</violation>
</file>
<file name="frontend/src/components/Markdown.tsx">
<violation number="1" location="frontend/src/components/Markdown.tsx:102">
P1: Using `!renderMarkdown` will skip markdown rendering when the prop is `undefined` (not passed), breaking backward compatibility. Existing callers that don't pass this prop will now get plain text instead of rendered markdown.
Use strict equality `renderMarkdown === false` to only skip markdown when explicitly disabled, preserving the default markdown behavior.</violation>
</file>
<file name="frontend/src/components/chat/MessagesContainer/index.tsx">
<violation number="1" location="frontend/src/components/chat/MessagesContainer/index.tsx:127">
P1: Missing `config?.features?.user_message_markdown` in the `useMemo` dependency array. If this config value changes, the memoized context won't update, causing stale `renderUserMarkdown` values to be passed to children. Add it to the dependency array like `unsafe_allow_html` is handled.</violation>
</file>
<file name="frontend/src/components/ReadOnlyThread.tsx">
<violation number="1" location="frontend/src/components/ReadOnlyThread.tsx:160">
P2: Missing `config?.features?.user_message_markdown` in the `useMemo` dependency array. If this config value changes, the memoized context won't update, causing stale `renderMarkdown` values to be used.</violation>
</file>
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
| }: Props) => { | ||
| const apiClient = useContext(ChainlitContext); | ||
|
|
||
| if (!renderMarkdown) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Using !renderMarkdown will skip markdown rendering when the prop is undefined (not passed), breaking backward compatibility. Existing callers that don't pass this prop will now get plain text instead of rendered markdown.
Use strict equality renderMarkdown === false to only skip markdown when explicitly disabled, preserving the default markdown behavior.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At frontend/src/components/Markdown.tsx, line 102:
<comment>Using `!renderMarkdown` will skip markdown rendering when the prop is `undefined` (not passed), breaking backward compatibility. Existing callers that don't pass this prop will now get plain text instead of rendered markdown.
Use strict equality `renderMarkdown === false` to only skip markdown when explicitly disabled, preserving the default markdown behavior.</comment>
<file context>
@@ -91,12 +92,24 @@ const cursorPlugin = () => {
}: Props) => {
const apiClient = useContext(ChainlitContext);
+ if (!renderMarkdown) {
+ return (
+ <pre
</file context>
| if (!renderMarkdown) { | |
| if (renderMarkdown === false) { |
| askUser, | ||
| allowHtml: config?.features?.unsafe_allow_html, | ||
| latex: config?.features?.latex, | ||
| renderUserMarkdown: config?.features?.user_message_markdown, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Missing config?.features?.user_message_markdown in the useMemo dependency array. If this config value changes, the memoized context won't update, causing stale renderUserMarkdown values to be passed to children. Add it to the dependency array like unsafe_allow_html is handled.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At frontend/src/components/chat/MessagesContainer/index.tsx, line 127:
<comment>Missing `config?.features?.user_message_markdown` in the `useMemo` dependency array. If this config value changes, the memoized context won't update, causing stale `renderUserMarkdown` values to be passed to children. Add it to the dependency array like `unsafe_allow_html` is handled.</comment>
<file context>
@@ -124,6 +124,7 @@ const MessagesContainer = ({ navigate }: Props) => {
askUser,
allowHtml: config?.features?.unsafe_allow_html,
latex: config?.features?.latex,
+ renderUserMarkdown: config?.features?.user_message_markdown,
editable: !!config?.features.edit_message,
loading,
</file context>
| return { | ||
| allowHtml: config?.features?.unsafe_allow_html, | ||
| latex: config?.features?.latex, | ||
| renderMarkdown: config?.features?.user_message_markdown, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Missing config?.features?.user_message_markdown in the useMemo dependency array. If this config value changes, the memoized context won't update, causing stale renderMarkdown values to be used.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At frontend/src/components/ReadOnlyThread.tsx, line 160:
<comment>Missing `config?.features?.user_message_markdown` in the `useMemo` dependency array. If this config value changes, the memoized context won't update, causing stale `renderMarkdown` values to be used.</comment>
<file context>
@@ -153,6 +157,7 @@ const ReadOnlyThread = ({ id }: Props) => {
return {
allowHtml: config?.features?.unsafe_allow_html,
latex: config?.features?.latex,
+ renderMarkdown: config?.features?.user_message_markdown,
editable: false,
loading: false,
</file context>
For a user message like this:
By default, Chainlit renders them as markdown:
This can lead to confusion. With the new user_message_markdown option set to false, such messages render as sent by the user:
Summary by cubic
Adds a config option to control markdown rendering for user messages. When disabled, user messages render as plain text to avoid confusing formatting.
New Features
Migration
Written for commit e7ddf30. Summary will update automatically on new commits.