Emoji loading performance (#38784)

This commit is contained in:
Echo authored and GitHub committed 2026-04-23 07:48:00 +00:00
1 parent fdb2563abf
commit 5bc69ea668
7 files changed
+67 -23

No files matched your search

@@ -0,0 +1,35 @@
import { useEffect, useState } from 'react';
import type { ExtraCustomEmojiMap } from '../features/emoji/types';
let emojis: ExtraCustomEmojiMap | null = null;
export function useCustomEmojis() {
const [, setLoaded] = useState(emojis !== null);
useEffect(() => {
if (!emojis) {
void loadEmojisIntoCache().then(() => {
setLoaded(true);
});
}
}, []);
return emojis;
}
async function loadEmojisIntoCache() {
const { loadAllCustomEmoji } = await import('../features/emoji/database');
const emojisRaw = await loadAllCustomEmoji();
if (emojisRaw.length === 0) {
return;
}
emojis = {};
for (const emoji of emojisRaw) {
emojis[emoji.shortcode] = {
url: emoji.url,
shortcode: emoji.shortcode,
static_url: emoji.static_url,
};
}
}