From ba3f328613dbb0792e94bdaffe7da4ea68d60205 Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Sat, 17 Oct 2026 03:50:04 -0700 Subject: [PATCH] fix(web): a project action's error belongs to the request that opened it Co-Authored-By: Claude Opus 5.5 --- .../src/components/projectScriptEditor.tsx | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/web/src/components/projectScriptEditor.tsx b/apps/web/src/components/projectScriptEditor.tsx index 3f58813ce932..b3ea5301be83 100644 --- a/apps/web/src/components/projectScriptEditor.tsx +++ b/apps/web/src/components/projectScriptEditor.tsx @@ -158,14 +158,23 @@ export function ProjectScriptEditorDialog({ onClose: () => void; }) { const canEditActions = useEnvironmentScope(environmentId, editScope); - const [validationError, setValidationError] = useState(null); + // Keyed by the request it belongs to: a new request starts from its own error, + // and a late save from the previous request can't overwrite it. + const [errorState, setErrorState] = useState<{ + readonly request: ProjectScriptEditorRequest; + readonly message: string | null; + } | null>(null); + const validationError = + request === null + ? null + : errorState?.request === request + ? errorState.message + : (request.error ?? null); + const setValidationError = (message: string | null) => { + if (request !== null) setErrorState({ request, message }); + }; const [deleteConfirmOpen, setDeleteConfirmOpen] = useComposerMenuState(!canEditActions); const [deleteName, setDeleteName] = useState(""); - const [errorRequest, setErrorRequest] = useState(null); - if (request !== errorRequest) { - setErrorRequest(request); - if (request) setValidationError(request.error ?? null); - } return ( <>