LibreChat/client/src/components
Danny Avila 5353e2c138
👐 fix: Open/Close Sidebar Button Animation UX Regression from #10521 (#10694)
Problem:
--------
Commit 5ed1f2991 introduced a layout shift regression when opening the
sidebar. The UI would visibly "jump" as elements shifted right before
the animation completed. Closing the sidebar worked correctly.

Root Cause Analysis:
--------------------
The accessibility PR added a redundant `{navVisible && ...}` conditional
wrapper around the `<nav>` content inside Nav.tsx's `motion.div`. This
caused a race condition:

1. User clicks "Open Sidebar" button
2. `navVisible` state becomes `true`
3. React renders the `motion.div` AND its children simultaneously
4. The inner `{navVisible && (<nav>...)}` renders content at full width
   (320px/260px) BEFORE framer-motion applies `initial={{ width: 0 }}`
5. Brief flash of full-width content causes visible layout shift
6. Animation then starts from width: 0, but damage is done

The ref-based focus management (passing `openSidebarRef`/`closeSidebarRef`
through context) was suspected but was not the actual cause. However,
`requestAnimationFrame` focus calls during animation start could trigger
forced layout calculations, exacerbating the issue.

Solution:
---------
1. Remove redundant conditional rendering in Nav.tsx
   - The outer `{navVisible && (<motion.div>...)}` already controls
     visibility
   - The `overflow-x-hidden` class on motion.div clips content during
     animation
   - Content should always exist inside motion.div for smooth clipping

2. Replace ref-based focus with ID-based focus management
   - Refs passed through component tree can affect React's reconciliation
   - Using `document.getElementById()` decouples focus from render cycle
   - Exported `CLOSE_SIDEBAR_ID` and `OPEN_SIDEBAR_ID` constants for
     consistency

3. Delay focus until after animation completes
   - Changed from `requestAnimationFrame` to `setTimeout(..., 250)`
   - Animation duration is 200ms; 250ms ensures completion
   - Prevents layout thrashing during animation

4. Clean up prop drilling
   - Removed `openSidebarRef`/`closeSidebarRef` from Root.tsx context
   - Simplified Nav.tsx, Header.tsx, NewChat.tsx prop signatures
   - Updated ContextType to remove ref properties

Files Changed:
--------------
- client/src/routes/Root.tsx
- client/src/components/Nav/Nav.tsx
- client/src/components/Nav/NewChat.tsx
- client/src/components/Chat/Header.tsx
- client/src/components/Chat/Menus/OpenSidebar.tsx
- client/src/common/types.ts

Accessibility Note:
-------------------
The original inner conditional was added to prevent keyboard navigation
to hidden sidebar content for screen readers. This is still handled by:
- AnimatePresence unmounting the motion.div after exit animation
- The motion.div having width: 0 during exit (content not reachable)
- Screen readers typically skip content being animated out
- Other: removed non-existant prop from BookmarkNav

Testing:
--------
- Verified smooth animation when opening sidebar (no layout shift)
- Verified smooth animation when closing sidebar (unchanged)
- Verified focus transfers correctly between open/close buttons
- Verified keyboard navigation works as expected
2025-11-27 12:27:03 -05:00
..
Agents 🌐 refactor: Interpolate Localization Keys (#10650) 2025-11-27 12:27:00 -05:00
Artifacts 📢 fix: Resolved Screen Reader Issues with TooltipAnchor (#10580) 2025-11-19 17:10:10 -05:00
Audio ️ fix: Accessibility, UI consistency, dialog & avatar refactors (#9975) 2025-10-07 14:12:49 -04:00
Auth 🛗 fix: Address Accessibility Issues - Axe Rating: Serious (#10521) 2025-11-27 12:27:02 -05:00
Banners 🛂 feat: OpenID Logout Redirect to end_session_endpoint (#5626) 2025-02-03 10:53:04 -05:00
Bookmarks 🧩 refactor: Decouple MCP Config from Startup Config (#10689) 2025-11-27 12:27:03 -05:00
Chat 👐 fix: Open/Close Sidebar Button Animation UX Regression from #10521 (#10694) 2025-11-27 12:27:03 -05:00
Conversations 🛗 fix: Address Accessibility Issues - Axe Rating: Serious (#10521) 2025-11-27 12:27:02 -05:00
Endpoints 🪦 refactor: Remove Legacy Code (#10533) 2025-11-27 12:27:01 -05:00
Files 📦 feat: Move Shared Components to @librechat/client (#8685) 2025-07-27 12:19:01 -04:00
Input 🪦 refactor: Remove Legacy Code (#10533) 2025-11-27 12:27:01 -05:00
MCP 🧩 refactor: Decouple MCP Config from Startup Config (#10689) 2025-11-27 12:27:03 -05:00
Messages 🛗 fix: Address Accessibility Issues - Axe Rating: Serious (#10521) 2025-11-27 12:27:02 -05:00
Nav 👐 fix: Open/Close Sidebar Button Animation UX Regression from #10521 (#10694) 2025-11-27 12:27:03 -05:00
OAuth 🪐 feat: MCP OAuth 2.0 Discovery Support (#7924) 2025-06-17 13:50:33 -04:00
Plugins/Store 🪦 refactor: Remove Legacy Code (#10533) 2025-11-27 12:27:01 -05:00
Prompts 🛗 fix: Address Accessibility Issues - Axe Rating: Serious (#10521) 2025-11-27 12:27:02 -05:00
Share 🪦 refactor: Remove Legacy Code (#10533) 2025-11-27 12:27:01 -05:00
SharePoint 🎨 style: Theming in SharePointPickerDialog, PrincipalAvatar, and PeoplePickerSearchItem 2025-08-13 16:24:23 -04:00
Sharing 🌐 refactor: Interpolate Localization Keys (#10650) 2025-11-27 12:27:00 -05:00
SidePanel 🧩 refactor: Decouple MCP Config from Startup Config (#10689) 2025-11-27 12:27:03 -05:00
System feat: Prevent Screen Sleep During Response Generation (#10597) 2025-11-21 09:14:32 -05:00
Tools 🧩 refactor: Decouple MCP Config from Startup Config (#10689) 2025-11-27 12:27:03 -05:00
ui 🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety 2025-08-13 16:24:20 -04:00
Web 🔗 fix: File Citation Processing to Use Tool Artifacts 2025-08-13 16:24:21 -04:00
index.ts 🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety 2025-08-13 16:24:20 -04:00