Skip to content

fix(render): handle nil changes when cycling tabs#309

Closed
iamavolk wants to merge 1 commit intoesmuellert:mainfrom
iamavolk:fix_untracked_render
Closed

fix(render): handle nil changes when cycling tabs#309
iamavolk wants to merge 1 commit intoesmuellert:mainfrom
iamavolk:fix_untracked_render

Conversation

@iamavolk
Copy link

@iamavolk iamavolk commented Mar 5, 2026

Setup:

  1. One or more untracked files in the repo.
  2. A few tabs are open besides the CodeDiff exporer with the selected untracked file in diff.
  3. Start moving through tabs with gt (gT) to cycle around and get back to the same tab.
  4. Observe an error: nil value passed down.

What's changed:

This fix adds a defensive nil check before invoking the iterator.

Potential implications:

Maybe not the right place to handle the error since on the first cycling through tabs the untracked file has all of its entirety in the lines_diff.changes table, and also renders momentarily.

when cycling through tabs more than once,
the changes appear to be nil starting
with the second cycle. As such, nil is
passed down to the iterator factory.

Add a defensive nil check beforehand
esmuellert added a commit that referenced this pull request Mar 7, 2026
show_untracked_file() and similar single-pane functions stored {} as
stored_diff_result, missing the required .changes and .moves fields.
When resume_diff() reused this value after tab cycling, render_diff()
crashed on ipairs(nil) because {}.changes is nil.

Replace {} with {changes={}, moves={}} in side_by_side.lua and
inline_view.lua to conform to the diff result schema. Add E2E test
that reproduces the exact PR #309 scenario.

Closes #309

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
esmuellert added a commit that referenced this pull request Mar 7, 2026
## Summary

Fixes the crash reported in #309 — cycling tabs with an untracked file
open in CodeDiff causes `render_diff()` to crash on `ipairs(nil)`.

## Root Cause

`show_untracked_file()` (and similar single-pane functions) stored `{}`
as `stored_diff_result`, missing the required `.changes` and `.moves`
fields. When `resume_diff()` reused this value after tab cycling (no
changedtick change → no recompute), `render_diff()` crashed because
`{}.changes` is `nil`.

## Changes

- **`side_by_side.lua`**: Replace `{}` with `{changes={}, moves={}}` in
`show_single_file()`
- **`inline_view.lua`**: Same fix in both inline single-file paths
- **`layout_spec.lua`**: Update 2 tests that asserted the old buggy
`nil` behavior
- **`tab_cycle_untracked.lua`** (new): E2E test reproducing the exact PR
#309 scenario — verified to fail without fix, pass with fix

## Testing

- All plenary tests pass (500+)
- E2E test confirms fix: `stored_diff_result.changes` is `{}` (not
`nil`) immediately after `show_untracked_file()`
- Full tab-cycle path (`suspend_diff` → `resume_diff` → `render_diff`)
exercised end-to-end

Closes #309
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