Skip to content

Replace react-clipboard.js with copy-to-clipboard (#527) - #532

Open
rahulwalunje wants to merge 1 commit into
mainfrom
issues/527-replace-react-clipboard
Open

rahulwalunje wants to merge 1 commit into
mainfrom
issues/527-replace-react-clipboard

Conversation

@rahulwalunje

Copy link
Copy Markdown
Collaborator
  • Removes an unmaintained library: react-clipboard.js is gone, so its findDOMNode warning goes away and the React 19 crash it would cause can't happen.
  • Copy buttons work the same: the URL field's copy button and the Media list's "Copy URL" still copy the same URLs, including on plain HTTP sites.
  • No new dependency: uses copy-to-clipboard, which the plugin already depends on.

Fixes #527

What changed

  • src/system/ui/controls/url/index.js and src/system/ui/lists/attachments/index.js: each <Clipboard> is now a Fluid <Button appearance="transparent" onClick={ () => copy( url ) }>. The Media list button keeps title="Copy URL" and tabIndex="-1", matching its neighbors. The rendered element is the same <button type="button" class="fluid-button fluid-appearance-transparent">.
  • package.json: removes react-clipboard.js.
  • package-lock.json: removes only react-clipboard.js and its six orphaned dependencies (clipboard, @types/clipboard, delegate, good-listener, select, tiny-emitter). Nothing is added or changed.

copy-to-clipboard copies with execCommand('copy') first, like clipboard.js did, so it works over plain HTTP. If that fails it shows a prompt() with the text instead of failing silently.

Notes for reviewers

Testing

  • npm run build passes. No bundle contains findDOMNode or clipboard.js code anymore.
  • ESLint passes on both changed files. (npm test reports existing errors in other files.)
  • In Chrome on a plain-HTTP local site, with real clicks (checked against the macOS clipboard):
    • Content app, post detail, URL field copy button: copied the post URL.
    • Media app, grid view, "Copy URL": copied the full-size file URL, and the list stayed on the list page.
    • execCommand('copy') succeeded both times, and the prompt() fallback never ran.
  • Not covered: the dev-mode warning itself (needs SCRIPT_DEBUG), React 19 (the plugin is on React 17), other browsers.

🤖 Generated with Claude Code

react-clipboard.js calls ReactDOM.findDOMNode, which warns on React 17 and is removed in React 19. The two copy buttons (URL control and the Media list's Copy URL) now use a Fluid Button that calls copy-to-clipboard, already a direct dependency. The lockfile change only removes react-clipboard.js and its six orphaned dependencies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codente

codente commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Merge Check

State: Ready for testing: @rahulwalunje or a tester runs the Test plan below, then a person merges. Lane ui recorded in the sticky only; this repo has not opted into the risk lanes (no risk: labels).

Review

Fast review: Ship, no blockers or concerns.

Review detail

No findings. Both copy buttons now use the same Fluid Button with onClick that already backs the neighboring Trash button. copy-to-clipboard is an existing direct dependency, and no other react-clipboard.js import or data-clipboard-text remains in src.


fast review · 4 files / +9/-67 lines reviewed.

Sanity check

High depth (UI surface), adversarial pass: right fix, nothing locked in, nothing to escalate.

Sanity check detail

Lane: ui — UI/UX (two copy controls people click; markup unchanged, click path reimplemented). Removing a dependency selects no lane.

  • navigator.clipboard.writeText (used by copy-public-url.js) was the simpler option, but it needs a secure context and breaks on plain-HTTP wp-admin; copy-to-clipboard's execCommand path keeps parity.
  • Fluid Button (0.7.24) defaults type to "button", so the URL control inside forms/items/url can't submit an enclosing form.
  • Media list: the .fl-asst-item-extras wrapper already stops propagation, so the click still doesn't open the item.
  • Visible change: when both copy paths fail, copy-to-clipboard shows a prompt() where clipboard.js failed silently.
  • Lockfile hand edit: none of the seven removed packages is required by any remaining entry; copy-to-clipboard and toggle-selection keep their integrity hashes. No CI here runs npm ci, so the Test plan does.

Merge context

#531 also edits package.json and package-lock.json; whichever merges second likely needs a lockfile rebase.

Test plan

  1. On the PR branch, npm ci completes, then npm run build succeeds.
  2. On a site running the built plugin, open Assistant → Content, open a post, click the link icon beside its URL: the post URL is on the clipboard and the page doesn't submit or navigate.
  3. Assistant → Media, list view, hover an item, click Copy URL: the file URL is on the clipboard and the list stays put.
  4. With SCRIPT_DEBUG on, the console shows no findDOMNode warning while doing 2–3.
  5. Nothing else broke: the item's View, Edit in Admin and Trash buttons still work.
Agent playbook

Preconditions: Assistant checkout at e376d5f (PR #532), symlinked into a local WP site with SCRIPT_DEBUG true and media + at least one post; browser-tools tab enabled on that site's wp-admin, logged in.

  1. npm ci in the assistant checkout — exit 0.
  2. npm run build — exit 0. grep -rl findDOMNode build/ dist/ 2>/dev/null finds no Assistant bundle.
  3. npx eslint src/system/ui/controls/url/index.js src/system/ui/lists/attachments/index.js — exit 0.
  4. /navigate?url=/wp-admin/ then open the Assistant panel; /wait?selector=.fl-asst-app — found.
  5. Install a copy probe: /eval?code=window.__copied=[];document.addEventListener('copy',()=>window.__copied.push(String(document.getSelection())),true).
  6. Open the Content app and a post's detail screen; /wait?selector=.fl-asst-control-url-actions button — found. /element?selector=.fl-asst-control-url-actions button — tag BUTTON, type="button", classes include fluid-button fluid-appearance-transparent.
  7. /click?selector=.fl-asst-control-url-actions button; /eval?code=window.__copied — last entry equals the href of .fl-asst-control-url-wrap a. URL unchanged.
    capture: post detail with the URL control visible
  8. Open the Media app, list view; /wait?selector=.fl-asst-item-extras button[title="Copy URL"] — found.
  9. /click?selector=.fl-asst-item-extras button[title="Copy URL"] (first item); /eval?code=window.__copied — new last entry is an uploads file URL. Still on the list screen (no detail view opened).
    capture: Media list after Copy URL
  10. /console?level=warn and /console?level=error — no findDOMNode entry, no new errors since step 4.
  11. Nothing-else-broke sweep: /element on the item's button[title="View Attachment Page"] and button[title="Edit in Admin"] — still render with their href; /hover an item, extras appear.
    capture: Media list item with extras showing
Run history
When (UTC) Head State Delta
2026-11-09 e376d5f ready first run: fast review Ship; high-depth sanity clean; marker-only (repo has no risk: or merge: labels, no merge-gate)

bb-merge-check · head:e376d5f · state:ready · risk:ui

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace unmaintained react-clipboard.js: findDOMNode deprecation, breaks on React 19

3 participants