Skip to content

🤯 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.

🐛 fix(chat): prevent mobile input auto-zoom (#17013)

H-TTTTTea6b92fadcfa
diff --git a/src/features/ChatInput/InputEditor/index.test.tsx b/src/features/ChatInput/InputEditor/index.test.tsx
index a0d01e52fa9..a2ad48c5418 100644
--- a/src/features/ChatInput/InputEditor/index.test.tsx
+++ b/src/features/ChatInput/InputEditor/index.test.tsx
@@ -7,6 +7,10 @@ const permission = vi.hoisted(() => ({
allowed: false,
}));
+const platform = vi.hoisted(() => ({
+ isMobile: false,
+}));
+
const mocks = vi.hoisted(() => {
const chatInputState = {
clearInputCompletionError: vi.fn(() => {
@@ -62,6 +66,16 @@ const getAutoCompleteProps = async (): Promise<AutoCompleteProps> => {
return autoCompleteProps!;
};
+const getEditorStyle = async () => {
+ const { Editor } = await import('@lobehub/editor/react');
+ const props = vi.mocked(Editor).mock.lastCall?.[0] as
+ { style?: { fontSize?: number } } | undefined;
+
+ expect(props).toBeDefined();
+
+ return props!.style;
+};
+
vi.mock('@lobechat/const', () => ({
isDesktop: false,
TRACING_SCENARIOS: { InputCompletion: 'input_completion' },
@@ -148,6 +162,10 @@ vi.mock('@/store/chat', () => ({
getState: () => ({ activeTopicId: undefined }),
}),
}));
+vi.mock('@/store/serverConfig', () => ({
+ useServerConfigStore: <T,>(selector: StoreSelector<T>) =>
+ selector({ isMobile: platform.isMobile }),
+}));
vi.mock('../hooks/useChatInputDraft', () => ({
useChatInputDraft: () => ({ restoreDraft: vi.fn(), saveDraftDebounced: vi.fn() }),
}));
@@ -232,6 +250,7 @@ describe('ChatInput InputEditor', () => {
beforeEach(() => {
vi.clearAllMocks();
permission.allowed = false;
+ platform.isMobile = false;
mocks.inputCompletionConfig.enabled = false;
mocks.inputCompletionConfig.model = 'gpt-4o-mini';
mocks.inputCompletionConfig.provider = 'openai';
@@ -252,6 +271,23 @@ describe('ChatInput InputEditor', () => {
expect(screen.getByTestId('mock-editor')).toHaveAttribute('data-editable', 'false');
});
+ it('renders the editor at 16px on mobile', async () => {
+ permission.allowed = true;
+ platform.isMobile = true;
+
+ render(<InputEditor />);
+
+ expect((await getEditorStyle())?.fontSize).toBe(16);
+ });
+
+ it('keeps the editor font size unchanged on desktop', async () => {
+ permission.allowed = true;
+
+ render(<InputEditor />);
+
+ expect((await getEditorStyle())?.fontSize).toBeUndefined();
+ });
+
it('pauses autocomplete after a non-abort generation error', async () => {
permission.allowed = true;
mocks.inputCompletionConfig.enabled = true;
diff --git a/src/features/ChatInput/InputEditor/index.tsx b/src/features/ChatInput/InputEditor/index.tsx
index 574e8369148..ce0d0645fe7 100644
--- a/src/features/ChatInput/InputEditor/index.tsx
+++ b/src/features/ChatInput/InputEditor/index.tsx
@@ -26,6 +26,7 @@ import { aiChatService } from '@/services/aiChat';
import { useAgentStore } from '@/store/agent';
import { agentByIdSelectors } from '@/store/agent/selectors';
import { useChatStore } from '@/store/chat';
+import { useServerConfigStore } from '@/store/serverConfig';
import { useUserStore } from '@/store/user';
import {
labPreferSelectors,
@@ -81,6 +82,7 @@ const InputEditor = memo<{
placeholderVariant?: PlaceholderVariant;
}>(({ defaultRows = 2, placeholder, placeholderVariant }) => {
const { t } = useTranslation('chat');
+ const mobile = useServerConfigStore((s) => s.isMobile);
const [
editor,
slashMenuRef,
@@ -564,6 +566,7 @@ const InputEditor = memo<{
)
}
style={{
+ fontSize: mobile ? 16 : undefined,
minHeight: defaultRows > 1 ? defaultRows * 23 : undefined,
}}
onCompositionEnd={({ event }) => compositionProps.onCompositionEnd(event)}