fix(ui): harden Lighthouse context compiler against invalid items and budget pressure (#12286)

This commit is contained in:
Alejandro Bailo
2026-08-04 13:41:20 +02:00
committed by GitHub
parent ab13d111c2
commit f9dbb0eee9
4 changed files with 238 additions and 17 deletions
@@ -52,6 +52,18 @@ describe("buildOverviewProviderContextItems", () => {
]);
});
it("dedupes repeated provider ids before filling the bounded slots", () => {
const items = buildOverviewProviderContextItems({
searchParams: {
"filter[provider_id__in]": "prov-1,prov-1,prov-1,prov-2,prov-3",
},
providers,
groups,
});
expect(items.map((item) => item.id)).toEqual(["prov-1", "prov-2"]);
});
it("resolves URL-filtered group ids to labeled group items", () => {
const items = buildOverviewProviderContextItems({
searchParams: { "filter[provider_groups__in]": "group-1,unknown" },
@@ -10,8 +10,8 @@ import type { ProviderProps } from "@/types/providers";
import { parseFilterIds } from "./provider-scope";
const OVERVIEW_PATHNAME = "/";
// Bounded so provider items cannot crowd out the page, ThreatScore, and
// posture summaries within the shared context item budget.
// Bounded so provider items take a small share of the context item budget;
// under byte pressure the compiler additionally evicts provider items first.
const MAX_PROVIDER_ITEMS = 2;
const MAX_TOTAL_ITEMS = 3;
@@ -26,8 +26,14 @@ export function buildOverviewProviderContextItems({
providers,
groups,
}: OverviewProviderContextInput): LighthouseProviderContextItem[] {
const providerIds = parseFilterIds(searchParams["filter[provider_id__in]"]);
const groupIds = parseFilterIds(searchParams["filter[provider_groups__in]"]);
// Dedupe before slicing so a repeated id cannot fill the bounded slots and
// silently push the remaining selected providers out of the context.
const providerIds = Array.from(
new Set(parseFilterIds(searchParams["filter[provider_id__in]"])),
);
const groupIds = Array.from(
new Set(parseFilterIds(searchParams["filter[provider_groups__in]"])),
);
const providerItems = providerIds
.map((id) => providers.find((provider) => provider.id === id))