You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[GH-27911] Keep right-to-left messages right-to-left when they start with a mention - #40050
A right-to-left message that starts with a mention was laid out left-to-right.
Message text is rendered with dir='auto', so the browser takes the direction of the whole message from its first strongly directional character. When a Persian, Arabic or Hebrew message starts with @username, @all and so on, that character is a Latin letter of the mention. The message then gets a left-to-right base direction, the mention sits at the far left, and mixed text such as یک دو one two سه چهار shows its parts in the wrong order.
This PR wraps every mention rendered by AtMention in a <bdi> element (user mentions, group mentions, and the fallback used for @all, @channel, @here and unknown names). The browser skips <bdi> content when it resolves dir='auto', so the message takes its direction from its own text. The <bdi> also isolates the mention from the text around it, so inside a right-to-left message a Latin username keeps its @ in front (on master it renders as sam@).
Nothing changes for left-to-right messages, or for right-to-left messages without a mention. Text alignment is not touched.
flowchart TD
A[Right to left message starts with a mention] --> B{Where the direction comes from}
B -->|Before| C[The mention so the message is left to right]
B -->|After| D[The message text so it stays right to left]
Loading
Two existing tests looked for the data-mention attribute directly on the element that holds the mention text. That text is now one level deeper, inside the <bdi>, so those assertions now look up the enclosing [data-mention] element.
QA steps:
Post @someuser جلسه با تیم design ساعت ده است in a channel.
Before: the mention is at the far left and the message reads left-to-right. After: the message reads right-to-left with the mention at its start.
Post @someuser the design meeting starts at ten. It stays left-to-right.
Edge cases and unchanged behaviour checked:
In the running app, shown in the recording:
@all on its own line above Persian text reads right-to-left.
A user mention in the middle of a Persian sentence reads right-to-left, with the @ in front of the username.
An English message that starts with a mention stays left-to-right.
A Persian message without a mention is unchanged.
Clicking a mention still opens the profile popover.
By unit tests only:
A group mention is wrapped in <bdi>.
A mention that matches no user or group (the @all fallback) is wrapped in <bdi>.
Punctuation that trails a mention (for example the period in @someuser.) stays outside the <bdi>, for user mentions, group mentions and unknown names, so it follows the direction of the message.
Tests run locally, from webapp/channels:
npm test -- src/components/at_mention/at_mention.test.tsx with the change to at_mention.tsx reverted: 3 failed (the three new tests), 3 passed.
The same command with the change: 9 passed (this includes three tests added later for trailing punctuation; they fail without that follow-up commit).
npm test -- src/components/at_mention src/components/post_markdown src/components/post_view/combined_system_message src/components/post_view/post_add_channel_member src/components/markdown src/utils/message_html_to_component.test.tsx src/components/quote_selection_button src/components/channel_invite_modal src/components/advanced_text_editor/wysiwyg_editor src/plugins/published_editor.test.tsx: 26 suites, 368 tests, all passed.
npx eslint --quiet on the four changed files: no errors.
Not run: the full webapp test suite, npm run check-types, and the end-to-end tests.
AI assistance (Claude Code) was used to write and test this change.
The recording is the web app built from master (before) and from this branch (after), against a local server, with the same account and the same message.
Release Note
Fixed right-to-left messages being displayed left-to-right when they start with an at-mention.
+77 -27 Production Changes (45%)
+93 -6 Test Changes (55%)
Regression Risk:AtMention is a shared component, so its DOM output changes for every user, group, and fallback mention in post rendering. New tests cover the bdi wrapping and trailing punctuation, and existing tests were updated for the new data-mention location, but the full webapp suite, type checks, and end-to-end tests were not run.
A message is rendered with dir='auto', so the browser takes its direction
from the first strongly directional character. When a right-to-left message
starts with a mention, that character is the Latin text of the mention, and
the whole message is laid out left-to-right.
Wrap every mention in a <bdi> element. The browser skips <bdi> content when
it resolves dir='auto', so the message takes its direction from its own
text. The <bdi> also isolates the mention, so the @ sign stays in front of a
Latin username inside a right-to-left message.
Fixesmattermost#27911
Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.
Please help complete the Mattermost contribution license agreement?
Once you have signed the CLA, please comment with /check-cla and confirm that the CLA check is green.
This is a standard procedure for many open source projects.
Please let us know if you have any questions.
We are very happy to have you join our growing community! If you're not yet a member, please consider joining our Contributors community channel to meet other contributors and discuss new opportunities with the core team.
No actionable comments were generated in the recent review.
Walkthrough
AtMention now wraps user mentions, group mentions, and fallback content in bdi elements. It renders trailing periods, underscores, and hyphens outside the wrapper. Tests check the wrappers and locate mention attributes on containing elements.
Changes: Mention rendering
Layer / File(s)
Summary
Mention wrappers and validation webapp/channels/src/components/at_mention/at_mention.tsx, webapp/channels/src/components/at_mention/at_mention.test.tsx, webapp/channels/src/components/post_markdown/post_markdown.test.tsx, webapp/channels/src/components/post_view/combined_system_message/last_users.test.tsx
AtMention wraps user mentions, group mentions, and fallback content in bdi elements. It renders trailing ., _, and - characters outside the wrapper. Tests check the wrappers and locate data-mention on the closest matching ancestor.
The change wraps mentions in bidirectional isolation so right-to-left messages that start with a mention keep their direction. Trailing punctuation stays outside the wrapper. The change is small and localized, with no remaining merge-blocking risk identified in the code.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: right-to-left messages that begin with a mention keep their right-to-left direction. The raw summary shows the change wraps user, group, and fallback mentions in bdi e…
Linked Issues check
[#27911] The issue requires that a right-to-left message that starts with a mention keeps its bidirectional text layout. The message text uses dir='auto', so the browser takes the direction from the f…
Out of Scope Changes check
The at_mention.tsx changes implement the linked issue. The new trailing-punctuation handling refines the same mention rendering, so it is part of this objective and not an unrelated change. It is also…
Full details: Title check
Explanation
The title names the main change: right-to-left messages that begin with a mention keep their right-to-left direction. The raw summary shows the change wraps user, group, and fallback mentions in bdi elements, which matches this goal. The title is specific, and the ticket reference is a standard prefix.
Full details: Linked Issues check
Explanation
[#27911] The issue requires that a right-to-left message that starts with a mention keeps its bidirectional text layout. The message text uses dir='auto', so the browser takes the direction from the first strong character. A leading Latin mention forces left-to-right. At the reviewed head (7e7a87b), at_mention.tsx wraps every rendered mention in <bdi>: the user branch, the group branch, and the fallback branch (<bdi>{props.children}</bdi> or the trailing-string variant). The browser skips <bdi> content when it resolves dir='auto', so the mention no longer sets the message direction. The new commit since the previous review keeps trailing periods, underscores, and hyphens outside the <bdi> in the fallback branch. This does not weaken the fix. It only changes where punctuation sits. Visual behaviour in a real browser is shown only by the PR recording. Automated tests cover the wrapper and the trailing-punctuation cases, as reported in the PR description.
Full details: Out of Scope Changes check
Explanation
The at_mention.tsx changes implement the linked issue. The new trailing-punctuation handling refines the same mention rendering, so it is part of this objective and not an unrelated change. It is also described in the PR commit messages. The at_mention.test.tsx, post_markdown.test.tsx, and last_users.test.tsx changes support the wrapper change. Those tests now look up the enclosing [data-mention] element because the mention text is one level deeper. The PR does not alter text alignment or the profile popover behaviour. No unrelated change was found in the reviewed code.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 8636d74b-8d38-4764-9942-3cb2bf7b8342
Commits
Reviewing files that changed from the base of the PR and between dd7c8fe and 7e7a87b.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
In a right-to-left message that ends with a mention and a period, the period was inside the <bdi> and showed on the wrong side of the mention. The punctuation now stays outside the <bdi>, for user mentions, group mentions and names that match no user or group.
This file contains hidden or 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
Contributorrelease-noteDenotes a PR that will be considered when it comes time to generate release notes.
3 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A right-to-left message that starts with a mention was laid out left-to-right.
Message text is rendered with
dir='auto', so the browser takes the direction of the whole message from its first strongly directional character. When a Persian, Arabic or Hebrew message starts with@username,@alland so on, that character is a Latin letter of the mention. The message then gets a left-to-right base direction, the mention sits at the far left, and mixed text such asیک دو one two سه چهارshows its parts in the wrong order.This PR wraps every mention rendered by
AtMentionin a<bdi>element (user mentions, group mentions, and the fallback used for@all,@channel,@hereand unknown names). The browser skips<bdi>content when it resolvesdir='auto', so the message takes its direction from its own text. The<bdi>also isolates the mention from the text around it, so inside a right-to-left message a Latin username keeps its@in front (on master it renders assam@).Nothing changes for left-to-right messages, or for right-to-left messages without a mention. Text alignment is not touched.
flowchart TD A[Right to left message starts with a mention] --> B{Where the direction comes from} B -->|Before| C[The mention so the message is left to right] B -->|After| D[The message text so it stays right to left]Two existing tests looked for the
data-mentionattribute directly on the element that holds the mention text. That text is now one level deeper, inside the<bdi>, so those assertions now look up the enclosing[data-mention]element.QA steps:
@someuser جلسه با تیم design ساعت ده استin a channel.@someuser the design meeting starts at ten. It stays left-to-right.Edge cases and unchanged behaviour checked:
@allon its own line above Persian text reads right-to-left.@in front of the username.<bdi>.@allfallback) is wrapped in<bdi>.@someuser.) stays outside the<bdi>, for user mentions, group mentions and unknown names, so it follows the direction of the message.Tests run locally, from
webapp/channels:npm test -- src/components/at_mention/at_mention.test.tsxwith the change toat_mention.tsxreverted: 3 failed (the three new tests), 3 passed.npm test -- src/components/at_mention src/components/post_markdown src/components/post_view/combined_system_message src/components/post_view/post_add_channel_member src/components/markdown src/utils/message_html_to_component.test.tsx src/components/quote_selection_button src/components/channel_invite_modal src/components/advanced_text_editor/wysiwyg_editor src/plugins/published_editor.test.tsx: 26 suites, 368 tests, all passed.npx eslint --quieton the four changed files: no errors.npm run check-types, and the end-to-end tests.AI assistance (Claude Code) was used to write and test this change.
Ticket Link
Fixes: #27911
Screenshots
Narrated recording, before then after (sound on):
evidence.mp4
The recording is the web app built from
master(before) and from this branch (after), against a local server, with the same account and the same message.Release Note
🤖 Generated with Claude Code
Change Impact: Medium 🟡
Changes Breakdown:
+77 -27 Production Changes (45%)
+93 -6 Test Changes (55%)
Regression Risk:
AtMentionis a shared component, so its DOM output changes for every user, group, and fallback mention in post rendering. New tests cover thebdiwrapping and trailing punctuation, and existing tests were updated for the newdata-mentionlocation, but the full webapp suite, type checks, and end-to-end tests were not run.Generated by CodeRabbitAI