[Optimistic Updates] ArgumentValidationError: Value does not match validator.
I get with my implementation of the optimistic updates this error:
Code (I quadruple-checked it, and it has no type errors):
Error: [CONVEX M(messages:markMessageRead)] [Request ID: c6981e014a16ba01] Server Error
ArgumentValidationError: Value does not match validator.
Path: .messageId
Value: "5b234bb4-ce93-46d7-add3-448b90a09be9"
Validator: v.id("messages")
Called by clientError: [CONVEX M(messages:markMessageRead)] [Request ID: c6981e014a16ba01] Server Error
ArgumentValidationError: Value does not match validator.
Path: .messageId
Value: "5b234bb4-ce93-46d7-add3-448b90a09be9"
Validator: v.id("messages")
Called by clientCode (I quadruple-checked it, and it has no type errors):
const sendMessage = useMutation(
api.messages.createMessage,
).withOptimisticUpdate((localStore, args) => {
const chatId: Id<"privateChats"> = args.chatId as Id<"privateChats">;
const content = args.content;
const existingMessages = localStore.getQuery(api.messages.getMessages, {
chatId,
});
const existingChats = localStore.getQuery(api.chats.getChats);
// If we've loaded the api.messages.list query, push an optimistic message
// onto the list.
if (existingMessages !== undefined && existingChats && userInfo) {
const now = Date.now();
const newMessage: FunctionReturnType<
typeof api.messages.getMessages
>[number] = {
userId: undefined,
_id: crypto.randomUUID() as Id<"messages">,
_creationTime: now,
content,
deleted: false,
privateChatId: chatId,
from: userInfo,
readBy: [userInfo],
};
localStore.setQuery(api.messages.getMessages, { chatId }, [
...existingMessages,
newMessage,
]);
localStore.setQuery(
api.chats.getChats,
{},
existingChats.map((chat) => {
if (chat._id === chatId) {
return {
...chat,
lastMessage: {
...newMessage,
userId: userInfo._id,
},
};
} else {
return chat;
}
}),
);
}
});const sendMessage = useMutation(
api.messages.createMessage,
).withOptimisticUpdate((localStore, args) => {
const chatId: Id<"privateChats"> = args.chatId as Id<"privateChats">;
const content = args.content;
const existingMessages = localStore.getQuery(api.messages.getMessages, {
chatId,
});
const existingChats = localStore.getQuery(api.chats.getChats);
// If we've loaded the api.messages.list query, push an optimistic message
// onto the list.
if (existingMessages !== undefined && existingChats && userInfo) {
const now = Date.now();
const newMessage: FunctionReturnType<
typeof api.messages.getMessages
>[number] = {
userId: undefined,
_id: crypto.randomUUID() as Id<"messages">,
_creationTime: now,
content,
deleted: false,
privateChatId: chatId,
from: userInfo,
readBy: [userInfo],
};
localStore.setQuery(api.messages.getMessages, { chatId }, [
...existingMessages,
newMessage,
]);
localStore.setQuery(
api.chats.getChats,
{},
existingChats.map((chat) => {
if (chat._id === chatId) {
return {
...chat,
lastMessage: {
...newMessage,
userId: userInfo._id,
},
};
} else {
return chat;
}
}),
);
}
});