Avoid spurious warnings about unexpected renders triggered by appEvents and coreEvents. (#17160)

This commit is contained in:
Jacob Richman
2026-01-20 16:46:10 -08:00
committed by GitHub
parent e1fd5be429
commit 995ae42f53
2 changed files with 59 additions and 1 deletions

View File

@@ -6,6 +6,7 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { appEvents, AppEvent } from '../../utils/events.js';
import { coreEvents } from '@google/gemini-cli-core';
import {
profiler,
DebugProfiler,
@@ -16,6 +17,7 @@ import { render } from '../../test-utils/render.js';
import { useUIState, type UIState } from '../contexts/UIStateContext.js';
import { FixedDeque } from 'mnemonist';
import { debugState } from '../debug.js';
import { act } from 'react';
vi.mock('../contexts/UIStateContext.js', () => ({
useUIState: vi.fn(),
@@ -266,4 +268,40 @@ describe('DebugProfiler Component', () => {
expect(output).toContain('5 (idle)');
expect(output).toContain('2 (flicker)');
});
it('should report an action when a CoreEvent is emitted', async () => {
vi.mocked(useUIState).mockReturnValue({
showDebugProfiler: true,
constrainHeight: false,
} as unknown as UIState);
const reportActionSpy = vi.spyOn(profiler, 'reportAction');
const { unmount } = render(<DebugProfiler />);
act(() => {
coreEvents.emitModelChanged('new-model');
});
expect(reportActionSpy).toHaveBeenCalled();
unmount();
});
it('should report an action when an AppEvent is emitted', async () => {
vi.mocked(useUIState).mockReturnValue({
showDebugProfiler: true,
constrainHeight: false,
} as unknown as UIState);
const reportActionSpy = vi.spyOn(profiler, 'reportAction');
const { unmount } = render(<DebugProfiler />);
act(() => {
appEvents.emit(AppEvent.SelectionWarning);
});
expect(reportActionSpy).toHaveBeenCalled();
unmount();
});
});

View File

@@ -11,7 +11,7 @@ import { theme } from '../semantic-colors.js';
import { useUIState } from '../contexts/UIStateContext.js';
import { debugState } from '../debug.js';
import { appEvents, AppEvent } from '../../utils/events.js';
import { debugLogger } from '@google/gemini-cli-core';
import { coreEvents, CoreEvent, debugLogger } from '@google/gemini-cli-core';
// Frames that render at least this far before or after an action are considered
// idle frames.
@@ -160,9 +160,29 @@ export const DebugProfiler = () => {
stdin.on('data', handler);
stdout.on('resize', handler);
// Register handlers for all core and app events to ensure they are
// considered "actions" and don't trigger spurious idle frame warnings.
// These events are expected to trigger UI renders.
for (const eventName of Object.values(CoreEvent)) {
coreEvents.on(eventName, handler);
}
for (const eventName of Object.values(AppEvent)) {
appEvents.on(eventName, handler);
}
return () => {
stdin.off('data', handler);
stdout.off('resize', handler);
for (const eventName of Object.values(CoreEvent)) {
coreEvents.off(eventName, handler);
}
for (const eventName of Object.values(AppEvent)) {
appEvents.off(eventName, handler);
}
profiler.profilersActive--;
};
}, []);