Skip to content

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

Merged
amadeus merged 1 commit into
pierrecomputer:mainfrom
AnatoleLucet:fix/empty-files-unchanged
Apr 29, 2026
Merged

fix(diffs): empty files marked as deleted#599
amadeus merged 1 commit into
pierrecomputer:mainfrom
AnatoleLucet:fix/empty-files-unchanged

Conversation

@AnatoleLucet

@AnatoleLucet AnatoleLucet commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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 now 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

  • 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

vercel Bot commented Apr 23, 2026

Copy link
Copy Markdown

@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.

@vercel

vercel Bot commented Apr 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierrejs-diff-demo Ready Ready Preview Apr 29, 2026 5:29pm
pierrejs-docs Ready Ready Preview Apr 29, 2026 5:29pm

Request Review

@amadeus amadeus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! I probably will want to strengthen this a bit more in the future even (by using undefined-ness to make this more explicit, but for now I think this is a good change!

@amadeus
amadeus merged commit 51088b9 into pierrecomputer:main Apr 29, 2026
10 checks passed
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.

2 participants