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
This commit is contained in:
1 parent
5748a995f7
commit
8a567ba3d5
2 files changed
+20
-3
No files matched your search
@@ -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 [];
|
||||
|
||||
@@ -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"),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user