mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-04-04 06:47:19 +02:00
📐 style: Resolve Stale Active Sidebar Panel and Favorites Row Height (#12366)
Some checks failed
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Has been cancelled
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Has been cancelled
Publish `@librechat/client` to NPM / build-and-publish (push) Has been cancelled
Publish `librechat-data-provider` to NPM / build (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Publish `librechat-data-provider` to NPM / publish-npm (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled
Some checks failed
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Has been cancelled
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Has been cancelled
Publish `@librechat/client` to NPM / build-and-publish (push) Has been cancelled
Publish `librechat-data-provider` to NPM / build (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Publish `librechat-data-provider` to NPM / publish-npm (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled
* 🐛 fix: Sidebar favorites row height stuck at stale measurement
Use a content-aware cache key for the favorites row in the virtualized
sidebar list. The CellMeasurerCache keyMapper now encodes
favorites.length, showAgentMarketplace, and isFavoritesLoading into the
key so the cache naturally invalidates when the content shape changes,
forcing CellMeasurer to re-measure from scratch instead of returning a
stale height from a transient render state.
Remove the onHeightChange callback and its useEffect from FavoritesList
since the content-aware key handles all height-affecting state
transitions.
* test: Add unit tests for Conversations component favorites height caching
Introduced a new test suite for the Conversations component to validate the behavior of the favorites CellMeasurerCache. The tests ensure that the cache correctly invalidates when the favorites count changes, loading state transitions occur, and marketplace visibility toggles. This enhances the reliability of the component's rendering logic and ensures proper height management in the virtualized list.
* fix: Validate active sidebar panel against available links
The `side:active-panel` localStorage key was shared with the old
right-side panel. On first load of the unified sidebar, a stale value
(e.g. 'hide-panel', or a conditional panel not currently available)
would match no link, leaving the expanded panel empty.
Add `resolveActivePanel` as derived state in both Nav and ExpandedPanel
so content and icon highlight always fall back to the first link when
the stored value doesn't match any available link.
* refactor: Remove redundant new-chat button from Agent Marketplace header
The sidebar icon strip already provides a new chat button, making the
sticky header in the marketplace page unnecessary.
* chore: import order and linting
* fix: Update dependencies in Conversations component to include marketplace visibility
Modified the useEffect dependency array in the Conversations component to include `showAgentMarketplace`, ensuring proper reactivity to changes in marketplace visibility. Additionally, updated the test suite to mock favorites state for accurate height caching validation when marketplace visibility changes.
This commit is contained in:
parent
ccd049d8ce
commit
5a373825a5
8 changed files with 234 additions and 35 deletions
|
|
@ -35,3 +35,11 @@ export function useActivePanel() {
|
|||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
/** Returns `active` when it matches a known link, otherwise the first link's id. */
|
||||
export function resolveActivePanel(active: string, links: { id: string }[]): string {
|
||||
if (links.length > 0 && links.some((l) => l.id === active)) {
|
||||
return active;
|
||||
}
|
||||
return links[0]?.id ?? active;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
import React from 'react';
|
||||
import { render, fireEvent, screen } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom/extend-expect';
|
||||
import { ActivePanelProvider, useActivePanel } from '~/Providers/ActivePanelContext';
|
||||
import {
|
||||
ActivePanelProvider,
|
||||
resolveActivePanel,
|
||||
useActivePanel,
|
||||
} from '~/Providers/ActivePanelContext';
|
||||
|
||||
const STORAGE_KEY = 'side:active-panel';
|
||||
|
||||
|
|
@ -58,3 +62,23 @@ describe('ActivePanelContext', () => {
|
|||
spy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveActivePanel', () => {
|
||||
const links = [{ id: 'conversations' }, { id: 'prompts' }, { id: 'files' }];
|
||||
|
||||
it('returns active when it matches a link', () => {
|
||||
expect(resolveActivePanel('prompts', links)).toBe('prompts');
|
||||
});
|
||||
|
||||
it('falls back to first link when active does not match', () => {
|
||||
expect(resolveActivePanel('hide-panel', links)).toBe('conversations');
|
||||
});
|
||||
|
||||
it('returns active unchanged when links is empty', () => {
|
||||
expect(resolveActivePanel('agents', [])).toBe('agents');
|
||||
});
|
||||
|
||||
it('falls back to the only link when active is stale', () => {
|
||||
expect(resolveActivePanel('agents', [{ id: 'conversations' }])).toBe('conversations');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue