diff --git a/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx b/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx index 8c06248..b58cd09 100644 --- a/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx +++ b/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx @@ -42,6 +42,7 @@ export default function LabelStudioTextEditor() { const origin = useMemo(() => window.location.origin, []); const iframeRef = useRef(null); const initSeqRef = useRef(0); + const expectedTaskIdRef = useRef(null); const [loadingProject, setLoadingProject] = useState(true); const [loadingTasks, setLoadingTasks] = useState(false); @@ -49,6 +50,7 @@ export default function LabelStudioTextEditor() { const [saving, setSaving] = useState(false); const [iframeReady, setIframeReady] = useState(false); + const [lsReady, setLsReady] = useState(false); const [project, setProject] = useState(null); const [tasks, setTasks] = useState([]); const [selectedFileId, setSelectedFileId] = useState(""); @@ -109,6 +111,8 @@ export default function LabelStudioTextEditor() { const seq = ++initSeqRef.current; setLoadingTaskDetail(true); + setLsReady(false); + expectedTaskIdRef.current = null; try { const resp = (await getEditorTaskUsingGet(projectId, fileId)) as any; @@ -119,6 +123,7 @@ export default function LabelStudioTextEditor() { } if (seq !== initSeqRef.current) return; + expectedTaskIdRef.current = Number(task?.id) || null; postToIframe("LS_INIT", { labelConfig: project.labelConfig, task, @@ -179,6 +184,8 @@ export default function LabelStudioTextEditor() { setTasks([]); setSelectedFileId(""); initSeqRef.current = 0; + setLsReady(false); + expectedTaskIdRef.current = null; if (projectId) loadProject(); // eslint-disable-next-line react-hooks/exhaustive-deps @@ -207,6 +214,15 @@ export default function LabelStudioTextEditor() { return; } + if (msg.type === "LS_READY") { + const readyTaskId = msg.payload?.taskId; + if (expectedTaskIdRef.current && readyTaskId) { + if (Number(readyTaskId) !== expectedTaskIdRef.current) return; + } + setLsReady(true); + return; + } + if (msg.type === "LS_EXPORT_RESULT") { saveFromExport(msg.payload); return; @@ -220,6 +236,7 @@ export default function LabelStudioTextEditor() { if (msg.type === "LS_ERROR") { message.error(msg.payload?.message || "编辑器发生错误"); + setLsReady(false); } }; @@ -332,9 +349,17 @@ export default function LabelStudioTextEditor() {
- {loadingTaskDetail && ( + {(!iframeReady || loadingTaskDetail || (selectedFileId && !lsReady)) && (
- +
)}