🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(tabbar): debounce route meta publish to avoid tab item flicker (#15238)
Innei72d34046c08d
diff --git a/src/features/RouteMeta/RouteMetaBridge.test.tsx b/src/features/RouteMeta/RouteMetaBridge.test.tsxindex f968ca93886..1ecef2a69c3 100644--- a/src/features/RouteMeta/RouteMetaBridge.test.tsx+++ b/src/features/RouteMeta/RouteMetaBridge.test.tsx@@ -92,17 +92,20 @@ describe('RouteMetaBridge', () => {render(<RouteMetaBridge />);- await waitFor(() => {- expect(document.title).toBe(`Chat A · ${BRANDING_NAME}`);- expect(mocks.setCurrentRouteMeta).toHaveBeenLastCalledWith(- {- avatar: undefined,- backgroundColor: undefined,- title: 'Chat A',- },- '/agent/agent-a',- );- });+ await waitFor(+ () => {+ expect(document.title).toBe(`Chat A · ${BRANDING_NAME}`);+ expect(mocks.setCurrentRouteMeta).toHaveBeenLastCalledWith(+ {+ avatar: undefined,+ backgroundColor: undefined,+ title: 'Chat A',+ },+ '/agent/agent-a',+ );+ },+ { timeout: 2000 },+ );act(() => {mocks.setMatches([@@ -121,4 +124,56 @@ describe('RouteMetaBridge', () => {expect(mocks.setCurrentRouteMeta).toHaveBeenLastCalledWith(null);});});++ it('keeps the previous title when switching params within the same route', async () => {+ const titleSets: string[] = [];+ const titleDescriptor = Object.getOwnPropertyDescriptor(document, 'title');+ let titleStore = '';+ Object.defineProperty(document, 'title', {+ configurable: true,+ get: () => titleStore,+ set: (value: string) => {+ titleStore = value;+ titleSets.push(value);+ },+ });++ try {+ const makeMatch = (topicId: string) => ({+ data: undefined,+ handle: {+ meta: {+ titleKey: 'navigation.chat',+ useDynamicMeta: (params: Record<string, string | undefined>) => ({+ title: `Topic ${params.topicId}`,+ }),+ },+ },+ id: 'routes/agent',+ params: { topicId },+ pathname: `/agent/${topicId}`,+ });++ mocks.setMatches([makeMatch('a')]);+ render(<RouteMetaBridge />);++ await waitFor(() => {+ expect(document.title).toBe(`Topic a · ${BRANDING_NAME}`);+ });++ titleSets.length = 0;++ act(() => {+ mocks.setMatches([makeMatch('b')]);+ });++ await waitFor(() => {+ expect(document.title).toBe(`Topic b · ${BRANDING_NAME}`);+ });++ expect(titleSets).not.toContain(`translated:navigation.chat · ${BRANDING_NAME}`);+ } finally {+ if (titleDescriptor) Object.defineProperty(document, 'title', titleDescriptor);+ }+ });});diff --git a/src/features/RouteMeta/RouteMetaBridge.tsx b/src/features/RouteMeta/RouteMetaBridge.tsxindex 76e914dbf99..ce0616322c2 100644--- a/src/features/RouteMeta/RouteMetaBridge.tsx+++ b/src/features/RouteMeta/RouteMetaBridge.tsx@@ -22,8 +22,8 @@ interface MatchedRouteMeta {}interface DynamicRouteMetaState {- matchKey: string | null;meta: DynamicRouteMeta;+ routeId: string | null;}const useMatchedRouteMeta = (): MatchedRouteMeta | null => {@@ -49,28 +49,37 @@ const RouteMetaBridge = memo(() => {const setCurrentRouteMeta = useElectronStore((s) => s.setCurrentRouteMeta);const matched = useMatchedRouteMeta();const currentUrl = location.pathname + location.search;- const matchedKey = matched ? `${matched.routeId}:${currentUrl}` : null;- const [dynamic, setDynamic] = useState<DynamicRouteMetaState>({ matchKey: null, meta: {} });+ const matchedRouteId = matched?.routeId ?? null;+ const [dynamic, setDynamic] = useState<DynamicRouteMetaState>({ meta: {}, routeId: null });++ const publishRouteMeta = useCallback(+ (resolved: DynamicRouteMeta, url: string) => setCurrentRouteMeta(resolved, url),+ [setCurrentRouteMeta],+ );const handleResolve = useCallback((resolved: DynamicRouteMeta) => {- setDynamic({ matchKey: matchedKey, meta: resolved });- if (isDesktop) setCurrentRouteMeta(resolved, currentUrl);+ setDynamic({ meta: resolved, routeId: matchedRouteId });+ if (isDesktop) publishRouteMeta(resolved, currentUrl);},- [currentUrl, matchedKey, setCurrentRouteMeta],+ [currentUrl, matchedRouteId, publishRouteMeta],);const translate = t as unknown as Translate;const titleKey = matched?.meta.titleKey;- const currentDynamic = dynamic.matchKey === matchedKey ? dynamic.meta : {};+ // Keep the previously resolved meta while navigating within the same route family+ // (e.g. switching topics) so the title doesn't briefly fall back to the static label.+ const currentDynamic = matched && dynamic.routeId === matched.routeId ? dynamic.meta : {};const title = matched ? currentDynamic.title || (titleKey ? translate(titleKey) : '') : '';useEffect(() => {- if (matchedKey) return;+ if (matchedRouteId) return;- setDynamic({ matchKey: null, meta: {} });- if (isDesktop) setCurrentRouteMeta(null);- }, [matchedKey, setCurrentRouteMeta]);+ setDynamic({ meta: {}, routeId: null });+ if (isDesktop) {+ setCurrentRouteMeta(null);+ }+ }, [matchedRouteId, publishRouteMeta, setCurrentRouteMeta]);useEffect(() => {document.title = title ? `${title} · ${BRANDING_NAME}` : BRANDING_NAME;diff --git a/src/store/electron/actions/navigationHistory.ts b/src/store/electron/actions/navigationHistory.tsindex a0d9b1dd191..7b7418a76f0 100644--- a/src/store/electron/actions/navigationHistory.ts+++ b/src/store/electron/actions/navigationHistory.ts@@ -204,6 +204,16 @@ export class NavigationHistoryActionImpl {};setCurrentRouteMeta = (meta: DynamicRouteMeta | null, url: string | null = null): void => {+ const { currentRouteMeta, currentRouteMetaUrl } = this.#get();+ if (+ currentRouteMetaUrl === url &&+ (currentRouteMeta === null) === (meta === null) &&+ currentRouteMeta?.avatar === meta?.avatar &&+ currentRouteMeta?.backgroundColor === meta?.backgroundColor &&+ currentRouteMeta?.title === meta?.title+ ) {+ return;+ }this.#set({ currentRouteMeta: meta, currentRouteMetaUrl: url }, false, 'setCurrentRouteMeta');};