From 209929d57a5b9bd6b8f0a47c7935a48c762c472e Mon Sep 17 00:00:00 2001 From: Arul Sharma Date: Mon, 23 Nov 2026 10:56:33 -0500 Subject: [PATCH 1/2] fix(desktop): read icon links from an HTML rel token list A project whose only icon was declared through a token-list rel value showed the generic placeholder: the icon resolver compared rel as a literal string (`icon` or `shortcut icon`), so , a tab-separated variant, and the { rel: "icon shortcut", href } __root.tsx head-config form never matched, and the declared icon was never resolved even when the file existed. The same regex accepted a mismatched closing quote, so rel="icon's" wrongly resolved an icon. Parse rel as the unordered, whitespace-separated token list the HTML spec defines, in both the HTML and object forms, keeping apple-touch-icon, mask-icon and fluid-icon unmatched. Proof: pre-fix, an out-of-tree driver bundling the real module was 5/9 (rel="icon shortcut", rel="Iconshortcut" and the object form returned null while rel="icon's" wrongly resolved), and the focused test failed with "expected null to be .../public/brand/logo.svg". Post-fix: driver 9/9, and the extended case in projectIconResolver.test.ts passes (25 passed). The two other failures in that file also fail on unmodified HEAD on this Windows machine (file-mode bits and symlink EPERM) and are unrelated. Desktop and ade-cli typechecks pass. Co-Authored-By: Claude Code --- .../projects/projectIconResolver.test.ts | 23 +++++++++++++++++++ .../services/projects/projectIconResolver.ts | 14 +++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src/main/services/projects/projectIconResolver.test.ts b/apps/desktop/src/main/services/projects/projectIconResolver.test.ts index 63a8c10e73..d2c5ec433d 100644 --- a/apps/desktop/src/main/services/projects/projectIconResolver.test.ts +++ b/apps/desktop/src/main/services/projects/projectIconResolver.test.ts @@ -71,6 +71,29 @@ describe("projectIconResolver", () => { const iconPath = writeFile(root, "public/brand/logo.svg", "brand"); expect(resolveProjectIconPath(root)).toBe(iconPath); + + // `rel` is an unordered, whitespace-separated token list; any `icon` token + // marks an icon link, wherever it sits in the list. + const tokenListRoot = makeProjectRoot(); + writeFile(tokenListRoot, "index.html", ''); + const tokenListIconPath = writeFile(tokenListRoot, "public/brand/logo.svg", "brand"); + expect(resolveProjectIconPath(tokenListRoot)).toBe(tokenListIconPath); + + // The same token list in the `__root.tsx` head-config object form. + const objectRoot = makeProjectRoot(); + writeFile( + objectRoot, + "app/routes/__root.tsx", + 'export const Route = { head: () => ({ links: [{ rel: "icon shortcut", href: "/brand/logo.svg" }] }) };', + ); + const objectIconPath = writeFile(objectRoot, "public/brand/logo.svg", "brand"); + expect(resolveProjectIconPath(objectRoot)).toBe(objectIconPath); + + // The closing quote pairs with the opening one, so `icon's` has no `icon` token. + const possessiveRoot = makeProjectRoot(); + writeFile(possessiveRoot, "index.html", ''); + writeFile(possessiveRoot, "public/brand/logo.svg", "brand"); + expect(resolveProjectIconPath(possessiveRoot)).toBeNull(); }); it("detects nested app icons in monorepos", () => { diff --git a/apps/desktop/src/main/services/projects/projectIconResolver.ts b/apps/desktop/src/main/services/projects/projectIconResolver.ts index 908ba148ba..cfb8768890 100644 --- a/apps/desktop/src/main/services/projects/projectIconResolver.ts +++ b/apps/desktop/src/main/services/projects/projectIconResolver.ts @@ -76,10 +76,16 @@ const IOS_ASSET_CATALOG_CANDIDATE_DIRS = [ const IOS_ASSET_ICONSET_EXTENSIONS = new Set([".appiconset", ".imageset"]); -const LINK_ICON_HTML_RE = - /]*\brel=["'](?:icon|shortcut icon)["'])(?=[^>]*\bhref=["']([^"'?]+))[^>]*>/i; -const LINK_ICON_OBJ_RE = - /(?=[^}]*\brel\s*:\s*["'](?:icon|shortcut icon)["'])(?=[^}]*\bhref\s*:\s*["']([^"'?]+))[^}]*/i; +// `rel` is an unordered, whitespace-separated token list; any `icon` token marks an icon link. +const ICON_REL_VALUE = String.raw`(?:"(?:[^"]*[\t\n\f\r ])?icon(?=[\t\n\f\r "])|'(?:[^']*[\t\n\f\r ])?icon(?=[\t\n\f\r ']))`; +const LINK_ICON_HTML_RE = new RegExp( + String.raw`]*\brel=${ICON_REL_VALUE})(?=[^>]*\bhref=["']([^"'?]+))[^>]*>`, + "i", +); +const LINK_ICON_OBJ_RE = new RegExp( + String.raw`(?=[^}]*\brel\s*:\s*${ICON_REL_VALUE})(?=[^}]*\bhref\s*:\s*["']([^"'?]+))[^}]*`, + "i", +); type ProjectIconOverride = string | null | undefined; From ea7efb28c28114bb3ea03423f819c3988b98840c Mon Sep 17 00:00:00 2001 From: Arul Sharma Date: Mon, 23 Nov 2026 11:53:18 -0500 Subject: [PATCH 2/2] fix(desktop): try every icon link so one bad href cannot mask a usable icon Review finding on PR #2474: widening the rel match made a previously ignored first icon link win extractIconHref, but only that one href was tried, so a link pointing at a missing file, a CDN URL or a data: URL masked a later usable icon that the old exact `icon`/`shortcut icon` pattern still resolved. extractIconHrefs now collects every icon href in source order (HTML links, then head-config objects), and resolveProjectIconPath tries each through the existing isLocalIconHref / findExistingFile / supported / inlineable checks. The proof test covers the fallback in both forms; it fails on the pre-fix source (null instead of the later icon) and passes with the fix. Co-Authored-By: Claude Code --- .../projects/projectIconResolver.test.ts | 25 +++++++++++++++ .../services/projects/projectIconResolver.ts | 32 +++++++++++-------- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/apps/desktop/src/main/services/projects/projectIconResolver.test.ts b/apps/desktop/src/main/services/projects/projectIconResolver.test.ts index d2c5ec433d..1b9e286187 100644 --- a/apps/desktop/src/main/services/projects/projectIconResolver.test.ts +++ b/apps/desktop/src/main/services/projects/projectIconResolver.test.ts @@ -94,6 +94,31 @@ describe("projectIconResolver", () => { writeFile(possessiveRoot, "index.html", ''); writeFile(possessiveRoot, "public/brand/logo.svg", "brand"); expect(resolveProjectIconPath(possessiveRoot)).toBeNull(); + + // A matched link whose href cannot be used (missing file, remote URL) must + // not mask a later usable icon link in the same file. + const maskedRoot = makeProjectRoot(); + writeFile( + maskedRoot, + "index.html", + [ + '', + '', + '', + ].join("\n"), + ); + const maskedIconPath = writeFile(maskedRoot, "public/brand/logo.svg", "brand"); + expect(resolveProjectIconPath(maskedRoot)).toBe(maskedIconPath); + + // The same fallback across head-config link objects. + const maskedObjectRoot = makeProjectRoot(); + writeFile( + maskedObjectRoot, + "app/routes/__root.tsx", + 'export const Route = { head: () => ({ links: [{ rel: "icon shortcut", href: "/brand/missing.png" }, { rel: "icon", href: "/brand/logo.svg" }] }) };', + ); + const maskedObjectIconPath = writeFile(maskedObjectRoot, "public/brand/logo.svg", "brand"); + expect(resolveProjectIconPath(maskedObjectRoot)).toBe(maskedObjectIconPath); }); it("detects nested app icons in monorepos", () => { diff --git a/apps/desktop/src/main/services/projects/projectIconResolver.ts b/apps/desktop/src/main/services/projects/projectIconResolver.ts index cfb8768890..e95b72db44 100644 --- a/apps/desktop/src/main/services/projects/projectIconResolver.ts +++ b/apps/desktop/src/main/services/projects/projectIconResolver.ts @@ -80,21 +80,26 @@ const IOS_ASSET_ICONSET_EXTENSIONS = new Set([".appiconset", ".imageset"]); const ICON_REL_VALUE = String.raw`(?:"(?:[^"]*[\t\n\f\r ])?icon(?=[\t\n\f\r "])|'(?:[^']*[\t\n\f\r ])?icon(?=[\t\n\f\r ']))`; const LINK_ICON_HTML_RE = new RegExp( String.raw`]*\brel=${ICON_REL_VALUE})(?=[^>]*\bhref=["']([^"'?]+))[^>]*>`, - "i", + "gi", ); const LINK_ICON_OBJ_RE = new RegExp( String.raw`(?=[^}]*\brel\s*:\s*${ICON_REL_VALUE})(?=[^}]*\bhref\s*:\s*["']([^"'?]+))[^}]*`, - "i", + "gi", ); type ProjectIconOverride = string | null | undefined; -function extractIconHref(source: string): string | null { - const htmlMatch = source.match(LINK_ICON_HTML_RE); - if (htmlMatch?.[1]) return htmlMatch[1]; - const objMatch = source.match(LINK_ICON_OBJ_RE); - if (objMatch?.[1]) return objMatch[1]; - return null; +function extractIconHrefs(source: string): string[] { + // Every icon link in order, so one unusable href (a missing file, a CDN URL, + // a `data:` URL) does not mask a later usable icon in the same file. + const hrefs: string[] = []; + for (const match of source.matchAll(LINK_ICON_HTML_RE)) { + if (match[1]) hrefs.push(match[1]); + } + for (const match of source.matchAll(LINK_ICON_OBJ_RE)) { + if (match[1]) hrefs.push(match[1]); + } + return hrefs; } function isLocalIconHref(href: string): boolean { @@ -816,11 +821,12 @@ export function resolveProjectIconPath( } catch { continue; } - const href = extractIconHref(source); - if (!href || !isLocalIconHref(href)) continue; - const existing = findExistingFile(root, resolveIconHref(root, href)); - if (existing && isSupportedIconPath(existing) && isInlineableIconFile(existing)) { - return cacheValue(existing); + for (const href of extractIconHrefs(source)) { + if (!isLocalIconHref(href)) continue; + const existing = findExistingFile(root, resolveIconHref(root, href)); + if (existing && isSupportedIconPath(existing) && isInlineableIconFile(existing)) { + return cacheValue(existing); + } } }