From 3fc07508eee47eb7e73bec6e729fc31abcb3c422 Mon Sep 17 00:00:00 2001 From: Echo Date: Mon, 4 Aug 2025 19:16:12 +0200 Subject: [PATCH] [Glitch] Performance regression fixes Port 570c9d16be2f2e0e95da6723aa5281f600424fba to glitch-soc Signed-off-by: Claire --- .../glitch/features/emoji/emoji_html.tsx | 19 ++++++++++++++++++- .../flavours/glitch/features/emoji/hooks.ts | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/javascript/flavours/glitch/features/emoji/emoji_html.tsx b/app/javascript/flavours/glitch/features/emoji/emoji_html.tsx index fdda62a3e6..b1939c4fda 100644 --- a/app/javascript/flavours/glitch/features/emoji/emoji_html.tsx +++ b/app/javascript/flavours/glitch/features/emoji/emoji_html.tsx @@ -1,5 +1,7 @@ import type { ComponentPropsWithoutRef, ElementType } from 'react'; +import { isModernEmojiEnabled } from '@/flavours/glitch/utils/environment'; + import { useEmojify } from './hooks'; import type { CustomEmojiMapArg } from './types'; @@ -12,7 +14,7 @@ type EmojiHTMLProps = Omit< as?: Element; }; -export const EmojiHTML = ({ +export const ModernEmojiHTML = ({ extraEmojis, htmlString, as: asElement, // Rename for syntax highlighting @@ -29,3 +31,18 @@ export const EmojiHTML = ({ ); }; + +export const EmojiHTML = ( + props: EmojiHTMLProps, +) => { + if (isModernEmojiEnabled()) { + return ; + } + const Wrapper = props.as ?? 'div'; + return ( + + ); +}; diff --git a/app/javascript/flavours/glitch/features/emoji/hooks.ts b/app/javascript/flavours/glitch/features/emoji/hooks.ts index c5c2773100..a985c3e97f 100644 --- a/app/javascript/flavours/glitch/features/emoji/hooks.ts +++ b/app/javascript/flavours/glitch/features/emoji/hooks.ts @@ -8,7 +8,6 @@ import { isModernEmojiEnabled } from '@/flavours/glitch/utils/environment'; import { toSupportedLocale } from './locale'; import { determineEmojiMode } from './mode'; -import { emojifyElement } from './render'; import type { CustomEmojiMapArg, EmojiAppState, @@ -39,6 +38,7 @@ export function useEmojify(text: string, extraEmojis?: CustomEmojiMapArg) { async (input: string) => { const wrapper = document.createElement('div'); wrapper.innerHTML = input; + const { emojifyElement } = await import('./render'); const result = await emojifyElement(wrapper, appState, extra); if (result) { setEmojifiedText(result.innerHTML);