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