Repository navigation
fix: Custom background for conversations is not taking effect #7813
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,12 @@ const list = useConversationListStore() | |
| <!-- 只显示变体:仅 message-list,无 header、无 message-input(不发起对话)。 | ||
| 里面的 form 拿不到发送能力时自动只读。 --> | ||
| <main class="mk-conversation-main"> | ||
| <MessageList :key="list.currentChatId.value" :app-name="list.appInfo.value?.name || 'AI 助手'" /> | ||
| <!-- 聊天背景铺满消息区,与显示设置预览一致 --> | ||
| <div | ||
| class="flex-column min-h-0 flex-1 bg-cover bg-center" | ||
| :style="{ backgroundImage: list.appInfo.value?.chat_background ? `url(${JSON.stringify(list.appInfo.value.chat_background)})` : undefined }" | ||
| > | ||
| <MessageList :key="list.currentChatId.value" :app-name="list.appInfo.value?.name || 'AI 助手'" /> | ||
| </div> | ||
| </main> | ||
| </template> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is a review of the provided Vue code snippet, highlighting potential issues and optimization suggestions. 1. Critical Issue:
|
||
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.
Here are the findings regarding irregularities, potential issues, and optimization suggestions for the provided code snippet:
1. Potential Issue: Unnecessary Double Quotes in URL Generation
Problem:
Using
JSON.stringify()on thechat_backgroundstring wraps it in double quotes (e.g.,"http://example.com/image.jpg"). When interpolated into a CSSurl(), this results in:background-image: url("http://example.com/image.jpg")While many browsers handle this fine, it is redundant and potentially problematic if the underlying CSS parser is strict or if the string already contains escaped characters. It complicates potential future logic checking for specific protocols (like
data:).Suggestion:
Use the string directly without
JSON.stringify. Ensure the value is sanitized if it comes from user input to prevent CSS injection/XSS, though forurl(), risks are lower than inhref.2. Optimization: Conditional Style Object
Problem:
The inline style generates an object with
undefinedvalues when no background is set. While functional, creating a new object on every render can cause unnecessary re-renders or diffing overhead in some Vue configurations. A computed property or simpler ternary for the style object is cleaner.Suggestion:
Extract the background style logic into a computed property for better readability and performance.
3. Security Warning: Missing Validation/Sanitization
Problem:
If
list.appInfo.value.chat_backgroundcomes from user-configurable data (e.g., admin settings), inserting it directly into a CSSurl()context carries a minor risk if the value is malformed (e.g., containing)or breaking out of theurl()context, though modern CSP helps mitigate this).Suggestion:
Ensure
chat_backgroundis validated against allowed protocols (e.g., onlyhttps://,http://, ordata:image/) before rendering. If using Vue's:style, ensure the content is trusted.4. Layout/Rendering Note
Problem:
The comment says "background covers message area and input area," which is achieved by wrapping both in the
div. This looks correct for the layout intent. However, ifMessageListor<footer>have their own background colors (e.g., white), they will obscure the background image unless they are set to transparent (transparentorbg-transparent).Check:
Verify that child components (
<MessageList>,<MessageInput>) do not have opaque backgrounds defined in their scoped styles, or explicitly set them to transparent when a chat background is active.Recommended Refactored Code
Note: Added quotes around
${bg}inurl("${bg}")to safely handle spaces or special characters in filenames/URIs, which is best practice.