v6.5.2
π 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 fallbackThe 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-docusaurussite is gone. reactuse.com has been served frompackages/website-astrofor 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/topackages/website-astro/api/β next to the site that actually renders it at the%%API%%marker. It is still produced bypnpm --filter @reactuses/core gendand still read bypackages/mcp.
Full Changelog: v6.5.1...v6.5.2