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: Keep Long Chats Stationary Under the Mobile Drawer (#17377)

lia-by-librechat[bot]1b49b5d8e277
diff --git a/client/src/components/UnifiedSidebar/constants.ts b/client/src/components/UnifiedSidebar/constants.ts
index 7948dd65d5..230634dc3e 100644
--- a/client/src/components/UnifiedSidebar/constants.ts
+++ b/client/src/components/UnifiedSidebar/constants.ts
@@ -9,22 +9,12 @@ export const EXPANDED_MIN = 360;
* of the conversation stays visible, which keeps the drawer reading as a layer
* over the conversation and gives the close gesture a target to tap.
*
- * Both the drawer and the pane read the one custom property, so their travel
- * cannot drift apart (see SIDEBAR_TRANSITION) and the setting can change at
- * runtime without threading a number through either. The fallback is the
- * default, so anything rendered outside the property's scope still agrees.
+ * The scrim and drawer share this width so the optional strip stays aligned.
*/
export const MOBILE_DRAWER_WIDTH_VAR = '--mobile-drawer-width';
export const MOBILE_DRAWER_FULL_WIDTH = '100%';
export const MOBILE_DRAWER_STRIP_WIDTH = '80%';
export const MOBILE_DRAWER_WIDTH = `var(${MOBILE_DRAWER_WIDTH_VAR}, ${MOBILE_DRAWER_FULL_WIDTH})`;
-/**
- * Which way the drawer opens: 1 when it sits on the left (LTR), -1 when it sits on
- * the right (RTL). Root sets it with an `rtl:` utility, so the pane's declarative
- * transform follows the document direction without React reading it.
- */
-export const MOBILE_DRAWER_SIGN_VAR = '--mobile-drawer-sign';
-export const MOBILE_PANE_SHIFT = `translateX(calc(var(${MOBILE_DRAWER_SIGN_VAR}, 1) * ${MOBILE_DRAWER_WIDTH}))`;
export const TRANSITION_MS = 300;
/**
* Decelerating, but it settles rather than crawls. The previous
@@ -35,19 +25,11 @@ export const TRANSITION_MS = 300;
export const EASING = 'cubic-bezier(0.32, 0.72, 0, 1)';
/**
- * The drawer and the chat pane move as one object, so they must stay
- * frame-locked; a second copy of this string is a visible seam mid-animation.
+ * Shared transform timing for the sidebar and mobile drawer.
*/
export const SIDEBAR_TRANSITION = `transform ${TRANSITION_MS}ms ${EASING}`;
-/**
- * The drawer also transitions its width, because that is the one property the
- * pane tracks through its own transform. Changing the strip setting while the
- * drawer is open would otherwise jump the width in a frame while the pane
- * eased across 300ms, leaving the newly exposed slice with no conversation
- * under it. Only the drawer needs this: the pane's width is flex-driven and
- * animating it would reach the desktop sidebar's collapse as well.
- */
+/** The optional strip setting can change while the drawer is open. */
export const MOBILE_DRAWER_TRANSITION = `${SIDEBAR_TRANSITION}, width ${TRANSITION_MS}ms ${EASING}`;
/**
diff --git a/client/src/hooks/Nav/__tests__/useDrawerSwipe.spec.tsx b/client/src/hooks/Nav/__tests__/useDrawerSwipe.spec.tsx
index ffdeafa106..d1a01cf615 100644
--- a/client/src/hooks/Nav/__tests__/useDrawerSwipe.spec.tsx
+++ b/client/src/hooks/Nav/__tests__/useDrawerSwipe.spec.tsx
@@ -8,7 +8,6 @@ import useDrawerSwipe, {
import {
DRAWER_UNPAINTED,
MOBILE_DRAWER_ID,
- MOBILE_PANE_SHIFT,
MOBILE_SCRIM_ID,
TRANSITION_MS,
} from '~/components/UnifiedSidebar/constants';
@@ -121,6 +120,39 @@ afterEach(() => {
document.getElementById(MOBILE_SCRIM_ID)?.remove();
});
+describe('useDrawerSwipe: stationary transcript', () => {
+ it.each([false, true])('never promotes or transforms the chat (reduced motion=%s)', (reduced) => {
+ jest.useFakeTimers();
+ const harness = setup(false, reduced);
+ const transcript = document.createElement('div');
+ const row = document.createElement('button');
+ row.textContent = 'Existing message';
+ transcript.append(row);
+ transcript.scrollTop = 2400;
+ harness.pane.append(transcript);
+
+ kickDrawerAnimation(true, jest.fn());
+ expect(harness.pane.style.transform).toBe('');
+ expect(harness.pane.style.willChange).toBe('');
+ jest.runAllTimers();
+ harness.rerender({ open: true, enabled: true });
+ harness.swipe(harness.drawer, [
+ { x: 350, y: 100, t: 0 },
+ { x: 120, y: 100, t: 100 },
+ ]);
+ jest.runAllTimers();
+ harness.rerender({ open: false, enabled: true });
+
+ expect(harness.pane.style.transform).toBe('');
+ expect(harness.pane.style.willChange).toBe('');
+ expect(harness.pane.firstElementChild).toBe(transcript);
+ expect(transcript.firstElementChild).toBe(row);
+ expect(transcript.scrollTop).toBe(2400);
+ jest.useRealTimers();
+ harness.unmount();
+ });
+});
+
describe('useDrawerSwipe — opening from the chat pane', () => {
it('follows the finger and commits past the distance threshold', () => {
const harness = setup(false);
@@ -136,14 +168,14 @@ describe('useDrawerSwipe — opening from the chat pane', () => {
expect(events[1].defaultPrevented).toBe(true);
expect(harness.drawer.style.transform).toBe(`translate3d(${200 - DRAWER_WIDTH}px, 0, 0)`);
- expect(harness.pane.style.transform).toBe('translate3d(200px, 0, 0)');
+ expect(harness.pane.style.transform).toBe('');
expect(harness.drawer.style.transition).toBe('none');
harness.pane.dispatchEvent(touchEvent('touchend', [], 120));
expect(harness.onOpenChange).toHaveBeenCalledWith(true);
expect(harness.drawer.style.transform).toBe('translate3d(0, 0, 0)');
- expect(harness.pane.style.transform).toBe(MOBILE_PANE_SHIFT);
+ expect(harness.pane.style.transform).toBe('');
harness.unmount();
});
@@ -157,7 +189,7 @@ describe('useDrawerSwipe — opening from the chat pane', () => {
expect(harness.onOpenChange).not.toHaveBeenCalled();
expect(harness.drawer.style.transform).toBe('translate3d(-100%, 0, 0)');
- expect(harness.pane.style.transform).toBe('translate3d(0, 0, 0)');
+ expect(harness.pane.style.transform).toBe('');
harness.unmount();
});
@@ -253,7 +285,7 @@ describe('useDrawerSwipe — opening from the chat pane', () => {
expect(harness.onOpenChange).toHaveBeenCalledWith(true);
/** The snap must suppress the shared 300ms transition for the flip. */
expect(harness.drawer.style.transition).toBe('none');
- expect(harness.pane.style.transition).toBe('none');
+ expect(harness.pane.style.transition).toBe('');
harness.unmount();
});
@@ -273,7 +305,7 @@ describe('useDrawerSwipe — opening from the chat pane', () => {
jest.runAllTimers();
expect(harness.drawer.style.transition).toBe('none');
- expect(harness.pane.style.transition).toBe('none');
+ expect(harness.pane.style.transition).toBe('');
jest.useRealTimers();
harness.unmount();
});
@@ -307,7 +339,7 @@ describe('useDrawerSwipe — closing from the drawer', () => {
expect(harness.onOpenChange).toHaveBeenCalledWith(false);
expect(harness.drawer.style.transform).toBe('translate3d(-100%, 0, 0)');
- expect(harness.pane.style.transform).toBe('translate3d(0, 0, 0)');
+ expect(harness.pane.style.transform).toBe('');
harness.unmount();
});
@@ -346,7 +378,7 @@ describe('useDrawerSwipe — interruptions and re-arming', () => {
{ x: 220, y: 100, t: 50 },
]);
expect(harness.onOpenChange).toHaveBeenCalledWith(true);
- expect(harness.pane.style.transform).toBe(MOBILE_PANE_SHIFT);
+ expect(harness.pane.style.transform).toBe('');
harness.rerender({ open: true, enabled: true });
harness.rerender({ open: false, enabled: true });
@@ -371,7 +403,7 @@ describe('useDrawerSwipe — interruptions and re-arming', () => {
expect(harness.drawer.style.transform).toBe('translate3d(0, 0, 0)');
jest.runAllTimers();
- expect(harness.pane.style.transform).toBe(MOBILE_PANE_SHIFT);
+ expect(harness.pane.style.transform).toBe('');
expect(harness.drawer.style.transform).toBe('');
jest.useRealTimers();
harness.unmount();
@@ -392,7 +424,7 @@ describe('useDrawerSwipe — interruptions and re-arming', () => {
touchEvent('touchend', [createTouch(220, 100, 0)], 80, [createTouch(80, 200, 1)]),
);
expect(harness.onOpenChange).not.toHaveBeenCalled();
- expect(harness.pane.style.transform).toBe('translate3d(200px, 0, 0)');
+ expect(harness.pane.style.transform).toBe('');
harness.pane.dispatchEvent(touchEvent('touchend', [], 100));
expect(harness.onOpenChange).toHaveBeenCalledWith(true);
@@ -416,7 +448,7 @@ describe('useDrawerSwipe — interruptions and re-arming', () => {
expect(harness.drawer.style.transition).not.toBe('none');
/** React committed the open pane transform before this cleanup and will
* not re-assert it — the release must restore it, not clear it. */
- expect(harness.pane.style.transform).toBe(MOBILE_PANE_SHIFT);
+ expect(harness.pane.style.transform).toBe('');
harness.unmount();
});
@@ -495,7 +527,7 @@ describe('useDrawerSwipe — interruptions and re-arming', () => {
});
describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
- it('slides both elements before the state flip runs, then hands off to classes', () => {
+ it('slides only the drawer before the state flip, then hands off to classes', () => {
jest.useFakeTimers();
const harness = setup(false);
/** The sync rAF mock collapses the two-frame deferral, so capturing the
@@ -506,8 +538,9 @@ describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
});
expect(transformAtApply).toEqual(['translate3d(0, 0, 0)']);
- expect(harness.pane.style.transform).toBe(MOBILE_PANE_SHIFT);
+ expect(harness.pane.style.transform).toBe('');
expect(harness.drawer.style.willChange).toBe('transform');
+ expect(harness.pane.style.willChange).toBe('');
expect(harness.onOpenChange).not.toHaveBeenCalled();
harness.rerender({ open: true, enabled: true });
@@ -516,7 +549,7 @@ describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
jest.runAllTimers();
expect(harness.drawer.style.transform).toBe('');
expect(harness.drawer.style.willChange).toBe('');
- expect(harness.pane.style.transform).toBe(MOBILE_PANE_SHIFT);
+ expect(harness.pane.style.transform).toBe('');
jest.useRealTimers();
harness.unmount();
});
@@ -553,7 +586,7 @@ describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
expect(harness.drawer.style.transform).toBe('translate3d(-100%, 0, 0)');
/** Retargeting to a close takes the reveal, since this drawer covers. */
- expect(harness.pane.style.transform).toBe('none');
+ expect(harness.pane.style.transform).toBe('');
harness.rerender({ open: false, enabled: true });
jest.runAllTimers();
@@ -590,7 +623,7 @@ describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
const applyState = jest.fn();
kickDrawerAnimation(true, applyState);
- expect(harness.pane.style.transform).toBe('translate3d(100px, 0, 0)');
+ expect(harness.pane.style.transform).toBe('');
expect(applyState).toHaveBeenCalledTimes(1);
harness.pane.dispatchEvent(touchEvent('touchend', [], 400));
harness.unmount();
@@ -614,7 +647,7 @@ describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
harness.rerender({ open: true, enabled: true });
jest.runAllTimers();
expect(harness.drawer.style.transition).toBe('none');
- expect(harness.pane.style.transition).toBe('none');
+ expect(harness.pane.style.transition).toBe('');
jest.useRealTimers();
harness.unmount();
});
@@ -629,7 +662,7 @@ describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
jest.runAllTimers();
expect(harness.drawer.style.transition).toContain('transform');
- expect(harness.pane.style.transition).toContain('transform');
+ expect(harness.pane.style.transition).toBe('');
jest.useRealTimers();
harness.unmount();
});
@@ -685,22 +718,17 @@ describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
queued.shift()?.(0);
expect(harness.drawer.style.transform).toBe('translate3d(0, 0, 0)');
- expect(harness.pane.style.transform).toBe(MOBILE_PANE_SHIFT);
+ expect(harness.pane.style.transform).toBe('');
harness.rerender({ open: true, enabled: true });
jest.advanceTimersByTime(400);
expect(harness.drawer.style.transform).toBe('');
- expect(harness.pane.style.transform).toBe(MOBILE_PANE_SHIFT);
+ expect(harness.pane.style.transform).toBe('');
jest.useRealTimers();
harness.unmount();
});
- /**
- * A reveal while the drawer covers the pane: repositioning instantly under an
- * opaque full-width layer is invisible, and animating the pane in from the
- * right instead makes every tap-to-navigate close visibly shift the chat
- * while the new conversation commits into the moving layer.
- */
+ /** Closing reveals the chat already in place underneath the drawer. */
it('reveals rather than animating when the drawer covers the pane', () => {
jest.useFakeTimers();
const harness = setup(true);
@@ -709,8 +737,8 @@ describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
expect(harness.drawer.style.transform).toBe('translate3d(-100%, 0, 0)');
expect(harness.drawer.style.transition).not.toBe('none');
- expect(harness.pane.style.transform).toBe('none');
- expect(harness.pane.style.transition).toBe('none');
+ expect(harness.pane.style.transform).toBe('');
+ expect(harness.pane.style.transition).toBe('');
harness.rerender({ open: false, enabled: true });
jest.runAllTimers();
@@ -724,11 +752,6 @@ describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
* reposition would land in the visible slice. Both surfaces animate together
* instead, matching what a finger drag already produces.
*/
- /**
- * The pane tracks the drawer's width through its own transform, so a runtime
- * width change has to move on the same curve or the newly exposed slice has
- * no conversation under it for the length of the transition.
- */
it('transitions the drawer width alongside its transform', () => {
jest.useFakeTimers();
const harness = setup(true, false, Math.round(DRAWER_WIDTH / 0.8));
@@ -738,13 +761,13 @@ describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
expect(harness.drawer.style.transition).toContain('width');
expect(harness.drawer.style.transition).toContain('transform');
/** Flex-driven, and animating it would reach the desktop collapse too. */
- expect(harness.pane.style.transition).toContain('transform');
+ expect(harness.pane.style.transition).toBe('');
expect(harness.pane.style.transition).not.toContain('width');
jest.useRealTimers();
harness.unmount();
});
- it('animates both surfaces when a strip of chat is left visible', () => {
+ it('overlays the stationary chat when a strip is left visible', () => {
jest.useFakeTimers();
const harness = setup(true, false, Math.round(DRAWER_WIDTH / 0.8));
@@ -752,12 +775,12 @@ describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
expect(harness.drawer.style.transform).toBe('translate3d(-100%, 0, 0)');
expect(harness.drawer.style.transition).not.toBe('none');
- expect(harness.pane.style.transform).toBe('translate3d(0, 0, 0)');
- expect(harness.pane.style.transition).not.toBe('none');
+ expect(harness.pane.style.transform).toBe('');
+ expect(harness.pane.style.transition).toBe('');
harness.rerender({ open: false, enabled: true });
jest.runAllTimers();
- expect(harness.pane.style.transition).not.toBe('none');
+ expect(harness.pane.style.transition).toBe('');
expect(harness.drawer.style.transform).toBe('');
jest.useRealTimers();
harness.unmount();
@@ -976,7 +999,7 @@ describe('useDrawerSwipe — kickDrawerAnimation (button toggles)', () => {
harness.pane.dispatchEvent(touchEvent('touchmove', [createTouch(60, 0)], 32));
expect(harness.drawer.style.transform).toBe('translate3d(-240px, 0, 0)');
- expect(harness.pane.style.transform).toBe('translate3d(60px, 0, 0)');
+ expect(harness.pane.style.transform).toBe('');
harness.unmount();
});
});
@@ -1197,7 +1220,7 @@ describe('useDrawerSwipe: right-to-left layouts', () => {
return el;
};
- it('opens on a leftward swipe and mirrors the drag transforms', () => {
+ it('opens on a leftward swipe without translating the chat', () => {
const harness = setupRtl(false);
const events = harness.swipe(
harness.pane,
@@ -1211,13 +1234,13 @@ describe('useDrawerSwipe: right-to-left layouts', () => {
expect(events[1].defaultPrevented).toBe(true);
expect(harness.drawer.style.transform).toBe(`translate3d(${DRAWER_WIDTH - 200}px, 0, 0)`);
- expect(harness.pane.style.transform).toBe('translate3d(-200px, 0, 0)');
+ expect(harness.pane.style.transform).toBe('');
harness.pane.dispatchEvent(touchEvent('touchend', [], 120));
expect(harness.onOpenChange).toHaveBeenCalledWith(true);
expect(harness.drawer.style.transform).toBe('translate3d(0, 0, 0)');
- expect(harness.pane.style.transform).toBe(MOBILE_PANE_SHIFT);
+ expect(harness.pane.style.transform).toBe('');
harness.unmount();
});
@@ -1243,7 +1266,7 @@ describe('useDrawerSwipe: right-to-left layouts', () => {
expect(harness.onOpenChange).not.toHaveBeenCalled();
expect(harness.drawer.style.transform).toBe('translate3d(100%, 0, 0)');
- expect(harness.pane.style.transform).toBe('translate3d(0, 0, 0)');
+ expect(harness.pane.style.transform).toBe('');
harness.unmount();
});
@@ -1277,7 +1300,7 @@ describe('useDrawerSwipe: right-to-left layouts', () => {
expect(harness.onOpenChange).toHaveBeenCalledWith(false);
expect(harness.drawer.style.transform).toBe('translate3d(100%, 0, 0)');
- expect(harness.pane.style.transform).toBe('translate3d(0, 0, 0)');
+ expect(harness.pane.style.transform).toBe('');
harness.unmount();
});
@@ -1316,7 +1339,7 @@ describe('useDrawerSwipe: right-to-left layouts', () => {
kickDrawerAnimation(false, jest.fn());
expect(harness.drawer.style.transform).toBe('translate3d(100%, 0, 0)');
- expect(harness.pane.style.transform).toBe('translate3d(0, 0, 0)');
+ expect(harness.pane.style.transform).toBe('');
harness.rerender({ open: false, enabled: true });
jest.runAllTimers();
diff --git a/client/src/hooks/Nav/useDrawerSwipe.ts b/client/src/hooks/Nav/useDrawerSwipe.ts
index 8d80a515f6..f7e7b62375 100644
--- a/client/src/hooks/Nav/useDrawerSwipe.ts
+++ b/client/src/hooks/Nav/useDrawerSwipe.ts
@@ -4,9 +4,7 @@ import {
MOBILE_DRAWER_ID,
MOBILE_DRAWER_WIDTH,
MOBILE_DRAWER_TRANSITION,
- MOBILE_PANE_SHIFT,
MOBILE_SCRIM_ID,
- SIDEBAR_TRANSITION,
DRAWER_UNPAINTED,
} from '~/components/UnifiedSidebar/constants';
@@ -25,15 +23,6 @@ const VELOCITY_HOLD_MS = 100;
/** Inline styles are cleared this long after TRANSITION_MS, then classes own the state. */
const SETTLE_BUFFER_MS = 80;
-/**
- * Whether the drawer hides the pane entirely, which is what makes repositioning
- * the pane instantly invisible. A geometric fact rather than a reading of the
- * setting: the reveal is safe exactly when there is nothing uncovered to see it
- * in, however the width was arrived at.
- */
-const drawerCoversPane = (drawer: HTMLElement): boolean =>
- (drawer.clientWidth || window.innerWidth) >= window.innerWidth;
-
/**
* Which physical way "open" points: 1 when the drawer sits on the left (LTR),
* -1 when it sits on the right (RTL). Read from the drawer itself, the element
@@ -47,7 +36,7 @@ const drawerSign = (drawer: HTMLElement): 1 | -1 =>
/** Fully offscreen past the drawer's inline-start edge. */
const closedDrawerTransform = (sign: 1 | -1) => `translate3d(${-100 * sign}%, 0, 0)`;
-/** Same kick as the drawer/pane transforms: the scrim must not wait for the
+/** Same kick as the drawer transforms: the scrim must not wait for the
* Recoil commit, which a large conversation can delay past the slide. */
const setScrimOpacity = (open: boolean) => {
const scrim = document.getElementById(MOBILE_SCRIM_ID);
@@ -66,7 +55,7 @@ const setScrimOpacity = (open: boolean) => {
/**
* A close whose open never committed — a second toggle retargets the slide
* inside the deferred flip, or an open drag falls short and snaps back — moves
- * the pane without `expanded` ever changing, so the dismiss guard has no state
+ * the drawer without `expanded` ever changing, so the dismiss guard has no state
* transition to arm from. The slide reports itself here instead.
*/
let slideListener: ((next: boolean) => void) | null = null;
@@ -111,7 +100,7 @@ export function getDrawerAnimationStartedAt(): number | null {
}
/**
- * Starts the drawer/pane slide imperatively and owns WHEN the caller's state
+ * Starts the drawer slide imperatively and owns WHEN the caller's state
* flip runs. Wrapping the flip in `startTransition` is not enough: Recoil
* notifies subscribers outside the transition scope, so the commit — which a
* large conversation stretches to hundreds of ms of context re-renders plus
@@ -210,7 +199,7 @@ export function findHorizontalScrollBlocker(
}
type DrawerSwipeOptions = {
- /** The chat pane that mirrors the drawer's motion (Root's Outlet wrapper). */
+ /** The stationary chat pane used as the opening gesture surface. */
paneRef: React.RefObject<HTMLDivElement | null>;
enabled: boolean;
open: boolean;
@@ -233,7 +222,6 @@ type Gesture = {
width: number;
reducedMotion: boolean;
drawer: HTMLElement;
- pane: HTMLElement;
prevSample: Sample;
lastSample: Sample;
raf: number | null;
@@ -242,22 +230,18 @@ type Gesture = {
};
/**
- * What the two surfaces settle back to. Nothing under reduced motion, where
+ * The drawer's resting transition. Nothing under reduced motion, where
* every drawer move snaps: handing an animating value back would leave the
* element ready to ease the next change, and the strip setting changes the
* drawer's width without passing through the snap path at all.
*/
-const settledTransitions = (): { drawer: string; pane: string } =>
- window.matchMedia('(prefers-reduced-motion: reduce)').matches
- ? { drawer: 'none', pane: 'none' }
- : { drawer: MOBILE_DRAWER_TRANSITION, pane: SIDEBAR_TRANSITION };
+const settledTransition = (): string =>
+ window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'none' : MOBILE_DRAWER_TRANSITION;
/** Returns every transient inline property to what React/classes render for
- * `paneOpen`. The drawer's transform is class-driven so clearing suffices, but
- * the pane's is a React style prop React will NOT re-assert while its value is
- * unchanged — an open pane must get its committed transform back explicitly. */
-const releaseInlineStyles = (drawer: HTMLElement, pane: HTMLElement, paneOpen: boolean) => {
- const settled = settledTransitions();
+ * `open`. Width and visibility are reasserted because React does not restore
+ * unchanged style props after an imperative write. */
+const releaseInlineStyles = (drawer: HTMLElement, open: boolean) => {
drawer.style.transform = '';
drawer.style.willChange = '';
/** Re-asserted rather than cleared, for the same reason as the width below:
@@ -266,15 +250,12 @@ const releaseInlineStyles = (drawer: HTMLElement, pane: HTMLElement, paneOpen: b
* 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;
+ drawer.style.visibility = open ? '' : 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. */
drawer.style.width = MOBILE_DRAWER_WIDTH;
- drawer.style.transition = settled.drawer;
- pane.style.transform = paneOpen ? MOBILE_PANE_SHIFT : '';
- pane.style.willChange = '';
- pane.style.transition = settled.pane;
+ drawer.style.transition = settledTransition();
markDrawerAnimationStart(null);
const scrim = document.getElementById(MOBILE_SCRIM_ID);
if (scrim != null) {
@@ -282,23 +263,20 @@ const releaseInlineStyles = (drawer: HTMLElement, pane: HTMLElement, paneOpen: b
}
};
-const dragTransforms = (gesture: Gesture): { drawer: string; pane: string } => {
+const dragTransform = (gesture: Gesture): string => {
const progress = gesture.opening
? Math.min(Math.max(gesture.dx, 0), gesture.width)
: Math.min(Math.max(gesture.dx, -gesture.width), 0) + gesture.width;
- return {
- drawer: `translate3d(${(progress - gesture.width) * gesture.sign}px, 0, 0)`,
- pane: `translate3d(${progress * gesture.sign}px, 0, 0)`,
- };
+ return `translate3d(${(progress - gesture.width) * gesture.sign}px, 0, 0)`;
};
/**
* Follow-the-finger swipe between the mobile drawer and the chat pane, which
- * move as one object (see SIDEBAR_TRANSITION). Built on touch events with a
+ * stays stationary beneath it. Built on touch events with a
* selectively non-passive `touchmove` — `touch-action` on the app shell would
* silently kill every horizontal scroller in the chat (code blocks, tables,
* carousels), and React's own onTouchMove registers passive, so
- * `preventDefault` there is a no-op. During a drag both elements get direct
+ * `preventDefault` there is a no-op. During a drag the drawer gets direct
* rAF-coalesced transform writes and no React state changes; release animates
* to the nearest state and only then flips `useSidebarState`.
*
@@ -321,7 +299,6 @@ export default function useDrawerSwipe({
id: ReturnType<typeof setTimeout> | null;
target: boolean;
drawer: HTMLElement;
- pane: HTMLElement;
} | null>(null);
const onOpenChangeRef = useRef(onOpenChange);
onOpenChangeRef.current = onOpenChange;
@@ -330,7 +307,7 @@ export default function useDrawerSwipe({
/** A settle whose target the world has since contradicted — drawer closed
* via a button inside its 380ms window, or the breakpoint crossed and
* disabled the hook — must not fire: its stale write would strand the
- * pane offscreen with React believing nothing changed. A settle that
+ * drawer offscreen with React believing nothing changed. A settle that
* AGREES with `open` keeps running so its handoff finishes undisturbed. */
const pending = settleRef.current;
if (pending != null && (!enabled || pending.target !== open)) {
@@ -338,7 +315,7 @@ export default function useDrawerSwipe({
clearTimeout(pending.id);
}
settleRef.current = null;
- releaseInlineStyles(pending.drawer, pending.pane, enabled && open);
+ releaseInlineStyles(pending.drawer, enabled && open);
}
/** A gesture surviving into a new effect run was interrupted — its
* listeners are gone, so its drag styles must resolve to the CURRENT
@@ -346,7 +323,7 @@ export default function useDrawerSwipe({
const abandoned = gestureRef.current;
if (abandoned != null) {
if (abandoned.phase === 'claimed' && !abandoned.reducedMotion) {
- releaseInlineStyles(abandoned.drawer, abandoned.pane, enabled && open);
+ releaseInlineStyles(abandoned.drawer, enabled && open);
}
if (abandoned.raf != null) {
cancelAnimationFrame(abandoned.raf);
@@ -373,15 +350,15 @@ export default function useDrawerSwipe({
/** Arms the inline-style handoff: after the shared transition has played
* out, every transient property returns to what React/classes render. */
- const scheduleRelease = (drawerEl: HTMLElement, paneEl: HTMLElement, next: boolean) => {
+ const scheduleRelease = (drawerEl: HTMLElement, next: boolean) => {
const id = setTimeout(() => {
settleRef.current = null;
- releaseInlineStyles(drawerEl, paneEl, next);
+ releaseInlineStyles(drawerEl, next);
}, TRANSITION_MS + SETTLE_BUFFER_MS);
- settleRef.current = { id, target: next, drawer: drawerEl, pane: paneEl };
+ settleRef.current = { id, target: next, drawer: drawerEl };
};
- /** Animates both elements to `next`, flips state, then returns ownership
+ /** Animates the drawer to `next`, flips state, then returns ownership
* of every inline property to what React/classes render for that state. */
const settle = (gesture: Gesture, next: boolean) => {
clearDrag(gesture);
@@ -390,32 +367,27 @@ export default function useDrawerSwipe({
/** Snap: suppress the shared 300ms transition for this state flip,
* then hand it back once the render has committed. */
gesture.drawer.style.transition = 'none';
- gesture.pane.style.transition = 'none';
onOpenChangeRef.current(next);
const id = setTimeout(() => {
settleRef.current = null;
- const settled = settledTransitions();
- gesture.drawer.style.transition = settled.drawer;
- gesture.pane.style.transition = settled.pane;
+ gesture.drawer.style.transition = settledTransition();
}, SETTLE_BUFFER_MS);
- settleRef.current = { id, target: next, drawer: gesture.drawer, pane: gesture.pane };
+ settleRef.current = { id, target: next, drawer: gesture.drawer };
}
return;
}
- const { drawer: drawerEl, pane: paneEl } = gesture;
+ const { drawer: drawerEl } = gesture;
drawerEl.style.transition = MOBILE_DRAWER_TRANSITION;
- paneEl.style.transition = SIDEBAR_TRANSITION;
drawerEl.style.transform = next
? 'translate3d(0, 0, 0)'
: closedDrawerTransform(gesture.sign);
- paneEl.style.transform = next ? MOBILE_PANE_SHIFT : 'translate3d(0, 0, 0)';
markDrawerAnimationStart();
notifyDrawerSlide(next);
setScrimOpacity(next);
if (next !== open) {
onOpenChangeRef.current(next);
}
- scheduleRelease(drawerEl, paneEl, next);
+ scheduleRelease(drawerEl, next);
};
/** Imperative slide for button/keyboard toggles: same transforms and
@@ -443,29 +415,22 @@ export default function useDrawerSwipe({
/** Snap: suppress the shared transition through the state flip the
* caller is about to make, then hand it back once committed. */
drawer.style.transition = 'none';
- pane.style.transition = 'none';
const id = setTimeout(() => {
settleRef.current = null;
- const settled = settledTransitions();
- drawer.style.transition = settled.drawer;
- pane.style.transition = settled.pane;
+ drawer.style.transition = settledTransition();
}, SETTLE_BUFFER_MS);
- settleRef.current = { id, target: next, drawer, pane };
+ settleRef.current = { id, target: next, drawer };
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. */
+ /** Paint before the deferred state flip, including on a retargeted close. */
drawer.style.visibility = 'visible';
- if (next) {
- pane.style.willChange = 'transform';
- }
/** Armed BEFORE the frame below (id: null — no deadline yet) so the
* staged write can verify its target is still wanted, and so a
* touchstart in between defers to the pending settle. A retarget or
* a reconciliation cancel clears/replaces the settle and thereby
* voids the write. */
- settleRef.current = { id: null, target: next, drawer, pane };
+ settleRef.current = { id: null, target: next, drawer };
/** The transforms are written in a FRESH frame task, not the tap's own
* task: a transition armed inside the click task is not reliably
* created for the offscreen drawer (observed via `transitionrun`
@@ -482,11 +447,8 @@ export default function useDrawerSwipe({
return;
}
drawer.style.transition = MOBILE_DRAWER_TRANSITION;
- /** A width transition still in flight (the strip setting changing, or
- * a rotation re-resolving the percentage) runs on its own clock, so
- * the drawer's edge and the pane's would separate for the rest of it.
- * Pinning the measured width settles the drawer onto this slide's
- * clock; the opening kick hands the property back. */
+ /** Pin the closing width so rotation or a strip change cannot retarget
+ * the slide's travel midway. Opening restores the configured width. */
drawer.style.width = next
? MOBILE_DRAWER_WIDTH
: `${drawer.getBoundingClientRect().width || window.innerWidth}px`;
@@ -496,29 +458,10 @@ export default function useDrawerSwipe({
markDrawerAnimationStart();
notifyDrawerSlide(next);
setScrimOpacity(next);
- if (next) {
- pane.style.transition = SIDEBAR_TRANSITION;
- pane.style.transform = MOBILE_PANE_SHIFT;
- } else if (drawerCoversPane(drawer)) {
- /** A programmatic close is a REVEAL while the drawer is full width:
- * the pane repositions instantly beneath the opaque cover and only
- * the drawer slides away, uncovering content already in place.
- * Animating the pane in from the right makes every tap-to-navigate
- * close visibly shift the chat leftward while the new conversation
- * commits into the moving layer mid-slide. */
- pane.style.transition = 'none';
- pane.style.transform = 'none';
- } else {
- /** With the strip enabled that jump would land in the visible slice,
- * so both surfaces animate together, which is the motion the drag
- * path already produces in `settle`. */
- pane.style.transition = SIDEBAR_TRANSITION;
- pane.style.transform = 'translate3d(0, 0, 0)';
- }
void drawer.getBoundingClientRect();
armed.id = setTimeout(() => {
settleRef.current = null;
- releaseInlineStyles(drawer, pane, next);
+ releaseInlineStyles(drawer, next);
}, TRANSITION_MS + SETTLE_BUFFER_MS);
});
};
@@ -545,7 +488,6 @@ export default function useDrawerSwipe({
width: drawer.clientWidth || window.innerWidth,
reducedMotion: window.matchMedia('(prefers-reduced-motion: reduce)').matches,
drawer,
- pane,
prevSample: sample,
lastSample: sample,
raf: null,
@@ -561,9 +503,7 @@ export default function useDrawerSwipe({
gesture.raf = requestAnimationFrame(() => {
gesture.rafScheduled = false;
gesture.raf = null;
- const transforms = dragTransforms(gesture);
- gesture.drawer.style.transform = transforms.drawer;
- gesture.pane.style.transform = transforms.pane;
+ gesture.drawer.style.transform = dragTransform(gesture);
});
};
@@ -608,16 +548,14 @@ export default function useDrawerSwipe({
gesture.phase = 'claimed';
if (!gesture.reducedMotion) {
gesture.drawer.style.transition = 'none';
- 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
- * for both surfaces, which would hold a gap open for the whole
+ * for the drawer, which would hold a gap open for the whole
* drag. */
gesture.width = gesture.drawer.clientWidth || window.innerWidth;
}
diff --git a/client/src/routes/Root.tsx b/client/src/routes/Root.tsx
index 4a2fbed2df..ca935e574f 100644
--- a/client/src/routes/Root.tsx
+++ b/client/src/routes/Root.tsx
@@ -15,14 +15,6 @@ import {
useAssistantsMap,
useUnseenConversations,
} from '~/hooks';
-import {
- UnifiedSidebar,
- SIDEBAR_TRANSITION,
- MOBILE_DRAWER_WIDTH_VAR,
- MOBILE_DRAWER_STRIP_WIDTH,
- MOBILE_DRAWER_FULL_WIDTH,
- MOBILE_PANE_SHIFT,
-} from '~/components/UnifiedSidebar';
import {
PromptGroupsProvider,
AssistantsMapContext,
@@ -31,6 +23,12 @@ import {
FileMapContext,
MCPAppsPolicyProvider,
} from '~/Providers';
+import {
+ UnifiedSidebar,
+ MOBILE_DRAWER_WIDTH_VAR,
+ MOBILE_DRAWER_STRIP_WIDTH,
+ MOBILE_DRAWER_FULL_WIDTH,
+} from '~/components/UnifiedSidebar';
import {
CodeHighlightThrottleContext,
normalizeCodeHighlightThrottleMs,
@@ -91,7 +89,7 @@ function RootLayout() {
/** The one path drawer mutations take: it kicks the slide imperatively and
* defers the Recoil flip, so a large conversation cannot stall first motion. */
const { setSidebarOpen } = useSidebarToggle();
- /** The drawer and pane snap under reduced motion (see kickDrawerAnimation),
+ /** The drawer snaps under reduced motion (see kickDrawerAnimation),
* so the scrim must not keep fading on its own. */
const prefersReducedMotion = useMediaQuery('(prefers-reduced-motion: reduce)');
/** Off by default, matching the drawer that covers the screen and closes by
@@ -187,11 +185,8 @@ function RootLayout() {
<Banner onHeightChange={setBannerHeight} />
<div className="flex" style={{ height: `calc(100dvh - ${bannerHeight}px)` }}>
<div
- className="relative z-0 flex h-full w-full overflow-hidden rtl:[--mobile-drawer-sign:-1]"
- /** The drawer and the pane both read this, so their travel
- * cannot disagree about how far the drawer opens. The sign
- * above sends the pane the other way when the drawer opens
- * from the right. */
+ className="relative z-0 flex h-full w-full overflow-hidden"
+ /** Drawer width also defines the uncovered dismiss strip. */
style={
{
[MOBILE_DRAWER_WIDTH_VAR]: drawerStrip
@@ -209,16 +204,12 @@ function RootLayout() {
/>
<div
ref={paneRef}
+ data-testid="app-pane"
/** Focus target of last resort when the drawer closes on a
* route that renders no opener. Not in the tab order. */
tabIndex={-1}
- className="relative flex h-full max-w-full flex-1 flex-col overflow-hidden focus:outline-hidden"
- style={{
- /** A percentage of the pane's own width, so it tracks the
- * drawer without a literal and survives rotation. */
- transform: isSmallScreen && sidebarExpanded ? MOBILE_PANE_SHIFT : 'none',
- transition: prefersReducedMotion ? undefined : SIDEBAR_TRANSITION,
- }}
+ className="relative isolate flex h-full max-w-full flex-1 flex-col overflow-hidden focus:outline-hidden"
+ /** Keep the live conversation out of the drawer's compositor animation. */
/** Recoil's flip is deferred past the opening frames and
* the closing transition outlives it at the other end, so
* `isSliding` covers the travel `sidebarExpanded` brackets
diff --git a/e2e/specs/mock/scenarios/mobile-drawer-large-chat.spec.ts b/e2e/specs/mock/scenarios/mobile-drawer-large-chat.spec.ts
new file mode 100644
index 0000000000..c0fbe7394e
--- /dev/null
+++ b/e2e/specs/mock/scenarios/mobile-drawer-large-chat.spec.ts
@@ -0,0 +1,117 @@
+import { randomUUID } from 'node:crypto';
+import { expect, test } from '@playwright/test';
+import { buildStressMessages, ROWS } from '../../../benchmarks-mobile-chat/payload';
+import { getE2EUser } from '../../../setup/user';
+import {
+ deleteConversations,
+ deleteMessagesByConversation,
+ seedConversations,
+ seedMessages,
+} from '../db';
+
+test.use({ viewport: { width: 390, height: 844 } });
+
+for (const { strip, direction } of [
+ { strip: false, direction: 'ltr' },
+ { strip: true, direction: 'ltr' },
+ { strip: true, direction: 'rtl' },
+] as const) {
+ test(`drawer overlays a long stationary chat (${direction}, strip=${strip})`, async ({
+ page,
+ }) => {
+ test.setTimeout(90_000);
+ const id = randomUUID();
+ const email = getE2EUser().email;
+ try {
+ await seedConversations(email, [{ conversationId: id, title: 'Long drawer regression' }]);
+ await seedMessages(email, id, buildStressMessages(id));
+ await page.addInitScript((withStrip) => {
+ localStorage.setItem('mobileDrawerStrip', JSON.stringify(withStrip));
+ }, strip);
+ await page.goto(`/c/${id}`);
+ await expect(page.locator('.message-render')).toHaveCount(ROWS, { timeout: 60_000 });
+ await page.evaluate((dir) => document.documentElement.setAttribute('dir', dir), direction);
+ const opener = page.getByTestId('header-open-sidebar-button');
+ const pane = page.getByTestId('app-pane');
+ await expect(pane).toBeVisible();
+ const monitor = await pane.evaluateHandle((element) => {
+ const firstRow = element.querySelector('.message-render');
+ const scroller = element.querySelector<HTMLElement>('.scrollbar-gutter-stable');
+ if (!firstRow || !scroller) {
+ throw new Error('Transcript is not mounted');
+ }
+ scroller.scrollTop = scroller.scrollHeight;
+ const scrollTop = scroller.scrollTop;
+ const initial = element.getBoundingClientRect().x;
+ const changes: Array<{ transform: string; willChange: string; x: number }> = [];
+ const observer = new MutationObserver(() => {
+ changes.push({
+ transform: (element as HTMLElement).style.transform,
+ willChange: (element as HTMLElement).style.willChange,
+ x: element.getBoundingClientRect().x,
+ });
+ });
+ observer.observe(element, { attributes: true });
+ return {
+ finish() {
+ observer.disconnect();
+ return {
+ changes,
+ initial,
+ sameRow: firstRow === element.querySelector('.message-render'),
+ scrollTop,
+ finalScrollTop: scroller.scrollTop,
+ };
+ },
+ };
+ });
+ await pane.evaluate((element) => {
+ // Model an in-pane Versions panel at the drawer's z-index.
+ const panel = document.createElement('div');
+ panel.dataset.testid = 'pane-overlay';
+ Object.assign(panel.style, {
+ position: 'absolute',
+ zIndex: '110',
+ top: '100px',
+ bottom: '100px',
+ insetInline: '0',
+ });
+ element.append(panel);
+ });
+ await opener.click();
+ const drawer = page.locator('#mobile-drawer');
+ await expect(drawer.getByTestId('close-sidebar-button')).toBeVisible();
+ await expect(drawer).not.toHaveAttribute('inert');
+ await expect(pane).toHaveAttribute('inert');
+ const coveredByDrawer = await drawer.evaluate((element) => {
+ const box = element.getBoundingClientRect();
+ return (
+ document
+ .elementFromPoint(box.x + box.width / 2, box.y + 200)
+ ?.closest('#mobile-drawer') != null
+ );
+ });
+ expect(coveredByDrawer).toBe(true);
+ await expect(pane).toHaveCSS('isolation', 'isolate');
+ await pane.getByTestId('pane-overlay').evaluate((element) => element.remove());
+ await drawer.getByTestId('close-sidebar-button').click();
+ await expect(drawer).toHaveCSS('visibility', 'hidden');
+ await expect(pane).not.toHaveAttribute('inert');
+ const result = await monitor.evaluate((value) => value.finish());
+ await monitor.dispose();
+ expect(result.changes.length).toBeGreaterThan(0);
+ expect(
+ result.changes.every((change) => change.transform === '' || change.transform === 'none'),
+ ).toBe(true);
+ expect(result.changes.every((change) => !change.willChange.includes('transform'))).toBe(true);
+ expect(result.changes.every((change) => Math.abs(change.x - result.initial) < 1)).toBe(true);
+ expect(result.sameRow).toBe(true);
+ expect(result.finalScrollTop).toBeCloseTo(result.scrollTop, 0);
+ await expect(page.locator('.message-render')).toHaveCount(ROWS);
+ await expect(opener).toBeFocused();
+ } finally {
+ await deleteMessagesByConversation([id]);
+ await deleteConversations([id]);
+ }
+ });
+}
diff --git a/eslint-suppressions.json b/eslint-suppressions.json
index b9c20f336d..0cff280ce0 100644
--- a/eslint-suppressions.json
+++ b/eslint-suppressions.json
@@ -1418,7 +1418,7 @@
},
"client/src/routes/Root.tsx": {
"shadcn/no-inline-styles": {
- "count": 2
+ "count": 1
}
},
"client/src/routes/RouteErrorBoundary.tsx": {