Skip to content

Commit 03f7da1

Browse files
Umais-Adeedclaude
andcommitted
fix(web): typing after a selected skill no longer lags
A skill chip is stored as `$name`, and a lone `$` sent every prompt through the full remark math parser several times per keystroke. Skip math parsing unless the text has a pair of `$`, and build the editor's initial content once instead of on every render. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e68e19d commit 03f7da1

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎apps/web/src/components/ComposerPromptEditorTiptap.tsx‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,13 +1103,17 @@ function ComposerPromptEditorTiptapInner(
11031103
"aria-placeholder": placeholder,
11041104
};
11051105

1106+
// useEditor reads content only on mount; building it per render reparses the prompt every keystroke.
1107+
const [initialContent] = useState(() =>
1108+
buildDocJson(value, (name) => composerSkillMeta(skills, name), {
1109+
styling: richText,
1110+
literalText,
1111+
}),
1112+
);
11061113
const editor = useEditor(
11071114
{
11081115
extensions: richText ? RICH_TEXT_EXTENSIONS : PLAIN_TEXT_EXTENSIONS,
1109-
content: buildDocJson(value, (name) => composerSkillMeta(skills, name), {
1110-
styling: richText,
1111-
literalText,
1112-
}),
1116+
content: initialContent,
11131117
editable: !disabled,
11141118
editorProps: {
11151119
attributes: editorAttributes,

‎packages/shared/src/markdownMath.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ export function markdownMathRanges(source: string, tree?: Root) {
5252

5353
/** Messages without these characters skip math parsing entirely. */
5454
function mayContainMath(text: string): boolean {
55+
// Dollar math needs a pair, so a lone `$` (such as one `$skill` chip) cannot open a formula.
5556
return (
56-
text.includes("$") ||
57+
text.indexOf("$") !== text.lastIndexOf("$") ||
5758
text.includes("\\(") ||
5859
text.includes("\\[") ||
5960
/(?:`{3,}|~{3,})[ \t]*math\b/.test(text)

0 commit comments

Comments
 (0)