Skip to content

Unsloth Studio: make a newly created API key selectable when the clipboard is unavailable - #11489

Merged
Lyxot merged 4 commits into
unslothai:mainfrom
LeoBorcherding:fix/api-key-selectable
Sep 22, 2026
Merged

Lyxot merged 4 commits into
unslothai:mainfrom
LeoBorcherding:fix/api-key-selectable

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #11387, fixes #9899. Supersedes #9906 with a one-file change on current main.

Problem

On a plain http:// Unsloth Studio (a LAN address rather than localhost) the browser exposes no navigator.clipboard, and the execCommand fallback can refuse too. key-reveal-card.tsx rendered the new token inside the copy <button>, so when the copy failed the token wasn't selectable either: the click did nothing, the text couldn't be dragged over, and the only way to get the key was the DOM inspector.

Change (studio/frontend/src/features/settings/components/key-reveal-card.tsx only)

  • The token sits in a read-only <input> beside a separate copy button, so it can always be selected and copied by hand.
  • The field is focused and fully selected when the card appears, so Ctrl+C works straight away.
  • If the copy button fails, the field is re-selected instead of silently doing nothing.
  • Same layout as before. data-reload-snapshot-sensitive moves to the input, and mirrorFieldState in reload-snapshot.js already strips value on a sensitive INPUT, so the token stays out of the reload snapshot.

No new strings, so locale parity is unaffected.

Testing (at 96e81b8024)

  • biome check and eslint on the file: clean.

  • npm run typecheck: the app project passes. tsconfig.test.json has one pre-existing error in tests/sidebar-row-drag.test.ts that this PR doesn't touch.

  • npm test: 8217 passed, 0 failed.

  • Browser check on Linux (WSL2, Ubuntu 24.04) with Playwright headless Firefox 155 and Chromium 153, real input events. A static page served from inside WSL carried main's copyToClipboard behind a button (before) and this PR's read-only input, selected on load, followed by Ctrl+C (after). Pass means the pasted value matched the token.

    browser origin secure context before: copy button after: select + Ctrl+C
    Firefox 155 http://127.0.0.1 yes pass via writeText pass
    Firefox 155 http://172.19.x.x no pass via execCommand fallback pass
    Chromium 153 http://127.0.0.1 yes pass via execCommand fallback (headless denies clipboard-write; desktop Chrome grants it on a click) pass
    Chromium 153 http://172.19.x.x no pass via execCommand fallback pass

    The copy button on main already copies on a plain http:// LAN origin in both engines, so the "copy does nothing" report on Firefox and Brave on Linux is not reproduced here. Headless browsers use an in-process clipboard, so a desktop clipboard problem (X11 or Wayland) or a Brave shield would not show up in this table. What holds in every row is that the token on main could not be selected at all, and with this PR it is selected on reveal and Ctrl+C copies it.

  • Not yet run inside Unsloth Studio itself over a LAN http:// URL; that check is in progress on a second machine.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed main still renders the token inside the copy button in key-reveal-card.tsx, so a failed clipboard call leaves nothing selectable, and I checked that mirrorFieldState in reload-snapshot.js does strip value on a sensitive input. Note #9906 covers the same ground, so I will pick between the two when I review this.

@Lyxot Lyxot self-assigned this Sep 22, 2026
…vent

Inside a modal dialog on a plain http:// origin, the fallback textarea is appended outside the dialog's focus trap, focus is pulled back, and execCommand("copy") copies an empty selection while still returning true. Set the payload from a capture-phase copy listener and report success only when it was written.
The recipe-studio copyTextToClipboard duplicated the textarea fallback and reported execCommand's result, so inside a dialog on a plain http:// origin it claimed success with an unchanged clipboard. Several audio and Codex-connect copies called navigator.clipboard.writeText directly, which is undefined over plain http:// and in the desktop shell. All now use the shared helper, keeping their existing toasts.
@Lyxot

Lyxot commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Pushed three commits on top of the original change (head cb1d8989b5):

  • 15f3097982 fixes the root cause of [Bug] Created API Keys cannot be copied #11387. The settings dialog is a Radix modal, so on a plain http:// origin the execCommand fallback's textarea was appended outside the focus trap. Focus was pulled back, and execCommand("copy") copied an empty selection while still returning true: the button showed "copied" but the clipboard was unchanged. The fallback now writes the text from a capture-phase copy listener and reports success only when it was written. Checked in a real browser on an insecure LAN origin inside a Radix dialog: before, the clipboard was untouched with a true result; after, the text lands. Also confirmed manually in Safari and Firefox.
  • bd495fc0fa rewords the preselection comment.
  • cb1d8989b5 fixes the same class elsewhere. The duplicate recipe-studio copyTextToClipboard had the same fallback bug, and several audio and Codex-connect copies called navigator.clipboard.writeText directly, which is undefined over plain http:// and in the desktop shell. They now all use the shared copyToClipboard and keep their existing toasts.

Codex review on the same head: Lyxot#71 (comment) ("Didn't find any major issues", reviewed commit cb1d8989b5).

CI on the same head (staging run, Lyxot#71): 41 passed, 4 failed. None of the 4 failures touches this PR's files. Three fail identically on main at the same base b490d56bc2, and the Mac job fails at the same banner step; main's Mac run there had not concluded:

  • Chat UI Tests (chat), Chat UI Tests (Windows, "extra" lane), and Chat UI, API, Update and GGUF inference (Mac): Update banner layout regression at 320x480 and 390x500 with 20px text ("the card does not clip its own copy away").
  • Repo tests (CPU, studio): sidebar, titlebar and image-page contract tests in tests/studio/test_desktop_reliability_frontend_contract.py, plus test_update_release_notes.py::test_notes_surface_is_borderless_and_lifts_in_dark_mode.

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Fixes the root cause of #11387 and makes the token selectable for #9899. Codex review is clean and CI is green apart from failures that also occur on main.

@Lyxot
Lyxot merged commit a9f5348 into unslothai:main Sep 22, 2026
42 of 46 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…board is unavailable (unslothai#11489)

* Unsloth Studio: make a newly created API key selectable when the clipboard is unavailable

* fix(studio): write the execCommand clipboard fallback from the copy event

Inside a modal dialog on a plain http:// origin, the fallback textarea is appended outside the dialog's focus trap, focus is pulled back, and execCommand("copy") copies an empty selection while still returning true. Set the payload from a capture-phase copy listener and report success only when it was written.

* docs(studio): clarify why the new API key is preselected

* fix(studio): route remaining text copies through copyToClipboard

The recipe-studio copyTextToClipboard duplicated the textarea fallback and reported execCommand's result, so inside a dialog on a plain http:// origin it claimed success with an unchanged clipboard. Several audio and Codex-connect copies called navigator.clipboard.writeText directly, which is undefined over plain http:// and in the desktop shell. All now use the shared helper, keeping their existing toasts.

---------

Co-authored-by: Lyxot <[email protected]>
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] Created API Keys cannot be copied [Feature] Turn API Token into selectable text

3 participants