mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -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(
|
const uiActions: UIActions = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
handleThemeSelect,
|
handleThemeSelect,
|
||||||
@@ -1248,7 +1253,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
|
|||||||
onAuthError,
|
onAuthError,
|
||||||
handleEditorSelect,
|
handleEditorSelect,
|
||||||
exitEditorDialog,
|
exitEditorDialog,
|
||||||
exitPrivacyNotice: () => setShowPrivacyNotice(false),
|
exitPrivacyNotice,
|
||||||
closeSettingsDialog,
|
closeSettingsDialog,
|
||||||
closeModelDialog,
|
closeModelDialog,
|
||||||
closePermissionsDialog,
|
closePermissionsDialog,
|
||||||
@@ -1273,6 +1278,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
|
|||||||
onAuthError,
|
onAuthError,
|
||||||
handleEditorSelect,
|
handleEditorSelect,
|
||||||
exitEditorDialog,
|
exitEditorDialog,
|
||||||
|
exitPrivacyNotice,
|
||||||
closeSettingsDialog,
|
closeSettingsDialog,
|
||||||
closeModelDialog,
|
closeModelDialog,
|
||||||
closePermissionsDialog,
|
closePermissionsDialog,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* 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';
|
import type { HistoryItem } from '../types.js';
|
||||||
|
|
||||||
// Type for the updater function passed to updateHistoryItem
|
// Type for the updater function passed to updateHistoryItem
|
||||||
@@ -101,11 +101,14 @@ export function useHistory(): UseHistoryManagerReturn {
|
|||||||
messageIdCounterRef.current = 0;
|
messageIdCounterRef.current = 0;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return {
|
return useMemo(
|
||||||
|
() => ({
|
||||||
history,
|
history,
|
||||||
addItem,
|
addItem,
|
||||||
updateItem,
|
updateItem,
|
||||||
clearItems,
|
clearItems,
|
||||||
loadHistory,
|
loadHistory,
|
||||||
};
|
}),
|
||||||
|
[history, addItem, updateItem, clearItems, loadHistory],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* 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 type { GeminiCLIExtension } from '@google/gemini-cli-core';
|
||||||
import { getWorkspaceExtensions } from '../../config/extension.js';
|
import { getWorkspaceExtensions } from '../../config/extension.js';
|
||||||
import { type LoadedSettings, SettingScope } from '../../config/settings.js';
|
import { type LoadedSettings, SettingScope } from '../../config/settings.js';
|
||||||
@@ -37,7 +37,7 @@ export function useWorkspaceMigration(settings: LoadedSettings) {
|
|||||||
settings.merged.experimental?.extensionManagement,
|
settings.merged.experimental?.extensionManagement,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const onWorkspaceMigrationDialogOpen = () => {
|
const onWorkspaceMigrationDialogOpen = useCallback(() => {
|
||||||
const userSettings = settings.forScope(SettingScope.User);
|
const userSettings = settings.forScope(SettingScope.User);
|
||||||
const extensionSettings = userSettings.settings.extensions || {
|
const extensionSettings = userSettings.settings.extensions || {
|
||||||
disabled: [],
|
disabled: [],
|
||||||
@@ -53,16 +53,24 @@ export function useWorkspaceMigration(settings: LoadedSettings) {
|
|||||||
extensionSettings.workspacesWithMigrationNudge =
|
extensionSettings.workspacesWithMigrationNudge =
|
||||||
workspacesWithMigrationNudge;
|
workspacesWithMigrationNudge;
|
||||||
settings.setValue(SettingScope.User, 'extensions', extensionSettings);
|
settings.setValue(SettingScope.User, 'extensions', extensionSettings);
|
||||||
};
|
}, [settings]);
|
||||||
|
|
||||||
const onWorkspaceMigrationDialogClose = () => {
|
const onWorkspaceMigrationDialogClose = useCallback(() => {
|
||||||
setShowWorkspaceMigrationDialog(false);
|
setShowWorkspaceMigrationDialog(false);
|
||||||
};
|
}, [setShowWorkspaceMigrationDialog]);
|
||||||
|
|
||||||
return {
|
return useMemo(
|
||||||
|
() => ({
|
||||||
showWorkspaceMigrationDialog,
|
showWorkspaceMigrationDialog,
|
||||||
workspaceExtensions,
|
workspaceExtensions,
|
||||||
onWorkspaceMigrationDialogOpen,
|
onWorkspaceMigrationDialogOpen,
|
||||||
onWorkspaceMigrationDialogClose,
|
onWorkspaceMigrationDialogClose,
|
||||||
};
|
}),
|
||||||
|
[
|
||||||
|
showWorkspaceMigrationDialog,
|
||||||
|
workspaceExtensions,
|
||||||
|
onWorkspaceMigrationDialogOpen,
|
||||||
|
onWorkspaceMigrationDialogClose,
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user