From 06faf2f977f56d939b725047c962e13877bf3dc3 Mon Sep 17 00:00:00 2001 From: Jeremy Kescher Date: Mon, 14 Nov 2022 22:40:37 +0100 Subject: [PATCH] [Glitch] Fix nodes order being sometimes mangled when rewriting emoji backport https://github.com/mastodon/mastodon/commit/ccbca50a2502108884f7f3c9ea24df8b2129731d by Claire --- .../flavours/glitch/features/emoji/emoji.js | 15 +++++++++++---- lib/mastodon/version.rb | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/javascript/flavours/glitch/features/emoji/emoji.js b/app/javascript/flavours/glitch/features/emoji/emoji.js index 6138164e05..880f9401da 100644 --- a/app/javascript/flavours/glitch/features/emoji/emoji.js +++ b/app/javascript/flavours/glitch/features/emoji/emoji.js @@ -19,10 +19,13 @@ const emojiFilename = (filename) => { return borderedEmoji.includes(filename) ? (filename + '_border') : filename; }; +const domParser = new DOMParser(); + const emojifyTextNode = (node, customEmojis) => { - const parentElement = node.parentElement; let str = node.textContent; + const fragment = new DocumentFragment(); + for (;;) { let match, i = 0; @@ -64,12 +67,16 @@ const emojifyTextNode = (node, customEmojis) => { } } + fragment.append(document.createTextNode(str.slice(0, i))); + if (replacement) { + fragment.append(domParser.parseFromString(replacement, 'text/html').documentElement.getElementsByTagName('img')[0]); + } node.textContent = str.slice(0, i); - parentElement.insertAdjacentHTML('beforeend', replacement); str = str.slice(rend); - node = document.createTextNode(str); - parentElement.append(node); } + + fragment.append(document.createTextNode(str)); + node.parentElement.replaceChild(fragment, node); }; const emojifyNode = (node, customEmojis) => { diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb index 8e3727d777..d5809a0ca4 100644 --- a/lib/mastodon/version.rb +++ b/lib/mastodon/version.rb @@ -25,7 +25,7 @@ module Mastodon end def suffix_version - '+1.0.0' + '+1.0.1' end def to_a