TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed
Unanswered
Sloth bear posted this in #help-forum
Sloth bearOP
I don't understand the essence of the problem, my program is safe, there are no bugs, and when it is built there are no problems either, but this always appears, when executing this code:
const handleNavigation = (e: MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => {
e.stopPropagation()
if (isPending) return;
window.location.href = `/${dataNotification.sourceUser?.username}`
// Kode ini di bawah sini. cmiiw.
if (!dataNotification.isRead) {
startTransition(() => {
markAsReadNotification(dataNotification.id, path)
})
}
}
export const markAsReadNotification = async (
notificationId: string,
path: string
) => {
if (!notificationId) throw new Error("notificationId required");
if (!path) throw new Error("path required");
try {
await prisma.notification.update({
where: { id: notificationId },
data: {
isRead: true,
},
});
} catch (error) {
console.info("[ERROR_MARK_AS_READ_NOTIFICATION]", error);
} finally {
revalidatePath(path);
}
};3 Replies
Standard Chinchilla
I have the same error and I'm almost sure it happens on the server
Standard Chinchilla
@Sloth bear I don't understand the essence of the problem, my program is safe, there are no bugs, and when it is built there are no problems either, but this always appears, when executing this code:
js
const handleNavigation = (e: MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => {
e.stopPropagation()
if (isPending) return;
window.location.href = `/${dataNotification.sourceUser?.username}`
// Kode ini di bawah sini. cmiiw.
if (!dataNotification.isRead) {
startTransition(() => {
markAsReadNotification(dataNotification.id, path)
})
}
}
export const markAsReadNotification = async (
notificationId: string,
path: string
) => {
if (!notificationId) throw new Error("notificationId required");
if (!path) throw new Error("path required");
try {
await prisma.notification.update({
where: { id: notificationId },
data: {
isRead: true,
},
});
} catch (error) {
console.info("[ERROR_MARK_AS_READ_NOTIFICATION]", error);
} finally {
revalidatePath(path);
}
};
i encounter this error a few times in random unreproducible scenarios, i just rm -rf .next and it goes away