Repository navigation
fix(link-dialog): hide the copy button when the Clipboard API is unavailable - #992
Merged
petyosi merged 2 commits intoOct 13, 2026
Conversation
…ailable navigator.clipboard is undefined outside secure contexts, so clicking the copy button in the link preview over plain http threw a TypeError. Fixes mdx-editor#990
Hiding the copy button removed copying for exactly the apps that hit mdx-editor#990: intranet deployments served over plain http, where navigator.clipboard is undefined. execCommand('copy') still works there, so fall back to it instead of hiding the button. The fallback also covers a rejected writeText call, for example when a permissions policy blocks clipboard-write, which previously surfaced as an unhandled rejection. "Copied!" now appears only when a copy actually succeeded, and the button is hidden only when neither path can copy.
Contributor
|
Thanks for this! I pushed a follow-up commit (ca2a284) on top of yours that falls back to What changed:
I checked it in Chromium on a non-localhost http origin ( Let me know if anything looks off to you. |
|
🎉 This PR is included in version 4.3.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
fixes #990
navigator.clipboardis undefined outside secure contexts, so the copy button in the link preview threw a TypeError over plain http (non-localhost origin)LinkDialognow renders the copy button only whennavigator.clipboard.writeTextexists. everything else in the preview (open, edit, remove) is untouchedexecCommand('copy')fallback: it's deprecated and the issue itself suggests making the action optionalsrc/test/link-dialog.test.tsx: no button without the Clipboard API,writeTextcalled with the url when it's there. the first test fails without the fixnpm run lint,npm run typecheck,npm run test:once,npm run buildall pass