TypeScript
fix(web): a project action's error belongs to the request that opened it (#20891)
Julius Marminge87ce906e4fba
diff --git a/apps/web/src/components/projectScriptEditor.tsx b/apps/web/src/components/projectScriptEditor.tsxindex 3f58813ce93..b3ea5301be8 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<string | null>(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<ProjectScriptEditorRequest | null>(null);- if (request !== errorRequest) {- setErrorRequest(request);- if (request) setValidationError(request.error ?? null);- }return (<>