Skip to content

dispose of ref instead of object itself to avoid null objects.#266299

Merged
mjbvz merged 1 commit intomicrosoft:mainfrom
dmiska25:fix-invisible-code-blocks
Sep 29, 2025
Merged

dispose of ref instead of object itself to avoid null objects.#266299
mjbvz merged 1 commit intomicrosoft:mainfrom
dmiska25:fix-invisible-code-blocks

Conversation

@dmiska25
Copy link
Contributor

This PR fixes an issue with scrolling in Copilot chats with many code blocks (100+). The behavior is that after scrolling up and down through the chat, some code blocks shrink to 0 height and the code is no longer visible. See the included video for an example:

Screen.Recording.2025-09-11.at.5.21.20.PM.mov

Root Cause

The problem came from how CodeBlockModelCollection was disposing models. It was calling ref.object.dispose(), which disposes the underlying text model itself. Instead, it should call ref.dispose(), which disposes the reference and releases it.

By disposing the model directly, later code block components ended up with null/invalid models during virtualization cycles. That’s why editors collapsed or reported content height = -1.


Fix

Replace calls to ref.object.dispose() with ref.dispose() in delete() and clear(). This properly disposes the reference, allowing models to remain valid and be reused when scrolling back.


Testing

  • Manually tested with an OSS build of VS Code and Copilot Chat, reproducing the bug with >100 code blocks. After the fix, blocks remain visible when scrolling.
  • Ran automated tests (./scripts/test.sh) with no regressions.
  • See fix example here:
Screen.Recording.2025-09-11.at.5.16.12.PM.mov

Related

Fixes #266296
Related telemetry issues: #240028, #248829, #255827

Copy link

@saky-semicolon saky-semicolon left a comment

Choose a reason for hiding this comment

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

Yeah we can drop the first call (ref.object.dispose()) and keep ref.dispose() as the correct disposal.

@connor4312 connor4312 assigned mjbvz and unassigned connor4312 Sep 12, 2025
@dmiska25
Copy link
Contributor Author

I did notice there was a recent pr for the telemetry issues here. I could remove the check and or comment if desired, or leave it; whichever is desired there. #260445

@kuhesh699-glitch

This comment was marked as spam.

@kuhesh699-glitch

This comment was marked as spam.

Copilot AI review requested due to automatic review settings September 22, 2025 19:00
@dmiska25 dmiska25 force-pushed the fix-invisible-code-blocks branch from 0da28cf to 4aa9b2e Compare September 22, 2025 19:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a critical bug in Copilot chat where code blocks would shrink to 0 height and become invisible when scrolling through chats with many code blocks (100+). The issue was caused by improper disposal of text model references in the CodeBlockModelCollection class.

Key changes:

  • Fixed disposal logic to dispose references instead of the underlying models
  • Corrected both delete() and clear() methods in CodeBlockModelCollection
  • Ensures models remain valid during virtualization cycles

@mjbvz mjbvz enabled auto-merge September 29, 2025 20:05
@vs-code-engineering vs-code-engineering bot added this to the September 2025 milestone Sep 29, 2025
@mjbvz mjbvz merged commit dadf926 into microsoft:main Sep 29, 2025
17 checks passed
@dmiska25 dmiska25 deleted the fix-invisible-code-blocks branch September 29, 2025 21:06
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Nov 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copilot Chat Code Blocks Collapse / Disappear During Scroll

7 participants