From 5aa6d1a5d65c599d47be1d81003ff366ca6fba84 Mon Sep 17 00:00:00 2001
From: Stephen Zhou <38493346+hyoban@users.noreply.github.com>
Date: Tue, 21 Oct 2025 20:14:08 +0800
Subject: [PATCH] fix: stable groupedSuggestions
---
.../mention/components/MentionDropdown.tsx | 38 +++++++++++--------
1 file changed, 22 insertions(+), 16 deletions(-)
diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/components/MentionDropdown.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/components/MentionDropdown.tsx
index 714b743c4..f9471a43a 100644
--- a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/components/MentionDropdown.tsx
+++ b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/mention/components/MentionDropdown.tsx
@@ -68,7 +68,7 @@ const MentionSuggestionItem = React.memo(
return (
{part}
@@ -79,7 +79,7 @@ const MentionSuggestionItem = React.memo(
return (
+
{label}
)
@@ -154,24 +154,30 @@ export const MentionDropdown: React.FC
= ({
}) => {
if (!isVisible) throw thenable
- // Group suggestions by type
+ // Group suggestions by type with stable ordering
const groupedSuggestions = useMemo[]>(() => {
- const groups: TypeaheadGroup[] = []
- let currentType: MentionData["type"] | null = null
+ const groupMap = new Map()
- suggestions.forEach((mention) => {
- if (mention.type !== currentType) {
- currentType = mention.type
- groups.push({ key: currentType, items: [mention] })
+ // Group mentions by type
+ for (const mention of suggestions) {
+ const items = groupMap.get(mention.type)
+ if (items) {
+ items.push(mention)
} else {
- const lastGroup = groups.at(-1)
- if (lastGroup) {
- lastGroup.items.push(mention)
- }
+ groupMap.set(mention.type, [mention])
}
- })
+ }
- return groups
+ // Define stable type order
+ const typeOrder: MentionData["type"][] = ["view", "date", "category", "feed", "entry"]
+
+ // Convert to array with stable ordering
+ return typeOrder
+ .map((type) => {
+ const items = groupMap.get(type)
+ return items?.length ? { key: type, items } : null
+ })
+ .filter((group): group is TypeaheadGroup => group !== null)
}, [suggestions])
return (