fix: その場で書き換えることで再レンダリングを最小限に抑える(かも)

This commit is contained in:
kakkokari-gtyih 2025-05-24 17:42:14 +09:00
parent aaf93607bc
commit 7081c4f30e
1 changed files with 10 additions and 9 deletions

View File

@ -196,17 +196,18 @@ export function useNoteCapture(props: {
} { } {
const { note, parentNote, $note } = props; const { note, parentNote, $note } = props;
// Normalize reactions // Normalize reactions in-place
if (Object.keys($note.reactions).length > 0) { for (const name of Object.keys($note.reactions)) {
$note.reactions = Object.entries($note.reactions).reduce((acc, [name, count]) => { const normalizedName = name.replace(/^:(\w+):$/, ':$1@.:');
const normalizedName = name.replace(/^:(\w+):$/, ':$1@.:'); if (normalizedName !== name) {
if (acc[normalizedName] == null) { const count = $note.reactions[name];
acc[normalizedName] = count; if ($note.reactions[normalizedName] == null) {
$note.reactions[normalizedName] = count;
} else { } else {
acc[normalizedName] += count; $note.reactions[normalizedName] += count;
} }
return acc; delete $note.reactions[name];
}, {} as Misskey.entities.Note['reactions']); }
} }
noteEvents.on(`reacted:${note.id}`, onReacted); noteEvents.on(`reacted:${note.id}`, onReacted);