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
+69
-66
@@ -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,80 +247,82 @@ export function AuditClient() {
|
|||||||
try {
|
try {
|
||||||
const evt = JSON.parse(part.slice(6)) as AuditEvent;
|
const evt = JSON.parse(part.slice(6)) as AuditEvent;
|
||||||
|
|
||||||
if (evt.type === "progress") {
|
flushSync(() => {
|
||||||
setProgress(evt.message ?? "");
|
if (evt.type === "progress") {
|
||||||
}
|
setProgress(evt.message ?? "");
|
||||||
|
}
|
||||||
|
|
||||||
if (evt.type === "items_loaded") {
|
if (evt.type === "items_loaded") {
|
||||||
setProgress(`Loaded ${evt.total} items_base entries`);
|
setProgress(`Loaded ${evt.total} items_base entries`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evt.type === "catalog_loaded") {
|
if (evt.type === "catalog_loaded") {
|
||||||
setProgress(`Loaded ${evt.total} catalog_items entries`);
|
setProgress(`Loaded ${evt.total} catalog_items entries`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evt.type === "checking") {
|
if (evt.type === "checking") {
|
||||||
setProgress(`Checking ${evt.section}…`);
|
setProgress(`Checking ${evt.section}…`);
|
||||||
if (evt.total) {
|
if (evt.total) {
|
||||||
setCheckProgress({
|
setCheckProgress({
|
||||||
section: evt.section ?? "",
|
section: evt.section ?? "",
|
||||||
current: evt.current ?? 0,
|
current: evt.current ?? 0,
|
||||||
total: evt.total,
|
total: evt.total,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (evt.type === "repair_complete") {
|
||||||
|
if (evt.repair) setRepairStats(evt.repair);
|
||||||
|
if (evt.repairNitro) setNitroRepairStats(evt.repairNitro);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (evt.type === "sql_ready") {
|
||||||
|
setSqlText(evt.sql ?? null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (evt.type === "sql_applied") {
|
||||||
|
setSqlApplied({
|
||||||
|
applied: evt.applied ?? 0,
|
||||||
|
failed: evt.sqlFailed ?? 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (evt.type === "repair_complete") {
|
if (evt.type === "furnidata_repair_complete") {
|
||||||
if (evt.repair) setRepairStats(evt.repair);
|
if (evt.furniData) setFurniDataResult(evt.furniData);
|
||||||
if (evt.repairNitro) setNitroRepairStats(evt.repairNitro);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (evt.type === "sql_ready") {
|
|
||||||
setSqlText(evt.sql ?? null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (evt.type === "sql_applied") {
|
|
||||||
setSqlApplied({
|
|
||||||
applied: evt.applied ?? 0,
|
|
||||||
failed: evt.sqlFailed ?? 0,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (evt.type === "furnidata_repair_complete") {
|
|
||||||
if (evt.furniData) setFurniDataResult(evt.furniData);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (evt.type === "structure_repair_complete") {
|
|
||||||
if (evt.structure) setStructureResult(evt.structure);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (evt.type === "batch_complete") {
|
|
||||||
setIssues(evt.issues ?? []);
|
|
||||||
setMissingFromSources(evt.missingFromSources ?? []);
|
|
||||||
if (evt.summary) setSummary(evt.summary);
|
|
||||||
setCheckProgress(null);
|
|
||||||
setProgress("Done");
|
|
||||||
if (
|
|
||||||
evt.issues &&
|
|
||||||
evt.issues.filter((i) => i.severity === "error").length > 0
|
|
||||||
) {
|
|
||||||
toast.error(
|
|
||||||
`${evt.issues.filter((i) => i.severity === "error").length} error(s) found`,
|
|
||||||
);
|
|
||||||
} else if (
|
|
||||||
evt.issues &&
|
|
||||||
evt.issues.filter((i) => i.severity === "warning").length > 0
|
|
||||||
) {
|
|
||||||
toast.warning("Warnings found");
|
|
||||||
} else {
|
|
||||||
toast.success("No issues found");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (evt.type === "error") {
|
if (evt.type === "structure_repair_complete") {
|
||||||
setProgress(`ERROR: ${evt.message ?? ""}`);
|
if (evt.structure) setStructureResult(evt.structure);
|
||||||
toast.error(evt.message ?? "Audit failed");
|
}
|
||||||
}
|
|
||||||
|
if (evt.type === "batch_complete") {
|
||||||
|
setIssues(evt.issues ?? []);
|
||||||
|
setMissingFromSources(evt.missingFromSources ?? []);
|
||||||
|
if (evt.summary) setSummary(evt.summary);
|
||||||
|
setCheckProgress(null);
|
||||||
|
setProgress("Done");
|
||||||
|
if (
|
||||||
|
evt.issues &&
|
||||||
|
evt.issues.filter((i) => i.severity === "error").length > 0
|
||||||
|
) {
|
||||||
|
toast.error(
|
||||||
|
`${evt.issues.filter((i) => i.severity === "error").length} error(s) found`,
|
||||||
|
);
|
||||||
|
} else if (
|
||||||
|
evt.issues &&
|
||||||
|
evt.issues.filter((i) => i.severity === "warning").length > 0
|
||||||
|
) {
|
||||||
|
toast.warning("Warnings found");
|
||||||
|
} else {
|
||||||
|
toast.success("No issues found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (evt.type === "error") {
|
||||||
|
setProgress(`ERROR: ${evt.message ?? ""}`);
|
||||||
|
toast.error(evt.message ?? "Audit failed");
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch {
|
} catch {
|
||||||
// skip parse errors
|
// skip parse errors
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user