← Back to Pull requests

[lexical][lexical-code] Bug Fix: Make getTextDirection match the browser's dir="auto" #9942

Closed
unknown closed this pull request without merging on Nov 20, 2026 16:33 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 08:41 UTC
Author

Description

getTextDirection did not match the browser's dir="auto". Its ranges had no u flag and were too wide: emoji, U+FE0F, U+3000 and U+FEFF counted as LTR, Arabic-Indic digits as RTL, and RLM as neither. For example, "🎉 שלום" renders RTL but returned 'ltr'.

Now it finds the first letter (\p{L}), LRM, RLM or ALM, and returns 'rtl' if that character is in a Unicode RTL block or is RLM or ALM. This matches Chromium's dir="auto" for every assigned letter, except 26 neutral modifier letters. \p{...} needs Chrome 64, Firefox 78 and Safari 11.1, which is below our browserslist.

Behavior change: text that starts with an emoji and then Hebrew or Arabic is now 'rtl', not 'ltr'. RTL code lines use this through $getCodeLineDirection.

Changeset

.changeset/text-direction-matches-dir-auto.md: [fix] for lexical.

Test plan

Before

$ pnpm exec vitest --project unit --no-watch packages/lexical/src/__tests__/unit/LexicalUtils.test.ts packages/lexical-code/src/__tests__/unit/LexicalCodeNode.test.ts
     × getTextDirection()
         × MOVE_TO_END moves caret to visual right when the line starts with an emoji
      Tests  2 failed | 134 passed | 1 skipped (137)

After

$ pnpm exec vitest --project unit --no-watch packages/lexical/ packages/lexical-code/ packages/lexical-code-core/ packages/lexical-code-prism/ packages/lexical-code-shiki/
      Tests  3054 passed | 1 skipped (3055)
$ pnpm run ci-check
Found 0 errors

Firefox and WebKit were not tested.

Diff: 191 lines (+143 / -48) across 2 files Reviewer: potatowagon Review duration: 3351m
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 191 lines diff across 2 files
0.36
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.315
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #9942"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 35.9% (MEDIUM) · Higher = larger blast radius
35.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 14.2% · Safe to merge
14.2%
Repository