Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3504966
D6504.id21799.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6504.id21799.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D6504: [native] Add some memoization to InnerRobotextMessage
Attached
Detach File
Event Timeline
Log In to Comment