Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🌁 fix: Stop Painting the Closed Mobile Drawer (#16127)

lia-by-librechat[bot]fe79265b2f47
diff --git a/client/src/components/UnifiedSidebar/UnifiedSidebar.tsx b/client/src/components/UnifiedSidebar/UnifiedSidebar.tsx
index 7495e14051..22b6f704bc 100644
--- a/client/src/components/UnifiedSidebar/UnifiedSidebar.tsx
+++ b/client/src/components/UnifiedSidebar/UnifiedSidebar.tsx
@@ -13,6 +13,7 @@ import {
DRAWER_Z_INDEX,
MOBILE_DRAWER_ID,
MOBILE_DRAWER_WIDTH,
+ DRAWER_UNPAINTED,
} from './constants';
import { ChatContext, ChatFormProvider, ActivePanelProvider } from '~/Providers';
import { MobileHeader, MobileBottomBar, MobileShortcutTargets } from './mobile';
@@ -45,7 +46,7 @@ function SidebarChatProvider({ children }: { children: ReactNode }) {
);
}
-function UnifiedSidebar() {
+function UnifiedSidebar({ isSliding = false }: { isSliding?: boolean }) {
const localize = useLocalize();
const location = useLocation();
const navigate = useNavigate();
@@ -201,6 +202,12 @@ function UnifiedSidebar() {
* too or that one change still animates. */
transition: prefersReducedMotion ? undefined : MOBILE_DRAWER_TRANSITION,
zIndex: DRAWER_Z_INDEX,
+ /** Why a closed drawer is not painted at all: see DRAWER_UNPAINTED.
+ * The travel stays painted — `isSliding` covers the frames Recoil's
+ * deferred flip leaves uncovered at both ends, and a drag claims
+ * painting inline (see useDrawerSwipe), which hands this value back
+ * explicitly because React cannot re-assert it on its own. */
+ visibility: expanded || isSliding ? undefined : DRAWER_UNPAINTED,
}}
inert={!expanded ? '' : undefined}
>
diff --git a/client/src/components/UnifiedSidebar/__tests__/drawerPaint.spec.tsx b/client/src/components/UnifiedSidebar/__tests__/drawerPaint.spec.tsx
new file mode 100644
index 0000000000..4fd08f72cf
--- /dev/null
+++ b/client/src/components/UnifiedSidebar/__tests__/drawerPaint.spec.tsx
@@ -0,0 +1,100 @@
+import { render } from '@testing-library/react';
+import { MemoryRouter } from 'react-router-dom';
+import type { ReactNode } from 'react';
+import { DRAWER_UNPAINTED, MOBILE_DRAWER_ID } from '../constants';
+import UnifiedSidebar from '../UnifiedSidebar';
+
+/**
+ * A closed drawer is translated off the viewport, which hides it without taking
+ * it out of the paint: iOS Safari composites the scroller inside it separately
+ * and can leave that layer behind at the position it held while open, so the
+ * Projects and Pinned rows keep painting over the conversation. These pin the
+ * one state that cannot happen — a settled, closed drawer still being painted —
+ * and the two windows where painting it is exactly the point.
+ *
+ * React owns the resting value here; the slide's release in useDrawerSwipe hands
+ * this same value back rather than clearing the property, because React will not
+ * re-assert a prop whose value it has not changed. Both sides read one constant
+ * so they cannot drift apart.
+ */
+
+const mockSidebarState = { isSmallScreen: true, expanded: false, setExpanded: jest.fn() };
+
+jest.mock('@librechat/client', () => ({
+ useMediaQuery: () => false,
+}));
+
+jest.mock('~/hooks/Nav/useSidebarState', () => ({
+ __esModule: true,
+ default: () => mockSidebarState,
+}));
+
+jest.mock('~/hooks/Nav/useSidebarToggle', () => ({
+ __esModule: true,
+ default: () => ({ setSidebarOpen: jest.fn(), toggleSidebar: jest.fn() }),
+}));
+
+jest.mock('~/hooks/Nav/useUnifiedSidebarLinks', () => ({
+ __esModule: true,
+ default: () => [],
+}));
+
+jest.mock('~/hooks', () => ({
+ useLocalize: () => (key: string) => key,
+ useChatHelpers: () => ({}),
+}));
+
+jest.mock('~/Providers', () => ({
+ ChatContext: { Provider: ({ children }: { children: ReactNode }) => <>{children}</> },
+ ChatFormProvider: ({ children }: { children: ReactNode }) => <>{children}</>,
+ ActivePanelProvider: ({ children }: { children: ReactNode }) => <>{children}</>,
+}));
+
+jest.mock('~/components/SidePanel/Nav', () => ({
+ __esModule: true,
+ default: () => <div data-testid="side-panel-nav" />,
+}));
+
+jest.mock('../mobile', () => ({
+ MobileHeader: () => <div data-testid="mobile-header" />,
+ MobileBottomBar: () => <div data-testid="mobile-bottom-bar" />,
+ MobileShortcutTargets: () => <div data-testid="mobile-shortcut-targets" />,
+}));
+
+jest.mock('../Sidebar', () => ({
+ __esModule: true,
+ default: () => <div data-testid="desktop-sidebar" />,
+}));
+
+const drawerVisibility = (expanded: boolean, isSliding: boolean): string => {
+ mockSidebarState.expanded = expanded;
+ const { unmount } = render(
+ <MemoryRouter>
+ <UnifiedSidebar isSliding={isSliding} />
+ </MemoryRouter>,
+ );
+ const drawer = document.getElementById(MOBILE_DRAWER_ID);
+ if (drawer == null) {
+ throw new Error('the mobile drawer did not render');
+ }
+ const { visibility } = drawer.style;
+ unmount();
+ return visibility;
+};
+
+describe('mobile drawer painting', () => {
+ it('is not painted once closed and settled', () => {
+ expect(drawerVisibility(false, false)).toBe(DRAWER_UNPAINTED);
+ });
+
+ /** Recoil's flip is deferred past the opening frames and the closing
+ * transition outlives it at the other end, so the committed state brackets
+ * the wrong window; `isSliding` is what covers the travel. */
+ it('is painted while a slide is still travelling', () => {
+ expect(drawerVisibility(false, true)).toBe('');
+ });
+
+ it('is painted while open', () => {
+ expect(drawerVisibility(true, false)).toBe('');
+ });
+});
diff --git a/client/src/components/UnifiedSidebar/constants.ts b/client/src/components/UnifiedSidebar/constants.ts
index 8953123590..d586f1ba4c 100644
--- a/client/src/components/UnifiedSidebar/constants.ts
+++ b/client/src/components/UnifiedSidebar/constants.ts
@@ -62,6 +62,26 @@ export const DRAWER_Z_INDEX = 110;
*/
export const MOBILE_DRAWER_ID = 'mobile-drawer';
+/**
+ * What a closed, settled drawer's `visibility` is.
+ *
+ * Translating the drawer off the viewport hides it without taking it out of the
+ * paint, and iOS Safari composites the scroller inside it separately — that
+ * layer can be left behind at the position it held while open, painting the
+ * Projects and Pinned rows over the conversation. Not painting a closed drawer
+ * removes the layer the artifact is made of.
+ *
+ * Shared because React renders it and the slide's release hands it back (see
+ * useDrawerSwipe): React will not re-assert a style prop whose value it has not
+ * changed, so the release must write this exact value rather than clear the
+ * property, and the two sides cannot be allowed to drift.
+ *
+ * `visibility` and not `display`: the chats list is virtualized against this
+ * subtree and an undisplayed one reports no viewport, and the swipe gesture
+ * measures the closed drawer's width.
+ */
+export const DRAWER_UNPAINTED = 'hidden';
+
/**
* Lets a kicked toggle start the scrim fade with the drawer, rather than
* waiting for the deferred Recoil commit that a large conversation stalls.
diff --git a/client/src/hooks/Nav/__tests__/useDrawerSwipe.spec.tsx b/client/src/hooks/Nav/__tests__/useDrawerSwipe.spec.tsx
index 7c4f5b01c6..009d079c41 100644
--- a/client/src/hooks/Nav/__tests__/useDrawerSwipe.spec.tsx
+++ b/client/src/hooks/Nav/__tests__/useDrawerSwipe.spec.tsx
@@ -6,11 +6,17 @@ import useDrawerSwipe, {
setDrawerSlideListener,
} from '../useDrawerSwipe';
import {
+ DRAWER_UNPAINTED,
MOBILE_DRAWER_ID,
MOBILE_PANE_SHIFT,
MOBILE_SCRIM_ID,
+ TRANSITION_MS,
} from '~/components/UnifiedSidebar/constants';
+/** Mirrors the hook's own settle buffer: the window between React writing the
+ * resting value and the release handing the inline styles back. */
+const SETTLE_BUFFER_MS = 80;
+
const DRAWER_WIDTH = 375;
const createTouch = (x: number, y: number, identifier = 0) =>
@@ -975,6 +981,147 @@ describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
});
});
+/**
+ * A closed drawer is not painted at all (see UnifiedSidebar), so every path
+ * that moves it has to claim painting for the travel and hand it back once the
+ * slide is over: claimed too late the opening frames are invisible, released
+ * too late — or never — and the settled drawer keeps the off-screen layer whose
+ * stale tiles this is all here to avoid.
+ */
+describe('useDrawerSwipe — painting through the travel', () => {
+ it('paints the drawer for a drag that opens it out of a closed state', () => {
+ jest.useFakeTimers();
+ const harness = setup(false);
+ harness.swipe(
+ harness.pane,
+ [
+ { x: 20, y: 100, t: 0 },
+ { x: 120, y: 104, t: 50 },
+ ],
+ false,
+ );
+
+ expect(harness.drawer.style.visibility).toBe('visible');
+
+ harness.pane.dispatchEvent(touchEvent('touchend', [], 120));
+ jest.runAllTimers();
+
+ expect(harness.onOpenChange).toHaveBeenCalledWith(true);
+ expect(harness.drawer.style.visibility).toBe('');
+ jest.useRealTimers();
+ harness.unmount();
+ });
+
+ /** The drawer never commits open here, so nothing else would ever resolve the
+ * inline override: the settle has to land on the closed value itself. */
+ it('settles a drag that snaps back on the unpainted value', () => {
+ jest.useFakeTimers();
+ const harness = setup(false);
+ harness.swipe(harness.pane, [
+ { x: 20, y: 100, t: 0 },
+ { x: 60, y: 100, t: 200 },
+ { x: 80, y: 100, t: 400 },
+ ]);
+ jest.runAllTimers();
+
+ expect(harness.onOpenChange).not.toHaveBeenCalled();
+ expect(harness.drawer.style.visibility).toBe(DRAWER_UNPAINTED);
+ jest.useRealTimers();
+ harness.unmount();
+ });
+
+ it.each([
+ ['open', false, true, ''],
+ ['close', true, false, DRAWER_UNPAINTED],
+ ])(
+ 'paints a kicked %s slide before its state flip commits, then settles',
+ (_name, open, next, settled) => {
+ jest.useFakeTimers();
+ const harness = setup(open);
+ const visibilityAtApply: string[] = [];
+ kickDrawerAnimation(next, () => {
+ visibilityAtApply.push(harness.drawer.style.visibility);
+ });
+
+ expect(visibilityAtApply).toEqual(['visible']);
+
+ jest.advanceTimersByTime(400);
+
+ expect(harness.drawer.style.visibility).toBe(settled);
+ jest.useRealTimers();
+ harness.unmount();
+ },
+ );
+
+ /**
+ * The regression that made the first pass of this change a no-op for every
+ * button and keyboard close. React owns the resting value and writes
+ * `hidden` when the travel window closes at TRANSITION_MS; the release runs a
+ * buffer later, and clearing the property there dropped that value while
+ * React still believed its unchanged prop was applied — so React never wrote
+ * it again and the settled, closed drawer was painted for the rest of the
+ * session. Modelled the way the pane's transform already is: the declarative
+ * value is in the DOM before the release, and the release must respect it.
+ */
+ it('leaves a settled close on the value React rendered, not cleared', () => {
+ jest.useFakeTimers();
+ const harness = setup(true);
+ kickDrawerAnimation(false, () => undefined);
+ /** What React writes once `isSliding` expires, mid-way through the buffer
+ * the release waits out. */
+ jest.advanceTimersByTime(TRANSITION_MS);
+ harness.drawer.style.visibility = DRAWER_UNPAINTED;
+
+ jest.advanceTimersByTime(SETTLE_BUFFER_MS + 20);
+
+ expect(harness.drawer.style.visibility).toBe(DRAWER_UNPAINTED);
+ jest.useRealTimers();
+ harness.unmount();
+ });
+
+ /** A gesture surviving into a new effect run was interrupted, and the run that
+ * inherits it resolves the drag styles to the state it finds rather than to
+ * the gesture's own target. That is the other path that can strand the
+ * claim — here an external close commits while a close drag is still held. */
+ it('resolves an interrupted drag to the state that superseded it', () => {
+ jest.useFakeTimers();
+ const harness = setup(true);
+ harness.swipe(
+ harness.drawer,
+ [
+ { x: 350, y: 100, t: 0 },
+ { x: 250, y: 100, t: 50 },
+ ],
+ false,
+ );
+
+ expect(harness.drawer.style.visibility).toBe('visible');
+
+ harness.rerender({ open: false, enabled: true });
+
+ expect(harness.drawer.style.visibility).toBe(DRAWER_UNPAINTED);
+ jest.useRealTimers();
+ harness.unmount();
+ });
+
+ /** Reduced motion has no travel to paint: the state flip is the whole
+ * transition, so nothing claims painting and React's value stands alone. */
+ it('never claims painting under reduced motion', () => {
+ jest.useFakeTimers();
+ const harness = setup(false, true);
+ harness.swipe(harness.pane, [
+ { x: 20, y: 100, t: 0 },
+ { x: 240, y: 100, t: 50 },
+ ]);
+ kickDrawerAnimation(false, jest.fn());
+ jest.runAllTimers();
+
+ expect(harness.drawer.style.visibility).not.toBe('visible');
+ jest.useRealTimers();
+ harness.unmount();
+ });
+});
+
describe('findHorizontalScrollBlocker', () => {
const scroller = (scrollLeft: number) => {
const el = document.createElement('div');
diff --git a/client/src/hooks/Nav/useDrawerSwipe.ts b/client/src/hooks/Nav/useDrawerSwipe.ts
index 9d9c91a7c5..48dfa4faf5 100644
--- a/client/src/hooks/Nav/useDrawerSwipe.ts
+++ b/client/src/hooks/Nav/useDrawerSwipe.ts
@@ -7,6 +7,7 @@ import {
MOBILE_PANE_SHIFT,
MOBILE_SCRIM_ID,
SIDEBAR_TRANSITION,
+ DRAWER_UNPAINTED,
} from '~/components/UnifiedSidebar/constants';
/** Horizontal travel before the gesture claims the touch (also the tap filter). */
@@ -241,6 +242,13 @@ const releaseInlineStyles = (drawer: HTMLElement, pane: HTMLElement, paneOpen: b
const settled = settledTransitions();
drawer.style.transform = '';
drawer.style.willChange = '';
+ /** Re-asserted rather than cleared, for the same reason as the width below:
+ * a closed drawer is not painted (see DRAWER_UNPAINTED), React has already
+ * written that value by the time this runs — the travel window closes at
+ * TRANSITION_MS and this runs a buffer later — and clearing the property
+ * would drop it while React believes its unchanged prop is still applied.
+ * The drawer would be painted again, closed, which is the whole artifact. */
+ drawer.style.visibility = paneOpen ? '' : DRAWER_UNPAINTED;
/** The close pins a measured width, and clearing would drop the declarative
* value with it: React will not re-assert a style prop whose value it has
* not changed. */
@@ -426,6 +434,9 @@ export default function useDrawerSwipe({
return;
}
drawer.style.willChange = 'transform';
+ /** Same reason as the drag above, and the closing direction needs it too:
+ * the deferred flip that commits `expanded` lands after these frames. */
+ drawer.style.visibility = 'visible';
if (next) {
pane.style.willChange = 'transform';
}
@@ -571,6 +582,9 @@ export default function useDrawerSwipe({
gesture.pane.style.transition = 'none';
gesture.drawer.style.willChange = 'transform';
gesture.pane.style.willChange = 'transform';
+ /** The drag paints the drawer before any state flip: it follows the
+ * finger out of a closed state, which is not painted. */
+ gesture.drawer.style.visibility = 'visible';
/** Dropping the transition lands a width still easing toward the
* strip target on that target in this frame, so the touchstart
* snapshot is now stale — and the paired transforms below read it
diff --git a/client/src/routes/Root.tsx b/client/src/routes/Root.tsx
index 274cfd29d2..11f5bba1c4 100644
--- a/client/src/routes/Root.tsx
+++ b/client/src/routes/Root.tsx
@@ -156,7 +156,10 @@ export default function Root() {
} as React.CSSProperties
}
>
- <UnifiedSidebar />
+ {/* The drawer stops being painted once it is closed and
+ settled, so it needs the same travel window the scrim and
+ the pane's `inert` read. */}
+ <UnifiedSidebar isSliding={isSliding} />
<div
ref={paneRef}
/** Focus target of last resort when the drawer closes on a