-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix playground Share button showing "Copied!" before clipboard copy completes #21942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix playground Share button showing "Copied!" before clipboard copy completes #21942
Conversation
|
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. |
MichaReiser
left a comment
There was a problem hiding this 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.
| await persist(settings, pythonSource).catch((error) => | ||
| // eslint-disable-next-line no-console | ||
| console.error(`Failed to share playground: ${error}`), | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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(); |
There was a problem hiding this comment.
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 isSharecopying: Button is disabled, label isSharecopied: Button is disabled, label isCopied
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)
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
persistandclipboard.writeTextoperations finished. This caused a confusing UX where users would see "Copied!" but if they tabbed away quickly, the copy would fail with aNotAllowedError: Document is not focusederror.Now the button waits for
onShare()to complete before updating the UI state.Fixes #21691
Test Plan
Tested locally with
npm start --workspace ruff-playgroundDemo