From 42568a0077bcd13ce00f95261eb34d811db41673 Mon Sep 17 00:00:00 2001 From: Shuki Vaknin Date: Tue, 29 Sep 2026 03:59:28 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=80=20fix:=20Resolve=20SplitText=20Dir?= =?UTF-8?q?ection=20From=20Its=20Own=20Text=20Under=20RTL=20(#16454)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🔀 fix: Resolve SplitText Direction From Its Own Text Under RTL SplitText wraps every grapheme and every word in its own inline-block box, so the bidi algorithm never sees the text as one run. Under an RTL document the boxes lay out right to left, and a Latin greeting or agent name on the landing page renders mirrored, letter by letter and word by word. The paragraph and each word box now carry dir="auto", so direction resolves from the first strong character of the text itself: the paragraph decides word order and each word decides its own letter order. RTL text still lays out right to left, and mixed greetings render each part correctly. Claude-Session: https://claude.ai/code/session_01EhJ8HUVBZ53ArUzgXDnxom * 🐛 fix: Preserve RTL Greeting Word Order --------- Co-authored-by: Lia --- .../client/src/components/SplitText.spec.tsx | 31 +++++++++++++++++++ packages/client/src/components/SplitText.tsx | 14 ++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/packages/client/src/components/SplitText.spec.tsx b/packages/client/src/components/SplitText.spec.tsx index daf6419bc9..3e7671c7f1 100644 --- a/packages/client/src/components/SplitText.spec.tsx +++ b/packages/client/src/components/SplitText.spec.tsx @@ -22,4 +22,35 @@ describe('SplitText', () => { expect(Array.from(textSpans)[i].textContent).toBe(emojis[i]); } }); + + it.each([ + ['rtl', 'Welcome to reeva::chat', ['Welcome', 'to', 'reeva::chat']], + ['ltr', 'שלום עולם', ['שלום', 'עולם']], + ])('uses the accessible copy to resolve %s-document greeting %s', (dir, text, expectedWords) => { + const previousDir = document.documentElement.dir; + document.documentElement.dir = dir; + try { + const { container } = render(); + const paragraph = container.querySelector('p'); + expect(paragraph).toHaveAttribute('dir', 'auto'); + + const accessibleCopy = paragraph?.querySelector('.sr-only'); + expect(paragraph?.firstElementChild).toBe(accessibleCopy); + expect(accessibleCopy).toHaveTextContent(text); + expect(accessibleCopy?.closest('[aria-hidden="true"]')).toBeNull(); + + const wordBoxes = container.querySelectorAll('p > span[dir="auto"]'); + expect(wordBoxes).toHaveLength(expectedWords.length); + for (const [index, box] of Array.from(wordBoxes).entries()) { + expect(box).toHaveAttribute('aria-hidden', 'true'); + expect( + Array.from(box.querySelectorAll('span.inline-block')) + .map((span) => span.textContent) + .join(''), + ).toBe(expectedWords[index]); + } + } finally { + document.documentElement.dir = previousDir; + } + }); }); diff --git a/packages/client/src/components/SplitText.tsx b/packages/client/src/components/SplitText.tsx index 46dd757365..dfbc410139 100644 --- a/packages/client/src/components/SplitText.tsx +++ b/packages/client/src/components/SplitText.tsx @@ -1,5 +1,5 @@ -import { useSprings, animated, SpringConfig } from '@react-spring/web'; import { useEffect, useRef, useState } from 'react'; +import { useSprings, animated, SpringConfig } from '@react-spring/web'; interface SegmenterOptions { granularity?: 'grapheme' | 'word' | 'sentence'; @@ -135,15 +135,21 @@ const SplitText: React.FC = ({ return ( <> - {text}