Skip to content

Comments

Fix copy button not working during chat code block streaming#297590

Open
pierceboggan wants to merge 1 commit intomainfrom
fix-255290-copy-streaming
Open

Fix copy button not working during chat code block streaming#297590
pierceboggan wants to merge 1 commit intomainfrom
fix-255290-copy-streaming

Conversation

@pierceboggan
Copy link
Contributor

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 the code property 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.code is 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 text parameter is optional, so existing callers that don't pass it continue to work.

Fixes #255290


Created with Copilot Desktop

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>
Copilot AI review requested due to automatic review settings February 25, 2026 03:35
@vs-code-engineering vs-code-engineering bot added this to the February 2026 milestone Feb 25, 2026
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.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Copy link

@DevFlex-AI DevFlex-AI left a comment

Choose a reason for hiding this comment

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

honeslty i think this is a goo dfix thta should be merged

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy button for code snippets only works after AI finishes streaming response

3 participants