Explorar el Código

tui: prevent crash when opening session switcher from an active session

Dax Raad hace 4 semanas
padre
commit
5cf24bf185

+ 2 - 3
packages/tui/src/ui/dialog-select.tsx

@@ -155,11 +155,10 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
       .filter((item) => item.label),
     ...(props.footerHints ?? []),
   ])
-  const actionItems = createMemo(() =>
+  const actionItems = () =>
     visibleActions()
       .filter(isActionItem)
-      .filter((item) => !isActionDisabled(item)),
-  )
+      .filter((item) => !isActionDisabled(item))
 
   createEffect(() => {
     const index = focusedAction()

+ 19 - 0
packages/tui/test/cli/tui/dialog-select.test.tsx

@@ -16,6 +16,7 @@ async function renderSelect(
   options: DialogSelectOption<string>[],
   onGlobal: () => void,
   onRow: (option: DialogSelectOption<string>) => void,
+  current?: string,
 ) {
   const state = path.join(root, "state")
   await mkdir(state, { recursive: true })
@@ -52,6 +53,7 @@ async function renderSelect(
                   <DialogSelect
                     title="Items"
                     options={options}
+                    current={current}
                     actions={[
                       {
                         command: "dialog.move_session.delete",
@@ -153,6 +155,23 @@ async function mountSelect(root: string, initial: DialogSelectOption<string>[])
   return { app, moved, replaceOptions, selected }
 }
 
+test("renders actions with a current selection", async () => {
+  await using tmp = await tmpdir()
+  const app = await renderSelect(
+    tmp.path,
+    [{ title: "Alpha", value: "alpha" }],
+    () => {},
+    () => {},
+    "alpha",
+  )
+
+  try {
+    await app.waitForFrame((frame) => frame.includes("delete"))
+  } finally {
+    app.renderer.destroy()
+  }
+})
+
 test("dialog actions run without options while row actions still require a selection", async () => {
   await using tmp = await tmpdir()
   let global = 0