Merge branch 'onlyemoji-crash-fix' into 'develop'
Big emojis: fix possible web crash See merge request soapbox-pub/soapbox-fe!602
This commit is contained in:
commit
284972aa76
|
@ -2,6 +2,7 @@
|
||||||
export const onlyEmoji = (node, limit = 1, ignoreMentions = true) => {
|
export const onlyEmoji = (node, limit = 1, ignoreMentions = true) => {
|
||||||
if (!node) return false;
|
if (!node) return false;
|
||||||
|
|
||||||
|
try {
|
||||||
// Remove mentions before checking content
|
// Remove mentions before checking content
|
||||||
if (ignoreMentions) {
|
if (ignoreMentions) {
|
||||||
node = node.cloneNode(true);
|
node = node.cloneNode(true);
|
||||||
|
@ -15,4 +16,10 @@ export const onlyEmoji = (node, limit = 1, ignoreMentions = true) => {
|
||||||
const images = Array.from(node.querySelectorAll('img'));
|
const images = Array.from(node.querySelectorAll('img'));
|
||||||
if (images.length > emojis.length) return false;
|
if (images.length > emojis.length) return false;
|
||||||
return true;
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
// Apparently some browsers can't handle `node.textContent.replaceAll`??
|
||||||
|
// If anything in here crashes, skipping it is inconsequential.
|
||||||
|
console.error(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue