mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	Fix [UI/UX] [Chat] [Front End] React Warning
- [+] refactor(chat.tsx): capture current input reference value for use in component unmount or dependencies change
This commit is contained in:
		@@ -1044,10 +1044,14 @@ function _Chat() {
 | 
			
		||||
      localStorage.removeItem(key);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // This function will be called when the component unmounts.
 | 
			
		||||
    // Capture the current value of the input reference.
 | 
			
		||||
    const currentInputRef = inputRef.current;
 | 
			
		||||
 | 
			
		||||
    // This function will be called when the component unmounts or dependencies change.
 | 
			
		||||
    return () => {
 | 
			
		||||
      // Save the current input to local storage only if it is not a command.
 | 
			
		||||
      const currentInputValue = inputRef.current?.value ?? "";
 | 
			
		||||
      // Use the captured value from the input reference.
 | 
			
		||||
      const currentInputValue = currentInputRef?.value ?? "";
 | 
			
		||||
      if (!currentInputValue.startsWith(ChatCommandPrefix)) {
 | 
			
		||||
        localStorage.setItem(key, currentInputValue);
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user