Skip to content

fix(core): invalidate overlay layers and reset screen state on resize#1914

Open
ionfwsrijan wants to merge 2 commits into
Karanjot786:mainfrom
ionfwsrijan:fix/resize-overlay-disappear-1911
Open

fix(core): invalidate overlay layers and reset screen state on resize#1914
ionfwsrijan wants to merge 2 commits into
Karanjot786:mainfrom
ionfwsrijan:fix/resize-overlay-disappear-1911

Conversation

@ionfwsrijan

@ionfwsrijan ionfwsrijan commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Description

Two coordinated bugs caused overlay content (modals, dropdowns, toasts) to permanently disappear after terminal resize:

Fix 1: LayerManager.resize() — Invalidate all layers

Changed dirtyRegion = null to dirtyRegion = { x: 0, y: 0, width: cols, height: rows } so every layer is fully recomposited after resize (LayerManager.ts:258-261).

Fix 2: Screen.resize() — Reset all ancillary state

Added reset of _previousStyleLines, _clipStack, _translateYStack, _translateY, _ansiQueue, _flushEpoch, _swapping, and _backdropFilters to prevent stale state from causing clipping/translation/swap errors after resize (Screen.ts:433-446).

Tests

  • Updated LayerManager.test.ts to verify dirtyRegion covers the full new dimensions after resize and that compositing works post-resize.
  • Added Screen.test.ts test verifying all ancillary state is reset after resize.

Closes #1911

Summary by CodeRabbit

  • Bug Fixes
    • Resizing now fully refreshes terminal layers so content is redrawn correctly after a size change.
    • Resizing the screen now clears leftover rendering state, preventing clipping, translation, or queued output from affecting new content.
    • Content entered after a resize now renders properly using the updated terminal dimensions.

@ionfwsrijan ionfwsrijan requested a review from Karanjot786 as a code owner June 30, 2026 16:41
@github-actions github-actions Bot added type:bug +10 pts. Bug fix. area:core @termuijs/core type:testing +10 pts. Tests. and removed type:bug +10 pts. Bug fix. labels Jun 30, 2026
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ionfwsrijan, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 839fe1f6-b016-4387-b16a-170fe95833f1

📥 Commits

Reviewing files that changed from the base of the PR and between 2dad0f8 and 9423c85.

📒 Files selected for processing (1)
  • packages/core/src/terminal/LayerManager.test.ts
📝 Walkthrough

Walkthrough

LayerManager.resize() now sets each layer's dirtyRegion to the full new grid dimensions instead of null, ensuring compositing rerenders all layers after resize. Screen.resize() additionally clears clip/translate stacks, ANSI queue, style fingerprints, flush epoch, swap flag, and backdrop filters. Tests are updated accordingly.

Resize State Reset Fix

Layer / File(s) Summary
LayerManager and Screen resize fixes + tests
packages/core/src/terminal/LayerManager.ts, packages/core/src/terminal/Screen.ts, packages/core/src/terminal/LayerManager.test.ts, packages/core/src/terminal/Screen.test.ts
LayerManager.resize() sets dirtyRegion to {x:0, y:0, width:cols, height:rows} instead of null; Screen.resize() clears _previousStyleLines, _clipStack, _translateYStack, _translateY, _ansiQueue, _flushEpoch, _swapping, and _backdropFilters. Tests replace the old "clears dirty region" assertion with full-grid dirty checks and composite correctness, and add a new Screen test verifying all ancillary state is reset.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Karanjot786/TermUI#694: Adjusts LayerManager dirty-region and resize unit-test coverage, directly overlapping with this PR's test changes.
  • Karanjot786/TermUI#1184: Changes LayerManager's dirtyRegion handling so resized layers are marked dirty across full bounds rather than cleared to null.
  • Karanjot786/TermUI#1856: Introduces _backdropFilters in Screen.ts, which this PR now clears in Screen.resize().

Suggested labels

gssoc:approved, quality:clean, type:bug, level:intermediate

Suggested reviewers

  • Karanjot786

Poem

🐇 A resize once made overlays flee,
dirtyRegion set to null — oh me!
Now the whole grid is marked as changed,
clips and queues are all rearranged.
Modals stay put, as they should be! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and accurately summarizes the resize-state fix.
Description check ✅ Passed The description covers the bug, fix, tests, and linked issue, though several template sections are left unfilled.
Linked Issues check ✅ Passed The changes satisfy #1911 by invalidating layers on resize, resetting screen state, and adding tests for both behaviors.
Out of Scope Changes check ✅ Passed The PR stays focused on resize handling and related tests, with no clear unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions github-actions Bot added the type:bug +10 pts. Bug fix. label Jun 30, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/src/terminal/LayerManager.test.ts`:
- Around line 331-343: The resize composition test in LayerManager.test.ts is
using require() to construct Screen even though the file runs as ESM, so replace
that usage with the already imported Screen symbol in the composite test. Keep
the rest of the resize assertions intact and ensure the test instantiates Screen
directly before calling lm.composite(screen).

In `@packages/core/src/terminal/Screen.test.ts`:
- Around line 73-93: The resize test in Screen.test is not actually seeding the
saved-line caches, so it can pass even if Screen.resize stops clearing them.
Update the Screen resize test by populating the back buffer, invoking
saveLines(), and then asserting that both getPreviousLine(0) and
getPreviousStyleLine(0) are empty after resize; keep the existing checks around
resize, activeClip, and the Screen state helpers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a61e2b1f-88c5-4576-a6f3-6c951998dea0

📥 Commits

Reviewing files that changed from the base of the PR and between 85e8d36 and 2dad0f8.

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

Comment thread packages/core/src/terminal/LayerManager.test.ts
Comment thread packages/core/src/terminal/Screen.test.ts
@ionfwsrijan

Copy link
Copy Markdown
Contributor Author

@Karanjot786 Please review this

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

Labels

area:core @termuijs/core type:bug +10 pts. Bug fix. type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Terminal resize causes all overlay layers to disappear permanently until next explicit write

1 participant