@devries-cameron20 / t3code Mirror · read-only / commits / 8176b58931
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 18:15 UTC

fix(html): honor preview light and dark mode (#24521)

Bilal Bakr committed Oct 24, 2026 at 23:06 UTC 8176b589310fac6f59f1878ede4f7287c6c36d8f
3 files changed +37 -3
apps/server/src/htmlRender/HtmlRender.test.ts
+25
@@ -316,6 +316,31 @@ describe("HtmlRender", () => {
316 },
317 );
318
319 + it.live("matches preview media queries and text colors to the requested appearance", (ctx) =>
320 + Effect.gen(function* () {
321 + const executable = (yield* HostProcess.Environment)[TEST_BROWSER_ENV];
322 + if (!executable) return ctx.skip(`Set ${TEST_BROWSER_ENV} to run this test.`);
323 + yield* Effect.gen(function* () {
324 + const htmlRender = yield* HtmlRender.HtmlRender;
325 + for (const appearance of [undefined, "dark", "light"] as const) {
326 + const preview = yield* htmlRender.preview({
327 + appearance,
328 + html: [
329 + "<style>h1{color:#18181b}@media(prefers-color-scheme:dark){h1{color:#fafafa}}</style>",
330 + "<h1>The moon garden opens at dusk</h1>",
331 + '<script>console.log(matchMedia("(prefers-color-scheme:dark)").matches,',
332 + 'getComputedStyle(document.querySelector("h1")).color);</script>',
333 + ].join(""),
334 + });
335 + expect(preview.consoleMessages).toContainEqual({
336 + level: "log",
337 + text: appearance === "light" ? "false rgb(24, 24, 27)" : "true rgb(250, 250, 250)",
338 + });
339 + }
340 + }).pipe(Effect.provide(layerHtmlRender(executable)));
341 + }),
342 + );
343 +
344 it.live("keeps every local file but the page itself out of the browser", (ctx) =>
345 Effect.gen(function* () {
346 const executable = (yield* HostProcess.Environment)[TEST_BROWSER_ENV];
apps/server/src/htmlRender/HtmlRender.ts
+1
@@ -492,6 +492,7 @@ const make = Effect.gen(function* () {
492 html: inlined.html,
493 width,
494 urlFragment: htmlRenderThemeFragment(theme),
495 + appearance,
496 }).pipe(Effect.provideContext(services)),
497 );
498 return {
apps/server/src/htmlRender/headlessChrome.ts
+11 -3
@@ -1,3 +1,4 @@
1 +import type { ThemeAppearance } from "@t3tools/shared/themePalettes";
2 import * as Deferred from "effect/Deferred";
3 import * as Effect from "effect/Effect";
4 import * as Fiber from "effect/Fiber";
@@ -413,7 +414,7 @@ const launchBrowser = Effect.fnUntraced(function* (input: {
414 );
415 });
416
416 - const openPage = Effect.fnUntraced(function* (width: number) {
417 + const openPage = Effect.fnUntraced(function* (width: number, appearance: ThemeAppearance) {
418 const { targetId } = yield* send(
419 "Target.createTarget",
420 { url: "about:blank" },
@@ -436,6 +437,12 @@ const launchBrowser = Effect.fnUntraced(function* (input: {
437 yield* send("Page.enable", {}, Ignored, sessionId);
438 yield* send("Runtime.enable", {}, Ignored, sessionId);
439 yield* send("Log.enable", {}, Ignored, sessionId);
440 + yield* send(
441 + "Emulation.setEmulatedMedia",
442 + { features: [{ name: "prefers-color-scheme", value: appearance }] },
443 + Ignored,
444 + sessionId,
445 + );
446 // Previews have no use for WebRTC, whose ICE servers can make the browser
447 // resolve names outside the proxy. Runs before page scripts in every frame.
448 yield* send(
@@ -550,6 +557,7 @@ export const captureHtmlScreenshot = Effect.fn("headlessChrome.captureHtmlScreen
557 readonly html: string;
558 readonly width: number;
559 readonly urlFragment: string;
560 + readonly appearance: ThemeAppearance;
561 }) {
562 const path = yield* Path.Path;
563 const directory = yield* scratchDirectory;
@@ -558,7 +566,7 @@ export const captureHtmlScreenshot = Effect.fn("headlessChrome.captureHtmlScreen
566 noSandbox: input.noSandbox,
567 profileDirectory: path.join(directory, "profile"),
568 });
561 - const page = yield* browser.openPage(input.width);
569 + const page = yield* browser.openPage(input.width, input.appearance);
570 const contentHeight = yield* page.load(pageBody(input.html), input.urlFragment);
571 const capturedHeight = Math.max(1, Math.min(contentHeight, MAX_CAPTURE_HEIGHT));
572 const png = yield* page.screenshot(capturedHeight);
@@ -598,7 +606,7 @@ export const measureHtmlHeights = Effect.fn("headlessChrome.measureHtmlHeights")
606 return yield* Effect.forEach(
607 input.widths,
608 (width) =>
601 - browser.openPage(width).pipe(
609 + browser.openPage(width, "dark").pipe(
610 Effect.flatMap((page) =>
611 page.load(body, input.urlFragment).pipe(Effect.ensuring(page.close)),
612 ),