chore: memoized Messages component, will require custom equality check

This commit is contained in:
Danny Avila 2023-03-15 14:36:17 -04:00
parent 2fd50c99b8
commit a8aad30fc8
2 changed files with 16 additions and 7 deletions

View file

@ -1,6 +1,7 @@
const { titleConvo, citeText, detectCode } = require('../../app/');
const _ = require('lodash');
const sanitizeHtml = require('sanitize-html');
const { titleConvo, citeText, detectCode } = require('../../app/');
const htmlTagRegex = /(<\/?\s*[a-zA-Z]*\s*(?:\s+[a-zA-Z]+\s*=\s*(?:"[^"]*"|'[^']*'))*\s*(?:\/?)>|<\s*[a-zA-Z]+\s*(?:\s+[a-zA-Z]+\s*=\s*(?:"[^"]*"|'[^']*'))*\s*(?:\/?>|<\/?>))/g;
const handleError = (res, message) => {
res.write(`event: error\ndata: ${JSON.stringify(message)}\n\n`);
@ -42,8 +43,13 @@ const createOnProgress = () => {
if (tokens.match(/^\n/)) {
tokens = tokens.replace(/^\n/, '');
}
// if (tokens.includes('```')) {
// tokens = sanitizeHtml(tokens);
// const htmlTags = tokens.match(htmlTagRegex);
// if (tokens.includes('```') && htmlTags && htmlTags.length > 0) {
// htmlTags.forEach((tag) => {
// const sanitizedTag = sanitizeHtml(tag);
// tokens = tokens.replaceAll(tag, sanitizedTag);
// });
// }
if (bing) {
@ -65,9 +71,12 @@ const createOnProgress = () => {
const handleText = async (input) => {
let text = input;
text = await detectCode(text);
// if (text.includes('```')) {
// text = sanitizeHtml(text);
// text = text.replaceAll(') =&gt;', ') =>');
// const htmlTags = text.match(htmlTagRegex);
// if (text.includes('```') && htmlTags && htmlTags.length > 0) {
// htmlTags.forEach((tag) => {
// const sanitizedTag = sanitizeHtml(tag);
// text = text.replaceAll(tag, sanitizedTag);
// });
// }
return text;

View file

@ -95,4 +95,4 @@ const Messages = ({ messages, messageTree }) => {
);
};
export default Messages;
export default React.memo(Messages);