fix(render): handle nil changes when cycling tabs#309
Closed
iamavolk wants to merge 1 commit intoesmuellert:mainfrom
Closed
fix(render): handle nil changes when cycling tabs#309iamavolk wants to merge 1 commit intoesmuellert:mainfrom
iamavolk wants to merge 1 commit intoesmuellert:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Setup:
gt(gT) to cycle around and get back to the same tab.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.changestable, and also renders momentarily.