From 5abf89ddd16dee1f7f1777143155f5043f7b7704 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Thu, 21 May 2026 18:57:18 -0500 Subject: [PATCH] Revert "Revert "perf(desktop): use textContent for trigger precondition"" This reverts commit 0739588f4896902f7f0d4ded8b5eaeb92bfdf042. --- apps/desktop/src/app/chat/composer/index.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/desktop/src/app/chat/composer/index.tsx b/apps/desktop/src/app/chat/composer/index.tsx index 3c58c41848f6..10887fbb8d6d 100644 --- a/apps/desktop/src/app/chat/composer/index.tsx +++ b/apps/desktop/src/app/chat/composer/index.tsx @@ -408,13 +408,13 @@ export function ChatBar({ } // Fast-bail: if neither `@` nor `/` appears in the current draft, there's - // nothing for `detectTrigger` to match. Skip the DOM range walk inside - // `textBeforeCaret` (which calls `range.toString()`, O(n) over the draft) - // and the regex pass that follows. Only when a relevant char is present - // do we pay the cost. - const text = composerPlainText(editor) + // nothing for `detectTrigger` to match. Use `textContent` (cheap browser- + // native walk) for the precondition check rather than `composerPlainText` + // (recursive child walk with chip-aware logic). Only when a trigger char + // is present do we pay the cost of the full walk + DOM range work. + const rawText = editor.textContent ?? '' - if (!text.includes('@') && !text.includes('/')) { + if (!rawText.includes('@') && !rawText.includes('/')) { if (trigger) { setTrigger(null) setTriggerActive(0) @@ -424,7 +424,7 @@ export function ChatBar({ } const before = textBeforeCaret(editor) - const detected = detectTrigger(before ?? text) + const detected = detectTrigger(before ?? composerPlainText(editor)) setTrigger(detected) setTriggerActive(0)