Skip to content

Conversation

@lukocode
Copy link
Contributor

@lukocode lukocode commented Aug 28, 2025

Fixes intermittent clipboard copy failures for SVG output where users
encountered "No blob data to write to clipboard" errors. The issue was
caused by a race condition where canvas operations proceeded before
the dynamically created Image element finished loading the SVG data URL.

  • Add ensureImageLoaded helper to wait for image load completion
  • Handle both already-loaded and loading states
  • Include error handling and 5-second timeout protection
  • Maintain backward compatibility with existing image copy functionality

Fixes: #265020

Fixes intermittent clipboard copy failures for SVG output where users
encountered "No blob data to write to clipboard" errors. The issue was
caused by a race condition where canvas operations proceeded before
the dynamically created Image element finished loading the SVG data URL.
- Add ensureImageLoaded helper to wait for image load completion
- Handle both already-loaded and loading states
- Include error handling and 5-second timeout protection
- Maintain backward compatibility with existing image copy functionality
@mjbvz mjbvz assigned rebornix and amunger and unassigned mjbvz Aug 28, 2025
@amunger
Copy link
Collaborator

amunger commented Sep 3, 2025

is there an issue that can be linked to this?

@lukocode
Copy link
Contributor Author

lukocode commented Sep 3, 2025

I’ve registered issue #265020 and linked it to this pull request.

@lukocode
Copy link
Contributor Author

lukocode commented Sep 9, 2025

I've updated issue #265020 with details about the visible error in the browser console, which is triggered by the patched function. Please let me know if there's anything I can do to help move the review process forward.

@amunger
Copy link
Collaborator

amunger commented Sep 11, 2025

verified the fix, thanks!

amunger
amunger previously approved these changes Sep 11, 2025
@vs-code-engineering vs-code-engineering bot added this to the September 2025 milestone Sep 11, 2025

if (image) {
const imageToCopy = image;
//FIX: Ensure image is loaded before proceeding
Copy link
Member

Choose a reason for hiding this comment

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

// FIX: Normally means there's a todo here? Can we remove that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching that. I’ve removed the // FIX: and clarified the comments.

} else {
img.onload = () => resolve(img);
img.onerror = () => reject(new Error('Failed to load image'));
// Add timeout to prevent hanging
Copy link
Member

Choose a reason for hiding this comment

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

Seems redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the feedback!
I understand why it might seem redundant, but in practice, the image is not always guaranteed to be fully loaded at this point - especially with dynamically created images. Adding this check prevents race conditions and intermittent clipboard errors, as seen in #265020.
I’ve clarified the comments in the code to explain this rationale.
Please let me know if you have further concerns or if I’ve missed something!

@lukocode
Copy link
Contributor Author

@microsoft-github-policy-service agree

@lukocode lukocode requested a review from Tyriar September 12, 2025 10:54
@Tyriar Tyriar requested a review from amunger September 12, 2025 11:03
@amunger amunger merged commit a5de10e into microsoft:main Sep 12, 2025
17 checks passed
@lukocode
Copy link
Contributor Author

Thanks, guys! I really appreciate your support.

@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Oct 27, 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.

Copying SVG cell output fails on first attempt in VSCode (Web, Codespaces)

6 participants