Skip to content

fix(core): reset _previousLines on Screen.resize() to prevent stale diff renderer state after terminal resize#690

Merged
Karanjot786 merged 2 commits into
Karanjot786:mainfrom
ionfwsrijan:fix-681-screen-reset-previousLines
Jun 5, 2026
Merged

fix(core): reset _previousLines on Screen.resize() to prevent stale diff renderer state after terminal resize#690
Karanjot786 merged 2 commits into
Karanjot786:mainfrom
ionfwsrijan:fix-681-screen-reset-previousLines

Conversation

@ionfwsrijan
Copy link
Copy Markdown
Contributor

@ionfwsrijan ionfwsrijan commented Jun 4, 2026

Description

When the terminal is resized, Screen.resize() creates fresh front/back grids but leaves _previousLines (the diff renderer's line cache) untouched. After a resize making the terminal smaller, stale content from the pre-resize grid remains in _previousLines, causing the diff renderer to skip rows whose current content happens to match the stale cached strings.

Root Cause

The resize() method recreated the front/back buffers but did not clear _previousLines.

Fix

Added this._previousLines = []; at the end of resize() to force a full re-render after terminal resize.

Changes

  • packages/core/src/terminal/Screen.ts:306 — reset _previousLines on resize

Closes #681

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an issue where terminal display content would not refresh correctly following a screen resize operation.

@ionfwsrijan ionfwsrijan requested a review from Karanjot786 as a code owner June 4, 2026 09:32
@github-actions github-actions Bot added type:bug +10 pts. Bug fix. area:core @termuijs/core and removed type:bug +10 pts. Bug fix. labels Jun 4, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4d2d3ec2-a42a-4668-9544-77e0b37f8c9b

📥 Commits

Reviewing files that changed from the base of the PR and between c36cc8c and 592fe41.

📒 Files selected for processing (1)
  • packages/core/src/terminal/Screen.ts

📝 Walkthrough

Walkthrough

This PR fixes a bug in the terminal screen resize logic. When the terminal is resized, the Screen.resize() method now clears the _previousLines cache by resetting it to an empty array, ensuring the diff renderer will not use stale pre-resize line content on the next render cycle.

Changes

Screen Resize Diff Cache Invalidation

Layer / File(s) Summary
Invalidate previous lines cache on resize
packages/core/src/terminal/Screen.ts
Screen.resize() resets _previousLines to an empty array to invalidate stale back-buffer line snapshots accumulated before the resize, preventing diff renderer corruption when terminal size changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A line once lost in the buffer cache,
Now cleared when the window takes a leap,
Fresh grids spring forth with pristine grace,
No phantom rows in resize's sweep! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and concisely describes the main change: resetting _previousLines on Screen.resize() to fix stale diff renderer state after terminal resize.
Description check ✅ Passed The PR description comprehensively explains the problem, root cause, and fix, with a clear reference to the related issue #681. All key template sections are adequately filled.
Linked Issues check ✅ Passed The code change directly addresses the requirement in issue #681 by adding the suggested fix to reset _previousLines in the resize() method, matching the proposed solution.
Out of Scope Changes check ✅ Passed The single-line change to packages/core/src/terminal/Screen.ts is directly scoped to addressing the stale diff renderer state issue described in issue #681 with no extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🎉 Thanks for your first PR to TermUI, @ionfwsrijan.

Before your PR merges:

  1. Star the repo. Required. The star-check job blocks your merge otherwise.
  2. ✅ All checks green: build, test, typecheck.
  3. 🏷 PR title follows type: short description. Example: fix: handle empty list.
  4. 🔗 Link your closing issue in the description.

GSSoC 2026 points come from labels after merge:

  • gssoc:approved. +50 base points.
  • level:beginner / intermediate / advanced / critical. +20 / +35 / +55 / +80.
  • quality:clean / exceptional. x 1.2 / x 1.5.
  • type:*. Stackable bonus.

Your reviewer responds within 48 hours. Ping @Karanjot786 on Discord for urgent help.

🚀 Welcome to the cohort.

@github-actions github-actions Bot added the type:bug +10 pts. Bug fix. label Jun 4, 2026
@ionfwsrijan
Copy link
Copy Markdown
Contributor Author

@Karanjot786 You may review and merge

@Karanjot786 Karanjot786 added gssoc:approved Approved PR. Earns +50 base points. quality:clean x 1.2 multiplier. Clean implementation. level:intermediate +35 pts. Moderate task. type:feature +10 pts. New feature. labels Jun 4, 2026
@Karanjot786 Karanjot786 merged commit e0df449 into Karanjot786:main Jun 5, 2026
5 checks passed
@Karanjot786
Copy link
Copy Markdown
Owner

Thank you so much for your contribution, @ionfwsrijan!

Your PR #690 fixed Screen.resize() to reset _previousLines. The diff renderer no longer shows stale output after a terminal resize.

Keep contributing. We appreciate your work.

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

Labels

area:core @termuijs/core gssoc:approved Approved PR. Earns +50 base points. level:intermediate +35 pts. Moderate task. quality:clean x 1.2 multiplier. Clean implementation. type:bug +10 pts. Bug fix. type:feature +10 pts. New feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Screen.resize() Does Not Reset _previousLines, Causing Diff Renderer Corruption After Terminal Resize

2 participants