mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 14:08:21 +00:00
* 📜 style: Scroll the Sidebar as One Surface Projects, Pinned and the chats list each owned a scroll pane, so only the chats list scrolled while the sections above it stayed pinned. The sidebar now has one scroll viewport holding all three: the virtualized chats list renders at its natural height and is windowed by that viewport instead of scrolling itself. `useOuterScrollWindow` translates the viewport's scroll position into the list's coordinates. It re-measures on scroll and observes both the viewport and the content wrapper, because a section collapsing above the list moves the list without resizing either the viewport or the list. * 🧪 test: Cover the Sidebar's Single Scroll Surface Four scenarios in the mock harness: the whole sidebar rides one wheel gesture, older chats keep loading as it reaches its end, collapsing a section above the chats leaves the visible rows painted, and a long pinned list scrolls with the sidebar instead of inside its own box. The chat list grid no longer matches its container's height — it renders at the height of the rows it holds — so the width-tracking spec measures width alone and seeds the rows it measures. * 🪟 fix: Keep the Windowed List Honest Without ResizeObserver A section collapsing above the chats list moves it without resizing the viewport or the list and without a scroll event. Where ResizeObserver is missing, the fallback only listened for window resizes, so the list kept windowing against the old offset and could paint the wrong rows. It now watches the content wrapper the same way the observer does: its mutations and the bubbling transitionend of its height tween. The hook gets its own spec — offset translation, clamping at the top, frame coalescing, the collapse re-measure, the fallback trigger and listener cleanup — and the scenario specs reach the drawer on emulated touch devices, where the header's opener appears only once the chat has rendered and a wheel gesture is not what a person produces. * 👁️ fix: Window the Chats List on What the Reader Can See The list was handed the whole sidebar's height as its window, so with a screenful of projects or pins above it, react-virtualized counted a viewport of chat rows as rendered at the top of the list and the eight-row pagination threshold was crossed before a single chat had been exposed — a second conversations request nobody had asked for, on the load path the Lighthouse lane guards. The window is now the slice of the list the viewport actually shows: zero while it is below the fold, the viewport's height once it fills it. Searching also kept the shared surface's scroll position while replacing what it held — Projects and Pinned leave and the chats become results — so results long enough to escape the browser's clamp opened partway down. The surface returns to the top whenever it swaps contents. * 🧪 test: Seed the Pagination Scenario's Pins Out of the First Page * 🧪 test: Claim the Settled Layout in the Pagination Scenario * 🩹 fix: Keep a Pixel of Window So an Unseen List Can Be Reached A list handed a zero window renders nothing, and react-virtualized only emits its inner container when it has children, so the list collapsed to no height and the surface had nothing to scroll toward: the chats below a screenful of pins could never be reached. The window keeps a single pixel, which renders the first row and restores the list's own height without claiming a screenful is on display. * 🧪 test: Scroll Until the Chats List Answers * 🚦 fix: Ask for Another Page Only Once the Chats Are in View A list below the fold still renders its first row — that pixel of window is what gives it a height to be scrolled to — and on a page whose chats are nearly all pinned, that single row already sits inside the eight-row threshold, so the list asked for another page before anyone had looked at it. Reaching the end of what is rendered now counts only while the list is on screen; the hook reports that separately from its height, and a page holding no chats at all is still drained by the all-pin effect. * 🔎 fix: Ask the Layout Whether the Chats Are in View Visibility was a value sampled on a frame, and a commit that swaps what the sidebar holds — leaving a search restores the sections and the unfiltered page together — moves the list before any observer runs, so rows reported during that commit were judged against the layout before it. The hook now answers from the layout as it stands when asked, and the pagination gate asks.
204 lines
8 KiB
TypeScript
204 lines
8 KiB
TypeScript
import { randomUUID } from 'crypto';
|
|
import { expect, test } from '@playwright/test';
|
|
import type { Page } from '@playwright/test';
|
|
import { getE2EUser } from '../../setup/user';
|
|
import { clearUserConversations, deleteConversations, seedConversations } from './db';
|
|
import type { SeedConvo } from './db';
|
|
|
|
/**
|
|
* Width of the virtualized chat list grid vs. its measured container. The list
|
|
* no longer owns a scroll pane: it renders at its natural height inside the
|
|
* sidebar's single scroll surface, so its height follows the rows it holds and
|
|
* only its width has to track the box it is measured against.
|
|
*/
|
|
const widths = (page: Page) =>
|
|
page.evaluate(() => {
|
|
const grid = document.querySelector<HTMLElement>('aside .ReactVirtualized__Grid');
|
|
const wrap = grid?.parentElement ?? null;
|
|
const gridRect = grid?.getBoundingClientRect();
|
|
const wrapRect = wrap?.getBoundingClientRect();
|
|
return {
|
|
grid: gridRect ? gridRect.width : -1,
|
|
wrap: wrapRect ? wrapRect.width : -1,
|
|
gridH: gridRect ? gridRect.height : -1,
|
|
};
|
|
});
|
|
|
|
/**
|
|
* Polls until the grid matches its container AND the width has stopped changing
|
|
* between samples — the sidebar expand/collapse animation runs for 300ms, and a
|
|
* tracking-only check can match mid-animation on slow CI machines.
|
|
*/
|
|
const settledWidths = async (page: Page) => {
|
|
let prev = await widths(page);
|
|
for (let attempt = 0; attempt < 40; attempt++) {
|
|
await page.waitForTimeout(350);
|
|
const next = await widths(page);
|
|
const tracked = next.wrap > 0 && next.gridH > 0 && Math.abs(next.grid - next.wrap) <= 1;
|
|
const stable = Math.abs(next.grid - prev.grid) <= 1;
|
|
if (tracked && stable) {
|
|
return next;
|
|
}
|
|
prev = next;
|
|
}
|
|
throw new Error(`Sidebar chat list never settled: ${JSON.stringify(prev)}`);
|
|
};
|
|
|
|
test.describe('sidebar chat list', () => {
|
|
let sized: SeedConvo[] = [];
|
|
|
|
test.afterEach(async () => {
|
|
if (sized.length) {
|
|
await deleteConversations(sized.map((convo) => convo.conversationId));
|
|
sized = [];
|
|
}
|
|
});
|
|
|
|
test('chat list width tracks the sidebar through resize and collapse cycles', async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(60000);
|
|
/* The grid is as tall as the rows it renders, so a list with nothing in it
|
|
* has no box to measure: seed the rows this test measures against. */
|
|
sized = buildSeed();
|
|
await seedConversations(getE2EUser().email, sized);
|
|
|
|
await page.goto('/c/new', { timeout: 10000 });
|
|
await expect(page.locator('aside .ReactVirtualized__Grid').first()).toBeVisible({
|
|
timeout: 20000,
|
|
});
|
|
|
|
const initial = await settledWidths(page);
|
|
|
|
const separator = page.locator('[role="separator"][aria-label="Resize sidebar"]');
|
|
const sepBox = await separator.boundingBox();
|
|
expect(sepBox).not.toBeNull();
|
|
const startX = (sepBox?.x ?? 0) + (sepBox?.width ?? 0) / 2;
|
|
const y = (sepBox?.y ?? 0) + (sepBox?.height ?? 0) / 2;
|
|
|
|
await page.mouse.move(startX, y);
|
|
await page.mouse.down();
|
|
for (let i = 1; i <= 5; i++) {
|
|
await page.mouse.move(startX + i * 20, y);
|
|
await page.waitForTimeout(50);
|
|
}
|
|
await page.mouse.up();
|
|
|
|
const widened = await settledWidths(page);
|
|
expect(widened.grid).toBeGreaterThan(initial.grid);
|
|
|
|
await page.locator('aside').getByTestId('close-sidebar-button').click();
|
|
await page.locator('aside').getByTestId('open-sidebar-button').click();
|
|
|
|
const reopened = await settledWidths(page);
|
|
expect(reopened.grid).toBeGreaterThan(initial.grid);
|
|
|
|
/* A shorter viewport changes how much of the list is on screen, never how
|
|
* wide its rows are measured. */
|
|
await page.setViewportSize({ width: 1280, height: 540 });
|
|
const shrunken = await settledWidths(page);
|
|
expect(Math.abs(shrunken.grid - reopened.grid)).toBeLessThanOrEqual(1);
|
|
});
|
|
});
|
|
|
|
/**
|
|
* Regression: expanding the sidebar from a collapsed reload first measured the
|
|
* virtualized conversation rows mid-animation (narrow width), so date-group headers
|
|
* ("Previous 7 days", ...) wrapped and cached oversized heights. With `fixedWidth`
|
|
* the cache never re-measured at full width, leaving a gap between each header's
|
|
* text and the row beneath it.
|
|
*/
|
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
const userEmail = getE2EUser().email;
|
|
|
|
/**
|
|
* The header `<h2>` is single-line; its row wrapper should hug it (just the small
|
|
* top margin). A stale wrapped measurement inflates the wrapper well past this.
|
|
*/
|
|
const MAX_HEADER_PADDING = 24;
|
|
|
|
const GROUPS = [
|
|
{ label: 'Today', offsetDays: 0 },
|
|
{ label: 'Previous 7 days', offsetDays: 3 },
|
|
{ label: 'Previous 30 days', offsetDays: 15 },
|
|
] as const;
|
|
|
|
function buildSeed(): SeedConvo[] {
|
|
// Anchor on local noon so the zero-day group stays inside "today" even when the
|
|
// spec runs right after midnight; second-level offsets keep ordering within a day.
|
|
const noon = new Date();
|
|
noon.setHours(12, 0, 0, 0);
|
|
const base = noon.getTime();
|
|
return GROUPS.flatMap((group, groupIndex) =>
|
|
[0, 1].map((n) => ({
|
|
conversationId: randomUUID(),
|
|
title: `E2E ${group.label} #${n}`,
|
|
updatedAt: new Date(base - group.offsetDays * DAY_MS - (groupIndex + n) * 1000),
|
|
})),
|
|
);
|
|
}
|
|
|
|
// The DateLabel <h2> exposes an aria-label ("Chats from {date}"), so its accessible
|
|
// name is the full phrase, not the visible group label.
|
|
const heading = (page: Page, label: string) =>
|
|
page.getByRole('heading', { name: `Chats from ${label}`, exact: true });
|
|
|
|
const headerRow = (page: Page, label: string) =>
|
|
page.getByTestId('convo-list-row').filter({ has: heading(page, label) });
|
|
|
|
test.describe('sidebar conversation grouping', () => {
|
|
let seeded: SeedConvo[] = [];
|
|
|
|
test.afterEach(async () => {
|
|
if (seeded.length) {
|
|
await deleteConversations(seeded.map((c) => c.conversationId));
|
|
seeded = [];
|
|
}
|
|
});
|
|
|
|
test('keeps date-group spacing tight after expanding from a collapsed reload', async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(60000);
|
|
// Isolate from rows other specs leave on the shared user, which could otherwise
|
|
// push the later date-group headers below the virtualized viewport.
|
|
await clearUserConversations(userEmail);
|
|
seeded = buildSeed();
|
|
await seedConversations(userEmail, seeded);
|
|
|
|
// Default load is expanded: confirm the seeded conversations render at all.
|
|
await page.goto('/c/new', { timeout: 10000 });
|
|
await expect(page.getByTestId('convo-item').first()).toBeVisible({ timeout: 15000 });
|
|
|
|
// Force the collapsed start state, then reload so the list mounts collapsed.
|
|
await page.evaluate(() =>
|
|
localStorage.setItem('unifiedSidebarExpanded', JSON.stringify(false)),
|
|
);
|
|
await page.reload({ timeout: 10000 });
|
|
// The chat header keeps its own mobile toggle mounted and hides it with CSS, so this
|
|
// testid belongs to the rail alone — a second holder makes the click below strict-mode
|
|
// flaky rather than failing outright.
|
|
await expect(page.getByTestId('open-sidebar-button')).toHaveCount(1);
|
|
await expect(page.getByTestId('open-sidebar-button')).toBeVisible();
|
|
|
|
// Expand: rows first measure during the width animation — the regression window.
|
|
await page.getByTestId('open-sidebar-button').click();
|
|
await expect(page.getByTestId('close-sidebar-button')).toBeVisible();
|
|
await expect(page.getByTestId('convo-item').first()).toBeVisible({ timeout: 15000 });
|
|
|
|
// Each header row must hug its single-line text, not retain an inflated height.
|
|
for (const { label } of GROUPS) {
|
|
const row = headerRow(page, label);
|
|
await expect(row).toBeVisible({ timeout: 10000 });
|
|
const rowBox = await row.boundingBox();
|
|
const textBox = await heading(page, label).boundingBox();
|
|
expect(rowBox, `row "${label}" should have a bounding box`).not.toBeNull();
|
|
expect(textBox, `heading "${label}" should have a bounding box`).not.toBeNull();
|
|
const padding = rowBox!.height - textBox!.height;
|
|
expect(
|
|
padding,
|
|
`header "${label}" row (${rowBox!.height}px) should hug its text (${textBox!.height}px)`,
|
|
).toBeLessThan(MAX_HEADER_PADDING);
|
|
}
|
|
});
|
|
});
|