Skip to content

Fix infinite loop on plain-text diffs#526

Merged
amadeus merged 1 commit intopierrecomputer:mainfrom
dimfeld:fix-text-infinite-loop
Apr 19, 2026
Merged

Fix infinite loop on plain-text diffs#526
amadeus merged 1 commit intopierrecomputer:mainfrom
dimfeld:fix-text-infinite-loop

Conversation

@dimfeld
Copy link
Copy Markdown
Contributor

@dimfeld dimfeld commented Apr 18, 2026

Description

Rendering a diff with language "text" or "ansi" would cause an infinite loop, because those languages are skipped in getSharedHighlighter and so never become attached.

This change updates areLanguagesAttached to always return true for those languages, to match the corresponding special treatment of those languages in other places.

Motivation & Context

Infinite loop when rendering "text" diffs. I specifically saw this on a .gitignore diff in my project using the Vanilla JS API. This diff had no attached language but the autodetection chose "text" as the language.

Excerpt of the stack trace:

  rerender (FileDiff.js:287)
  (anonymous) (FileDiff.js:76)
  onHighlightSuccess (DiffHunksRenderer.js:275)
  (anonymous) (DiffHunksRenderer.js:224)
  Promise.then
  renderDiff (DiffHunksRenderer.js:222)
  render (FileDiff.js:353)
  rerender (FileDiff.js:287)
  (anonymous) (FileDiff.js:76)
  onHighlightSuccess (DiffHunksRenderer.js:275)
  (anonymous) (DiffHunksRenderer.js:224)
  Promise.then
  renderDiff (DiffHunksRenderer.js:222)
  render (FileDiff.js:353)
  rerender (FileDiff.js:287)

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality). You must have
    first discussed with the dev team and they should be aware that this PR is
    being opened
  • Breaking change (fix or feature that would change existing functionality).
    You must have first discussed with the dev team and they should be aware
    that this PR is being opened
  • Documentation update

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)
  • [N/A] 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) -- Used cd packages/diffs && bun run test since diffs:test command doesn't seem to exist.

How was AI used in generating this PR

Fed the above stack trace into Codex, which diagnosed the error and generated the fix and tests.

I manually reviewed all changes and verified that it fixes the problem in my application.

Related issues

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 18, 2026

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

A member of the Team first needs to authorize it.

@dimfeld dimfeld changed the title Fix plain-text language attachment detection in diffs Fix infinite loop on plain-text diffs Apr 18, 2026
@wladimiiir
Copy link
Copy Markdown

wladimiiir commented Apr 19, 2026

I am experiencing the same issue: #534 that is being fixed by this PR.

Alternative fix might be by adding the 'text' and 'ansi' to the list of AttachedLanguages inside packages/diffs/src/highlighter/shared_highlighter.ts.

  // 'text' and 'ansi' are loaded during highlighter creation but skipped in
  // the language loop below. Track them as attached so areLanguagesAttached()
  // returns the correct value.
  AttachedLanguages.add('text');
  AttachedLanguages.add('ansi');

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 19, 2026

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

Project Deployment Actions Updated (UTC)
pierrejs-diff-demo Ready Ready Preview Apr 19, 2026 6:23pm
pierrejs-docs Ready Ready Preview Apr 19, 2026 6:23pm

Request Review

@amadeus
Copy link
Copy Markdown
Member

amadeus commented Apr 19, 2026

Great catch, and thanks for the fix, will merge when everything passes! 🙏

Also sorry, totally missed this PR the other day when you opened it.

@amadeus amadeus merged commit d18bca6 into pierrecomputer:main Apr 19, 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.

3 participants