Skip to content
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

feat(ui): safe clipboard handling #7626

Merged
merged 4 commits into from
Feb 7, 2025
Merged

Conversation

psychedelicious
Copy link
Collaborator

Summary

The clipboard API is not available by default on firefox. Until now, we have sometimes ignored (resulting in errors when a FF user attempts to copy something) and sometimes checked for access first. This PR refactors clipboard access across the UI to ensure it cannot cause errors.

The useClipboard hook exposes a boolean indicating if clipboard is available and provides a wrapper around the clipboard API.

The wrapper methods first check if clipboard access is available before attempting to copy to it. If not, a toast is displayed, linking to the new FAQ entry:
image

When clipboard access is available, there is no change to behaviour.

An eslint rule now prevents direct access to navigator.clipboard and points devs to the safe wrapper.

Related Issues / Discussions

One report for a copy feature that, via a happy code accident, handled errors from the clipboard API:
https://discord.com/channels/1020123559063990373/1149506274971631688/1337165581131972751

Been a number of issues over time, but I'm not sure if there are tickets for any of them.

QA Instructions

Follow the instructions in the new FAQ entry to disable clipboard on Firefox. You'll need to check the code in this PR for the instructions bc the docs link in the toast won't work until this is merged.

Attempt to copy an image via right-click or canvas. You should get the toast.

Enable clipboard, refresh the page and try again. Should work.

Merge Plan

Should go into v5.6.1

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

@github-actions github-actions bot added frontend PRs that change frontend files docs PRs that change docs labels Feb 6, 2025
@psychedelicious psychedelicious merged commit e7aafdf into main Feb 7, 2025
15 checks passed
@psychedelicious psychedelicious deleted the psyche/feat/ui/copy-error branch February 7, 2025 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs PRs that change docs frontend PRs that change frontend files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants