fix(web): address open vsx review findings

This commit is contained in:
t3-code[bot] committed 2026-08-08 00:25:57 +00:00
1 parent 64490d4c65
commit 4e5bafcff7
3 files changed
+43 -24

No files matched your search

@@ -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}
>
<div className="flex min-w-0 gap-3">
{extension.iconUrl ? (
<img
alt=""
className="size-10 shrink-0 rounded-lg bg-muted object-cover"
src={extension.iconUrl}
/>
) : (
<div className="flex size-10 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground">
<SearchIcon className="size-4" />
</div>
)}
<div className="flex size-10 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground">
<PaletteIcon className="size-4" />
</div>
<div className="min-w-0 flex-1">
<h4 className="truncate text-sm font-medium">{extension.name}</h4>
<p className="truncate text-muted-foreground text-xs">
+19 -2
View File
@@ -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`,
+20 -10
View File
@@ -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<string, unknown> {
@@ -331,18 +331,25 @@ async function readZipText(zip: JSZip, path: string, description: string): Promi
async function loadThemeObject(
zip: JSZip,
path: string,
cache: Map<string, Record<string, unknown>>,
ancestors: ReadonlySet<string> = new Set(),
): Promise<Record<string, unknown>> {
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<string, Record<string, unknown>>();
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()