mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-11 14:40:52 -07:00
Fix hooks to avoid unnecessary re-renders (#10820)
This commit is contained in:
committed by
GitHub
parent
b60c8858af
commit
cd354aebed
@@ -1239,6 +1239,11 @@ Logging in with Google... Please restart Gemini CLI to continue.
|
||||
],
|
||||
);
|
||||
|
||||
const exitPrivacyNotice = useCallback(
|
||||
() => setShowPrivacyNotice(false),
|
||||
[setShowPrivacyNotice],
|
||||
);
|
||||
|
||||
const uiActions: UIActions = useMemo(
|
||||
() => ({
|
||||
handleThemeSelect,
|
||||
@@ -1248,7 +1253,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
|
||||
onAuthError,
|
||||
handleEditorSelect,
|
||||
exitEditorDialog,
|
||||
exitPrivacyNotice: () => setShowPrivacyNotice(false),
|
||||
exitPrivacyNotice,
|
||||
closeSettingsDialog,
|
||||
closeModelDialog,
|
||||
closePermissionsDialog,
|
||||
@@ -1273,6 +1278,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
|
||||
onAuthError,
|
||||
handleEditorSelect,
|
||||
exitEditorDialog,
|
||||
exitPrivacyNotice,
|
||||
closeSettingsDialog,
|
||||
closeModelDialog,
|
||||
closePermissionsDialog,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { useState, useRef, useCallback } from 'react';
|
||||
import { useState, useRef, useCallback, useMemo } from 'react';
|
||||
import type { HistoryItem } from '../types.js';
|
||||
|
||||
// Type for the updater function passed to updateHistoryItem
|
||||
@@ -101,11 +101,14 @@ export function useHistory(): UseHistoryManagerReturn {
|
||||
messageIdCounterRef.current = 0;
|
||||
}, []);
|
||||
|
||||
return {
|
||||
history,
|
||||
addItem,
|
||||
updateItem,
|
||||
clearItems,
|
||||
loadHistory,
|
||||
};
|
||||
return useMemo(
|
||||
() => ({
|
||||
history,
|
||||
addItem,
|
||||
updateItem,
|
||||
clearItems,
|
||||
loadHistory,
|
||||
}),
|
||||
[history, addItem, updateItem, clearItems, loadHistory],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useCallback, useMemo } from 'react';
|
||||
import type { GeminiCLIExtension } from '@google/gemini-cli-core';
|
||||
import { getWorkspaceExtensions } from '../../config/extension.js';
|
||||
import { type LoadedSettings, SettingScope } from '../../config/settings.js';
|
||||
@@ -37,7 +37,7 @@ export function useWorkspaceMigration(settings: LoadedSettings) {
|
||||
settings.merged.experimental?.extensionManagement,
|
||||
]);
|
||||
|
||||
const onWorkspaceMigrationDialogOpen = () => {
|
||||
const onWorkspaceMigrationDialogOpen = useCallback(() => {
|
||||
const userSettings = settings.forScope(SettingScope.User);
|
||||
const extensionSettings = userSettings.settings.extensions || {
|
||||
disabled: [],
|
||||
@@ -53,16 +53,24 @@ export function useWorkspaceMigration(settings: LoadedSettings) {
|
||||
extensionSettings.workspacesWithMigrationNudge =
|
||||
workspacesWithMigrationNudge;
|
||||
settings.setValue(SettingScope.User, 'extensions', extensionSettings);
|
||||
};
|
||||
}, [settings]);
|
||||
|
||||
const onWorkspaceMigrationDialogClose = () => {
|
||||
const onWorkspaceMigrationDialogClose = useCallback(() => {
|
||||
setShowWorkspaceMigrationDialog(false);
|
||||
};
|
||||
}, [setShowWorkspaceMigrationDialog]);
|
||||
|
||||
return {
|
||||
showWorkspaceMigrationDialog,
|
||||
workspaceExtensions,
|
||||
onWorkspaceMigrationDialogOpen,
|
||||
onWorkspaceMigrationDialogClose,
|
||||
};
|
||||
return useMemo(
|
||||
() => ({
|
||||
showWorkspaceMigrationDialog,
|
||||
workspaceExtensions,
|
||||
onWorkspaceMigrationDialogOpen,
|
||||
onWorkspaceMigrationDialogClose,
|
||||
}),
|
||||
[
|
||||
showWorkspaceMigrationDialog,
|
||||
workspaceExtensions,
|
||||
onWorkspaceMigrationDialogOpen,
|
||||
onWorkspaceMigrationDialogClose,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user