mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-19 06:23:32 +00:00
🧩 refactor: Move Phase Label Ticker Into Chat Package (#18179)
- refactor: Move Phase Label Ticker Into Chat Package - test: Give Phase Entrance Scenarios Unique IDs
This commit is contained in:
parent
b07a9f9e9f
commit
11fdcf4f43
9 changed files with 407 additions and 129 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import { memo, useId, useCallback, useEffect, useMemo, useRef, useState, useContext } from 'react';
|
||||
import { useId, useCallback, useEffect, useMemo, useRef, useState, useContext } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { Shimmer } from '@librechat/client';
|
||||
import { ContentTypes } from 'librechat-data-provider';
|
||||
import { Check, CircleX, Lightbulb, ChevronDown, TriangleAlert } from 'lucide-react';
|
||||
import {
|
||||
|
|
@ -15,6 +14,8 @@ import {
|
|||
useThrottledValue,
|
||||
} from '@librechat/chat/react';
|
||||
import {
|
||||
PhaseLabel,
|
||||
FOLD_EASING,
|
||||
FOLD_RAIL_CLASSES,
|
||||
ROW_GLYPH_SLOT,
|
||||
TOOL_ROW_CLASSES,
|
||||
|
|
@ -53,17 +54,7 @@ import { AttachmentGroup } from './Parts';
|
|||
import SearchVerticals from './verticals';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
/** Matches `EXPAND_TRANSITION` so the panel and the label ticker resolve on
|
||||
* the same curve: two properties animating on two different easings is what
|
||||
* makes a fold read as two separate movements.
|
||||
*
|
||||
* Written as an arbitrary PROPERTY, not `ease-[…]`: `tailwindcss-animate`
|
||||
* registers its own `ease` utility for `animation-timing-function` alongside
|
||||
* Tailwind's `transition-timing-function` one, so an arbitrary value matches
|
||||
* both, and Tailwind resolves that ambiguity by emitting NOTHING. The class
|
||||
* this replaces had been inert since the plugin landed — the curve it names
|
||||
* never reached the fold. */
|
||||
const FOLD_EASING = 'duration-300 [animation-timing-function:cubic-bezier(0.16,1,0.3,1)]';
|
||||
export { PhaseLabel } from '@librechat/chat/components';
|
||||
|
||||
type ActivityPhasePart = Extract<TMessageContentParts, { type: ContentTypes.ACTIVITY_LABEL }> & {
|
||||
activity_label_type?: 'phase';
|
||||
|
|
@ -115,118 +106,6 @@ function PhaseGlyph({ failed, partial = false }: { failed: boolean; partial?: bo
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The phase header is a ticker, not a title. A client-synthesized card
|
||||
* re-titles itself every time it absorbs another finished block, and swapping
|
||||
* that text instantly is what makes the absorbed row look like it simply
|
||||
* vanished from under the reader. The retired line rises out of the clipped
|
||||
* row while the new summary comes up from below, so the work visibly moves
|
||||
* into the line that now stands for it.
|
||||
*/
|
||||
/**
|
||||
* The shimmering text of a live line, on its own element. `.shimmer` declares
|
||||
* `position` and `display`, so sharing an element with the ticker would undo
|
||||
* the slide's absolute placement — the retired line would sit inline beside
|
||||
* its successor. `align-top` keeps the inline box from adding descender space,
|
||||
* which made a live row 2px taller than the settled row it becomes.
|
||||
*/
|
||||
function LiveLine({ text }: { text: string }) {
|
||||
return <Shimmer className="max-w-full truncate align-top">{text}</Shimmer>;
|
||||
}
|
||||
|
||||
export const PhaseLabel = memo(function PhaseLabel({
|
||||
text,
|
||||
animate,
|
||||
source,
|
||||
live = false,
|
||||
grow = true,
|
||||
lineId,
|
||||
}: {
|
||||
text: string;
|
||||
animate: boolean;
|
||||
/** Identity of what produced `text`. A streamed sentence keeps its source
|
||||
* while it grows, and sliding a line out to bring a longer copy of itself
|
||||
* in would read as flicker, so an unchanged source extends in place. */
|
||||
source?: string;
|
||||
live?: boolean;
|
||||
/** Claim the row's free space, the default. Cleared when something has to
|
||||
* sit immediately after the text — the box then measures the line itself,
|
||||
* so its neighbour reads as part of it instead of drifting to the margin. */
|
||||
grow?: boolean;
|
||||
/** Id for the current line, so a live disclosure can be named by it alone. */
|
||||
lineId?: string;
|
||||
}) {
|
||||
const [lines, setLines] = useState<{
|
||||
current: string;
|
||||
retired: string | null;
|
||||
entered: boolean;
|
||||
source?: string;
|
||||
}>({ current: text, retired: null, entered: false, source });
|
||||
|
||||
/** Adjusted during render rather than in an effect. A passive effect runs
|
||||
* after paint, so a swap with no animation would leave the previous summary
|
||||
* on screen for a frame while the button's `aria-label` already carried the
|
||||
* new one. React re-renders this component immediately instead. */
|
||||
if (lines.current !== text || lines.source !== source) {
|
||||
const moved = source == null || source !== lines.source;
|
||||
const swaps = animate && lines.current.length > 0 && moved;
|
||||
setLines({
|
||||
current: text,
|
||||
retired: swaps ? lines.current : null,
|
||||
entered: swaps || (lines.entered && source != null && source === lines.source),
|
||||
source,
|
||||
});
|
||||
}
|
||||
|
||||
/** Clears only the retired line. `entered` outlives it on purpose: dropping
|
||||
* the incoming line's animation class the moment its partner's
|
||||
* `animationend` fires would snap a still-running slide back to its resting
|
||||
* position. The class is inert once the animation has finished, and the
|
||||
* element is keyed by its text, so it cannot replay. */
|
||||
const clearRetired = useCallback(() => {
|
||||
setLines((previous) => (previous.retired == null ? previous : { ...previous, retired: null }));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
'tool-status-text relative block min-w-0 overflow-hidden text-start',
|
||||
grow && 'flex-1',
|
||||
)}
|
||||
title={text}
|
||||
>
|
||||
{lines.retired != null && (
|
||||
<span
|
||||
key={`retired-${lines.retired}`}
|
||||
className={cn(
|
||||
'absolute inset-x-0 top-0 block truncate',
|
||||
'animate-out fade-out-0 slide-out-to-top-5 [animation-fill-mode:forwards]',
|
||||
FOLD_EASING,
|
||||
)}
|
||||
/** The sweep on the inner span loops forever and its `animationend`
|
||||
* never comes; only this element's own slide may clear the line. */
|
||||
onAnimationEnd={(event) => event.target === event.currentTarget && clearRetired()}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{live ? <LiveLine text={lines.retired} /> : lines.retired}
|
||||
</span>
|
||||
)}
|
||||
<span
|
||||
/** Keyed by source while live, so a growing sentence updates one
|
||||
* element instead of remounting — and replaying its slide — per paint. */
|
||||
key={`current-${source ?? lines.current}`}
|
||||
id={lineId}
|
||||
className={cn(
|
||||
'block truncate',
|
||||
lines.entered && `animate-in fade-in-0 slide-in-from-bottom-5 ${FOLD_EASING}`,
|
||||
)}
|
||||
>
|
||||
{live ? <LiveLine text={lines.current} /> : lines.current}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
});
|
||||
|
||||
/** Glyphs a span header shows: up to this many, of which at most `SPAN_SITES`
|
||||
* are the sites a web search read. */
|
||||
const SPAN_ICONS = 4;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
import { useContext } from 'react';
|
||||
import fs from 'fs';
|
||||
import { ContentTypes, Tools } from 'librechat-data-provider';
|
||||
import { GeneratedToolLabelContext } from '@librechat/chat/react';
|
||||
import { act, fireEvent, render, screen, within } from '@testing-library/react';
|
||||
import { PhaseLabel as PackagePhaseLabel, FOLD_EASING } from '@librechat/chat/components';
|
||||
import { ROW_GLYPH_SLOT, TOOL_ROW_CLASSES, useFailedReveal } from '@librechat/chat/components';
|
||||
import type { TAttachment, TMessageContentParts } from 'librechat-data-provider';
|
||||
import ActivityPhaseGroup, { PhaseLabel } from '../ActivityPhaseGroup';
|
||||
import { MessageSurfaceContext } from '../../ui/surface';
|
||||
import ActivityPhaseGroup from '../ActivityPhaseGroup';
|
||||
|
||||
const mockUseSmoothStreaming = jest.fn(() => true);
|
||||
const mockScheduleLayoutReconcile = jest.fn((_target: HTMLElement | null) => jest.fn());
|
||||
|
|
@ -79,6 +81,44 @@ const searchAttachment = {
|
|||
} as unknown as TAttachment;
|
||||
|
||||
describe('ActivityPhaseGroup', () => {
|
||||
test('preserves the package ticker export for existing tool group consumers', () => {
|
||||
expect(PhaseLabel).toBe(PackagePhaseLabel);
|
||||
});
|
||||
|
||||
test('exports real phase consumers for the browser cascade checks', () => {
|
||||
const ticker = render(<PhaseLabel text={LABEL} animate live />);
|
||||
ticker.rerender(<PhaseLabel text={NEXT_LABEL} animate live />);
|
||||
expect(ticker.container.querySelector('.animate-out')).toHaveAttribute('aria-hidden', 'true');
|
||||
const tickerMarkup = ticker.container.innerHTML;
|
||||
ticker.unmount();
|
||||
|
||||
const entrance = render(
|
||||
<ActivityPhaseGroup labelPart={labelPart} hasContent={false} animateEntrance>
|
||||
<div />
|
||||
</ActivityPhaseGroup>,
|
||||
);
|
||||
for (const name of FOLD_EASING.split(' ')) {
|
||||
expect(screen.getByTestId('activity-phase-card')).toHaveClass(name);
|
||||
}
|
||||
const entranceMarkup = entrance.container.innerHTML;
|
||||
entrance.unmount();
|
||||
|
||||
const reduced = render(<PhaseLabel text={LABEL} animate={false} live />);
|
||||
reduced.rerender(<PhaseLabel text={NEXT_LABEL} animate={false} live />);
|
||||
expect(reduced.container.querySelector('.animate-in, .animate-out')).toBeNull();
|
||||
const fixturePath = process.env.E2E_PHASE_CASCADE_FIXTURE;
|
||||
if (fixturePath) {
|
||||
fs.writeFileSync(
|
||||
fixturePath,
|
||||
JSON.stringify({
|
||||
ticker: tickerMarkup,
|
||||
entrance: entranceMarkup,
|
||||
reduced: reduced.container.innerHTML,
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
let frames: Array<FrameRequestCallback | undefined>;
|
||||
const originalRequestAnimationFrame = window.requestAnimationFrame;
|
||||
const originalCancelAnimationFrame = window.cancelAnimationFrame;
|
||||
|
|
@ -283,6 +323,9 @@ describe('ActivityPhaseGroup', () => {
|
|||
* new one comes up from below — the absorbed block is the thing that
|
||||
* moved, so it has to be visible while it moves. */
|
||||
const retired = screen.getByText(LABEL);
|
||||
for (const easingClass of FOLD_EASING.split(' ')) {
|
||||
expect(retired).toHaveClass(easingClass);
|
||||
}
|
||||
expect(retired).toHaveClass('animate-out', 'slide-out-to-top-5');
|
||||
expect(retired).toHaveAttribute('aria-hidden', 'true');
|
||||
expect(
|
||||
|
|
@ -379,6 +422,9 @@ describe('ActivityPhaseGroup', () => {
|
|||
|
||||
expect(screen.queryByRole('button')).not.toBeInTheDocument();
|
||||
expect(screen.getByText(LABEL)).toHaveClass('text-start');
|
||||
for (const easingClass of FOLD_EASING.split(' ')) {
|
||||
expect(screen.getByTestId('activity-phase-card')).toHaveClass(easingClass);
|
||||
}
|
||||
expect(pendingFrames()).toBe(0);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { repoRoot, run } from './lint.helpers';
|
||||
|
||||
/**
|
||||
|
|
@ -196,3 +197,94 @@ Promise.all(${JSON.stringify([
|
|||
expect((await read('disabled', ['cursor'])).cursor).toBe('not-allowed');
|
||||
});
|
||||
});
|
||||
|
||||
/** The client test renders both real consumers. Only this browser lane asks it to save markup,
|
||||
* so ordinary Jest needs neither a browser binary nor the browser lane's services. */
|
||||
test.describe('phase label animation cascade', () => {
|
||||
let fixture: { ticker: string; entrance: string; reduced: string };
|
||||
let css: string;
|
||||
|
||||
test.beforeAll(async ({ browserName }, testInfo) => {
|
||||
const fixturePath = testInfo.outputPath(`phase-label-${browserName}.json`);
|
||||
mkdirSync(resolve(fixturePath, '..'), { recursive: true });
|
||||
const rendered = spawnSync(
|
||||
process.execPath,
|
||||
[
|
||||
resolve(repoRoot, 'node_modules/jest/bin/jest.js'),
|
||||
'src/components/Chat/Messages/Content/__tests__/ActivityPhaseGroup.test.tsx',
|
||||
'--maxWorkers=2',
|
||||
'-t',
|
||||
'exports real phase consumers for the browser cascade checks',
|
||||
],
|
||||
{
|
||||
cwd: resolve(repoRoot, 'client'),
|
||||
env: { ...process.env, E2E_PHASE_CASCADE_FIXTURE: fixturePath },
|
||||
encoding: 'utf8',
|
||||
},
|
||||
);
|
||||
expect(rendered.status, rendered.stdout + rendered.stderr).toBe(0);
|
||||
fixture = JSON.parse(readFileSync(fixturePath, 'utf8'));
|
||||
const compilerPath = testInfo.outputPath('compile.cjs');
|
||||
const compiledPath = testInfo.outputPath('app.css');
|
||||
writeFileSync(
|
||||
compilerPath,
|
||||
`const {readFileSync, writeFileSync} = require('node:fs');
|
||||
const postcss = require(${JSON.stringify(require.resolve('postcss'))});
|
||||
const tailwind = require(${JSON.stringify(require.resolve('@tailwindcss/postcss'))});
|
||||
const input = ${JSON.stringify(resolve(repoRoot, 'client/src/style.css'))};
|
||||
postcss([tailwind()]).process(readFileSync(input, 'utf8'), {from: input})
|
||||
.then(result => writeFileSync(${JSON.stringify(compiledPath)}, result.css))
|
||||
.catch(error => { console.error(error); process.exitCode = 1; });`,
|
||||
);
|
||||
const compiled = run(process.execPath, [compilerPath]);
|
||||
expect(compiled.status, compiled.output).toBe(0);
|
||||
css = `${readFileSync(DIST_STYLESHEET, 'utf8')}\n${readFileSync(compiledPath, 'utf8')}`;
|
||||
});
|
||||
|
||||
test('keeps the ticker curve, duration and retired fill @scenario:phase-label-ticker-cascade', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.setContent(`<style>${css}</style>${fixture.ticker}`);
|
||||
await expect(page.locator('.animate-in')).toHaveCSS(
|
||||
'animation-timing-function',
|
||||
'cubic-bezier(0.16, 1, 0.3, 1)',
|
||||
);
|
||||
await expect(page.locator('.animate-out')).toHaveCSS(
|
||||
'animation-timing-function',
|
||||
'cubic-bezier(0.16, 1, 0.3, 1)',
|
||||
);
|
||||
await expect(page.locator('.animate-in')).toHaveCSS('animation-duration', '0.3s');
|
||||
await expect(page.locator('.animate-out')).toHaveCSS('animation-duration', '0.3s');
|
||||
await expect(page.locator('.animate-in')).toHaveCSS('animation-fill-mode', 'none');
|
||||
await expect(page.locator('.animate-out')).toHaveCSS('animation-fill-mode', 'forwards');
|
||||
});
|
||||
|
||||
for (const { reduced, scenario } of [
|
||||
{ reduced: false, scenario: '@scenario:phase-label-entrance-normal-cascade' },
|
||||
{ reduced: true, scenario: '@scenario:phase-label-entrance-reduced-cascade' },
|
||||
]) {
|
||||
test(`keeps the phase entrance with reduced motion ${reduced} ${scenario}`, async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.emulateMedia({ reducedMotion: reduced ? 'reduce' : 'no-preference' });
|
||||
await page.setContent(`<style>${css}</style>${fixture.entrance}`);
|
||||
const card = page.getByTestId('activity-phase-card');
|
||||
await expect(card).toHaveCSS(
|
||||
'animation-timing-function',
|
||||
reduced ? 'ease' : 'cubic-bezier(0.16, 1, 0.3, 1)',
|
||||
);
|
||||
await expect(card).toHaveCSS('animation-duration', reduced ? '0s' : '0.3s');
|
||||
await expect(card).toHaveCSS('animation-fill-mode', 'none');
|
||||
await expect(card).toHaveCSS('animation-name', reduced ? 'none' : 'enter');
|
||||
});
|
||||
}
|
||||
|
||||
test('calms the ticker and shimmer for reduced motion @scenario:phase-label-reduced-motion', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.emulateMedia({ reducedMotion: 'reduce' });
|
||||
await page.setContent(`<style>${css}</style>${fixture.reduced}`);
|
||||
await expect(page.locator('.shimmer-clip')).toHaveCSS('display', 'none');
|
||||
await expect(page.locator('.animate-in, .animate-out')).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -130,9 +130,6 @@
|
|||
}
|
||||
},
|
||||
"client/src/components/Chat/Messages/Content/ActivityPhaseGroup.tsx": {
|
||||
"shadcn/no-arbitrary-values": {
|
||||
"count": 2
|
||||
},
|
||||
"shadcn/no-inline-styles": {
|
||||
"count": 2
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,6 +124,8 @@ export { default as MessageNav } from './components/messages/MessageNav';
|
|||
export type { MessageFooterProps } from './components/messages/MessageFooter';
|
||||
export { getMessageAriaLabel, getHeaderPrefixForScreenReader } from './components/messages/labels';
|
||||
|
||||
export { default as PhaseLabel, FOLD_EASING } from './components/parts/PhaseLabel';
|
||||
|
||||
/** Parts: the leaf components and row classes tool cards share. */
|
||||
export { default as Stdout } from './components/parts/Stdout';
|
||||
export { default as BareStatus } from './components/parts/BareStatus';
|
||||
|
|
|
|||
124
packages/chat/src/components/parts/PhaseLabel.tsx
Normal file
124
packages/chat/src/components/parts/PhaseLabel.tsx
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
import { memo, useCallback, useState } from 'react';
|
||||
import { cn, Shimmer } from '@librechat/client';
|
||||
import type { NamedExoticComponent } from 'react';
|
||||
|
||||
/** Matches `EXPAND_TRANSITION` so the panel and ticker follow the same curve.
|
||||
* The shared class sets animation timing: Tailwind's `ease-*` also names
|
||||
* transition timing, which makes an arbitrary easing value ambiguous. */
|
||||
export const FOLD_EASING = 'duration-300 animation-ease-fold';
|
||||
|
||||
/**
|
||||
* The phase header is a ticker, not a title. A client-synthesized card
|
||||
* re-titles itself every time it absorbs another finished block, and swapping
|
||||
* that text instantly is what makes the absorbed row look like it simply
|
||||
* vanished from under the reader. The retired line rises out of the clipped
|
||||
* row while the new summary comes up from below, so the work visibly moves
|
||||
* into the line that now stands for it.
|
||||
*/
|
||||
/**
|
||||
* The shimmering text of a live line, on its own element. `.shimmer` declares
|
||||
* `position` and `display`, so sharing an element with the ticker would undo
|
||||
* the slide's absolute placement; the retired line would sit inline beside
|
||||
* its successor. `align-top` keeps the inline box from adding descender space,
|
||||
* which made a live row 2px taller than the settled row it becomes.
|
||||
*/
|
||||
function LiveLine({ text }: { text: string }) {
|
||||
return <Shimmer className="max-w-full truncate align-top">{text}</Shimmer>;
|
||||
}
|
||||
|
||||
type PhaseLabelProps = {
|
||||
text: string;
|
||||
animate: boolean;
|
||||
/** Identity of what produced `text`. A streamed sentence keeps its source
|
||||
* while it grows, and sliding a line out to bring a longer copy of itself
|
||||
* in would read as flicker, so an unchanged source extends in place. */
|
||||
source?: string;
|
||||
live?: boolean;
|
||||
/** Claim the row's free space, the default. Cleared when something has to
|
||||
* sit immediately after the text; the box then measures the line itself,
|
||||
* so its neighbour reads as part of it instead of drifting to the margin. */
|
||||
grow?: boolean;
|
||||
/** Id for the current line, so a live disclosure can be named by it alone. */
|
||||
lineId?: string;
|
||||
};
|
||||
|
||||
const PhaseLabel: NamedExoticComponent<PhaseLabelProps> = memo(function PhaseLabel({
|
||||
text,
|
||||
animate,
|
||||
source,
|
||||
live = false,
|
||||
grow = true,
|
||||
lineId,
|
||||
}: PhaseLabelProps) {
|
||||
const [lines, setLines] = useState<{
|
||||
current: string;
|
||||
retired: string | null;
|
||||
entered: boolean;
|
||||
source?: string;
|
||||
}>({ current: text, retired: null, entered: false, source });
|
||||
|
||||
/** Adjusted during render rather than in an effect. A passive effect runs
|
||||
* after paint, so a swap with no animation would leave the previous summary
|
||||
* on screen for a frame while the button's `aria-label` already carried the
|
||||
* new one. React re-renders this component immediately instead. */
|
||||
if (lines.current !== text || lines.source !== source) {
|
||||
const moved = source == null || source !== lines.source;
|
||||
const swaps = animate && lines.current.length > 0 && moved;
|
||||
setLines({
|
||||
current: text,
|
||||
retired: swaps ? lines.current : null,
|
||||
entered: swaps || (lines.entered && source != null && source === lines.source),
|
||||
source,
|
||||
});
|
||||
}
|
||||
|
||||
/** Clears only the retired line. `entered` outlives it on purpose: dropping
|
||||
* the incoming line's animation class the moment its partner's
|
||||
* `animationend` fires would snap a still-running slide back to its resting
|
||||
* position. The class is inert once the animation has finished, and the
|
||||
* element is keyed by its text, so it cannot replay. */
|
||||
const clearRetired = useCallback(() => {
|
||||
setLines((previous) => (previous.retired == null ? previous : { ...previous, retired: null }));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
'tool-status-text relative block min-w-0 overflow-hidden text-start',
|
||||
grow && 'flex-1',
|
||||
)}
|
||||
title={text}
|
||||
>
|
||||
{lines.retired != null && (
|
||||
<span
|
||||
key={`retired-${lines.retired}`}
|
||||
className={cn(
|
||||
'absolute inset-x-0 top-0 block truncate',
|
||||
'animate-out fade-out-0 slide-out-to-top-5 animation-fill-forwards',
|
||||
FOLD_EASING,
|
||||
)}
|
||||
/** The sweep on the inner span loops forever and its `animationend`
|
||||
* never comes; only this element's own slide may clear the line. */
|
||||
onAnimationEnd={(event) => event.target === event.currentTarget && clearRetired()}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{live ? <LiveLine text={lines.retired} /> : lines.retired}
|
||||
</span>
|
||||
)}
|
||||
<span
|
||||
/** Keyed by source while live, so a growing sentence updates one
|
||||
* element instead of remounting; and replaying its slide; per paint. */
|
||||
key={`current-${source ?? lines.current}`}
|
||||
id={lineId}
|
||||
className={cn(
|
||||
'block truncate',
|
||||
lines.entered && `animate-in fade-in-0 slide-in-from-bottom-5 ${FOLD_EASING}`,
|
||||
)}
|
||||
>
|
||||
{live ? <LiveLine text={lines.current} /> : lines.current}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
});
|
||||
|
||||
export default PhaseLabel;
|
||||
112
packages/chat/src/components/parts/__tests__/PhaseLabel.spec.tsx
Normal file
112
packages/chat/src/components/parts/__tests__/PhaseLabel.spec.tsx
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/** @jest-environment jsdom */
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import PhaseLabel, { FOLD_EASING } from '../PhaseLabel';
|
||||
|
||||
const first = 'Compared both release paths';
|
||||
const next = 'Confirmed the rollback path is clean';
|
||||
|
||||
describe('PhaseLabel', () => {
|
||||
test('renders the initial line without replaying a slide', () => {
|
||||
render(<PhaseLabel text={first} animate lineId="phase-line" />);
|
||||
|
||||
expect(screen.getByText(first)).toHaveAttribute('id', 'phase-line');
|
||||
expect(screen.getByText(first)).not.toHaveClass('animate-in');
|
||||
expect(screen.getByTitle(first)).toHaveClass('tool-status-text', 'flex-1');
|
||||
});
|
||||
|
||||
test('retires the old summary with the same easing as the incoming line', () => {
|
||||
const { rerender } = render(<PhaseLabel text={first} animate />);
|
||||
rerender(<PhaseLabel text={next} animate />);
|
||||
|
||||
const retired = screen.getByText(first);
|
||||
const current = screen.getByText(next);
|
||||
expect(retired).toHaveAttribute('aria-hidden', 'true');
|
||||
expect(retired).toHaveClass('absolute', 'animate-out', 'slide-out-to-top-5');
|
||||
expect(current).toHaveClass('animate-in', 'slide-in-from-bottom-5');
|
||||
for (const easingClass of FOLD_EASING.split(' ')) {
|
||||
expect(retired).toHaveClass(easingClass);
|
||||
expect(current).toHaveClass(easingClass);
|
||||
}
|
||||
|
||||
fireEvent.animationEnd(retired);
|
||||
|
||||
expect(screen.queryByText(first)).not.toBeInTheDocument();
|
||||
expect(screen.getByText(next)).toBe(current);
|
||||
expect(current).toHaveClass('animate-in');
|
||||
});
|
||||
|
||||
test('replaces the summary immediately when animation is disabled', () => {
|
||||
const { rerender } = render(<PhaseLabel text={first} animate={false} />);
|
||||
rerender(<PhaseLabel text={next} animate={false} />);
|
||||
|
||||
expect(screen.queryByText(first)).not.toBeInTheDocument();
|
||||
expect(screen.getByText(next)).not.toHaveClass('animate-in');
|
||||
expect(screen.getByTitle(next)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('does not animate the first nonempty summary', () => {
|
||||
const { rerender } = render(<PhaseLabel text="" animate />);
|
||||
rerender(<PhaseLabel text={first} animate />);
|
||||
|
||||
expect(screen.getByText(first)).not.toHaveClass('animate-in');
|
||||
});
|
||||
|
||||
test('extends a streamed sentence in place while its source stays the same', () => {
|
||||
const { rerender } = render(<PhaseLabel text="Checking" source="think:1" animate live />);
|
||||
const line = screen.getByText('Checking').parentElement;
|
||||
rerender(<PhaseLabel text="Checking both release paths" source="think:1" animate live />);
|
||||
|
||||
expect(screen.queryByText('Checking')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('Checking both release paths').parentElement).toBe(line);
|
||||
expect(line).not.toHaveClass('animate-in');
|
||||
expect(screen.getByText('Checking both release paths')).toHaveClass('shimmer', 'align-top');
|
||||
});
|
||||
|
||||
test('keeps a slide on the same element as the incoming streamed sentence grows', () => {
|
||||
const { rerender } = render(<PhaseLabel text={first} source="tool:1" animate live />);
|
||||
rerender(<PhaseLabel text="Checking" source="think:1" animate live />);
|
||||
const current = screen.getByText('Checking').parentElement;
|
||||
expect(current).toHaveClass('animate-in');
|
||||
|
||||
rerender(<PhaseLabel text="Checking both paths" source="think:1" animate live />);
|
||||
|
||||
expect(screen.getByText('Checking both paths').parentElement).toBe(current);
|
||||
expect(current).toHaveClass('animate-in');
|
||||
});
|
||||
|
||||
test('ignores a bubbled shimmer animation ending before the retired slide ends', () => {
|
||||
const { rerender } = render(<PhaseLabel text={first} source="tool:1" animate live />);
|
||||
rerender(<PhaseLabel text={next} source="tool:2" animate live />);
|
||||
const retiredText = screen.getByText(first);
|
||||
const retired = retiredText.parentElement;
|
||||
expect(retired).toHaveAttribute('aria-hidden', 'true');
|
||||
expect(retiredText).toHaveClass('shimmer');
|
||||
expect(retiredText).not.toHaveClass('absolute');
|
||||
|
||||
fireEvent.animationEnd(retiredText);
|
||||
expect(screen.getByText(first)).toBeInTheDocument();
|
||||
|
||||
if (retired == null) {
|
||||
throw new Error('The retired line must wrap its shimmering text.');
|
||||
}
|
||||
fireEvent.animationEnd(retired);
|
||||
expect(screen.queryByText(first)).not.toBeInTheDocument();
|
||||
expect(screen.getByText(next).parentElement).toHaveClass('animate-in');
|
||||
});
|
||||
|
||||
test('keeps only the latest retired line across successive summary changes', () => {
|
||||
const { rerender } = render(<PhaseLabel text={first} animate />);
|
||||
rerender(<PhaseLabel text={next} animate />);
|
||||
rerender(<PhaseLabel text="Finished" animate />);
|
||||
|
||||
expect(screen.queryByText(first)).not.toBeInTheDocument();
|
||||
expect(screen.getByText(next)).toHaveAttribute('aria-hidden', 'true');
|
||||
expect(screen.getByText('Finished')).not.toHaveAttribute('aria-hidden');
|
||||
});
|
||||
|
||||
test('can size to the label so the multiplier sits immediately after it', () => {
|
||||
render(<PhaseLabel text={first} animate grow={false} />);
|
||||
|
||||
expect(screen.getByTitle(first)).not.toHaveClass('flex-1');
|
||||
});
|
||||
});
|
||||
|
|
@ -87,6 +87,20 @@ function tailwindDefault(variable) {
|
|||
}
|
||||
|
||||
describe('LibreChat Tailwind preset', () => {
|
||||
it('ships the phase ticker animation properties without changing transition easing', async () => {
|
||||
const css = await generate([
|
||||
'animation-ease-fold',
|
||||
'animation-fill-forwards',
|
||||
'fill-mode-forwards',
|
||||
]);
|
||||
|
||||
expect(rule(css, 'animation-ease-fold')).toBe(
|
||||
'animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);',
|
||||
);
|
||||
expect(rule(css, 'animation-fill-forwards')).toBe('animation-fill-mode: forwards;');
|
||||
expect(rule(css, 'animation-fill-forwards')).toBe(rule(css, 'fill-mode-forwards'));
|
||||
});
|
||||
|
||||
it('owns the loading-dot delay with a zero-delay fallback for plain preset consumers', async () => {
|
||||
const css = await generate(['animate-loading-dot']);
|
||||
|
||||
|
|
|
|||
|
|
@ -242,6 +242,18 @@ module.exports = {
|
|||
* Declared as a peer dependency so the consumer's install provides it.
|
||||
*/
|
||||
require('tailwindcss-animate'),
|
||||
/** The fold's animation properties need distinct names: `ease-*` also controls transitions,
|
||||
* and the design parser reads the plugin's `fill-mode-*` utilities as SVG fill colors. */
|
||||
{
|
||||
handler: ({ addUtilities }) => {
|
||||
addUtilities({
|
||||
'.animation-ease-fold': {
|
||||
animationTimingFunction: 'cubic-bezier(0.16, 1, 0.3, 1)',
|
||||
},
|
||||
'.animation-fill-forwards': { animationFillMode: 'forwards' },
|
||||
});
|
||||
},
|
||||
},
|
||||
/**
|
||||
* A bare function rather than `plugin()` from `tailwindcss/plugin`, because
|
||||
* this preset ships as a raw file through the `./tailwind-preset` export and
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue