From 6c0d3a7cbb977bdabe927ae38e95a6d3daf9d84c Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Mon, 19 Oct 2026 23:10:06 +0200 Subject: [PATCH] =?UTF-8?q?=E2=86=94=EF=B8=8F=20fix:=20Follow=20the=20Inte?= =?UTF-8?q?rface=20Direction=20in=20Radix,=20the=20Composer=20and=20First?= =?UTF-8?q?=20Paint=20(#17264)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Follow the Interface Direction in Radix, the Composer and First Paint Wrap the app in a Radix DirectionProvider driven by i18n so Tabs, Select and menus stop rendering LTR subtrees in right-to-left locales, and swipe toasts toward the inline end. Chat direction becomes auto, ltr or rtl (auto by default; stored LTR/RTL values are kept). The composer applies a forced direction as a dir attribute instead of reversing rows, which double-flipped under an RTL document, and the text fields default to dir=auto. The unused Jotai chat direction atom that pinned every TextareaAutosize to ltr is removed. index.html sets dir before first paint, and the language setting no longer races i18n over document.lang. * fix: Keep the Empty Composer Placeholder on the Interface's Reading Edge --- client/index.html | 18 +++++++ client/package.json | 1 + client/src/App.jsx | 36 +++++++------- client/src/Providers/Direction.tsx | 24 ++++++++++ .../src/Providers/MessagePartsHostContext.tsx | 3 +- .../Providers/__tests__/bootDirection.spec.ts | 48 +++++++++++++++++++ client/src/components/Chat/Input/ChatForm.tsx | 25 +++++----- .../components/Chat/Input/Composer/Bar.tsx | 12 +---- .../components/Chat/Input/Composer/Tray.tsx | 3 -- .../Input/Composer/__tests__/Tray.spec.tsx | 1 - .../components/Chat/Input/Files/FileRow.tsx | 10 +--- .../Messages/Content/EditContentParts.tsx | 9 ++-- .../Chat/Messages/Content/EditMessage.tsx | 7 ++- .../__tests__/EditContentParts.spec.tsx | 14 +++--- .../src/components/Nav/Settings/controls.tsx | 3 -- .../Nav/SettingsTabs/Chat/ChatDirection.tsx | 44 ++++++++--------- client/src/locales/en/translation.json | 1 - .../src/store/__tests__/chatDirection.spec.ts | 33 +++++++++++++ client/src/store/settings.ts | 15 +++++- package-lock.json | 2 + packages/chat/src/react/host.tsx | 4 +- packages/client/package.json | 1 + .../src/components/TextareaAutosize.tsx | 7 +-- packages/client/src/store.ts | 3 -- 24 files changed, 217 insertions(+), 107 deletions(-) create mode 100644 client/src/Providers/Direction.tsx create mode 100644 client/src/Providers/__tests__/bootDirection.spec.ts create mode 100644 client/src/store/__tests__/chatDirection.spec.ts diff --git a/client/index.html b/client/index.html index 049c2e3fc4..ca68ab0dee 100644 --- a/client/index.html +++ b/client/index.html @@ -47,6 +47,24 @@ document.documentElement.style.setProperty('--ui-scale', String(uiScale)); } + /* Direction before first paint, from the same sources `detectInitialLanguage` reads, + * so a right-to-left interface does not render one frame left-to-right. The list is + * the right-to-left locales the app ships; i18n.ts reapplies `dir` once it loads. */ + const cookie = document.cookie.match(/(?:^|;\s*)lang=([^;]*)/); + let lang = cookie ? cookie[1] : ''; + if (!lang) { + try { + lang = localStorage.getItem('lang') || ''; + lang = JSON.parse(lang); + } catch (e) { + /* Stored unquoted, or Web Storage denied: the raw value or the browser language. */ + } + } + lang = String(lang || navigator.language || '').toLowerCase(); + if (['ar', 'he', 'fa', 'ug'].indexOf(lang.split(/[-_]/)[0]) !== -1) { + document.documentElement.dir = 'rtl'; + } + let theme = null; try { theme = localStorage.getItem('color-theme'); diff --git a/client/package.json b/client/package.json index a26e0cb9ae..a07bb8cded 100644 --- a/client/package.json +++ b/client/package.json @@ -47,6 +47,7 @@ "@radix-ui/react-checkbox": "^1.3.11", "@radix-ui/react-collapsible": "^1.1.20", "@radix-ui/react-dialog": "^1.1.23", + "@radix-ui/react-direction": "^1.1.4", "@radix-ui/react-dropdown-menu": "^2.1.24", "@radix-ui/react-hover-card": "^1.1.23", "@radix-ui/react-icons": "^1.3.0", diff --git a/client/src/App.jsx b/client/src/App.jsx index f8fc49a552..7b57c13a59 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -2,10 +2,10 @@ import { useEffect } from 'react'; import { RecoilRoot } from 'recoil'; import { DndProvider } from 'react-dnd'; import { RouterProvider } from 'react-router-dom'; -import * as RadixToast from '@radix-ui/react-toast'; import { HTML5Backend } from 'react-dnd-html5-backend'; import { Toast, ToastViewport, ToastProvider, useInputModality } from '@librechat/client'; import { QueryClient, QueryClientProvider, QueryCache, MutationCache } from '@tanstack/react-query'; +import Direction, { ToastSwipeProvider } from '~/Providers/Direction'; import { ScreenshotProvider, useApiErrorBoundary } from './hooks'; import WakeLockManager from '~/components/System/WakeLockManager'; import QueryDevtoolsGate from '~/components/QueryDevtoolsGate'; @@ -55,12 +55,13 @@ const App = () => { - - - - - - {/* Location updates commit in the caller's own task instead + + + + + + + {/* Location updates commit in the caller's own task instead of React's transition lane. A transition keeps the OUTGOING route painted until the incoming one finishes rendering, so switching conversations left the previous @@ -79,16 +80,17 @@ const App = () => { transition-safe reads are gated behind `_TRANSITION_SUPPORT_UNSTABLE` hooks this app does not use. Worth revisiting once that state has moved to Jotai. */} - - - - - - - - - - + + + + + + + + + + + ); diff --git a/client/src/Providers/Direction.tsx b/client/src/Providers/Direction.tsx new file mode 100644 index 0000000000..314a46a795 --- /dev/null +++ b/client/src/Providers/Direction.tsx @@ -0,0 +1,24 @@ +import { useTranslation } from 'react-i18next'; +import * as RadixToast from '@radix-ui/react-toast'; +import { DirectionProvider, useDirection } from '@radix-ui/react-direction'; +import type { ReactNode } from 'react'; + +/** + * Radix primitives read their direction from this context, never from ``, and fall back + * to `ltr`. Without it Tabs, Select and menus render `dir="ltr"` subtrees and map arrow keys as LTR + * inside a right-to-left interface. + */ +export default function Direction({ children }: { children: ReactNode }) { + const { i18n } = useTranslation(); + return {children}; +} + +/** Swiping a toast away runs toward the inline end, which is the left edge in a right-to-left UI. */ +export function ToastSwipeProvider({ children }: { children: ReactNode }) { + const dir = useDirection(); + return ( + + {children} + + ); +} diff --git a/client/src/Providers/MessagePartsHostContext.tsx b/client/src/Providers/MessagePartsHostContext.tsx index 6b00fa3e44..7e73f7b271 100644 --- a/client/src/Providers/MessagePartsHostContext.tsx +++ b/client/src/Providers/MessagePartsHostContext.tsx @@ -130,8 +130,7 @@ export const appMessagePartsHost: MessagePartsHost = { useShowThinking: () => useAtomValue(showThinkingAtom), useAutoExpandTools: () => useRecoilValue(store.autoExpandTools), useLaTeXParsing: () => useRecoilValue(store.LaTeXParsing), - useChatDirection: () => - useRecoilValue(store.chatDirection).toLowerCase() === 'rtl' ? 'rtl' : 'ltr', + useChatDirection: () => useRecoilValue(store.chatDirection), useUserTextPreferences: useAppUserTextPreferences, /* The atom rather than the auth context: AuthContextProvider mirrors the user into it, and the * public share route mounts outside that provider. */ diff --git a/client/src/Providers/__tests__/bootDirection.spec.ts b/client/src/Providers/__tests__/bootDirection.spec.ts new file mode 100644 index 0000000000..967b6b250d --- /dev/null +++ b/client/src/Providers/__tests__/bootDirection.spec.ts @@ -0,0 +1,48 @@ +import { resolve } from 'path'; +import { readFileSync } from 'fs'; + +/** The inline shell script in `client/index.html` that sets `dir` before first paint. */ +const bootScript = (() => { + const html = readFileSync(resolve(__dirname, '../../../index.html'), 'utf8'); + const scripts = [...html.matchAll(/