Skip to content

Commit 1288b0a

Browse files
fix(web): composer menu keeps the user's scroll when items refresh unchanged
The highlight scroll effect depended on the items array identity, so an equal new array (thread shells updating in the @ menu) jumped a scrolled list back to the highlighted row. Key it on the highlight index and the first item's id instead, which still re-scrolls when a filter changes. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4ca4f5d commit 1288b0a

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎apps/web/src/components/chat/ComposerCommandMenu.browser.test.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,15 @@ it("shows the first row when filtering a scrolled list highlights it", async ()
117117
});
118118

119119
it("keeps the highlighted option mounted while the list scrolls away from it", async () => {
120-
await using _screen = await render(<Menu activeItemId={skillItems[0]!.id} />);
120+
await using screen = await render(<Menu activeItemId={skillItems[0]!.id} />);
121121
await scrollListToEnd();
122122

123123
expect(
124124
document.getElementById(composerSuggestionOptionId("composer-suggestions", skillItems[0]!.id)),
125125
"aria-activedescendant target",
126126
).not.toBeNull();
127+
128+
// Sources like thread shells hand over a new but equal array on unrelated updates.
129+
await screen.rerender(<Menu activeItemId={skillItems[0]!.id} items={[...skillItems]} />);
130+
await expect.element(page.getByRole("option", { name: /demo-skill-299/ })).toBeInViewport();
127131
});

‎apps/web/src/components/chat/ComposerCommandMenu.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: {
146146
// Keeps the row clear of the scroll fades.
147147
viewportMargin: { start: 24, end: 24 },
148148
});
149-
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- a filter can keep the index while the list stays scrolled.
150-
}, [activeIndex, props.items]);
149+
// A filter can keep the index while the list stays scrolled; an equal new array must not scroll.
150+
}, [activeIndex, props.items[0]?.id]);
151151

152152
return (
153153
<Command

0 commit comments

Comments
 (0)