mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-05-18 13:12:14 +00:00
Refactor chat update logic to prevent redundant state changes
This commit is contained in:
parent
89f6a34bc7
commit
1e6f661cd8
@ -285,15 +285,25 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Guard: If ChatThread ID and WorkspaceId haven't changed, skip entirely.
|
||||||
|
// Using ID-based comparison instead of name-based to correctly handle
|
||||||
|
// temporary chats where the workspace name is always empty.
|
||||||
if (this.currentChatThreadId == this.ChatThread.ChatId
|
if (this.currentChatThreadId == this.ChatThread.ChatId
|
||||||
&& this.currentWorkspaceId == this.ChatThread.WorkspaceId
|
&& this.currentWorkspaceId == this.ChatThread.WorkspaceId)
|
||||||
&& !string.IsNullOrWhiteSpace(this.currentWorkspaceName))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.currentChatThreadId = this.ChatThread.ChatId;
|
this.currentChatThreadId = this.ChatThread.ChatId;
|
||||||
this.currentWorkspaceId = this.ChatThread.WorkspaceId;
|
this.currentWorkspaceId = this.ChatThread.WorkspaceId;
|
||||||
this.currentWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceNameAsync(this.ChatThread.WorkspaceId);
|
var loadedWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceNameAsync(this.ChatThread.WorkspaceId);
|
||||||
this.WorkspaceName(this.currentWorkspaceName);
|
|
||||||
|
// Only notify the parent when the name actually changed to prevent
|
||||||
|
// an infinite render loop: WorkspaceName → UpdateWorkspaceName →
|
||||||
|
// StateHasChanged → re-render → OnParametersSetAsync → WorkspaceName → ...
|
||||||
|
if (this.currentWorkspaceName != loadedWorkspaceName)
|
||||||
|
{
|
||||||
|
this.currentWorkspaceName = loadedWorkspaceName;
|
||||||
|
this.WorkspaceName(this.currentWorkspaceName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsProviderSelected => this.Provider.UsedLLMProvider != LLMProviders.NONE;
|
private bool IsProviderSelected => this.Provider.UsedLLMProvider != LLMProviders.NONE;
|
||||||
@ -462,8 +472,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
if(!this.ChatThread.IsLLMProviderAllowed(this.Provider))
|
if(!this.ChatThread.IsLLMProviderAllowed(this.Provider))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// We need to blur the focus away from the input field
|
// Blur the focus away from the input field to be able to clear it:
|
||||||
// to be able to clear the field:
|
|
||||||
await this.inputField.BlurAsync();
|
await this.inputField.BlurAsync();
|
||||||
|
|
||||||
// Create a new chat thread if necessary:
|
// Create a new chat thread if necessary:
|
||||||
@ -554,8 +563,10 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
|
|
||||||
// Clear the input field:
|
// Clear the input field:
|
||||||
await this.inputField.FocusAsync();
|
await this.inputField.FocusAsync();
|
||||||
|
|
||||||
this.userInput = string.Empty;
|
this.userInput = string.Empty;
|
||||||
this.chatDocumentPaths.Clear();
|
this.chatDocumentPaths.Clear();
|
||||||
|
|
||||||
await this.inputField.BlurAsync();
|
await this.inputField.BlurAsync();
|
||||||
|
|
||||||
// Enable the stream state for the chat component:
|
// Enable the stream state for the chat component:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user