Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: revert previously removed mentions transformation on the client (#…
…23084) This partially reverts 2ecc829. The problem is that if we don't transform mentions right away, there is a noticeable lag before a mention gets fully rendered, while with the transformation, everything is super smooth. I'm reverting that change only for mentions. Another part was about category hashtags, but unfortunately they lag both with and without the transformation. We need to address them separately.
- Loading branch information
1 parent
0e00784
commit 2d16446
Showing
2 changed files
with
22 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
plugins/chat/assets/javascripts/discourse/lib/transform-mentions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import getURL from "discourse-common/lib/get-url"; | ||
|
||
const domParser = new DOMParser(); | ||
|
||
export default function transformMentions(cooked) { | ||
const html = domParser.parseFromString(cooked, "text/html"); | ||
transform(html); | ||
return html.body.innerHTML; | ||
} | ||
|
||
function transform(html) { | ||
(html.querySelectorAll("span.mention") || []).forEach((mentionSpan) => { | ||
let mentionLink = document.createElement("a"); | ||
let mentionText = document.createTextNode(mentionSpan.innerText); | ||
mentionLink.classList.add("mention"); | ||
mentionLink.appendChild(mentionText); | ||
mentionLink.href = getURL(`/u/${mentionSpan.innerText.substring(1)}`); | ||
mentionSpan.parentNode.replaceChild(mentionLink, mentionSpan); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters