Skip to content

v6.5.2

Choose a tag to compare

@childrentime childrentime released this 17 Aug 12:17
· 39 commits to main since this release

🐞 Bug Fixes

useClipboard: works in non-secure contexts β€” #218, #219

navigator.clipboard is undefined whenever window.isSecureContext is false β€” plain http://, LAN IPs, some embedded webviews β€” so copy() rejected outright and the hook was simply unusable there.

Copying now falls back to a temporary <textarea> plus document.execCommand('copy'), and copy / cut events fall back to the current document selection when a Clipboard API read is unavailable or denied.

const [text, copy, isSupported] = useClipboard();
// isSupported === false on http:// β€” copy() still works via the legacy fallback

The returned tuple gains a third element, isSupported, reporting whether navigator.clipboard exists. Destructuring stays backwards compatible; treat isSupported as a capability hint rather than a gate, since the copy fallback works either way.

One subtlety worth recording: the selection is read synchronously inside the event handler. document.execCommand('copy') dispatches its own bubbling copy event, and by the time an awaited continuation runs, the browser has already torn down the fallback textarea β€” or, on cut in Firefox, cleared the selection outright. Reading a microtask later returns an empty string, which silently blanked text.

Verified in Chromium, Firefox and WebKit with the real hook, real React and the Clipboard API removed:

scenario (no Clipboard API) before after
copy() β†’ execCommand fallback βœ— βœ— βœ— βœ“ βœ“ βœ“
user presses Ctrl+X βœ— firefox βœ“ βœ“ βœ“
user presses Ctrl+C βœ“ βœ“ βœ“ βœ“ βœ“ βœ“

useCopyToClipboard is an alias for the same implementation, so it gains all of this too. useClipboard also picks up a test suite (8 cases) covering the fallback, both event paths, and a denied Clipboard API read.

Thanks @tanukihee for reporting the issue and seeing the fix all the way through.

🧹 Housekeeping

No effect on the published package β€” repo cleanup only:

  • The deprecated packages/website-docusaurus site is gone. reactuse.com has been served from packages/website-astro for a while, and the stale copy was actively misleading contributors into updating docs that never ship.
  • The generated API markdown moved with it, from website-docusaurus/api/ to packages/website-astro/api/ β€” next to the site that actually renders it at the %%API%% marker. It is still produced by pnpm --filter @reactuses/core gend and still read by packages/mcp.

Full Changelog: v6.5.1...v6.5.2