From fcb3577cf622a4b72dde1f438a02c58aa732ad00 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Sun, 23 Aug 2026 17:56:53 +0530 Subject: [PATCH] fix infinite re-renders with malformed encrypted event --- src/app/components/encrypted-event/EncryptedEvent.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/app/components/encrypted-event/EncryptedEvent.tsx b/src/app/components/encrypted-event/EncryptedEvent.tsx index 9c160aeb..fea75c10 100644 --- a/src/app/components/encrypted-event/EncryptedEvent.tsx +++ b/src/app/components/encrypted-event/EncryptedEvent.tsx @@ -1,4 +1,4 @@ -import React, { ReactNode } from 'react'; +import React, { ReactNode, useMemo } from 'react'; import { as, Box, color, config, Icon, Icons, Text } from 'folds'; import { MessageEventWithoutRoomId } from 'neurone/lib/api/types'; import { @@ -53,7 +53,13 @@ export function EncryptedMessageEvent({ reply, children, }: EncryptedMessageEventProps) { - const encryptedEvent = decryptionManager.decryptableMessageEvent(roomId, event); + // Memoize the result because it can return new EncryptedEvent + // on every call if event content is missing sessionId. + // It can cause infinite re-renders in pair with `decryption` + const encryptedEvent = useMemo( + () => decryptionManager.decryptableMessageEvent(roomId, event), + [roomId, event, decryptionManager] + ); if (encryptedEvent.decryption.read instanceof EventDecryptionIdle) { encryptedEvent.decrypt(); }