🤯 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(input): revert #11755 to fix chat input unfocus (#11764)
Arvin Xu90ecaf6bc00f
diff --git a/src/app/[variants]/(main)/agent/cron/[cronId]/features/CronJobContentEditor.tsx b/src/app/[variants]/(main)/agent/cron/[cronId]/features/CronJobContentEditor.tsxindex 8f8748f488d..694abebdd51 100644--- a/src/app/[variants]/(main)/agent/cron/[cronId]/features/CronJobContentEditor.tsx+++ b/src/app/[variants]/(main)/agent/cron/[cronId]/features/CronJobContentEditor.tsx@@ -11,7 +11,7 @@ import { Editor, useEditor } from '@lobehub/editor/react';import { Flexbox, Icon, Text } from '@lobehub/ui';import { Card } from 'antd';import { Clock } from 'lucide-react';-import { type RefObject, memo, useCallback, useEffect, useRef } from 'react';+import { memo, useCallback, useEffect, useRef } from 'react';import { useTranslation } from 'react-i18next';interface CronJobContentEditorProps {@@ -20,12 +20,8 @@ interface CronJobContentEditorProps {onChange: (value: string) => void;}-interface CronJobContentEditorInnerProps extends CronJobContentEditorProps {- contentRef: RefObject<string>;-}--const CronJobContentEditorInner = memo<CronJobContentEditorInnerProps>(- ({ enableRichRender, initialValue, onChange, contentRef }) => {+const CronJobContentEditor = memo<CronJobContentEditorProps>(+ ({ enableRichRender, initialValue, onChange }) => {const { t } = useTranslation('setting');const editor = useEditor();const currentValueRef = useRef(initialValue);@@ -35,6 +31,23 @@ const CronJobContentEditorInner = memo<CronJobContentEditorInnerProps>(currentValueRef.current = initialValue;}, [initialValue]);+ // Initialize editor content when editor is ready+ useEffect(() => {+ if (!editor) return;+ try {+ setTimeout(() => {+ if (initialValue) {+ editor.setDocument(enableRichRender ? 'markdown' : 'text', initialValue);+ }+ }, 100);+ } catch (error) {+ console.error('[CronJobContentEditor] Failed to initialize editor content:', error);+ setTimeout(() => {+ editor.setDocument(enableRichRender ? 'markdown' : 'text', initialValue);+ }, 100);+ }+ }, [editor, enableRichRender, initialValue]);+// Handle content changesconst handleContentChange = useCallback((e: any) => {@@ -44,18 +57,13 @@ const CronJobContentEditorInner = memo<CronJobContentEditorInnerProps>(const finalContent = nextContent || '';- // Save to parent ref for restoration- if (contentRef) {- (contentRef as { current: string }).current = finalContent;- }-// Only call onChange if content actually changedif (finalContent !== currentValueRef.current) {currentValueRef.current = finalContent;onChange(finalContent);}},- [enableRichRender, onChange, contentRef],+ [enableRichRender, onChange],);return (@@ -74,14 +82,6 @@ const CronJobContentEditorInner = memo<CronJobContentEditorInnerProps>(content={''}editor={editor}lineEmptyPlaceholder={t('agentCronJobs.form.content.placeholder')}- onInit={(editor) => {- // Restore content from parent ref when editor re-initializes- if (contentRef?.current) {- editor.setDocument(enableRichRender ? 'markdown' : 'text', contentRef.current);- } else if (initialValue) {- editor.setDocument(enableRichRender ? 'markdown' : 'text', initialValue);- }- }}onTextChange={handleContentChange}placeholder={t('agentCronJobs.form.content.placeholder')}plugins={@@ -108,17 +108,4 @@ const CronJobContentEditorInner = memo<CronJobContentEditorInnerProps>(},);-const CronJobContentEditor = (props: CronJobContentEditorProps) => {- // Ref to persist content across re-mounts when enableRichRender changes- const contentRef = useRef<string>(props.initialValue);-- return (- <CronJobContentEditorInner- contentRef={contentRef}- key={`editor-${props.enableRichRender}`}- {...props}- />- );-};-export default CronJobContentEditor;diff --git a/src/features/ChatInput/ChatInputProvider.tsx b/src/features/ChatInput/ChatInputProvider.tsxindex 33dddd18174..ff6029d34e5 100644--- a/src/features/ChatInput/ChatInputProvider.tsx+++ b/src/features/ChatInput/ChatInputProvider.tsx@@ -1,8 +1,5 @@import { useEditor } from '@lobehub/editor/react';-import { type MutableRefObject, type ReactNode, memo, useRef } from 'react';--import { useUserStore } from '@/store/user';-import { labPreferSelectors } from '@/store/user/selectors';+import { type ReactNode, memo, useRef } from 'react';import StoreUpdater, { type StoreUpdaterProps } from './StoreUpdater';import { Provider, createStore } from './store';@@ -11,16 +8,10 @@ interface ChatInputProviderProps extends StoreUpdaterProps {children: ReactNode;}-interface ChatInputProviderInnerProps extends StoreUpdaterProps {- children: ReactNode;- contentRef: MutableRefObject<string>;-}--const ChatInputProviderInner = memo<ChatInputProviderInnerProps>(+export const ChatInputProvider = memo<ChatInputProviderProps>(({agentId,children,- contentRef,leftActions,rightActions,mobile,@@ -40,7 +31,6 @@ const ChatInputProviderInner = memo<ChatInputProviderInnerProps>(createStore={() =>createStore({allowExpand,- contentRef,editor,leftActions,mentionItems,@@ -70,13 +60,3 @@ const ChatInputProviderInner = memo<ChatInputProviderInnerProps>();},);--export const ChatInputProvider = (props: ChatInputProviderProps) => {- const enableRichRender = useUserStore(labPreferSelectors.enableInputMarkdown);- // Ref to persist content across re-mounts when enableRichRender changes- const contentRef = useRef<string>('');-- return (- <ChatInputProviderInner contentRef={contentRef} key={`editor-${enableRichRender}`} {...props} />- );-};diff --git a/src/features/ChatInput/InputEditor/index.tsx b/src/features/ChatInput/InputEditor/index.tsxindex 2441836a54c..3cfb467f8c6 100644--- a/src/features/ChatInput/InputEditor/index.tsx+++ b/src/features/ChatInput/InputEditor/index.tsx@@ -37,7 +37,7 @@ const className = cx(css``);const InputEditor = memo<{ defaultRows?: number }>(({ defaultRows = 2 }) => {- const [editor, slashMenuRef, send, updateMarkdownContent, expand, mentionItems, contentRef] =+ const [editor, slashMenuRef, send, updateMarkdownContent, expand, mentionItems] =useChatInputStore((s) => [s.editor,s.slashMenuRef,@@ -45,7 +45,6 @@ const InputEditor = memo<{ defaultRows?: number }>(({ defaultRows = 2 }) => {s.updateMarkdownContent,s.expand,s.mentionItems,- s.contentRef,]);const storeApi = useStoreApi();@@ -152,11 +151,7 @@ const InputEditor = memo<{ defaultRows?: number }>(({ defaultRows = 2 }) => {onBlur={() => {disableScope(HotkeyEnum.AddUserMessage);}}- onChange={(e) => {- // Save content to parent ref for restoration when enableRichRender changes- if (contentRef) {- contentRef.current = e.getDocument('markdown') as unknown as string;- }+ onChange={() => {updateMarkdownContent();}}onCompositionEnd={() => {@@ -182,13 +177,7 @@ const InputEditor = memo<{ defaultRows?: number }>(({ defaultRows = 2 }) => {onFocus={() => {enableScope(HotkeyEnum.AddUserMessage);}}- onInit={(editor) => {- storeApi.setState({ editor });- // Restore content from parent ref when editor re-initializes- if (contentRef?.current) {- editor.setDocument('markdown', contentRef.current);- }- }}+ onInit={(editor) => storeApi.setState({ editor })}onPressEnter={({ event: e }) => {if (e.shiftKey || isChineseInput.current) return;// when user like alt + enter to add ai messagediff --git a/src/features/ChatInput/store/initialState.ts b/src/features/ChatInput/store/initialState.tsindex dfd52c94424..010a54e82eb 100644--- a/src/features/ChatInput/store/initialState.ts+++ b/src/features/ChatInput/store/initialState.ts@@ -1,7 +1,6 @@import { type IEditor, type SlashOptions } from '@lobehub/editor';import type { ChatInputProps } from '@lobehub/editor/react';import type { MenuProps } from '@lobehub/ui';-import type { MutableRefObject } from 'react';import { type ActionKeys } from '@/features/ChatInput';@@ -40,7 +39,6 @@ export interface PublicState {}export interface State extends PublicState {- contentRef?: MutableRefObject<string>;editor?: IEditor;isContentEmpty: boolean;markdownContent: string;