Page MenuHomePhabricator

D6504.id21799.diff
No OneTemporary

D6504.id21799.diff

diff --git a/native/chat/inner-robotext-message.react.js b/native/chat/inner-robotext-message.react.js
--- a/native/chat/inner-robotext-message.react.js
+++ b/native/chat/inner-robotext-message.react.js
@@ -39,40 +39,46 @@
const { item, onLongPress, onPress } = props;
const activeTheme = useSelector(state => state.globalThemeInfo.activeTheme);
const styles = useOverlayStyles(unboundStyles);
- const { robotext } = item;
- const robotextParts = splitRobotext(robotext);
- const textParts = [];
- let keyIndex = 0;
-
- for (const splitPart of robotextParts) {
- if (splitPart === '') {
- continue;
- }
- if (splitPart.charAt(0) !== '<') {
- const darkColor = activeTheme === 'dark';
- const key = `text${keyIndex++}`;
- textParts.push(
- <Markdown
- style={styles.robotext}
- key={key}
- rules={inlineMarkdownRules(darkColor)}
- >
- {decodeURI(splitPart)}
- </Markdown>,
- );
- continue;
- }
- const { rawText, entityType, id } = parseRobotextEntity(splitPart);
-
- if (entityType === 't' && id !== item.messageInfo.threadID) {
- textParts.push(<ThreadEntity key={id} id={id} name={rawText} />);
- } else if (entityType === 'c') {
- textParts.push(<ColorEntity key={id} color={rawText} />);
- } else {
- textParts.push(rawText);
+ const { messageInfo, robotext } = item;
+ const { threadID } = messageInfo;
+ const textParts = React.useMemo(() => {
+ const robotextParts = splitRobotext(robotext);
+ const result = [];
+ let keyIndex = 0;
+
+ for (const splitPart of robotextParts) {
+ if (splitPart === '') {
+ continue;
+ }
+ if (splitPart.charAt(0) !== '<') {
+ const darkColor = activeTheme === 'dark';
+ const key = `text${keyIndex++}`;
+ result.push(
+ <Markdown
+ style={styles.robotext}
+ key={key}
+ rules={inlineMarkdownRules(darkColor)}
+ >
+ {decodeURI(splitPart)}
+ </Markdown>,
+ );
+ continue;
+ }
+
+ const { rawText, entityType, id } = parseRobotextEntity(splitPart);
+
+ if (entityType === 't' && id !== threadID) {
+ result.push(<ThreadEntity key={id} id={id} name={rawText} />);
+ } else if (entityType === 'c') {
+ result.push(<ColorEntity key={id} color={rawText} />);
+ } else {
+ result.push(rawText);
+ }
}
- }
+
+ return result;
+ }, [robotext, activeTheme, threadID, styles.robotext]);
const viewStyle = [styles.robotextContainer];
if (!__DEV__) {
@@ -143,4 +149,11 @@
},
};
-export { dummyNodeForRobotextMessageHeightMeasurement, InnerRobotextMessage };
+const MemoizedInnerRobotextMessage: React.ComponentType<InnerRobotextMessageProps> = React.memo<InnerRobotextMessageProps>(
+ InnerRobotextMessage,
+);
+
+export {
+ dummyNodeForRobotextMessageHeightMeasurement,
+ MemoizedInnerRobotextMessage as InnerRobotextMessage,
+};

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 11:38 AM (20 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2686635
Default Alt Text
D6504.id21799.diff (2 KB)

Event Timeline