Fix infinite redirect loop after deleting an organization#813
Open
Cryptoteep wants to merge 1 commit into
Open
Fix infinite redirect loop after deleting an organization#813Cryptoteep wants to merge 1 commit into
Cryptoteep wants to merge 1 commit into
Conversation
Deleting an organization navigated back to "/" with router.push(), which only performs a client-side transition. The root layout's session data (fetched once as a Server Component) was not refetched, so the stale organization list still contained the deleted org, and localStorage's lastActiveOrg still pointed at it. The landing page then redirected back into the now-deleted organization, which 404s and leaves the user stuck. Clear lastActiveOrg when it references the deleted organization and use a full navigation to "/" so the organization list is freshly fetched. Fixes #2131
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Reported in l3montree-dev/devguard#2131: deleting an organization from the
settings page ("Danger Zone") redirects the user back to
/, but they getstuck bouncing back into the page of the organization that was just
deleted (which no longer exists). A manual page refresh fixes it.
Root cause
handleDeleteOrganizationinsrc/app/(loading-group)/[organizationSlug]/settings/page.tsxcalledrouter.push("/")after a successful deletion. That is a client-sidetransition, so the root layout's
SessionShell(a Server Component thatfetches the session and organization list once) is not re-executed —
the organization list kept in
SessionContextstill contained thejust-deleted organization.
On
/,src/app/page.tsxreadslocalStorage.lastActiveOrg(which stillpointed at the deleted org, since it is set whenever an org page loads
successfully — including the settings page the user just deleted the org
from) and checks whether it exists in the (stale) organization list. Since
the stale list still contained the deleted org, the app redirected right
back into
/<deleted-org-slug>, which 404s server-side and leaves theuser stuck.
Fix
lastActiveOrgfromlocalStoragewhen it points at theorganization that was just deleted (new helper
clearStaleLastActiveOrginsrc/services/organizationService.ts, unittested).
/with a full page load (window.location.href = "/",a pattern already used elsewhere in this codebase) instead of
router.push, so the session/organization list is refetched from theserver and no longer contains the deleted organization.
This is a minimal, targeted fix — no unrelated files were touched.
Testing
src/services/organizationService.test.tscoveringclearStaleLastActiveOrg(removes stale entry, leaves unrelated entryuntouched, no-ops when unset).
npx jest— all pre-existing tests pass except one unrelated,pre-existing failure in
useAutosetup.test.tsx(fails identically onmainbefore this change — asonner/toast mocking issue unrelated tothis fix).
npx tsc --noEmit— no errors.Fixes l3montree-dev/devguard#2131