Skip to content

fix(theme/llmsUI): add LLMS clipboard fallback for HTTP pages#3237

Merged
SoonIter merged 3 commits intomainfrom
copilot/fix-llms-copy-button-http-support
Mar 17, 2026
Merged

fix(theme/llmsUI): add LLMS clipboard fallback for HTTP pages#3237
SoonIter merged 3 commits intomainfrom
copilot/fix-llms-copy-button-http-support

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

LlmsCopyButton and related LLMS copy actions assumed navigator.clipboard.writeText() was always available. On HTTP/insecure contexts, that API can be missing or reject, causing copy actions to fail instead of degrading gracefully.

  • Clipboard fallback

    • Added a shared LLMS copy helper that:
      • uses navigator.clipboard.writeText() when available
      • falls back to the existing copy-to-clipboard implementation when the Clipboard API is unavailable or rejects
    • This covers non-HTTPS pages without changing the UI contract
  • LLMS copy entry points updated

    • Switched all LLMS copy flows to the shared helper:
      • LlmsCopyButton
      • LlmsCopyRow
      • markdown-link copy action in LlmsViewOptions
    • The change keeps success/loading behavior unchanged while making copy resilient across page contexts
export async function copyToClipboard(text: string) {
  if (navigator.clipboard?.writeText) {
    try {
      await navigator.clipboard.writeText(text);
      return;
    } catch {}
  }

  copy(text);
}
  • UI
    • The LLMS copy button remains in the same location and now falls back correctly on HTTP pages
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: LlmsCopyButton not support http page</issue_title>
<issue_description>### Version

System:
    OS: Linux 6.6 Debian GNU/Linux 13 (trixie) 13 (trixie)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    Memory: 8.95 GB / 11.77 GB
    Container: Yes
    Shell: 5.2.37 - /bin/bash
  npmPackages:
    @rspress/core: ^2.0.2 => 2.0.5
    @rspress/plugin-preview: ^2.0.2 => 2.0.5

Details

LlmsCopyButton use navigator.clipboard api which only support in https page.

Reproduce link

Skip

Reproduce Steps

LlmsCopyButton use navigator.clipboard api which only support in https page.</issue_description>

<agent_instructions>看看有没有合理解法,复制到剪贴板有没有兜底策略</agent_instructions>

Comments on the Issue (you are @copilot in this section)


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Co-authored-by: SoonIter <79413249+SoonIter@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 17, 2026

Deploying rspress-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: a8674e8
Status: ✅  Deploy successful!
Preview URL: https://74c18480.rspress-v2.pages.dev
Branch Preview URL: https://copilot-fix-llms-copy-button.rspress-v2.pages.dev

View logs

Copilot AI changed the title [WIP] [Bug] Fix LlmsCopyButton not support http page fix(core): add LLMS clipboard fallback for HTTP pages Mar 17, 2026
Copilot AI requested a review from SoonIter March 17, 2026 09:05
Co-authored-by: SoonIter <79413249+SoonIter@users.noreply.github.com>
Copilot AI requested a review from SoonIter March 17, 2026 09:12
@SoonIter SoonIter marked this pull request as ready for review March 17, 2026 09:16
Copilot AI review requested due to automatic review settings March 17, 2026 09:16
@SoonIter SoonIter changed the title fix(core): add LLMS clipboard fallback for HTTP pages fix(theme/llmsUI): add LLMS clipboard fallback for HTTP pages Mar 17, 2026
@SoonIter SoonIter enabled auto-merge (squash) March 17, 2026 09:21
@SoonIter SoonIter requested a review from Timeless0911 March 17, 2026 09:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a clipboard fallback for LLMS copy actions so they work on HTTP (insecure) pages where navigator.clipboard.writeText() is unavailable.

Changes:

  • Introduces a shared copyToClipboard helper that tries the Clipboard API first, then falls back to copy-to-clipboard.
  • Updates LlmsCopyButton, LlmsCopyRow, and LlmsViewOptions to use the new helper.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/core/src/theme/components/Llms/copy.ts New shared clipboard helper with fallback
packages/core/src/theme/components/Llms/LlmsCopyButton.tsx Switches to copyToClipboard
packages/core/src/theme/components/Llms/LlmsCopyRow.tsx Switches to copyToClipboard
packages/core/src/theme/components/Llms/LlmsViewOptions.tsx Switches to copyToClipboard

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 3 projects in monorepo, 1 project with changes.

📊 Quick Summary
Project Total Size Change
node 12.4 MB 0
node_md 1.6 MB 0
web 16.1 MB +39.0 B (0.0%)
📋 Detailed Reports (Click to expand)

📁 web

Path: website/doc_build/diff-rsdoctor/web/rsdoctor-data.json

📌 Baseline Commit: 57912a0a9a | PR: #3217

Metric Current Baseline Change
📊 Total Size 16.1 MB 16.1 MB +39.0 B (0.0%)
📄 JavaScript 15.9 MB 15.9 MB +39.0 B (0.0%)
🎨 CSS 120.4 KB 120.4 KB 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 166.2 KB 166.2 KB 0

📦 Download Diff Report: web Bundle Diff

Generated by Rsdoctor GitHub Action

@SoonIter SoonIter merged commit 10031f9 into main Mar 17, 2026
10 checks passed
@SoonIter SoonIter deleted the copilot/fix-llms-copy-button-http-support branch March 17, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: LlmsCopyButton not support http page

4 participants