🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(chat): remove blank space around images in user messages (#21408)
AmAzing-187b2311df71
diff --git a/src/components/ImageItem/index.tsx b/src/components/ImageItem/index.tsxindex 2d4e5be055e..409cfa453c4 100644--- a/src/components/ImageItem/index.tsx+++ b/src/components/ImageItem/index.tsx@@ -93,6 +93,9 @@ const ImageItem = memo<ImageItemProps>(style={{aspectRatio,height: aspectRatio || isSafari ? 'auto' : '100%',+ // the grid's min-height and row stretch would push wide images past their ratio, leaving a blank strip+ alignSelf: aspectRatio ? 'start' : undefined,+ minHeight: aspectRatio ? 'auto' : undefined,width: '100%',...style,}}diff --git a/src/features/Conversation/Messages/User/components/MessageContent.test.tsx b/src/features/Conversation/Messages/User/components/MessageContent.test.tsxindex 456e8315258..5fe45fdd48a 100644--- a/src/features/Conversation/Messages/User/components/MessageContent.test.tsx+++ b/src/features/Conversation/Messages/User/components/MessageContent.test.tsx@@ -65,10 +65,16 @@ describe('User MessageContent', () => {<MessageContentcontent={'markdown-content'}createdAt={Date.now()}- editorData={{ root: { children: [], type: 'root', version: 1 } }}id={'msg-1'}role={'user'}updatedAt={Date.now()}+ editorData={{+ root: {+ children: [{ children: [{ text: 'rich', type: 'text' }], type: 'paragraph' }],+ type: 'root',+ version: 1,+ },+ }}/>,);@@ -76,6 +82,26 @@ describe('User MessageContent', () => {expect(screen.queryByTestId('markdown-message')).not.toBeInTheDocument();});+ /**+ * Regression: an image-only message persists the composer's empty paragraph,+ * which rendered a blank line above the images.+ */+ it('should not render a text body for an empty editor paragraph', () => {+ render(+ <MessageContent+ content={''}+ createdAt={Date.now()}+ editorData={{ root: { children: [{ children: [], type: 'paragraph' }], type: 'root' } }}+ id={'msg-image-only'}+ role={'user'}+ updatedAt={Date.now()}+ />,+ );++ expect(screen.queryByTestId('rich-message')).not.toBeInTheDocument();+ expect(screen.queryByTestId('markdown-message')).not.toBeInTheDocument();+ });+it('should render markdown when editorData is missing', () => {render(<MessageContentdiff --git a/src/features/Conversation/Messages/User/components/MessageContent.tsx b/src/features/Conversation/Messages/User/components/MessageContent.tsxindex c288e37b224..199f41e881c 100644--- a/src/features/Conversation/Messages/User/components/MessageContent.tsx+++ b/src/features/Conversation/Messages/User/components/MessageContent.tsx@@ -9,6 +9,7 @@ import { splitReferencedMessage } from '@/store/chat/utils/parseReferencedMessagimport { type UIChatMessage } from '@/types/index';import { useStartTopicConversation } from '../../../hooks/useStartTopicConversation';+import { hasRenderableEditorData } from '../editorData';import { useMarkdown } from '../useMarkdown';import AudioFileListViewer from './AudioFileListViewer';import FileListViewer from './FileListViewer';@@ -34,8 +35,7 @@ const UserMessageContent = memo<UIChatMessage>(return { displayContent: body, reference };}, [content]);- const hasEditorData =- editorData && typeof editorData === 'object' && Object.keys(editorData).length > 0;+ const hasEditorData = hasRenderableEditorData(editorData);const textBody = hasEditorData ? (// Rich-text folder chips render headlessly, so they receive thediff --git a/src/features/Conversation/Messages/User/editorData.test.ts b/src/features/Conversation/Messages/User/editorData.test.tsnew file mode 100644index 00000000000..188ea778d10--- /dev/null+++ b/src/features/Conversation/Messages/User/editorData.test.ts@@ -0,0 +1,32 @@+import { describe, expect, it } from 'vitest';++import { hasRenderableEditorData } from './editorData';++const paragraph = (children: unknown[] = []) => ({ children, type: 'paragraph' });+const state = (...blocks: unknown[]) => ({ root: { children: blocks, type: 'root' } });++describe('hasRenderableEditorData', () => {+ /**+ * Regression: an image-only message persists the composer's empty paragraph,+ * which rendered a blank line above the images.+ */+ it('treats empty paragraphs as nothing to render', () => {+ expect(hasRenderableEditorData(state(paragraph()))).toBe(false);+ expect(hasRenderableEditorData(state(paragraph(), paragraph()))).toBe(false);+ });++ it('renders paragraphs with inline nodes', () => {+ expect(hasRenderableEditorData(state(paragraph([{ text: 'hi', type: 'text' }])))).toBe(true);+ expect(hasRenderableEditorData(state(paragraph([{ type: 'mention' }])))).toBe(true);+ });++ it('renders non-paragraph blocks even when they have no children', () => {+ expect(hasRenderableEditorData(state(paragraph(), { type: 'horizontalrule' }))).toBe(true);+ });++ it('rejects missing or malformed state', () => {+ expect(hasRenderableEditorData(undefined)).toBe(false);+ expect(hasRenderableEditorData({})).toBe(false);+ expect(hasRenderableEditorData({ root: {} })).toBe(false);+ });+});diff --git a/src/features/Conversation/Messages/User/editorData.ts b/src/features/Conversation/Messages/User/editorData.tsnew file mode 100644index 00000000000..70bc0e75422--- /dev/null+++ b/src/features/Conversation/Messages/User/editorData.ts@@ -0,0 +1,16 @@+/**+ * Whether a persisted Lexical editor state has anything to render. Sending only+ * attachments still saves the composer's empty paragraph, which would render as+ * a blank line above the images.+ */+export const hasRenderableEditorData = (editorData: unknown): boolean => {+ if (!editorData || typeof editorData !== 'object') return false;++ const blocks = (editorData as { root?: { children?: unknown } }).root?.children;+ if (!Array.isArray(blocks)) return false;++ return blocks.some(+ (block) =>+ block?.type !== 'paragraph' || (Array.isArray(block.children) && block.children.length > 0),+ );+};