Skip to content

feat: defer api key generation with mutation - #22318

Merged
jakehwll merged 3 commits into
mainfrom
jakehwll/KIWI-24-defer-workspaceapps-api-key-generation
Mar 5, 2026
Merged

feat: defer api key generation with mutation#22318
jakehwll merged 3 commits into
mainfrom
jakehwll/KIWI-24-defer-workspaceapps-api-key-generation

Conversation

@jakehwll

Copy link
Copy Markdown
Contributor

Closes #22065

This pull-request ensures that when we load the <WorkspacePage /> we're not instantly attempting to generate an apiKey every-time. These are now only generated once the user attempts to actually click on the VSCode link, this is now a mutation also (which is the correct action for this).

Comment thread site/src/pages/WorkspacesPage/WorkspacesTable.tsx
Comment thread site/src/pages/WorkspacesPage/WorkspacesTable.tsx
@DanielleMaywood

Copy link
Copy Markdown
Contributor

Can we update all uses of get api key to be mutations? Thinking about the dedicated VSCode buttons

@jakehwll

jakehwll commented Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

Can we update all uses of get api key to be mutations? Thinking about the dedicated VSCode buttons

I'll scope this for another sprint 🙂

Comment on lines +808 to +821
const generateKeyMutation = useMutation({
mutationFn: () => API.getApiKey(),
onSuccess: ({ key }) => {
// We use a `location.href` here instead of a `navigate` because
// these are protocol-specific links.
location.href = getVSCodeHref(variant, {
owner,
workspace,
token: key,
agent,
folder,
});
},
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

non-blocking: future work will require making multiple useMutation({ mutationFn: () => API.getApiKey() }). Thoughts on creating a helper for that now?

kylecarbs added a commit that referenced this pull request Mar 3, 2026
The handler used window.location.assign() and an async/await pattern
that differed from the working VSCodeDesktopButton on the workspace
page. Align with that component's proven pattern: generate the API
key on click via useMutation and set location.href on success.

Also simplify by accepting "cursor" in getVSCodeHref so we don't
need the cursorApp lookup or regex replace hack.

Changes:
- Add "cursor" to getVSCodeHref app union type
- Use useMutation for on-click API key generation matching #22318
- Use location.href = getVSCodeHref(editor, ...) for navigation
- Remove workspace app lookup for cursor
- Remove SESSION_TOKEN_PLACEHOLDER import (no longer needed)
@jakehwll
jakehwll merged commit f609de8 into main Mar 5, 2026
24 of 25 checks passed
@jakehwll
jakehwll deleted the jakehwll/KIWI-24-defer-workspaceapps-api-key-generation branch March 5, 2026 04:50
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Defer API key generation in WorkspaceApps to on-click instead of page load

3 participants