LibreChat/client/src/hooks/useDocumentDirection.ts
Marco Beretta 30e2a3add6
📄 fix: Mirror Agents, Prompts, Skills and Other Pages for RTL (#17268)
* fix: Mirror Page Components For RTL Layouts

* fix: Keep the Project Workspace Panel Group LTR Under RTL

The workspace reversed its panels under RTL but left the group inheriting the document direction, so the flex row reversed them again: details stayed on the left and the separator dragged backwards. Add RTL scenarios for the project workspace, shared artifacts pane and marketplace category tabs.

* fix: Drop the Conflicting RTL Margins on the Agent Detail Close Button

The logical -me-2 already pulls the button to the inline end, so the leftover rtl: overrides pushed it into the header under RTL.

* test: Drag RTL Separators in Pointer-Sized Steps

* fix: Keep Input Adornments on the Side Their Field Reserves

* fix: Remount the Project Workspace Separator When Direction Changes

* test: Cover RTL Separator Keys and the Prompt Counter

* fix: Remount the Shared Artifacts Separator When Direction Changes

* test: Open the Prompt Counter Scenario From the Create Dialog

* test: Allow Sub-Pixel Rounding Beside the Prompt Counter

* fix: Inset the Prompt Name From Its Inline Start

* test: Open the Scrim Spec's Row Menu by Focus

The row's menu button mounts on row hover or focus. When this spec shares a
worker with specs that leave a streaming chat in the sidebar, the list
remounts rows under the pointer and the hover never mounts the button. The
leak is pre-existing and tracked separately; this spec now focuses the row it
seeded and repeats the focus until the menu button holds it.
2026-10-21 14:20:12 +02:00

18 lines
674 B
TypeScript

import { useSyncExternalStore } from 'react';
type Direction = 'ltr' | 'rtl';
const subscribe = (onChange: () => void) => {
const observer = new MutationObserver(onChange);
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['dir'] });
return () => observer.disconnect();
};
const getSnapshot = (): Direction => (document.documentElement.dir === 'rtl' ? 'rtl' : 'ltr');
const getServerSnapshot = (): Direction => 'ltr';
/** Reads the document direction and re-renders when `<html dir>` changes. */
export default function useDocumentDirection(): Direction {
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
}