Skip to content

fix(site): redirect to new organization after create - #26890

Merged
aslilac merged 1 commit into
mainfrom
lilac/fix-org-create-redirect
Jul 1, 2026
Merged

fix(site): redirect to new organization after create#26890
aslilac merged 1 commit into
mainfrom
lilac/fix-org-create-redirect

Conversation

@aslilac

@aslilac aslilac commented Jun 30, 2026

Copy link
Copy Markdown
Member

When submitting the create organization form on a deployment with more than a handful of organizations the form was being re-rendered as empty instead of taking the user to the freshly created organization, even though the API call succeeded.

The form posts through mutateAsync with a per-call onSuccess that calls navigate. The mutation-level onSuccess awaits invalidateQueries, which refetches the organizations list and changes the organizationsPermissions query key. While that new query loads, OrganizationSettingsLayout shows its loader and unmounts CreateOrganizationPage. @tanstack/react-query only fires per-call mutation callbacks when the observer still has listeners, so the navigate gets dropped. The form re-mounts on /organizations/new once permissions resolve, which the user sees as an empty form.

Awaiting mutateAsync and running navigate inline keeps the navigation out of the observer lifecycle.

Coder Agents generated.

The per-call onSuccess passed to mutateAsync only fires while the
MutationObserver still has listeners. After the mutation succeeds the
mutation-level onSuccess awaits invalidateQueries, which refetches the
organizations list. The new list updates the organizationsPermissions
query key, causing OrganizationSettingsLayout to render a Loader while
the new query loads. That unmounts CreateOrganizationPage and tears
down its mutation observer, so the per-call onSuccess is dropped and
navigate never runs. When the permissions query resolves, the route
remounts CreateOrganizationPage on /organizations/new with an empty
form. Awaiting mutateAsync and calling navigate inline avoids the
observer lifecycle entirely.

Coder Agents generated.
@aslilac
aslilac marked this pull request as ready for review July 1, 2026 18:56
@aslilac
aslilac merged commit 3e0875d into main Jul 1, 2026
62 of 63 checks passed
@aslilac
aslilac deleted the lilac/fix-org-create-redirect branch July 1, 2026 19:01
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants