@devries-cameron20 / t3code-1 / commits / 860fa7c7b6
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(shared): keep HTML bootstrap outside quoted attributes (#34344)

Lakshmi Tanmay committed Nov 12, 2026 at 04:56 UTC 860fa7c7b637bab209c38a14189cf42d0bb5f193
2 files changed +18 -2
packages/shared/src/htmlRender.test.ts
+16
@@ -21,6 +21,22 @@ describe("injectHtmlRenderBootstrap", () => {
21 expect(injected).toContain('name="viewport"');
22 });
23
24 + it.each([
25 + "<html><head data-condition='x > 0'>",
26 + '<html><head data-condition="x > 0" data-label=\'it "works"\'>',
27 + "<html data-condition='x > 0'>",
28 + '<html data-condition="x > 0" data-label="it \'works\'">',
29 + ])("keeps the bootstrap after the complete opening tag: %s", (opening) => {
30 + const prefix = `<!doctype html>${opening}`;
31 + const head = opening.startsWith("<html><head") ? "" : "<head>";
32 + const content = `${head ? "" : "<title>Report</title></head>"}<body><p>Report</p></body></html>`;
33 + const injected = injectHtmlRenderBootstrap(prefix + content);
34 + expect(injected.startsWith(`${prefix}${head}<meta charset="utf-8">`)).toBe(true);
35 + expect(injected.indexOf('<style id="t3-theme">')).toBeGreaterThan(prefix.length);
36 + expect(injected).toContain("<script>");
37 + expect(injected.endsWith(content)).toBe(true);
38 + });
39 +
40 it("wraps fragments without a head and keeps existing meta tags", () => {
41 const fragment =
42 '<meta charset="utf-8"><meta name="viewport" content="width=device-width"><p>hi</p>';
packages/shared/src/htmlRender.ts
+2 -2
@@ -419,12 +419,12 @@ const blankNonMarkup = (html: string) => {
419 export function injectHtmlRenderBootstrap(html: string): string {
420 const scan = blankNonMarkup(html);
421 const markup = bootstrapMarkup(scan);
422 - const headOpen = /<head(?:\s[^>]*)?>/i.exec(scan);
422 + const headOpen = /<head(?:\s(?:[^"'>]|"[^"]*"|'[^']*')*)?>/i.exec(scan);
423 if (headOpen) {
424 const at = headOpen.index + headOpen[0].length;
425 return html.slice(0, at) + markup + html.slice(at);
426 }
427 - const htmlOpen = /<html(?:\s[^>]*)?>/i.exec(scan);
427 + const htmlOpen = /<html(?:\s(?:[^"'>]|"[^"]*"|'[^']*')*)?>/i.exec(scan);
428 if (htmlOpen) {
429 const at = htmlOpen.index + htmlOpen[0].length;
430 return `${html.slice(0, at)}<head>${markup}</head>${html.slice(at)}`;