fix(theme): add clipboard fallback for non-HTTPS environments#11792
fix(theme): add clipboard fallback for non-HTTPS environments#11792io-ing wants to merge 1 commit intofacebook:mainfrom
Conversation
|
Hi @io-ing! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
slorber
left a comment
There was a problem hiding this comment.
I would prefer re-introducing copy-text-to-clipboard
because it handles quirks we don't want to deal with
We could eventually lazy load it with a dynamic import so that it doesn't need to load/init for users who are using https
| return; | ||
| } | ||
|
|
||
| // Fallback for non-HTTPS environments where navigator.clipboard is unavailable |
There was a problem hiding this comment.
If this doesn't work, I'd rather revert to the former lib we were using, that handles quirks too
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
0e17ed4 to
c146016
Compare
c146016 to
d0b9f0f
Compare
slorber
left a comment
There was a problem hiding this comment.
almost looks good but I'd like a comment to explain why we need this and also to not swallow errors
unhandled errors must remain unhandled. If someone is using Sentry/posthog/whatever observability tool on their website, they should be able to capture/report the unhandled errors
| } | ||
|
|
||
| try { | ||
| const copy = (await import('copy-text-to-clipboard')).default; |
There was a problem hiding this comment.
Can you add a comment, maybe linking to this PR, explaining why we still need the lib? (now and in the future)
| const copy = (await import('copy-text-to-clipboard')).default; | ||
| return copy(code); | ||
| } catch { | ||
| return false; |
There was a problem hiding this comment.
please do not swallow errors
| try { | ||
| await navigator.clipboard.writeText(code); | ||
| return true; | ||
| } catch {} |
There was a problem hiding this comment.
Please do not swallow errors
|
hey, I didn't notice but we got 2 PR for the same issue, and I already merged this other one: #11796 |
navigator.clipboard is undefined in non-HTTPS contexts (e.g. accessing dev server via LAN IP like http://192.168.x.x:3000), which causes the copy button to throw an error since #11422 removed the copy-text-to-clipboard fallback.
This PR adds a textarea-based fallback when navigator.clipboard is unavailable.
Fixes 11791