-
🔧 fix(playground): resolve message state issues after page refresh and config reset · 70409860**Problem 1: Chat interface not refreshing when resetting imported messages** - The "reset messages simultaneously" option during config import failed to update the chat interface properly - Normal conversation resets worked correctly **Problem 2: Messages stuck in loading state after page refresh** - When AI was generating a response and user refreshed the page, the message remained in loading state indefinitely - Stop button had no effect on these orphaned loading messages **Changes Made:** 1. **Fixed config reset message refresh** (`usePlaygroundState.js`): ```javascript // Clear messages first, then set defaults to force component re-render setMessage([]); setTimeout(() => { setMessage(DEFAULT_MESSAGES); }, 0); ``` 2. **Enhanced stop generator functionality** (`useApiRequest.js`): ```javascript // Handle orphaned loading messages even without active SSE connection const onStopGenerator = useCallback(() => { // Close active SSE if exists if (sseSourceRef.current) { sseSourceRef.current.close(); sseSourceRef.current = null; } // Always attempt to complete any loading/incomplete messages // ... processing logic }, [setMessage, applyAutoCollapseLogic, saveMessages]); ``` 3. **Added automatic message state recovery** (`usePlaygroundState.js`): ```javascript // Auto-fix loading/incomplete messages on page load useEffect(() => { const lastMsg = message[message.length - 1]; if (lastMsg.status === MESSAGE_STATUS.LOADING || lastMsg.status === MESSAGE_STATUS.INCOMPLETE) { // Process incomplete content and mark as complete // Save corrected message state } }, []); ``` **Root Cause:** - Config reset: Direct state assignment didn't trigger component refresh - Loading state: No recovery mechanism for interrupted SSE connections after refresh **Impact:** -✅ Config reset now properly refreshes chat interface -✅ Stop button works on orphaned loading messages -✅ Page refresh automatically recovers incomplete messages -✅ No more permanently stuck loading statesApple\Apple committed
| Name |
Last commit
|
Last Update |
|---|---|---|
| .. | ||
| components | Loading commit data... | |
| constants | Loading commit data... | |
| context | Loading commit data... | |
| helpers | Loading commit data... | |
| hooks | Loading commit data... | |
| i18n | Loading commit data... | |
| images | Loading commit data... | |
| pages | Loading commit data... | |
| utils | Loading commit data... | |
| App.js | Loading commit data... | |
| index.css | Loading commit data... | |
| index.js | Loading commit data... |