mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-10-31 06:13:43 +08:00 
			
		
		
		
	更新 revert 操作的实现逻辑
通过 ... 的语法创建一个新的 ChatSession[] 副本,在副本上执行 splice 操作,避免直接修改状态
This commit is contained in:
		| @@ -221,14 +221,16 @@ export const useChatStore = create<ChatStore>()( | |||||||
|             { |             { | ||||||
|               text: Locale.Home.Revert, |               text: Locale.Home.Revert, | ||||||
|               onClick() { |               onClick() { | ||||||
|                 const sessions = get().sessions; |                 set((state) => { | ||||||
|                 // if the deleted session is the only session in sessions array, |                   const newSessions = [...state.sessions]; | ||||||
|                 // we should delete the empty session first before inserting the deleted session |                   // if the deleted session is the only session in sessions array, | ||||||
|                 sessions.splice(index, isLastSession, deletedSession); |                   // we should delete the empty session first before inserting the deleted session | ||||||
|                 set(() => ({ |                   newSessions.splice(index, isLastSession, deletedSession); | ||||||
|                   sessions: sessions, |                   return { | ||||||
|                   currentSessionIndex: seletedSessionIndex, |                     sessions: newSessions, | ||||||
|                 })); |                     currentSessionIndex: seletedSessionIndex, | ||||||
|  |                   }; | ||||||
|  |                 }); | ||||||
|               }, |               }, | ||||||
|             }, |             }, | ||||||
|             5000, |             5000, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user