@devries-cameron20 / t3code Mirror · read-only / commits / 5ec8c9f79d
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 25, 17:15 UTC

Scope diff patch cache key by theme

- pass a cache scope into `getRenderablePatch` and include resolved theme in DiffPanel cache keys - add a test proving `buildPatchCacheKey` changes when cache scope changes

Julius Marminge committed Feb 26, 2026 at 17:38 UTC 5ec8c9f79d4a0676ad9107b6c328c2a388b2d825
2 files changed +20 -3
apps/web/src/components/DiffPanel.tsx
+12 -3
@@ -29,13 +29,19 @@ type RenderablePatch =
29 reason: string;
30 };
31
32 -function getRenderablePatch(patch: string | undefined): RenderablePatch | null {
32 +function getRenderablePatch(
33 + patch: string | undefined,
34 + cacheScope = "diff-panel",
35 +): RenderablePatch | null {
36 if (!patch) return null;
37 const normalizedPatch = patch.trim();
38 if (normalizedPatch.length === 0) return null;
39
40 try {
38 - const parsedPatches = parsePatchFiles(normalizedPatch, buildPatchCacheKey(normalizedPatch));
41 + const parsedPatches = parsePatchFiles(
42 + normalizedPatch,
43 + buildPatchCacheKey(normalizedPatch, cacheScope),
44 + );
45 const files = parsedPatches.flatMap((parsedPatch) => parsedPatch.files);
46 if (files.length > 0) {
47 return { kind: "files", files };
@@ -190,7 +196,10 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
196 const selectedPatch = selectedTurn ? selectedTurnCheckpointDiff : conversationCheckpointDiff;
197 const hasResolvedPatch = typeof selectedPatch === "string";
198 const hasNoNetChanges = hasResolvedPatch && selectedPatch.trim().length === 0;
193 - const renderablePatch = useMemo(() => getRenderablePatch(selectedPatch), [selectedPatch]);
199 + const renderablePatch = useMemo(
200 + () => getRenderablePatch(selectedPatch, `diff-panel:${resolvedTheme}`),
201 + [resolvedTheme, selectedPatch],
202 + );
203 const renderableFiles = useMemo(() => {
204 if (!renderablePatch || renderablePatch.kind !== "files") {
205 return [];
apps/web/src/lib/diffRendering.test.ts
+8
@@ -20,4 +20,12 @@ describe("buildPatchCacheKey", () => {
20
21 expect(buildPatchCacheKey(before)).not.toBe(buildPatchCacheKey(after));
22 });
23 +
24 + it("changes when cache scope changes", () => {
25 + const patch = "diff --git a/a.ts b/a.ts\n+console.log('hello')";
26 +
27 + expect(buildPatchCacheKey(patch, "diff-panel:light")).not.toBe(
28 + buildPatchCacheKey(patch, "diff-panel:dark"),
29 + );
30 + });
31 });