Skip to content

Commit e67cf77

Browse files
committed
fix(control-ui): hydrate palette commands on open
1 parent 7e1a9b0 commit e67cf77

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

ui/src/ui/app-render.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,6 +2210,9 @@ export function renderApp(state: AppViewState) {
22102210
open: state.paletteOpen,
22112211
query: state.paletteQuery,
22122212
activeIndex: state.paletteActiveIndex,
2213+
onOpen: () => {
2214+
void refreshChatCommands(state).finally(requestHostUpdate);
2215+
},
22132216
onToggle: () => {
22142217
state.paletteOpen = !state.paletteOpen;
22152218
},

ui/src/ui/views/command-palette.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ describe("command palette", () => {
130130
expect(prose?.label).toBe("/prose");
131131
});
132132

133+
it("requests slash command hydration when the palette opens", async () => {
134+
const onOpen = vi.fn();
135+
136+
await renderPalette({ onOpen });
137+
expect(onOpen).toHaveBeenCalledTimes(1);
138+
139+
render(renderCommandPalette(createProps({ onOpen, query: "overview" })), container);
140+
await nextFrame();
141+
expect(onOpen).toHaveBeenCalledTimes(1);
142+
});
143+
133144
it("matches localized base item labels and descriptions", async () => {
134145
await i18n.setLocale("zh-CN");
135146

ui/src/ui/views/command-palette.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export type CommandPaletteProps = {
101101
open: boolean;
102102
query: string;
103103
activeIndex: number;
104+
onOpen?: () => void | Promise<void>;
104105
onToggle: () => void;
105106
onQueryChange: (query: string) => void;
106107
onActiveIndexChange: (index: number) => void;
@@ -137,6 +138,7 @@ function groupItems(items: PaletteItem[]): Array<[string, PaletteItem[]]> {
137138

138139
let previouslyFocused: Element | null = null;
139140
let activeDialog: HTMLDialogElement | null = null;
141+
let activeProps: CommandPaletteProps | null = null;
140142

141143
const FOCUSABLE_SELECTOR = [
142144
"a[href]",
@@ -288,6 +290,7 @@ function syncDialog(el: Element | undefined) {
288290
if (activeDialog !== el) {
289291
saveFocus();
290292
activeDialog = el;
293+
void activeProps?.onOpen?.();
291294
}
292295
if (el.open) {
293296
return;
@@ -319,6 +322,7 @@ export function renderCommandPalette(props: CommandPaletteProps) {
319322
if (!props.open) {
320323
return nothing;
321324
}
325+
activeProps = props;
322326

323327
const items = filteredItems(props.query);
324328
const grouped = groupItems(items);

0 commit comments

Comments
 (0)