Skip to content

Conversation

@mahiro72
Copy link
Contributor

@mahiro72 mahiro72 commented Dec 12, 2025

Summary

Fix the playground Share button to only show "Copied!" after the clipboard copy operation actually completes.

Previously, the Share button would immediately show "Copied!" when clicked, before the async persist and clipboard.writeText operations finished. This caused a confusing UX where users would see "Copied!" but if they tabbed away quickly, the copy would fail with a NotAllowedError: Document is not focused error.

Now the button waits for onShare() to complete before updating the UI state.

Fixes #21691

Test Plan

Tested locally with npm start --workspace ruff-playground

Demo

Kapture 2025-12-12 at 20 47 51

@dhruvmanila
Copy link
Member

Ohh, this is what was happening! I noticed this multiple times but didn't dig into it. Thanks for opening a fix for this issue, it would be useful to add a short video to demo this in the PR description when you make it ready for review.

@mahiro72 mahiro72 marked this pull request as ready for review December 12, 2025 11:53
@AlexWaygood AlexWaygood added the playground A playground-specific issue label Dec 12, 2025
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Thank you.

I think we should move the error handling into ShareButton to avoid async race conditions or stale states if sharing failed.

Comment on lines +24 to 27
await persist(settings, pythonSource).catch((error) =>
// eslint-disable-next-line no-console
console.error(`Failed to share playground: ${error}`),
);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
await persist(settings, pythonSource).catch((error) =>
// eslint-disable-next-line no-console
console.error(`Failed to share playground: ${error}`),
);
try {
await persist(serialized);
} catch (error) {
// eslint-disable-next-line no-console
console.error("Failed to share playground", error);
}

disabled={copied}
onClick={() => {
onClick={async () => {
await onShare();
Copy link
Member

Choose a reason for hiding this comment

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

I think we want to distinguish between three states

  • initial: Button is clickable, label is Share
  • copying: Button is disabled, label is Share
  • copied: Button is disabled, label is Copied

We should ensure that we reset the state to Share if onShare throws (maybe by moving the try catch handling from onShare to here, we could even consider having a 4th state failed)

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

Labels

playground A playground-specific issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

playground: Share button says Copied! before actually copying, then fails if you tab away too fast

4 participants