From 6d656e4827a28d154a36fd5bc748c0bf9aacd02e Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Wed, 21 Jan 2026 14:21:52 -0600 Subject: [PATCH] fix(app): querySelector errors, more defensive scroll-to-item --- packages/ui/src/components/list.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/ui/src/components/list.tsx b/packages/ui/src/components/list.tsx index 6d7ad1da6..aeb2769d6 100644 --- a/packages/ui/src/components/list.tsx +++ b/packages/ui/src/components/list.tsx @@ -6,6 +6,13 @@ import { Icon, type IconProps } from "./icon" import { IconButton } from "./icon-button" import { TextField } from "./text-field" +function findByKey(container: HTMLElement, key: string) { + const nodes = container.querySelectorAll('[data-slot="list-item"][data-key]') + for (const node of nodes) { + if (node.getAttribute("data-key") === key) return node + } +} + export interface ListSearchProps { placeholder?: string autofocus?: boolean @@ -97,8 +104,8 @@ export function List(props: ListProps & { ref?: (ref: ListRef) => void }) if (!props.current) return const key = props.key(props.current) requestAnimationFrame(() => { - const element = scroll.querySelector(`[data-key="${CSS.escape(key)}"]`) - if (!(element instanceof HTMLElement)) return + const element = findByKey(scroll, key) + if (!element) return scrollIntoView(scroll, element, "center") }) }) @@ -114,8 +121,8 @@ export function List(props: ListProps & { ref?: (ref: ListRef) => void }) } const key = active() if (!key) return - const element = scroll.querySelector(`[data-key="${CSS.escape(key)}"]`) - if (!(element instanceof HTMLElement)) return + const element = findByKey(scroll, key) + if (!element) return scrollIntoView(scroll, element, "center") })