🪧 fix: Emit the Configured-Footer Answer With the HTML Shell (#15886)

* 🪧 fix: Emit the Configured-Footer Answer With the HTML Shell

The chat surface lays out against whether the deployment configured a footer
(customFooter, privacy policy, terms of service). The client answered that from
localStorage — whatever the last resolved `/api/config` recorded — so the answer
was a guess on a first-ever visit and could be stale for a deployment whose
configuration changed.

The backend already knows when it serves client/dist/index.html, so it says so
there: `injectConfiguredFooterBootstrap` writes `hasConfiguredFooter` into
`window.__LIBRECHAT_CONFIG__` ahead of the app's own scripts, once at boot from
the base app config, and the client reads it on its first render instead of
remembering the last answer. The `configured-footer` storage atom is gone.

Client and server share one predicate (`hasConfiguredFooter` in
librechat-data-provider) so the two cannot disagree, and the shell injection is
generalized (`injectBootstrapConfig`), with the query-devtools flag now going
through it.

* 🧷 fix: Keep Bootstrap Values Literal and State the Shell's Contract

`injectBootstrapConfig` passed its script as a replacement string, so a `$&`,
`$1` or `$'` inside an injected value was expanded by `String.replace` instead
of reaching the client. Both insertion points take a replacement function now,
and the spec reads its values back off the global through an explicit result
type rather than an unchecked dictionary.

The shell answers from the deployment's own configuration, which a per-tenant,
role or user override of `interface.privacyPolicy` or `termsOfService` can
disagree with — `/api/config` resolves the caller's and the client prefers it.
That contract was overstated in three comments ("a deployment-lifetime fact",
"the same one the config will give"); they now say what the answer is and what
resolves the rest. Two scenarios cover the disagreement end to end: a document
served without the answer, and a policy link only this caller's config carries.
This commit is contained in:
Marco Beretta 2026-09-14 03:53:54 +02:00 • committed by GitHub
parent 91e00bbe6e
commit 8e6e6f062d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 536 additions and 80 deletions

View file

@ -676,8 +676,13 @@ export type TThread = { id: string; createdAt: string };
declare global {
interface Window {
google_tag_manager?: unknown;
/** Answers the server emits with the document, ahead of the app's own
* scripts, for questions the first render must not guess at. */
__LIBRECHAT_CONFIG__?: {
enableQueryDevtools?: boolean;
/** Whether this deployment configured footer content of its own, so the
* composer reserves the footer bar's band on its first frame. */
hasConfiguredFooter?: boolean;
};
}
}

View file

@ -59,7 +59,7 @@ function ChatView({ index = 0, project }: { index?: number; project?: TChatProje
/** A conversation carries a footer only for configured content, and the
* composer's clearance has to account for the bar when it does — including
* while the config is still in flight, so a cold load does not jump. */
* before the config answers, so a cold load does not jump. */
const configuredFooter = useConfiguredFooter();
const methods = useForm<ChatFormValues>({
@ -114,10 +114,10 @@ function ChatView({ index = 0, project }: { index?: number; project?: TChatProje
(conversationId === Constants.NEW_CONVO || !conversationId);
/** A footer bar renders beneath the composer on the welcome screen always, and
* in a conversation when the deployment configured one. `present` already
* carries the remembered answer while the config is in flight, so this is the
* same value before and after it resolves. */
const footerBelow = isLandingPage || configuredFooter.present;
* in a conversation when the deployment configured one. The shell already
* carried that answer, so this is the same value before and after the config
* resolves. */
const footerBelow = isLandingPage || configuredFooter;
const isNavigating = (!messagesTree || messagesTree.length === 0) && conversationId != null;
const isProjectLandingPage = isLandingPage && project != null;
@ -214,7 +214,7 @@ function ChatView({ index = 0, project }: { index?: number; project?: TChatProje
{/* 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 && configuredFooter.present && <Footer configuredOnly />}
{!isLandingPage && configuredFooter && <Footer configuredOnly />}
</div>
</div>
{isLandingPage && <Footer />}

View file

@ -1,11 +1,9 @@
import React, { useEffect, memo } from 'react';
import { useAtom } from 'jotai';
import TagManager from 'react-gtm-module';
import ReactMarkdown from 'react-markdown';
import { Constants } from 'librechat-data-provider';
import { Constants, hasConfiguredFooter } from 'librechat-data-provider';
import type { TStartupConfig } from 'librechat-data-provider';
import { useGetStartupConfig } from '~/data-provider';
import { configuredFooterAtom } from './footerMemory';
import { useLocalize } from '~/hooks';
type FooterProps = {
@ -24,15 +22,17 @@ type FooterStartupConfig = Pick<Partial<TStartupConfig>, 'analyticsGtmId' | 'cus
interface?: Pick<NonNullable<TStartupConfig['interface']>, 'privacyPolicy' | 'termsOfService'>;
};
export type ConfiguredFooter = {
/** Whether a footer bar belongs under the composer in a conversation: the
* deployment configured a custom footer, a privacy policy or terms of
* service. Before the startup config answers this is the answer the last
* load recorded, which is what keeps a cold load from laying out twice. */
present: boolean;
/** The startup config has answered on this load. */
resolved: boolean;
};
/**
* Whether the deployment configured footer content of its own, as the server
* said when it served this document (`injectConfiguredFooterBootstrap`).
*
* Read once at module load: it is a property of the document, and an answer
* that arrived a render later would be the guess this replaces. A shell that
* carries no answer — the Vite dev server serves `client/index.html` itself —
* reads as no footer, which is the default deployment.
*/
const shellHasConfiguredFooter =
typeof window !== 'undefined' && window.__LIBRECHAT_CONFIG__?.hasConfiguredFooter === true;
/**
* What a conversation has to render beneath its composer. The conversation
@ -41,26 +41,16 @@ export type ConfiguredFooter = {
* zero-height wrapper, so a composer that did not reserve it would be painted
* over. Both decisions read this one answer so they cannot disagree.
*
* While `/api/config` is in flight the answer is the one this deployment gave
* last (`configuredFooterAtom`), so a cold load lays out once instead of
* guessing and correcting. Only a successful response replaces it: a request
* that exhausted its retries has answered nothing.
* Until `/api/config` answers, that answer is the shell's, which is the
* deployment's own configuration (`librechat.yaml` plus `CUSTOM_FOOTER`). A DB
* config override that adds or removes a policy link for the caller's tenant,
* role or user is resolved only by `/api/config`, so on such a deployment the
* resolved answer — the one that wins here — can differ from the shell's.
*/
export function useConfiguredFooter(): ConfiguredFooter {
export function useConfiguredFooter(): boolean {
const { data: config, isSuccess } = useGetStartupConfig();
const [remembered, remember] = useAtom(configuredFooterAtom);
const configured =
typeof config?.customFooter === 'string' ||
config?.interface?.privacyPolicy?.externalUrl != null ||
config?.interface?.termsOfService?.externalUrl != null;
useEffect(() => {
if (isSuccess && configured !== remembered) {
remember(configured);
}
}, [configured, isSuccess, remembered, remember]);
return { present: isSuccess ? configured : remembered, resolved: isSuccess };
return isSuccess ? hasConfiguredFooter(config) : shellHasConfiguredFooter;
}
function Footer({ className, startupConfig, configuredOnly = false }: FooterProps) {

View file

@ -110,9 +110,9 @@ const failedControlLocaleKey = (reason?: string) => {
};
export default function SubagentThreadPanel({ selection }: { selection: ActiveSubagentPanel }) {
/** `present` carries the remembered answer while the config is in flight, so
* this surface lays out once, like the composer beside it. */
const clearsFooter = useConfiguredFooter().present;
/** The shell carries the deployment's answer, so this surface lays out once,
* like the composer beside it. */
const clearsFooter = useConfiguredFooter();
const localize = useLocalize();
const panelStore = useStore();
const { showToast } = useToastContext();

View file

@ -1,14 +0,0 @@
import { createStorageAtom } from '~/store/jotai-utils';
/**
* Whether this deployment configured footer content of its own, as of the last
* time `/api/config` answered. Feature-owned and persisted: the chat surface
* both writes it (when the config resolves) and reads it (while the next load's
* config is still in flight), and a deployment's footer configuration is a
* deployment-lifetime fact, so remembering it is what lets the composer lay out
* once instead of guessing and correcting.
*
* `getOnInit` gives the stored value on the first render, which is the whole
* point — a value that arrived an effect later would be the guess again.
*/
export const configuredFooterAtom = createStorageAtom<boolean>('configured-footer', false);