Skip to content

fix(diffs): empty files marked as deleted#599

Open
AnatoleLucet wants to merge 1 commit intopierrecomputer:mainfrom
AnatoleLucet:fix/empty-files-unchanged
Open

fix(diffs): empty files marked as deleted#599
AnatoleLucet wants to merge 1 commit intopierrecomputer:mainfrom
AnatoleLucet:fix/empty-files-unchanged

Conversation

@AnatoleLucet
Copy link
Copy Markdown

Description

Hello 👋

I noticed a minor inconsistency while using newFile/oldFile between 1) rendering a diff of a file with content that didn't change, and 2) rendering a diff of an empty file that didn't change.

Motivation & Context

Current behavior:

File with content and no change
const fileDiffInstance = new FileDiff({ theme: "pierre-dark" });

fileDiffInstance.render({
  oldFile: { name: "my-file", contents: "abc" },
  newFile: { name: "my-file", contents: "abc" }, // content didn't change
  containerWrapper: document.body,
});

image

Empty file with no change
const fileDiffInstance = new FileDiff({ theme: "pierre-dark" });

fileDiffInstance.render({
  oldFile: { name: "my-file", contents: "" },
  newFile: { name: "my-file", contents: "" }, // stays empty
  containerWrapper: document.body,
});
image

We should expect both diff to be of type change, but the second one is rendered as deleted (even though the file has not been deleted, it's just empty).

New behavior:

File with content and no change
// same code as before and same result
const fileDiffInstance = new FileDiff({ theme: "pierre-dark" });

fileDiffInstance.render({
  oldFile: { name: "my-file", contents: "abc" },
  newFile: { name: "my-file", contents: "abc" },
  containerWrapper: document.body,
});

image

Empty file with no change
// same code as before, but not the rendered diff is "change", not "deleted"
const fileDiffInstance = new FileDiff({ theme: "pierre-dark" });

fileDiffInstance.render({
  oldFile: { name: "my-file", contents: "" },
  newFile: { name: "my-file", contents: "" },
  containerWrapper: document.body,
});
image

Now the empty file is correctly rendered as change and not deleted.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • [X ] I have read the
    contributing guidelines
  • My code follows the code style of the project (bun run lint)
  • My code is formatted properly (bun run format)
  • I have updated the documentation accordingly (if applicable)
  • I have added tests to cover my changes (if applicable)
  • All new and existing tests pass (bun run diffs:test)

How was AI used in generating this PR

No AI used at all. I just crawled trough the codebase like a caveman.

Related issues

#399-ish

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 23, 2026

@AnatoleLucet is attempting to deploy a commit to the Pierre Computer Company Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant