fix(web): resolve React #310 hook order crash in MessageList
Some checks failed
CI / test (push) Failing after 22s
Some checks failed
CI / test (push) Failing after 22s
- move forwardTargets useMemo above conditional early return - keep hooks call order stable after login/activeChat switch
This commit is contained in:
@@ -34,12 +34,6 @@ export function MessageList() {
|
|||||||
|
|
||||||
const messagesMap = useMemo(() => new Map(messages.map((m) => [m.id, m])), [messages]);
|
const messagesMap = useMemo(() => new Map(messages.map((m) => [m.id, m])), [messages]);
|
||||||
const activeChat = chats.find((chat) => chat.id === activeChatId);
|
const activeChat = chats.find((chat) => chat.id === activeChatId);
|
||||||
|
|
||||||
if (!activeChatId) {
|
|
||||||
return <div className="flex h-full items-center justify-center text-slate-300/80">Select a chat</div>;
|
|
||||||
}
|
|
||||||
const chatId = activeChatId;
|
|
||||||
|
|
||||||
const forwardTargets = useMemo(() => {
|
const forwardTargets = useMemo(() => {
|
||||||
const q = forwardQuery.trim().toLowerCase();
|
const q = forwardQuery.trim().toLowerCase();
|
||||||
if (!q) return chats;
|
if (!q) return chats;
|
||||||
@@ -50,6 +44,11 @@ export function MessageList() {
|
|||||||
});
|
});
|
||||||
}, [chats, forwardQuery]);
|
}, [chats, forwardQuery]);
|
||||||
|
|
||||||
|
if (!activeChatId) {
|
||||||
|
return <div className="flex h-full items-center justify-center text-slate-300/80">Select a chat</div>;
|
||||||
|
}
|
||||||
|
const chatId = activeChatId;
|
||||||
|
|
||||||
async function handleForward(targetChatId: number) {
|
async function handleForward(targetChatId: number) {
|
||||||
if (!forwardMessageId) return;
|
if (!forwardMessageId) return;
|
||||||
setIsForwarding(true);
|
setIsForwarding(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user