Skip to content

fix(frontend): redirect to default environment when URL env id is ialid#7734

Open
SketchRudy wants to merge 1 commit into
Flagsmith:mainfrom
mmaslov007:7446-redirect-default-environment
Open

fix(frontend): redirect to default environment when URL env id is ialid#7734
SketchRudy wants to merge 1 commit into
Flagsmith:mainfrom
mmaslov007:7446-redirect-default-environment

Conversation

@SketchRudy

Copy link
Copy Markdown
  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #7446

When a URL contains an environment identifier that does not correspond to a real environment for the current project (e.g. /project/1/environment/undefined/features), the dashboard previously showed an infinite loading spinner. Root cause:

  1. useFeatureListWithApiKey returns skipToken when the env api_key does not resolve, so the features query is permanently skipped and isLoading never flips to false.
  2. EnvironmentReadyChecker silently ignored the 404 from useGetEnvironmentQuery and fell through to render its children with the invalid environmentId.

EnvironmentReadyChecker now redirects to /project/:projectId/ when either the loaded environments list does not contain the URL's environmentId, or the per-environment query returns a 404. That route already handles "pick the default environment" via ProjectRedirectPage, so no new default-environment logic is introduced.

The redirect decision is extracted into a pure helper (common/utils/shouldRedirectMissingEnvironment) with unit tests covering nine cases including the ref guard against double-fire, partial loading states, zero-environment projects, and non-404 errors.

Notes for review

How did you test this code?

Automated

bash cd frontend npx jest common/utils/__tests__/shouldRedirectMissingEnvironment.test.ts ​

Expected: 9 passed. Type-check and lint are clean on the changed files.

Manual reproduction

With a local stack (ENV=local npm run dev against an API on localhost:8000), logged into a project with at least one environment:

  1. Visit /project/1/environment/undefined/features - before: infinite spinner + repeating environments/undefined/ 404s; after: URL flips to the default environment, list renders.
  2. Visit a valid env URL - no redirect, normal load.
  3. Visit /project/1/environment/create - env-create flow loads (checker skipped).
  4. Visit /project/99999/environment/undefined/features - bounces through /project/99999/ and inherits ProjectRedirectPage's org-home fallback.

…alid

Closes Flagsmith#7446

When a URL contains an environment identifier that does not correspond
to a real environment for the current project (e.g.
/project/1/environment/undefined/features), the dashboard previously
showed an infinite loading spinner. The root cause:

1. useFeatureListWithApiKey returns skipToken when the env api_key does
   not resolve, so the features query is permanently skipped and
   isLoading never flips to false.
2. EnvironmentReadyChecker silently ignored the 404 from
   useGetEnvironmentQuery and fell through to render children with the
   invalid environmentId.

EnvironmentReadyChecker now redirects to /project/:projectId/ when
either the loaded environments list does not contain the URL's
environmentId, or the per-environment query returns 404. That route
already handles "pick the default environment" via ProjectRedirectPage,
so no new default-environment logic is introduced.

The redirect decision is extracted into a pure helper
(common/utils/shouldRedirectMissingEnvironment) with unit tests covering
nine cases including the ref guard against double-fire, partial loading
states, zero-environment projects, and non-404 errors.

Also switches the checker from useRouteMatch to useRouteContext to match
the convention used by FeaturesPage and ProjectRedirectPage, and removes
the now-unused match prop passed in by ParameterizedRoute.

Acknowledges the reverted PR Flagsmith#7284 history: that attempt rendered a
NotFoundState UX which was reverted by Flagsmith#7312; this PR takes the redirect
approach explicitly called out in Flagsmith#7446's acceptance criterion.
@SketchRudy SketchRudy requested a review from a team as a code owner June 9, 2026 05:39
@SketchRudy SketchRudy requested review from kyle-ssg and removed request for a team June 9, 2026 05:39
@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

@SketchRudy is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the front-end Issue related to the React Front End Dashboard label Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Features list loops in loading forever

2 participants