Skip to content

fix(web): copy text over plain HTTP - #8023

Open
Michel-Liao wants to merge 3 commits into
pingdotgg:mainfrom
Michel-Liao:fix/plain-http-clipboard
Open

fix(web): copy text over plain HTTP#8023
Michel-Liao wants to merge 3 commits into
pingdotgg:mainfrom
Michel-Liao:fix/plain-http-clipboard

Conversation

@Michel-Liao

@Michel-Liao Michel-Liao commented Aug 23, 2026

Copy link
Copy Markdown

What Changed

  • fall back to a temporary selected textarea when the async Clipboard API is unavailable
  • remove the fallback element and restore the previously focused control after copying
  • cover the plain-HTTP path with a focused regression test

Why

Browsers do not expose navigator.clipboard on plain-HTTP remote origins. T3 Code is commonly reached over a LAN or Tailscale address, so shared copy actions currently throw instead of copying. The async Clipboard API remains the primary path; the legacy command is used only when that API is unavailable.

Fixes #7824.

Verification

  • vp test run apps/web/src/hooks/useCopyToClipboard.test.ts
  • vp fmt --check apps/web/src/hooks/useCopyToClipboard.ts apps/web/src/hooks/useCopyToClipboard.test.ts
  • vp lint apps/web/src/hooks/useCopyToClipboard.ts apps/web/src/hooks/useCopyToClipboard.test.ts --deny-warnings
  • tsgo --noEmit for @t3tools/web
  • git diff --check

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Screenshots are not applicable; this does not change UI appearance
  • Video is not applicable; this does not change animation or timing

Created with GPT-5.6 Sol via Codex in T3 Code.


Note

Low Risk
Small clipboard fallback in the web copy helper; no auth or data-handling changes. Uses a legacy DOM copy path only when the Clipboard API is unavailable.

Overview
Copy actions now work on remote pages served over plain HTTP (LAN/Tailscale), where navigator.clipboard is missing.

writeTextToClipboard still prefers the async Clipboard API. When that API is unavailable, it copies via a hidden textarea and document.execCommand("copy"), then removes the element and restores focus. It only throws ClipboardApiUnavailableError if both paths fail (or window is undefined).

Adds a regression test covering the fallback path.

Reviewed by Cursor Bugbot for commit 1cc367e. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add document.execCommand('copy') fallback to writeTextToClipboard

When navigator.clipboard.writeText is unavailable (e.g. plain HTTP), writeTextToClipboard now falls back to a hidden textarea approach via the new writeTextWithExecCommand helper instead of immediately throwing ClipboardApiUnavailableError. The helper creates a temporary textarea, selects its contents, calls document.execCommand('copy'), then removes the textarea and restores focus.

  • Risk: writeTextToClipboard in useCopyToClipboard.ts only throws ClipboardApiUnavailableError when window is undefined or the execCommand fallback fails; callers that relied on the error being thrown when navigator.clipboard is absent will now see true returned instead.

Macroscope summarized 1cc367e.

@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 237bc550-ddd0-46bd-9802-e7c36ed1fdd1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Aug 23, 2026
Comment thread apps/web/src/hooks/useCopyToClipboard.ts
@macroscopeapp

macroscopeapp Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 1cc367e

Macroscope's review found this PR approvable — This is a small, self-contained clipboard bug fix that preserves the normal async API and adds a narrowly scoped textarea fallback for unsupported contexts. Cleanup and focus restoration are covered by regression tests, with no schema, deployment, or authentication-logic changes.

You can add or adjust custom eligibility rules. Learn more.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4b28706. Configure here.

Comment thread apps/web/src/hooks/useCopyToClipboard.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Copy to clipboard not working on remote web

1 participant