Compare commits

...
Author SHA1 Message Date
Julius Marminge 8a567ba3d5 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
2026-02-26 17:38:19 -08:00
2 changed files with 20 additions and 3 deletions

No files matched your search

+12 -3
View File
@@ -29,13 +29,19 @@ type RenderablePatch =
reason: string;
};
function getRenderablePatch(patch: string | undefined): RenderablePatch | null {
function getRenderablePatch(
patch: string | undefined,
cacheScope = "diff-panel",
): RenderablePatch | null {
if (!patch) return null;
const normalizedPatch = patch.trim();
if (normalizedPatch.length === 0) return null;
try {
const parsedPatches = parsePatchFiles(normalizedPatch, buildPatchCacheKey(normalizedPatch));
const parsedPatches = parsePatchFiles(
normalizedPatch,
buildPatchCacheKey(normalizedPatch, cacheScope),
);
const files = parsedPatches.flatMap((parsedPatch) => parsedPatch.files);
if (files.length > 0) {
return { kind: "files", files };
@@ -190,7 +196,10 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
const selectedPatch = selectedTurn ? selectedTurnCheckpointDiff : conversationCheckpointDiff;
const hasResolvedPatch = typeof selectedPatch === "string";
const hasNoNetChanges = hasResolvedPatch && selectedPatch.trim().length === 0;
const renderablePatch = useMemo(() => getRenderablePatch(selectedPatch), [selectedPatch]);
const renderablePatch = useMemo(
() => getRenderablePatch(selectedPatch, `diff-panel:${resolvedTheme}`),
[resolvedTheme, selectedPatch],
);
const renderableFiles = useMemo(() => {
if (!renderablePatch || renderablePatch.kind !== "files") {
return [];
+8
View File
@@ -20,4 +20,12 @@ describe("buildPatchCacheKey", () => {
expect(buildPatchCacheKey(before)).not.toBe(buildPatchCacheKey(after));
});
it("changes when cache scope changes", () => {
const patch = "diff --git a/a.ts b/a.ts\n+console.log('hello')";
expect(buildPatchCacheKey(patch, "diff-panel:light")).not.toBe(
buildPatchCacheKey(patch, "diff-panel:dark"),
);
});
});