Skip to content

Commit 8a567ba

Browse files
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
1 parent 5748a99 commit 8a567ba

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎apps/web/src/components/DiffPanel.tsx‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ type RenderablePatch =
2929
reason: string;
3030
};
3131

32-
function getRenderablePatch(patch: string | undefined): RenderablePatch | null {
32+
function 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‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
});

0 commit comments

Comments
 (0)