From 4e5bafcff76a489393db8ded4390f49e86e367b9 Mon Sep 17 00:00:00 2001 From: "t3-code[bot]" <269035359+t3-code[bot]@users.noreply.github.com> Date: Fri, 7 Aug 2026 20:56:55 +0000 Subject: [PATCH] fix(web): address open vsx review findings --- .../components/settings/ThemeSearchDialog.tsx | 16 +++------- apps/web/src/openVsxThemes.test.ts | 21 +++++++++++-- apps/web/src/openVsxThemes.ts | 30 ++++++++++++------- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/apps/web/src/components/settings/ThemeSearchDialog.tsx b/apps/web/src/components/settings/ThemeSearchDialog.tsx index e26039b366..329c989c17 100644 --- a/apps/web/src/components/settings/ThemeSearchDialog.tsx +++ b/apps/web/src/components/settings/ThemeSearchDialog.tsx @@ -1,4 +1,4 @@ -import { CheckCircle2Icon, PlusIcon, SearchIcon, ShieldCheckIcon } from "lucide-react"; +import { CheckCircle2Icon, PaletteIcon, PlusIcon, SearchIcon, ShieldCheckIcon } from "lucide-react"; import type { FormEvent } from "react"; import { useCallback, useEffect, useRef, useState } from "react"; import { @@ -223,17 +223,9 @@ export function ThemeSearchDialog({ key={extension.id} >
- {extension.iconUrl ? ( - - ) : ( -
- -
- )} +
+ +

{extension.name}

diff --git a/apps/web/src/openVsxThemes.test.ts b/apps/web/src/openVsxThemes.test.ts index 4a74bb91c7..531f43e32f 100644 --- a/apps/web/src/openVsxThemes.test.ts +++ b/apps/web/src/openVsxThemes.test.ts @@ -80,6 +80,25 @@ describe("Open VSX themes", () => { expect(searchUrl.searchParams.get("size")).toBe("16"); }); + it("reports an unavailable search when every detail request fails", async () => { + vi.stubGlobal( + "fetch", + vi.fn(async (input: RequestInfo | URL) => { + if (String(input).includes("/-/search?")) { + return new Response( + JSON.stringify({ extensions: [{ namespace: "demo", name: "theme" }] }), + { status: 200 }, + ); + } + return new Response(null, { status: 429 }); + }), + ); + + await expect(searchOpenVsxThemes("dracula")).rejects.toThrow( + "Open VSX theme details are unavailable", + ); + }); + it("downloads a verified VSIX, reads JSONC includes, and pairs contributed variants", async () => { const zip = new JSZip(); zip.file( @@ -140,7 +159,6 @@ describe("Open VSX themes", () => { publisher: "demo", description: "", downloadCount: 1, - iconUrl: null, license: "MIT", manifestUrl: `${ASSET_ROOT}/package.json`, sha256Url: `${ASSET_ROOT}/demo.theme-1.0.0.sha256`, @@ -184,7 +202,6 @@ describe("Open VSX themes", () => { publisher: "demo", description: "", downloadCount: 1, - iconUrl: null, license: "MIT", manifestUrl: `${ASSET_ROOT}/package.json`, sha256Url: `${ASSET_ROOT}/demo.theme-1.0.0.sha256`, diff --git a/apps/web/src/openVsxThemes.ts b/apps/web/src/openVsxThemes.ts index eb0a63b400..302fefc5f5 100644 --- a/apps/web/src/openVsxThemes.ts +++ b/apps/web/src/openVsxThemes.ts @@ -39,7 +39,6 @@ export type OpenVsxThemeExtension = { publisher: string; description: string; downloadCount: number; - iconUrl: string | null; manifestUrl: string; sha256Url: string; vsixUrl: string; @@ -96,7 +95,6 @@ function extensionFromDetail(value: unknown): OpenVsxThemeExtension | null { typeof value.downloadCount === "number" && Number.isFinite(value.downloadCount) ? value.downloadCount : 0, - iconUrl: trustedOpenVsxUrl(value.files.icon), manifestUrl, sha256Url, vsixUrl, @@ -141,7 +139,7 @@ export async function searchOpenVsxThemes( identities.slice(0, 16).map(async ([namespace, name]) => { const detailUrl = `https://open-vsx.org/api/${encodeURIComponent(namespace)}/${encodeURIComponent(name)}`; const detailResponse = await fetch(detailUrl, signal ? { signal } : {}); - if (!detailResponse.ok) return null; + if (!detailResponse.ok) throw new Error("Open VSX theme details are unavailable."); const detailBytes = await readCappedResponse( detailResponse, MAX_DETAIL_BYTES, @@ -155,9 +153,11 @@ export async function searchOpenVsxThemes( }), ); if (signal?.aborted) throw new DOMException("The operation was aborted.", "AbortError"); - return details - .flatMap((result) => (result.status === "fulfilled" && result.value ? [result.value] : [])) - .slice(0, 8); + const completedDetails = details.filter((result) => result.status === "fulfilled"); + if (identities.length > 0 && completedDetails.length === 0) { + throw new Error("Open VSX theme details are unavailable right now."); + } + return completedDetails.flatMap((result) => (result.value ? [result.value] : [])).slice(0, 8); } function parseJsoncObject(source: string, description: string): Record { @@ -331,18 +331,25 @@ async function readZipText(zip: JSZip, path: string, description: string): Promi async function loadThemeObject( zip: JSZip, path: string, + cache: Map>, ancestors: ReadonlySet = new Set(), ): Promise> { if (ancestors.size >= MAX_INCLUDE_DEPTH) throw new Error("Theme includes are nested too deeply."); if (ancestors.has(path)) throw new Error("Theme includes contain a cycle."); + const cached = cache.get(path); + if (cached) return cached; + const value = parseJsoncObject(await readZipText(zip, path, path), path); - if (typeof value.include !== "string") return value; + if (typeof value.include !== "string") { + cache.set(path, value); + return value; + } const includePath = normalizePackagePath(value.include, path); const nextAncestors = new Set(ancestors); nextAncestors.add(path); - const base = await loadThemeObject(zip, includePath, nextAncestors); - return { + const base = await loadThemeObject(zip, includePath, cache, nextAncestors); + const resolved = { ...base, ...value, colors: { @@ -350,6 +357,8 @@ async function loadThemeObject( ...(isRecord(value.colors) ? value.colors : {}), }, }; + cache.set(path, resolved); + return resolved; } async function readCappedResponse( @@ -457,11 +466,12 @@ export async function importOpenVsxThemeExtension( const parsed: Array<{ theme: ThemeDefinition; sourceName: string }> = []; const failures: string[] = []; + const themeCache = new Map>(); for (const contribution of contributions as ThemeContribution[]) { if (typeof contribution.path !== "string") continue; try { const path = normalizePackagePath(contribution.path); - const themeValue = await loadThemeObject(zip, path); + const themeValue = await loadThemeObject(zip, path, themeCache); const type = contributionType(contribution.uiTheme); const label = typeof contribution.label === "string" && contribution.label.trim()