Skip to content

parseDiffFromFile defaults to low-specificity cache key #1052

Description

@jonatanklosko

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)}".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions