mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-25 18:55:44 +03:00
Prevent re-render dangerouslySetInnerHTML
This commit is contained in:
parent
4f28d3cc6d
commit
436277c6b4
1 changed files with 41 additions and 53 deletions
|
@ -106,6 +106,43 @@ function getPostText(status) {
|
|||
);
|
||||
}
|
||||
|
||||
const PostContent = memo(
|
||||
({ post, instance, previewMode }) => {
|
||||
const { content, emojis, language, mentions, url } = post;
|
||||
return (
|
||||
<div
|
||||
lang={language}
|
||||
dir="auto"
|
||||
class="inner-content"
|
||||
onClick={handleContentLinks({
|
||||
mentions,
|
||||
instance,
|
||||
previewMode,
|
||||
statusURL: url,
|
||||
})}
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: enhanceContent(content, {
|
||||
emojis,
|
||||
postEnhanceDOM: (dom) => {
|
||||
// Remove target="_blank" from links
|
||||
dom.querySelectorAll('a.u-url[target="_blank"]').forEach((a) => {
|
||||
if (!/http/i.test(a.innerText.trim())) {
|
||||
a.removeAttribute('target');
|
||||
}
|
||||
});
|
||||
},
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
(oldProps, newProps) => {
|
||||
const { content: oldContent } = oldProps;
|
||||
const { content: newContent } = newProps;
|
||||
return oldContent === newContent;
|
||||
},
|
||||
);
|
||||
|
||||
function Status({
|
||||
statusID,
|
||||
status,
|
||||
|
@ -1680,59 +1717,10 @@ function Status({
|
|||
ref={contentRef}
|
||||
data-read-more={readMoreText}
|
||||
>
|
||||
<div
|
||||
lang={language}
|
||||
dir="auto"
|
||||
class="inner-content"
|
||||
onClick={handleContentLinks({
|
||||
mentions,
|
||||
instance,
|
||||
previewMode,
|
||||
statusURL: url,
|
||||
})}
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: enhanceContent(content, {
|
||||
emojis,
|
||||
postEnhanceDOM: (dom) => {
|
||||
// Remove target="_blank" from links
|
||||
dom
|
||||
.querySelectorAll('a.u-url[target="_blank"]')
|
||||
.forEach((a) => {
|
||||
if (!/http/i.test(a.innerText.trim())) {
|
||||
a.removeAttribute('target');
|
||||
}
|
||||
});
|
||||
// if (previewMode) return;
|
||||
// Unfurl Mastodon links
|
||||
// Array.from(
|
||||
// dom.querySelectorAll(
|
||||
// 'a[href]:not(.u-url):not(.mention):not(.hashtag)',
|
||||
// ),
|
||||
// )
|
||||
// .filter((a) => {
|
||||
// const url = a.href;
|
||||
// const isPostItself =
|
||||
// url === status.url || url === status.uri;
|
||||
// return !isPostItself && isMastodonLinkMaybe(url);
|
||||
// })
|
||||
// .forEach((a, i) => {
|
||||
// unfurlMastodonLink(currentInstance, a.href).then(
|
||||
// (result) => {
|
||||
// if (!result) return;
|
||||
// a.removeAttribute('target');
|
||||
// if (!sKey) return;
|
||||
// if (!Array.isArray(states.statusQuotes[sKey])) {
|
||||
// states.statusQuotes[sKey] = [];
|
||||
// }
|
||||
// if (!states.statusQuotes[sKey][i]) {
|
||||
// states.statusQuotes[sKey].splice(i, 0, result);
|
||||
// }
|
||||
// },
|
||||
// );
|
||||
// });
|
||||
},
|
||||
}),
|
||||
}}
|
||||
<PostContent
|
||||
post={status}
|
||||
instance={instance}
|
||||
previewMode={previewMode}
|
||||
/>
|
||||
<QuoteStatuses id={id} instance={instance} level={quoted} />
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue