fix: keep canvas user message visible while pending
This commit is contained in:
parent
b17779e034
commit
f7676716bb
@ -7041,8 +7041,7 @@ export function CanvasChatPanel({
|
||||
inFlightRawChatIdRef.current = rawChatId;
|
||||
const launchUserMessageId = generateUUID();
|
||||
const launchCreatedAt = new Date();
|
||||
|
||||
sendMessage({
|
||||
const launchUserMessage = {
|
||||
id: launchUserMessageId,
|
||||
role: "user",
|
||||
parts,
|
||||
@ -7052,7 +7051,15 @@ export function CanvasChatPanel({
|
||||
composerMode: activeComposerModeRef.current || activeComposerMode,
|
||||
modelId: selectedModelId,
|
||||
},
|
||||
} as any);
|
||||
} as ChatMessage;
|
||||
|
||||
sendMessage(launchUserMessage as any);
|
||||
setMessages((previousMessages) =>
|
||||
sortCanvasMessagesByCreatedAt([
|
||||
...previousMessages.filter((message) => message.id !== launchUserMessageId),
|
||||
launchUserMessage,
|
||||
])
|
||||
);
|
||||
hasHydratedHistoryRef.current = true;
|
||||
|
||||
pendingLaunchRef.current = null;
|
||||
@ -7065,7 +7072,7 @@ export function CanvasChatPanel({
|
||||
if (editableDiv) {
|
||||
editableDiv.innerHTML = "";
|
||||
}
|
||||
}, [activeChatId, rawChatId, selectedModelId, status, sendMessage, clearSelection, launchAutoSendTick, activeComposerMode]);
|
||||
}, [activeChatId, rawChatId, selectedModelId, status, sendMessage, setMessages, clearSelection, launchAutoSendTick, activeComposerMode]);
|
||||
|
||||
// 当历史消息加载完成后,更新消息列表(支持同一会话的增量刷新)
|
||||
const loadedHistorySignatureRef = useRef<string>("");
|
||||
@ -7083,6 +7090,12 @@ export function CanvasChatPanel({
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const hasActiveRegularSubmission =
|
||||
inFlightChatIdRef.current === activeChatId ||
|
||||
inFlightRawChatIdRef.current === rawChatId;
|
||||
if (hasActiveRegularSubmission && !shouldForceHydrate) {
|
||||
return;
|
||||
}
|
||||
|
||||
const historyMessages = historyData.messages || [];
|
||||
const signature = buildCanvasHistoryMessagesSignature(rawChatId, historyMessages);
|
||||
@ -7112,7 +7125,7 @@ export function CanvasChatPanel({
|
||||
}
|
||||
};
|
||||
}
|
||||
}, [historyData, isClawdSubmitting, rawChatId, setMessages, status]);
|
||||
}, [activeChatId, historyData, isClawdSubmitting, rawChatId, setMessages, status]);
|
||||
|
||||
useEffect(() => {
|
||||
const streamState = streamImageGenerationStateByChatId[activeChatId];
|
||||
@ -10999,15 +11012,23 @@ export function CanvasChatPanel({
|
||||
});
|
||||
}
|
||||
|
||||
// 使用与 multimodal-input 相同的格式发送消息
|
||||
try {
|
||||
sendMessage({
|
||||
id: userMessageId,
|
||||
role: "user",
|
||||
parts: parts,
|
||||
createdAt: optimisticCreatedAt,
|
||||
metadata: optimisticUserMetadata,
|
||||
} as any);
|
||||
const optimisticUserMessage: ChatMessage = {
|
||||
id: userMessageId,
|
||||
role: "user",
|
||||
parts,
|
||||
createdAt: optimisticCreatedAt,
|
||||
metadata: optimisticUserMetadata,
|
||||
} as ChatMessage;
|
||||
|
||||
// 使用与 multimodal-input 相同的格式发送消息
|
||||
try {
|
||||
sendMessage(optimisticUserMessage as any);
|
||||
setMessages((previousMessages) =>
|
||||
sortCanvasMessagesByCreatedAt([
|
||||
...previousMessages.filter((message) => message.id !== userMessageId),
|
||||
optimisticUserMessage,
|
||||
])
|
||||
);
|
||||
} catch (error) {
|
||||
releaseSendGuard(activeChatId);
|
||||
if (shouldShowOptimisticImageGeneration) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user