fix(room): hoist mentionConfirmRef to module scope to fix TDZ error

ChatInputArea is defined before RoomChatPanel in the file, so its JSX
runs before mentionConfirmRef is declared inside RoomChatPanel. Moving the
ref to module level ensures it's initialized before either component renders.
This commit is contained in:
ZhenYi 2026-04-18 00:17:47 +08:00
parent 14bcc04991
commit 13f5ff328c

View File

@ -29,6 +29,8 @@ import { RoomThreadPanel } from './RoomThreadPanel';
const MENTION_PATTERN = /@([^:@\s]*)(:([^\s]*))?$/; const MENTION_PATTERN = /@([^:@\s]*)(:([^\s]*))?$/;
const MENTION_POPOVER_KEYS = ['Enter', 'Tab', 'ArrowUp', 'ArrowDown']; const MENTION_POPOVER_KEYS = ['Enter', 'Tab', 'ArrowUp', 'ArrowDown'];
/** Module-level ref shared between ChatInputArea (writes) and RoomChatPanel (reads) */
const mentionConfirmRef = { current: (() => {}) as () => void };
export interface ChatInputAreaHandle { export interface ChatInputAreaHandle {
insertMention: (id: string, label: string, type: 'user' | 'ai') => void; insertMention: (id: string, label: string, type: 'user' | 'ai') => void;
@ -283,8 +285,6 @@ export function RoomChatPanel({ room, isAdmin, onClose, onDelete }: RoomChatPane
const messagesEndRef = useRef<HTMLDivElement>(null); const messagesEndRef = useRef<HTMLDivElement>(null);
const chatInputRef = useRef<ChatInputAreaHandle>(null); const chatInputRef = useRef<ChatInputAreaHandle>(null);
/** Shared ref: MentionPopover writes the confirm fn here; ChatInputArea reads and calls it */
const mentionConfirmRef = useRef<() => void>(() => {});
const [replyingTo, setReplyingTo] = useState<MessageWithMeta | null>(null); const [replyingTo, setReplyingTo] = useState<MessageWithMeta | null>(null);
const [editingMessage, setEditingMessage] = useState<MessageWithMeta | null>(null); const [editingMessage, setEditingMessage] = useState<MessageWithMeta | null>(null);