Skip to content

Instance create form: automatically select SSH key after creation#3173

Merged
david-crespo merged 2 commits intomainfrom
ssh-key-autoselect
Apr 9, 2026
Merged

Instance create form: automatically select SSH key after creation#3173
david-crespo merged 2 commits intomainfrom
ssh-key-autoselect

Conversation

@david-crespo
Copy link
Copy Markdown
Collaborator

After you create an SSH key in the instance create form, it should automatically be checked to be injected into the instance. Otherwise why would you be adding it? Actual fix is 9285551, second commit is a tiny bit of code cleanup.

Did my favorite Claude thing and asked it whether we originally had a reason to not auto-select the SSH key. Definitively, no:

Ideally the new keys are pre-selected I suppose, though it might not be worth the work. #1867 (comment)

2026-04-08-ssh-key-auto.mp4

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
console Ready Ready Preview Apr 9, 2026 3:09am

Request Review

{showAddSshKey && (
<SSHKeyCreate
onDismiss={() => setShowAddSshKey(false)}
onSuccess={(sshKey) => onChange([...selectedKeys, sshKey.id])}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is the fix.

@david-crespo david-crespo enabled auto-merge (squash) April 9, 2026 03:10
@david-crespo david-crespo merged commit aec681b into main Apr 9, 2026
7 checks passed
@david-crespo david-crespo deleted the ssh-key-autoselect branch April 9, 2026 03:18
david-crespo added a commit that referenced this pull request Apr 10, 2026
It's barely worth fixing, but codex flagged it in #3173 and it's real.
Watch the `select all` checkbox below when I submit the create SSH key
form. In the very short interval of time after the key is created and
but before list of keys refetches, the select all checkbox flashes
checked (all are selected) before flipping back to intermediate when the
list comes in. It's trivial and it's not worth keeping the e2e test I
used to prove and fix it (removed in
966aac1), but it is worth fixing now
that I know about.


https://github.com/user-attachments/assets/0bc9e5ff-ceb0-49b5-856d-8998a8971528

The checkbox showing the wrong thing is not actually the entire bug — if
the user toggles select all during this interval, the behavior is
slightly weird because the list of keys is out of sync, but it's nearly
impossible for a human user to move fast enough to run into the issue,
and the state after the request comes back will be up to date. The real
fix would be to make `onSuccess` wait until after the invalidate is
complete. But we don't have any other examples of `async onSuccess`, so
I don't want to rush that fix in.

```diff
   const handleDismiss = onDismiss ? onDismiss : () => navigate(pb.sshKeys())
 
   const createSshKey = useApiMutation(api.currentUserSshKeyCreate, {
-    onSuccess(sshKey) {
-      queryClient.invalidateEndpoint('currentUserSshKeyList')
+    async onSuccess(sshKey) {
+      await queryClient.invalidateEndpoint('currentUserSshKeyList')
       onSuccess?.(sshKey)
       handleDismiss()
       // prettier-ignore
```
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.

1 participant