Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hashtag bar sometimes including tags that appear in the post's body #26506

Merged
merged 2 commits into from Aug 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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