Skip to content

fix: copy button not working on API Server and API Key pages#34515

Merged
hyoban merged 8 commits intolanggenius:mainfrom
BrianWang1990:fix/copy-button-api-pages
Apr 9, 2026
Merged

fix: copy button not working on API Server and API Key pages#34515
hyoban merged 8 commits intolanggenius:mainfrom
BrianWang1990:fix/copy-button-api-pages

Conversation

@BrianWang1990
Copy link
Copy Markdown
Contributor

@BrianWang1990 BrianWang1990 commented Apr 3, 2026

Fixes #34494
Close #34552

Problem

The copy buttons on the API Server endpoint and API Key pages do not work when Dify is accessed over a non-secure HTTP connection (common in self-hosted Docker deployments on local networks).

This is because the CopyFeedback, CopyIcon, and InputWithCopy components use foxact/use-clipboard, which internally relies on navigator.clipboard.writeText — an API that is restricted to secure contexts (HTTPS or localhost).

Reported in #34494.

Root Cause

PR #32287 previously fixed this issue for input-copy.tsx by introducing a writeTextToClipboard utility in web/utils/clipboard.ts with a document.execCommand("copy") fallback. However, the base copy components (CopyFeedback, CopyIcon, InputWithCopy) still used foxact/use-clipboard and were not updated — leaving the API Server URL and API Key copy buttons broken in HTTP contexts.

Solution

  • Created a custom useClipboard hook (web/hooks/use-clipboard.ts) that wraps the existing writeTextToClipboard utility, providing the same API surface as foxact/use-clipboard (copied, copy, reset).
  • Replaced foxact/use-clipboard imports in:
    • web/app/components/base/copy-feedback/index.tsx
    • web/app/components/base/copy-icon/index.tsx
    • web/app/components/base/input-with-copy/index.tsx
  • Updated corresponding test mocks and the global vitest.setup.ts.

This ensures all copy buttons in the app work correctly in both secure (HTTPS) and non-secure (HTTP) contexts.

Checklist

  • New hook reuses the existing writeTextToClipboard fallback — no duplication
  • Drop-in replacement: same API surface (copied, copy, reset)
  • Test mocks updated to match new module path
  • No impact on HTTPS/localhost functionality
  • Minimal, focused change set

…ecure HTTP contexts

Replace foxact/use-clipboard with a custom useClipboard hook that uses
the project's writeTextToClipboard utility. This utility includes a
fallback mechanism (document.execCommand) for non-secure HTTP contexts
where navigator.clipboard is unavailable.

Affected components:
- CopyFeedback (used by API Server URL copy button)
- CopyIcon
- InputWithCopy

Closes langgenius#34494
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 3, 2026
@github-actions github-actions Bot added the web This relates to changes on the web. label Apr 3, 2026
@dosubot dosubot Bot added the javascript Pull requests that update javascript code label Apr 3, 2026
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 9, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 9, 2026
@hyoban hyoban enabled auto-merge April 9, 2026 02:48
@hyoban hyoban added this pull request to the merge queue Apr 9, 2026
Merged via the queue into langgenius:main with commit 9308287 Apr 9, 2026
32 checks passed
HanqingZ pushed a commit to HanqingZ/dify that referenced this pull request Apr 23, 2026
…ius#34515)

Co-authored-by: Brian Wang <BrianWang1990@users.noreply.github.com>
Co-authored-by: test <test@testdeMac-mini.local>
Co-authored-by: BrianWang1990 <512dabing99@163.com>
Co-authored-by: Stephen Zhou <hi@hyoban.cc>
Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Pull requests that update javascript code lgtm This PR has been approved by a maintainer needs-revision size:L This PR changes 100-499 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy button not working on API Server and API Key pages

3 participants