Fix copy button not working during chat code block streaming#297590
Open
pierceboggan wants to merge 1 commit intomainfrom
Open
Fix copy button not working during chat code block streaming#297590pierceboggan wants to merge 1 commit intomainfrom
pierceboggan wants to merge 1 commit intomainfrom
Conversation
Set toolbar context immediately when rendering code blocks, before awaiting the text model promise. This ensures the Copy action has access to the code text even while the model is still loading during streaming. Previously, the toolbar context (including the 'code' property used by the Copy action) was only set after the text model promise resolved. This meant clicking Copy during streaming would fail since context.code was undefined. Now we pass the raw text to render() and set an initial context immediately, which is later refined when the model loads. Fixes #255290 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
DevFlex-AI
reviewed
Feb 25, 2026
DevFlex-AI
left a comment
There was a problem hiding this comment.
honeslty i think this is a goo dfix thta should be merged
dmitrivMS
approved these changes
Feb 25, 2026
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.
When users click the Copy button on a code block while Copilot Chat is still streaming its response, nothing gets copied. They have to wait for the entire response to finish before copying works.
Root Cause
The
CodeBlockPart.render()method sets the toolbar context (including thecodeproperty used by the Copy action) only after awaiting the text model promise. During streaming, this promise takes time to resolve while the model is being created and populated. If a user clicks Copy before the promise resolves,context.codeis undefined and the copy silently fails.Solution
Pass the raw text (which is already available from markdown parsing) to
render()and set an initial toolbar context immediately, before awaiting the model. This ensures the Copy action has access to the code text from the moment the code block appears. The context is later refined with the fully resolved model data once available.The change is backwards compatible — the
textparameter is optional, so existing callers that don't pass it continue to work.Fixes #255290
Created with Copilot Desktop