The docs currently say:
If both oldFile and newFile have a cacheKey, the resulting FileDiffMetadata will automatically receive a combined cache key (format: oldKey:newKey).
It would be fair to assume that if cacheKey is not set, it will not be cached. However, the current implementation defaults each file cache key to file name:
|
const fileData = processFile(patch, { |
|
cacheKey: (() => { |
|
const oldCacheKey = oldFile?.cacheKey ?? oldFile?.name; |
|
const newCacheKey = newFile?.cacheKey ?? newFile?.name; |
|
if (oldCacheKey != null && newCacheKey != null) { |
|
return oldCacheKey + ':' + newCacheKey; |
|
} |
|
return oldCacheKey ?? newCacheKey; |
|
})(), |
Consequently, when using parseDiffFromFile for two subsequent changes of the same file, the renderer uses wrong cached information and throws:
DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong
Given the above, I think either the docs should be clarified, or there should be no cacheKey generated unless explicitly specified (safer default).
An immediate fix on the user side is to specify a more specific cacheKey on each file, such as "{file_name}:{hash(file_content)}".
The docs currently say:
It would be fair to assume that if
cacheKeyis not set, it will not be cached. However, the current implementation defaults each file cache key to file name:pierre/packages/diffs/src/utils/parseDiffFromFile.ts
Lines 38 to 46 in 39ef68a
Consequently, when using
parseDiffFromFilefor two subsequent changes of the same file, the renderer uses wrong cached information and throws:Given the above, I think either the docs should be clarified, or there should be no
cacheKeygenerated unless explicitly specified (safer default).An immediate fix on the user side is to specify a more specific
cacheKeyon each file, such as"{file_name}:{hash(file_content)}".