🧷 fix: Clear the Configured Footer and Remeasure the Band on Contrast

Two findings from the round on d942b7c, one invariant each.

Keeping a configured footer in conversations left the composer reserving 16px
above an absolutely positioned bar about 32px tall, so the bar painted over the
composer's action row and would have taken its clicks. The clearance follows
what actually renders beneath the composer now, not which page it is: `ChatView`
reads `useConfiguredFooter` once and both decisions — whether to render the
footer, and how much room to leave for it — come from that same answer.
`ChatForm` takes `footerBelow` and keeps the welcome screen's rhythm for the
welcome screen.

The band is not a constant of the platform either: the contrast modes widen the
app's own scrollbar to 0.75rem, and a reader can turn contrast on — or have the
OS turn it on — while the welcome screen is the only thing mounted, with no
message column to republish. The seed remeasures when `ThemeProvider` flips a
class on the document element, which is the thing that changed the band.

Two scenarios, both failing before the fixes:

- `configured-footer-clears-the-composer`: with `customFooter` configured, the
  bar sits at or below the composer's bottom edge and the composer still takes a
  click at its own bottom row.
- `composer-holds-position-across-a-contrast-switch`: contrast turned on while
  the welcome screen is up, then a conversation opened; the composer keeps its
  left edge and width.

Findings:
https://github.com/danny-avila/LibreChat/pull/15838#discussion_r3992984510
https://github.com/danny-avila/LibreChat/pull/15838#discussion_r3992984517
This commit is contained in:
Marco Beretta 2026-09-11 22:27:57 +02:00
parent 9208a527dc
commit 1cd1942de7
No known key found for this signature in database
GPG key ID: D918033D8E74CC11
10 changed files with 264 additions and 23 deletions

View file

@ -21,13 +21,13 @@ import ApprovalProvider from './Messages/Content/ApprovalContext';
import ConversationStarters from './Input/ConversationStarters';
import { pendingApprovalActionFamily } from './approval/state';
import { useGetMessagesByConvoId } from '~/data-provider';
import Footer, { useConfiguredFooter } from './Footer';
import { AskAnswerHostProvider } from './ask/state';
import MessagesView from './Messages/MessagesView';
import Presentation from './Presentation';
import ChatForm from './Input/ChatForm';
import Landing from './Landing';
import Header from './Header';
import Footer from './Footer';
import { cn } from '~/utils';
import store from '~/store';
@ -56,6 +56,10 @@ function ChatView({ index = 0, project }: { index?: number; project?: TChatProje
* column exists to measure it (see the column's class list below). */
useScrollbarGutterSeed();
/** A conversation carries a footer only for configured content, and the
* composer's clearance has to account for the bar when it does. */
const hasConfiguredFooter = useConfiguredFooter();
const methods = useForm<ChatFormValues>({
defaultValues: { text: '' },
});
@ -195,12 +199,13 @@ function ChatView({ index = 0, project }: { index?: number; project?: TChatProje
placeholder={chatFormPlaceholder}
project={isProjectLandingPage ? project : undefined}
isLandingPage={isLandingPage}
footerBelow={isLandingPage || hasConfiguredFooter}
/>
)}
{/* The generic disclaimer is the welcome screen's; a
deployment's own footer, privacy policy and terms
stay with the conversation that always showed them. */}
{!isLandingPage && <Footer configuredOnly />}
{!isLandingPage && hasConfiguredFooter && <Footer configuredOnly />}
</div>
</div>
{isLandingPage && <Footer />}

View file

@ -22,6 +22,23 @@ type FooterStartupConfig = Pick<Partial<TStartupConfig>, 'analyticsGtmId' | 'cus
interface?: Pick<NonNullable<TStartupConfig['interface']>, 'privacyPolicy' | 'termsOfService'>;
};
/**
* Whether the deployment configured footer content of its own: a custom footer,
* a privacy policy or terms of service. A conversation renders the footer only
* for this content, and the composer above it reserves the clearance the bar
* needs — the bar is absolutely positioned in a zero-height wrapper, so a
* composer that did not reserve it would be painted over. Both decisions read
* the same answer from here so they cannot disagree.
*/
export function useConfiguredFooter(): boolean {
const { data: config } = useGetStartupConfig();
return (
typeof config?.customFooter === 'string' ||
config?.interface?.privacyPolicy?.externalUrl != null ||
config?.interface?.termsOfService?.externalUrl != null
);
}
function Footer({ className, startupConfig, configuredOnly = false }: FooterProps) {
const shouldFetchConfig = startupConfig === undefined;
const { data: fetchedConfig } = useGetStartupConfig({ enabled: shouldFetchConfig });

View file

@ -74,9 +74,15 @@ interface ChatFormProps {
index: number;
placeholder?: string;
project?: TChatProject;
/** Owned by ChatView: the disclaimer renders beneath the landing composer only,
* and the clearance this band leaves under itself follows it. */
/** Owned by ChatView: which layout the composer sits in — the welcome screen
* floats or bottoms it out, a conversation ends the page with it. */
isLandingPage: boolean;
/** Owned by ChatView: whether a footer bar renders under this band. It is an
* absolutely positioned bar in a zero-height wrapper, so the clearance here
* is the only thing keeping it off the composer. True on the welcome screen,
* which always carries one, and in a conversation whose deployment
* configured footer content of its own. */
footerBelow: boolean;
/** From ChatContext: individual values so memo can compare them */
files: Map<string, ExtendedFile>;
setFiles: FileSetter;
@ -111,6 +117,7 @@ const ChatForm = memo(function ChatForm({
placeholder,
project,
isLandingPage,
footerBelow,
files,
setFiles,
conversation,
@ -583,7 +590,14 @@ const ChatForm = memo(function ChatForm({
every state. */
const landingClearance =
centerFormOnLanding && !isSubmitting ? 'transition-all duration-200 sm:mb-28' : 'sm:mb-10';
const bottomClearance = isLandingPage ? landingClearance : 'sm:mb-4';
let bottomClearance = 'sm:mb-4';
if (isLandingPage) {
bottomClearance = landingClearance;
} else if (footerBelow) {
/* A conversation that carries a configured footer keeps the band that bar
needs, exactly as the welcome screen does. */
bottomClearance = 'sm:mb-10';
}
return (
<form
@ -906,11 +920,13 @@ function ChatFormWrapper({
placeholder,
project,
isLandingPage,
footerBelow,
}: {
index?: number;
placeholder?: string;
project?: TChatProject;
isLandingPage: boolean;
footerBelow: boolean;
}) {
const {
files,
@ -976,6 +992,7 @@ function ChatFormWrapper({
placeholder={placeholder}
project={project}
isLandingPage={isLandingPage}
footerBelow={footerBelow}
files={files}
setFiles={setFiles}
conversation={stableConversation}

View file

@ -110,7 +110,7 @@ function Harness() {
<ChatFormProvider {...methods}>
<ChatContext.Provider value={chatHelpers}>
<Profiler id="composer" onRender={() => (commits += 1)}>
<ChatForm index={0} isLandingPage={false} />
<ChatForm index={0} isLandingPage={false} footerBelow={false} />
</Profiler>
</ChatContext.Provider>
</ChatFormProvider>

View file

@ -108,7 +108,7 @@ function Harness() {
<ChatFormProvider {...methods}>
<ChatContext.Provider value={chatHelpers}>
<DragDropWrapper>
<ChatForm index={0} isLandingPage={false} />
<ChatForm index={0} isLandingPage={false} footerBelow={false} />
</DragDropWrapper>
</ChatContext.Provider>
</ChatFormProvider>

View file

@ -41,7 +41,11 @@ jest.mock('../Presentation', () => ({
default: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));
jest.mock('../Header', () => ({ __esModule: true, default: () => <div /> }));
jest.mock('../Footer', () => ({ __esModule: true, default: () => <div /> }));
jest.mock('../Footer', () => ({
__esModule: true,
default: () => <div />,
useConfiguredFooter: () => false,
}));
jest.mock('../Landing', () => ({ __esModule: true, default: () => <div /> }));
jest.mock('../Messages/MessagesView', () => ({ __esModule: true, default: () => <div /> }));
jest.mock('../Input/ChatForm', () => ({ __esModule: true, default: () => <div /> }));

View file

@ -67,7 +67,11 @@ jest.mock('../Presentation', () => ({ children }: { children: React.ReactNode })
));
jest.mock('../Input/ChatForm', () => () => <div data-testid="chat-form" />);
jest.mock('../Landing', () => () => <div data-testid="landing" />);
jest.mock('../Footer', () => () => <div data-testid="footer" />);
jest.mock('../Footer', () => ({
__esModule: true,
default: () => <div data-testid="footer" />,
useConfiguredFooter: () => false,
}));
jest.mock('../Header', () => ({ readOnly }: { readOnly?: boolean }) => (
<div data-read-only={String(readOnly)} data-testid="header" />
));

View file

@ -56,26 +56,47 @@ export default function useScrollbarGutter(
* It measures in a layout effect, before the browser paints: a passive effect
* would let the first frame reserve the token's 8px and then recentre the
* welcome screen by 4px once the real band is known, which is the same visible
* shift this reservation exists to remove. */
* shift this reservation exists to remove.
*
* The band is not a constant of the platform either: the contrast modes widen
* the app's own scrollbar (`--scrollbar-size` goes to 0.75rem under
* `html.high-contrast`), and a reader can turn contrast on — or have the OS
* turn it on — while the welcome screen is the only thing mounted, with no
* message column to republish. `ThemeProvider` carries every contrast and
* scheme decision as a class on the document element, so remeasuring on that
* is remeasuring on the thing that changed the band. */
export function useScrollbarGutterSeed(): void {
useLayoutEffect(() => {
const root = document.documentElement;
if (root.style.getPropertyValue(SCROLLBAR_GUTTER_PROPERTY) !== '') {
const measure = () => {
const probe = document.createElement('div');
probe.style.position = 'absolute';
probe.style.top = '-9999px';
probe.style.width = '100px';
probe.style.height = '100px';
probe.style.overflowY = 'auto';
probe.style.scrollbarGutter = 'stable';
probe.style.visibility = 'hidden';
document.body.appendChild(probe);
const gutter = Math.max(0, probe.offsetWidth - probe.clientWidth);
probe.remove();
root.style.setProperty(SCROLLBAR_GUTTER_PROPERTY, `${gutter}px`);
};
if (root.style.getPropertyValue(SCROLLBAR_GUTTER_PROPERTY) === '') {
measure();
}
if (typeof MutationObserver === 'undefined') {
return;
}
const probe = document.createElement('div');
probe.style.position = 'absolute';
probe.style.top = '-9999px';
probe.style.width = '100px';
probe.style.height = '100px';
probe.style.overflowY = 'auto';
probe.style.scrollbarGutter = 'stable';
probe.style.visibility = 'hidden';
document.body.appendChild(probe);
const gutter = Math.max(0, probe.offsetWidth - probe.clientWidth);
probe.remove();
/** A mounted column observes its own box and republishes on the same flip,
* so the two agree; this is what covers the screens that have no column. */
const observer = new MutationObserver(measure);
observer.observe(root, { attributes: true, attributeFilter: ['class', 'data-theme'] });
root.style.setProperty(SCROLLBAR_GUTTER_PROPERTY, `${gutter}px`);
return () => observer.disconnect();
}, []);
}

View file

@ -0,0 +1,68 @@
import { randomUUID } from 'crypto';
import { expect, test } from '@playwright/test';
import type { Page } from '@playwright/test';
import { getE2EUser } from '../../../setup/user';
import { deleteConversations, deleteMessagesByConversation, seedConversations } from '../db';
/**
* The footer is an absolutely positioned bar in a zero-height wrapper, so the
* composer above it is what reserves its band. A conversation that keeps a
* deployment's configured footer therefore has to keep that clearance too, or
* the bar paints over the composer's action row and takes the clicks meant for
* it.
*/
const COMPOSER = '[data-testid="composer-surface"]';
const CUSTOM_FOOTER = 'Operator policy footer';
const CONVERSATION_TITLE = 'Configured footer clearance';
test.use({ viewport: { width: 1280, height: 800 } });
async function withConfiguredFooter(page: Page) {
await page.route('**/api/config', async (route) => {
const response = await route.fetch();
const config = await response.json();
await route.fulfill({ response, json: { ...config, customFooter: CUSTOM_FOOTER } });
});
}
test.describe('configured footer clearance', () => {
test('a configured footer never covers the composer @scenario:configured-footer-clears-the-composer', async ({
page,
}) => {
test.setTimeout(60000);
const conversationId = randomUUID();
await seedConversations(getE2EUser().email, [
{ conversationId, title: CONVERSATION_TITLE, updatedAt: new Date() },
]);
try {
await withConfiguredFooter(page);
await page.goto(`/c/${conversationId}`, { timeout: 10000 });
await expect(page.locator(COMPOSER)).toBeVisible();
const footer = page.getByText(CUSTOM_FOOTER);
await expect(footer).toBeVisible();
const composerBox = await page.locator(COMPOSER).boundingBox();
const footerBox = await footer.boundingBox();
expect(composerBox).not.toBeNull();
expect(footerBox).not.toBeNull();
const composerBottom = (composerBox?.y ?? 0) + (composerBox?.height ?? 0);
expect(
footerBox?.y ?? 0,
'the configured footer overlaps the composer',
).toBeGreaterThanOrEqual(composerBottom);
/** Overlap is not only visual: the bar would take the composer's clicks. */
const input = page.getByRole('textbox', { name: 'Message input' });
await page
.locator(COMPOSER)
.click({ position: { x: 40, y: (composerBox?.height ?? 40) - 8 } });
await input.fill('still reachable');
await expect(input).toHaveValue('still reachable');
} finally {
await deleteMessagesByConversation([conversationId]);
await deleteConversations([conversationId]);
}
});
});

View file

@ -0,0 +1,105 @@
import { randomUUID } from 'crypto';
import { expect, test } from '@playwright/test';
import type { Page } from '@playwright/test';
import { getE2EUser } from '../../../setup/user';
import {
deleteConversations,
deleteMessagesByConversation,
seedConversations,
seedMessages,
} from '../db';
/**
* The band the message column reserves is not a constant of the platform: the
* contrast modes widen the app's own scrollbar. A reader who turns contrast on
* while the welcome screen is the only thing mounted has no message column to
* republish that width, so the welcome screen must remeasure it itself — or the
* first conversation corrects it and the composer steps sideways.
*/
const COMPOSER = '[data-testid="composer-surface"]';
const CONVERSATION_TITLE = 'Contrast switch';
test.use({ viewport: { width: 1280, height: 800 } });
type Box = { left: number; width: number };
const boxOf = (page: Page): Promise<Box> =>
page.evaluate((selector) => {
const node = document.querySelector(selector);
if (!node) {
throw new Error(`${selector} is not rendered`);
}
const rect = node.getBoundingClientRect();
return {
left: Math.round(rect.left * 100) / 100,
width: Math.round(rect.width * 100) / 100,
};
}, COMPOSER);
async function settle(page: Page): Promise<Box> {
let previous = await boxOf(page);
for (let attempt = 0; attempt < 20; attempt++) {
await page.waitForTimeout(200);
const next = await boxOf(page);
if (Math.abs(next.left - previous.left) < 0.5 && Math.abs(next.width - previous.width) < 0.5) {
return next;
}
previous = next;
}
throw new Error(`the composer never settled: ${JSON.stringify(previous)}`);
}
test.describe('contrast switch', () => {
test('the composer holds its position across a contrast switch @scenario:composer-holds-position-across-a-contrast-switch', async ({
page,
}) => {
test.setTimeout(60000);
const conversationId = randomUUID();
const { email } = getE2EUser();
await seedConversations(email, [
{ conversationId, title: CONVERSATION_TITLE, updatedAt: new Date() },
]);
const userMessageId = randomUUID();
await seedMessages(email, conversationId, [
{
messageId: userMessageId,
parentMessageId: '00000000-0000-0000-0000-000000000000',
text: 'Does contrast move the composer?',
isCreatedByUser: true,
sender: 'User',
},
{
messageId: randomUUID(),
parentMessageId: userMessageId,
text: 'It should not.',
isCreatedByUser: false,
sender: 'Mock Provider A',
},
]);
try {
await page.goto('/c/new', { timeout: 10000 });
await expect(page.locator(COMPOSER)).toBeVisible();
await settle(page);
/** The OS contrast preference, changed while the welcome screen is up. */
await page.emulateMedia({ contrast: 'more' });
await expect(page.locator('html.high-contrast')).toHaveCount(1, { timeout: 10000 });
const onWelcome = await settle(page);
const row = page.getByTestId('convo-item').filter({ hasText: CONVERSATION_TITLE }).first();
await expect(row).toBeVisible({ timeout: 20000 });
await row.click();
await expect(page.locator('.message-render').first()).toBeVisible({ timeout: 20000 });
const inConversation = await settle(page);
expect(inConversation.left).toBeCloseTo(onWelcome.left, 0);
expect(inConversation.width).toBeCloseTo(onWelcome.width, 0);
} finally {
await page.emulateMedia({ contrast: null });
await deleteMessagesByConversation([conversationId]);
await deleteConversations([conversationId]);
}
});
});