Spaces:
Sleeping
Sleeping
fix: The problem is the finally block from the aborted request runs after the new message
Browse files- web/src/App.tsx +14 -7
web/src/App.tsx
CHANGED
|
@@ -706,6 +706,8 @@ function App() {
|
|
| 706 |
|
| 707 |
setMessages((prev) => [...prev, assistantMessage]);
|
| 708 |
|
|
|
|
|
|
|
| 709 |
try {
|
| 710 |
// Create new AbortController for this request
|
| 711 |
abortControllerRef.current = new AbortController();
|
|
@@ -949,14 +951,16 @@ function App() {
|
|
| 949 |
}
|
| 950 |
}
|
| 951 |
} catch (error) {
|
| 952 |
-
// Don't show error message if request was aborted (
|
| 953 |
if (error instanceof Error && error.name === 'AbortError') {
|
|
|
|
| 954 |
console.log('Request aborted by user');
|
| 955 |
return;
|
| 956 |
}
|
| 957 |
|
| 958 |
console.error('Error sending message:', error);
|
| 959 |
setIsLoading(false);
|
|
|
|
| 960 |
setResponseComplete(true);
|
| 961 |
setStatusMessage('');
|
| 962 |
const errorDetail = error instanceof Error ? error.message : String(error);
|
|
@@ -972,12 +976,15 @@ function App() {
|
|
| 972 |
)
|
| 973 |
);
|
| 974 |
} finally {
|
| 975 |
-
//
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
| 980 |
-
|
|
|
|
|
|
|
|
|
|
| 981 |
}
|
| 982 |
};
|
| 983 |
|
|
|
|
| 706 |
|
| 707 |
setMessages((prev) => [...prev, assistantMessage]);
|
| 708 |
|
| 709 |
+
let wasAborted = false;
|
| 710 |
+
|
| 711 |
try {
|
| 712 |
// Create new AbortController for this request
|
| 713 |
abortControllerRef.current = new AbortController();
|
|
|
|
| 951 |
}
|
| 952 |
}
|
| 953 |
} catch (error) {
|
| 954 |
+
// Don't show error message if request was aborted (stop button)
|
| 955 |
if (error instanceof Error && error.name === 'AbortError') {
|
| 956 |
+
wasAborted = true;
|
| 957 |
console.log('Request aborted by user');
|
| 958 |
return;
|
| 959 |
}
|
| 960 |
|
| 961 |
console.error('Error sending message:', error);
|
| 962 |
setIsLoading(false);
|
| 963 |
+
setIsGenerating(false);
|
| 964 |
setResponseComplete(true);
|
| 965 |
setStatusMessage('');
|
| 966 |
const errorDetail = error instanceof Error ? error.message : String(error);
|
|
|
|
| 976 |
)
|
| 977 |
);
|
| 978 |
} finally {
|
| 979 |
+
// Skip cleanup if aborted — handleStopGeneration already cleared state
|
| 980 |
+
// and a new request may have started, so don't clobber its loading flags.
|
| 981 |
+
if (!wasAborted) {
|
| 982 |
+
setIsLoading(false);
|
| 983 |
+
setIsGenerating(false);
|
| 984 |
+
setResponseComplete(true);
|
| 985 |
+
setStatusMessage('');
|
| 986 |
+
abortControllerRef.current = null;
|
| 987 |
+
}
|
| 988 |
}
|
| 989 |
};
|
| 990 |
|