Skip to content

Open source CapCut alternative.

TypeScript

fix(site): drop white corners from search chips

David Leb67124f6efbd
diff --git a/site/src/cut/components/SearchSuggestions.tsx b/site/src/cut/components/SearchSuggestions.tsx
index 5407aaee..a5a0d1df 100644
--- a/site/src/cut/components/SearchSuggestions.tsx
+++ b/site/src/cut/components/SearchSuggestions.tsx
@@ -6,10 +6,13 @@ import { toolDisplayOf } from "@/cut/lib/toolDisplay";
// Google's Search Suggestions beside a grounded result, shown as Google sends
// them: HTML and CSS with links to the searches. The markup renders in a
// sandboxed frame that runs no script, sized to its content, and every link
-// opens a new tab.
+// opens a new tab. The frame takes the page's theme: a frame document that
+// declares no color scheme gets an opaque canvas when the page is dark, which
+// shows white around the chips' rounded corners.
const FRAME_HEAD =
'<meta charset="utf-8">' +
+ '<meta name="color-scheme" content="light dark">' +
"<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'none'; style-src 'unsafe-inline'; img-src https: data:; font-src https: data:\">" +
'<base target="_blank">' +
"<style>html,body{margin:0;padding:0;background:transparent;overflow:hidden}</style>";
diff --git a/site/src/cut/components/searchSuggestions.test.tsx b/site/src/cut/components/searchSuggestions.test.tsx
new file mode 100644
index 00000000..b53718e5
--- /dev/null
+++ b/site/src/cut/components/searchSuggestions.test.tsx
@@ -0,0 +1,12 @@
+import { expect, test } from "bun:test";
+import { renderToStaticMarkup } from "react-dom/server";
+import { SearchSuggestions } from "./SearchSuggestions";
+
+// A frame whose document takes neither theme gets an opaque canvas from the
+// browser whenever the page is dark, which shows white around the chips.
+test("the suggestion frame takes the page's light or dark theme", () => {
+ const output = { display: { searchSuggestions: ['<div class="container">chips</div>'] } };
+ const html = renderToStaticMarkup(<SearchSuggestions output={output} />);
+ const doc = /srcDoc="([^"]*)"/i.exec(html)?.[1].replaceAll("&quot;", '"').replaceAll("&lt;", "<").replaceAll("&gt;", ">") ?? "";
+ expect(doc).toContain('<meta name="color-scheme" content="light dark">');
+});