Files
new-api/web
Apple\Apple f422a0588b 🔧 fix(playground): resolve message state issues after page refresh and config reset
**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 states
2025-06-02 23:56:58 +08:00
..
2025-05-20 23:21:48 +08:00
2023-04-22 20:39:27 +08:00
2025-04-04 17:37:27 +08:00
2025-04-04 17:37:27 +08:00
2025-05-06 01:36:23 +08:00
2024-03-23 21:24:39 +08:00
2025-05-06 01:36:23 +08:00
2023-04-22 20:39:27 +08:00
2025-05-06 01:36:23 +08:00

React Template

Basic Usages

# Runs the app in the development mode
npm start

# Builds the app for production to the `build` folder
npm run build

If you want to change the default server, please set REACT_APP_SERVER environment variables before build, for example: REACT_APP_SERVER=http://your.domain.com.

Before you start editing, make sure your Actions on Save options have Optimize imports & Run Prettier enabled.

Reference

  1. https://github.com/OIerDb-ng/OIerDb
  2. https://github.com/cornflourblue/react-hooks-redux-registration-login-example