96f7187031
- emojibase (~965 KB) is now fully lazy: plugins/emoji.ts loads compact data + shortcode maps via a memoized dynamic import (rejections reset the memo so a mid-deploy chunk 404 can retry); reaction labels degrade to the raw glyph until loaded. Consumers get FRESH array references on load (the module arrays populate in place — same-ref state updates would skip re-render and leave emoji search empty; reviewer-caught). Verified out of the eager graph. - Service worker precaches hashed assets (workbox precacheAndRoute, 82 entries ~10.8 MB incl. the crypto wasm): repeat visits stop re-downloading the app. index.html is NOT precached — navigations stay network-first so deploys are picked up immediately; the media-auth fetch handler is untouched. - ReactPrism: curated 21-language set — chunk 574 KB → 71 KB. - Timeline inline images get loading="lazy". - Removed dead dompurify (+types); sanitize-html is the real sanitizer. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { ClientEvent, MatrixClient, MatrixEvent } from 'matrix-js-sdk';
|
|
import { getRecentEmojis } from '../plugins/recent-emoji';
|
|
import { AccountDataEvent } from '../../types/matrix/accountData';
|
|
import { IEmoji, loadEmojiData } from '../plugins/emoji';
|
|
|
|
export const useRecentEmoji = (mx: MatrixClient, limit?: number): IEmoji[] => {
|
|
const [recentEmoji, setRecentEmoji] = useState(() => getRecentEmojis(mx, limit));
|
|
|
|
// Recent emojis are resolved against the (now lazily loaded) emojibase data
|
|
// via getRecentEmojis. Recompute once loadEmojiData has populated it so the
|
|
// recent list fills in on first open.
|
|
useEffect(() => {
|
|
let alive = true;
|
|
loadEmojiData()
|
|
.then(() => {
|
|
if (alive) setRecentEmoji(getRecentEmojis(mx, limit));
|
|
})
|
|
.catch(() => undefined);
|
|
return () => {
|
|
alive = false;
|
|
};
|
|
}, [mx, limit]);
|
|
|
|
useEffect(() => {
|
|
const handleAccountData = (event: MatrixEvent) => {
|
|
if (event.getType() !== AccountDataEvent.ElementRecentEmoji) return;
|
|
setRecentEmoji(getRecentEmojis(mx, limit));
|
|
};
|
|
|
|
mx.on(ClientEvent.AccountData, handleAccountData);
|
|
return () => {
|
|
mx.removeListener(ClientEvent.AccountData, handleAccountData);
|
|
};
|
|
}, [mx, limit]);
|
|
|
|
return recentEmoji;
|
|
};
|