Next.js Discord

Discord Forum

TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed

Unanswered
Sloth bear posted this in #help-forum
Open in Discord
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