diff --git a/packages/starlight/__bench_fn__/generate-route-data.bench.ts b/packages/starlight/__bench_fn__/generate-route-data.bench.ts index bf487549a..c4b67bc22 100644 --- a/packages/starlight/__bench_fn__/generate-route-data.bench.ts +++ b/packages/starlight/__bench_fn__/generate-route-data.bench.ts @@ -1,8 +1,10 @@ +import { klona } from 'klona'; import { bench, describe, vi } from 'vitest'; import { getRouteDataTestContext } from '../__tests__/test-utils'; import { generateRouteData } from '../src/utils/routing/data'; import { getRouteBySlugParam } from '../src/utils/routing'; -import { getSidebar } from '../src/utils/navigation'; +import { flattenSidebar, getSidebar } from '../src/utils/navigation'; +import type { SidebarEntry } from '../src/utils/routing/types'; const docs = vi.hoisted(() => { const docs: [string, { title: string }][] = []; @@ -48,3 +50,17 @@ describe('routing', () => { getSidebar(context.url.pathname, route.locale); }); }); + +/** Recursive function that simulates the heavier logic in `` rendering. */ +function mockSidebarRender(sublist: SidebarEntry[]) { + for (const entry of sublist) { + if (entry.type !== 'link') { + flattenSidebar(entry.entries).some((i) => i.isCurrent); + mockSidebarRender(entry.entries); + } + } +} + +bench('sidebar current groups', () => { + mockSidebarRender(klona(getSidebar(context.url.pathname, route.locale))); +});