fix(sandbox): 修复 Markdown 编辑保存后内容被重置回原值
useArtifactContent 查询键含 publicShareCode(5 元素),而 onSuccess 的 setQueryData 仅用 4 元素,精确哈希不匹配导致写入幽灵缓存、真实缓存 仍为旧值;保存后 useEffect 据旧 content 重置 draftContent。改用 setQueriesData 前缀匹配命中真实缓存。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ce04f14f58
commit
2a2bb4d28e
1 file changed
+12
-2
@@ -133,8 +133,18 @@ export function useUpdateArtifactContent() {
|
|||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: updateArtifactContent,
|
mutationFn: updateArtifactContent,
|
||||||
onSuccess: (content, variables) => {
|
onSuccess: (content, variables) => {
|
||||||
queryClient.setQueryData(
|
// useArtifactContent 的查询键带第 5 个元素 publicShareCode,这里用前缀
|
||||||
["artifact", variables.filepath, variables.threadId, variables.isMock],
|
// 过滤(setQueriesData)匹配,避免精确键缺少 publicShareCode 写到幽灵缓存、
|
||||||
|
// 导致保存后内容被旧缓存重置回原值。
|
||||||
|
queryClient.setQueriesData(
|
||||||
|
{
|
||||||
|
queryKey: [
|
||||||
|
"artifact",
|
||||||
|
variables.filepath,
|
||||||
|
variables.threadId,
|
||||||
|
variables.isMock,
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
content,
|
content,
|
||||||
url: undefined,
|
url: undefined,
|
||||||
|
|||||||
Reference in new issue
Block a user