The best way to control Claude Code, Codex and more from any computer or phone
Handle favicon links when href precedes rel
- Update favicon regex parsing to support rel/href in either order - Add route tests for HTML link tags and object-style metadata with href-first ordering
Julius Marminge committed
Feb 27, 2026 at 15:11 UTC
e6c5a4a4bb962c8276887c26e889fe97a8668f44
2 files changed
+42
-3
apps/server/src/projectFaviconRoute.test.ts
+37
@@ -115,4 +115,41 @@ describe("tryHandleProjectFaviconRequest", () => {
115
expect(response.body).toBe("<svg>brand</svg>");
116
});
117
});
118
+
119
+ it("resolves icon link when href appears before rel in HTML", async () => {
120
+ const projectDir = makeTempDir("t3code-favicon-route-html-order-");
121
+ const iconPath = path.join(projectDir, "public", "brand", "logo.svg");
122
+ fs.mkdirSync(path.dirname(iconPath), { recursive: true });
123
+ fs.writeFileSync(path.join(projectDir, "index.html"), '<link href="/brand/logo.svg" rel="icon">');
124
+ fs.writeFileSync(iconPath, "<svg>brand-html-order</svg>", "utf8");
125
+
126
+ await withRouteServer(async (baseUrl) => {
127
+ const pathname = `/api/project-favicon?cwd=${encodeURIComponent(projectDir)}`;
128
+ const response = await request(baseUrl, pathname);
129
+ expect(response.statusCode).toBe(200);
130
+ expect(response.contentType).toContain("image/svg+xml");
131
+ expect(response.body).toBe("<svg>brand-html-order</svg>");
132
+ });
133
+ });
134
+
135
+ it("resolves object-style icon metadata when href appears before rel", async () => {
136
+ const projectDir = makeTempDir("t3code-favicon-route-obj-order-");
137
+ const iconPath = path.join(projectDir, "public", "brand", "obj.svg");
138
+ fs.mkdirSync(path.dirname(iconPath), { recursive: true });
139
+ fs.mkdirSync(path.join(projectDir, "src"), { recursive: true });
140
+ fs.writeFileSync(
141
+ path.join(projectDir, "src", "root.tsx"),
142
+ 'const links = [{ href: "/brand/obj.svg", rel: "icon" }];',
143
+ "utf8",
144
+ );
145
+ fs.writeFileSync(iconPath, "<svg>brand-obj-order</svg>", "utf8");
146
+
147
+ await withRouteServer(async (baseUrl) => {
148
+ const pathname = `/api/project-favicon?cwd=${encodeURIComponent(projectDir)}`;
149
+ const response = await request(baseUrl, pathname);
150
+ expect(response.statusCode).toBe(200);
151
+ expect(response.contentType).toContain("image/svg+xml");
152
+ expect(response.body).toBe("<svg>brand-obj-order</svg>");
153
+ });
154
+ });
155
});
apps/server/src/projectFaviconRoute.ts
+5
-3
@@ -44,9 +44,11 @@ const ICON_SOURCE_FILES = [
44
"src/index.html",
45
];
46
47
-// Matches <link rel="icon" href="..."> or { rel: "icon", href: "..." } patterns.
48
-const LINK_ICON_HTML_RE = /<link[^>]*rel=["'](?:icon|shortcut icon)["'][^>]*href=["']([^"'?]+)/i;
49
-const LINK_ICON_OBJ_RE = /rel:\s*["'](?:icon|shortcut icon)["'][^}]*href:\s*["']([^"'?]+)/i;
47
+// Matches <link ...> tags or object-like icon metadata where rel/href can appear in any order.
48
+const LINK_ICON_HTML_RE =
49
+ /<link\b(?=[^>]*\brel=["'](?:icon|shortcut icon)["'])(?=[^>]*\bhref=["']([^"'?]+))[^>]*>/i;
50
+const LINK_ICON_OBJ_RE =
51
+ /(?=[^}]*\brel\s*:\s*["'](?:icon|shortcut icon)["'])(?=[^}]*\bhref\s*:\s*["']([^"'?]+))[^}]*/i;
52
53
function extractIconHref(source: string): string | null {
54
const htmlMatch = source.match(LINK_ICON_HTML_RE);