Skip to content

Commit

Permalink
Fix hashtag bar sometimes including tags that appear in the post's bo…
Browse files Browse the repository at this point in the history
…dy (#26506)
  • Loading branch information
ClearlyClaire committed Aug 16, 2023
1 parent 26eaf05 commit f0862bc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/javascript/mastodon/components/hashtag_bar.jsx
Expand Up @@ -15,11 +15,11 @@ const VISIBLE_HASHTAGS = 7;
export const HashtagBar = ({ hashtags, text }) => {
const renderedHashtags = useMemo(() => {
const body = domParser.parseFromString(text, 'text/html').documentElement;
return [].map.call(body.querySelectorAll('[rel=tag]'), node => node.textContent.toLowerCase());
return [].filter.call(body.querySelectorAll('a[href]'), link => link.textContent[0] === '#' || (link.previousSibling?.textContent?.[link.previousSibling.textContent.length - 1] === '#')).map(node => node.textContent.toLowerCase());
}, [text]);

const invisibleHashtags = useMemo(() => (
hashtags.filter(hashtag => !renderedHashtags.some(textContent => textContent === `#${hashtag.get('name')}` || textContent === hashtag.get('name')))
hashtags.filter(hashtag => !renderedHashtags.some(textContent => textContent === `#${hashtag.get('name').toLowerCase()}` || textContent === hashtag.get('name').toLowerCase()))
), [hashtags, renderedHashtags]);

const [expanded, setExpanded] = useState(false);
Expand Down

0 comments on commit f0862bc

Please sign in to comment.