authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-02-26 17:38:19-08:00
committergravatar for jmarminge@gmail.comJulius Marminge <jmarminge@gmail.com> 2026-02-26 18:09:36-08:00
log5ec8c9f79d4a0676ad9107b6c328c2a388b2d825
tree97ddcb728242c4a1925b6dac2353e96e96b9e22f
parent08866367606b4a78c082c492d16bd6b86a26aee9

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

2 files changed, 20 insertions(+), 3 deletions(-)

apps/web/src/components/DiffPanel.tsx+12-3
......@@ -29,13 +29,19 @@ type RenderablePatch =
2929 reason: string;
3030 };
3131
32function getRenderablePatch(patch: string | undefined): RenderablePatch | null {
32function getRenderablePatch(
33 patch: string | undefined,
34 cacheScope = "diff-panel",
35): RenderablePatch | null {
3336 if (!patch) return null;
3437 const normalizedPatch = patch.trim();
3538 if (normalizedPatch.length === 0) return null;
3639
3740 try {
38 const parsedPatches = parsePatchFiles(normalizedPatch, buildPatchCacheKey(normalizedPatch));
41 const parsedPatches = parsePatchFiles(
42 normalizedPatch,
43 buildPatchCacheKey(normalizedPatch, cacheScope),
44 );
3945 const files = parsedPatches.flatMap((parsedPatch) => parsedPatch.files);
4046 if (files.length > 0) {
4147 return { kind: "files", files };
......@@ -190,7 +196,10 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
190196 const selectedPatch = selectedTurn ? selectedTurnCheckpointDiff : conversationCheckpointDiff;
191197 const hasResolvedPatch = typeof selectedPatch === "string";
192198 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 );
194203 const renderableFiles = useMemo(() => {
195204 if (!renderablePatch || renderablePatch.kind !== "files") {
196205 return [];
apps/web/src/lib/diffRendering.test.ts+8
......@@ -20,4 +20,12 @@ describe("buildPatchCacheKey", () => {
2020
2121 expect(buildPatchCacheKey(before)).not.toBe(buildPatchCacheKey(after));
2222 });
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 });
2331});