Repository navigation
fix(desktop): read icon links from an HTML rel token list - #2474
Conversation
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 <link rel="icon shortcut">, 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="Icon<TAB>shortcut" 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 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 25 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
| // `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", '<link rel="icon shortcut" href="/brand/logo.svg">'); | ||
| const tokenListIconPath = writeFile(tokenListRoot, "public/brand/logo.svg", "<svg>brand</svg>"); | ||
| 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", "<svg>brand</svg>"); | ||
| expect(resolveProjectIconPath(objectRoot)).toBe(objectIconPath); |
There was a problem hiding this comment.
Token-list cases lack coverage
Both new success cases put lowercase icon first and use a space. They do not exercise the preceding-token branch in ICON_REL_VALUE, tabs, mixed case, or single-quoted values. Those paths could break while these tests still pass.
Add table-driven cases such as rel="shortcut Icon", rel="Icon\tshortcut", and single-quoted values, including the object form, so the committed tests cover the behavior described by this fix.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/main/services/projects/projectIconResolver.test.ts
Line: 75-90
Comment:
**Token-list cases lack coverage**
Both new success cases put lowercase `icon` first and use a space. They do not exercise the preceding-token branch in `ICON_REL_VALUE`, tabs, mixed case, or single-quoted values. Those paths could break while these tests still pass.
Add table-driven cases such as `rel="shortcut Icon"`, `rel="Icon\tshortcut"`, and single-quoted values, including the object form, so the committed tests cover the behavior described by this fix.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Devin Review found 1 potential issue.
3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| 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`<link\b(?=[^>]*\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", |
There was a problem hiding this comment.
🟡 Unusable icon link hides local fallback
LINK_ICON_HTML_RE and LINK_ICON_OBJ_RE now pick an earlier multi-token icon link even when its target is unusable. resolveProjectIconPath skips the rest of the file after rejecting that target. The later local icon no longer appears.
Learn more
ADE checks well-known icon paths first, then scans selected project source files for icon declarations. extractIconHref returns just one href per file. An earlier multi-token declaration that the old matcher passed over now becomes that one href. resolveProjectIconPath rejects non-local or unusable targets but does not try another declaration in the same file.
Example: A project with no well-known icon declares rel="icon shortcut" with an HTTPS CDN URL before rel="icon" with /brand/product.svg. The previous matcher returned the local SVG. The new matcher returns the CDN URL, which ADE rejects, and the tab falls back to its default icon if no other source provides one.
Recommended fix: Yield candidate hrefs from both supported source forms. In resolveProjectIconPath, continue to the next href after a locality, containment, extension, or size rejection; keep the first usable path and retain the current priority of well-known icons and source files.
Was this helpful? React with 👍 or 👎 to provide feedback.
…e 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 <noreply@anthropic.com>
| for (const match of source.matchAll(LINK_ICON_OBJ_RE)) { | ||
| if (match[1]) hrefs.push(match[1]); | ||
| } |
There was a problem hiding this comment.
extractIconHrefs now runs LINK_ICON_OBJ_RE over the whole file before the caller can use a valid HTML link. When the file has no } or object-style rel: field, the regex scans the remaining text again at each position.
An 80 KB HTML input with a valid first icon link took about 2.24 seconds, versus under 1 ms for the previous extraction path. This runs synchronously in Electron's main process, so opening such a project stalls other app requests. Yield hrefs lazily so the caller can stop after a usable HTML link, or limit the object search to individual objects.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/main/services/projects/projectIconResolver.ts
Line: 99-101
Comment:
**Icon lookup freezes ADE**
`extractIconHrefs` now runs `LINK_ICON_OBJ_RE` over the whole file before the caller can use a valid HTML link. When the file has no `}` or object-style `rel:` field, the regex scans the remaining text again at each position.
An 80 KB HTML input with a valid first icon link took about 2.24 seconds, versus under 1 ms for the previous extraction path. This runs synchronously in Electron's main process, so opening such a project stalls other app requests. Yield hrefs lazily so the caller can stop after a usable HTML link, or limit the object search to individual objects.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Why
HTML's
relis an unordered, whitespace-separated token list, but ADE matched only the exact stringsiconandshortcut icon. A project declaring<link rel="icon shortcut" href="/brand/logo.svg">,rel="Icon<TAB>shortcut", or the__root.tsxobject formrel: "icon shortcut"got no icon when the file lived outside the direct candidate scan. The old regex also wrongly matchedrel="icon's".Same defect class as pingdotgg/t3code#41203, proven with an out-of-tree driver against ADE's real module.
What changed
icontoken in the quotedrelvalue marks an icon link, in both the HTML-tag and object-literal forms.apple-touch-icon,mask-iconandfluid-iconstill do not match, andrel="icon's"no longer does.Evidence
rel="icon shortcut",rel="Icon<TAB>shortcut", objectrel: "icon shortcut"return null, andrel="icon's"wrongly resolves. Against the patched module: 9/9 pass.projectIconResolver.test.ts: 25 pass; 2 fail identically on unmodified HEAD in this Windows environment (file-mode assertion, symlink EPERM), not caused by this change.Not checked
Not opened in a running app with a project whose only icon is a token-list declaration; the driver exercises the same resolver entry point. Full CI matrix not run locally.
🤖 Generated with Claude Code
Fix the eager object search before merging because icon lookup can stall ADE for seconds.
Fix with agent prompt
Summary
The PR reads
relas a token list and tries later icon links when earlier ones cannot be used.Reviews (2) · Last reviewed commit: "fix(desktop): try every icon link so one..." · Reviewed by Greptile