Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/core/webview/webviewMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -900,12 +900,20 @@ export const webviewMessageHandler = async (
}
case "mcpEnabled":
const mcpEnabled = message.bool ?? true
await updateGlobalState("mcpEnabled", mcpEnabled)
const currentMcpEnabled = getGlobalState("mcpEnabled") ?? true

// Delegate MCP enable/disable logic to McpHub
const mcpHubInstance = provider.getMcpHub()
if (mcpHubInstance) {
await mcpHubInstance.handleMcpEnabledChange(mcpEnabled)
// Only update and refresh if the value actually changed
if (currentMcpEnabled !== mcpEnabled) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment here explaining why we check for value changes. Something like:

This would help future maintainers understand the performance optimization.

await updateGlobalState("mcpEnabled", mcpEnabled)

// Delegate MCP enable/disable logic to McpHub
const mcpHubInstance = provider.getMcpHub()
if (mcpHubInstance) {
await mcpHubInstance.handleMcpEnabledChange(mcpEnabled)
}
} else {
// Just update the state without triggering refresh
await updateGlobalState("mcpEnabled", mcpEnabled)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this redundant state update intentional? Since the value hasn't changed, calling updateGlobalState("mcpEnabled", mcpEnabled) seems unnecessary. Could we simply skip this update entirely when the value is unchanged?

}

await provider.postStateToWebview()
Expand Down
Loading