fix: wrap SSE state updates in flushSync to resolve React error #418
This commit is contained in:
1 parent
cf89681576
commit
40a21ba767
1 file changed
+3
@@ -10,6 +10,7 @@ import {
|
|||||||
SearchX,
|
SearchX,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useCallback, useRef, useState } from "react";
|
import { useCallback, useRef, useState } from "react";
|
||||||
|
import { flushSync } from "react-dom";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { adminFetch } from "@/lib/admin-fetch";
|
import { adminFetch } from "@/lib/admin-fetch";
|
||||||
@@ -246,6 +247,7 @@ export function AuditClient() {
|
|||||||
try {
|
try {
|
||||||
const evt = JSON.parse(part.slice(6)) as AuditEvent;
|
const evt = JSON.parse(part.slice(6)) as AuditEvent;
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
if (evt.type === "progress") {
|
if (evt.type === "progress") {
|
||||||
setProgress(evt.message ?? "");
|
setProgress(evt.message ?? "");
|
||||||
}
|
}
|
||||||
@@ -320,6 +322,7 @@ export function AuditClient() {
|
|||||||
setProgress(`ERROR: ${evt.message ?? ""}`);
|
setProgress(`ERROR: ${evt.message ?? ""}`);
|
||||||
toast.error(evt.message ?? "Audit failed");
|
toast.error(evt.message ?? "Audit failed");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
} catch {
|
} catch {
|
||||||
// skip parse errors
|
// skip parse errors
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user