From c6c4a466d57e7178e4e7d2bce9b520e39c2c9627 Mon Sep 17 00:00:00 2001 From: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com> Date: Thu, 5 Nov 2026 01:56:36 +0530 Subject: [PATCH] perf: skip emoji parsing in text without shortcode delimiters --- resources/js/lib/emoji.ts | 8 ++++++++ tests/Unit/EmojiShortcodes.test.tsx | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/resources/js/lib/emoji.ts b/resources/js/lib/emoji.ts index 1cc6b1bb4f..f6b67bac84 100644 --- a/resources/js/lib/emoji.ts +++ b/resources/js/lib/emoji.ts @@ -16,6 +16,10 @@ const shortcodePattern = new RegExp( ); export function emojify(text: string): string { + if (!text.includes(':')) { + return text; + } + return text.replace( shortcodePattern, (_, name: string) => shortcodeEmoji[name], @@ -26,6 +30,10 @@ export function emojifyInput( text: string, caret: number, ): { text: string; caret: number } { + if (!text.includes(':')) { + return { text, caret }; + } + const emojifyTyped = (typed: string) => mapTypedProse(typed, emojify); return { diff --git a/tests/Unit/EmojiShortcodes.test.tsx b/tests/Unit/EmojiShortcodes.test.tsx index 2a42afb7d1..be35742ce5 100644 --- a/tests/Unit/EmojiShortcodes.test.tsx +++ b/tests/Unit/EmojiShortcodes.test.tsx @@ -26,3 +26,9 @@ test('keeps the shortcode being typed until its closing colon', () => { caret: 5, }); }); + +test('leaves plain prose untouched without shortcode processing', () => { + const text = 'shipping 🚀 without a shortcode'; + assert.equal(emojify(text), text); + assert.deepEqual(emojifyInput(text, 8), { text, caret: 8 }); +});