Skip to content

fix(Projects): Remove N+1 calls to get project environments - #8957

Merged
talissoncosta merged 8 commits into
mainfrom
fix/projects-list-environments-7949
Nov 18, 2026
Merged

talissoncosta merged 8 commits into
mainfrom
fix/projects-list-environments-7949

Conversation

@talissoncosta

@talissoncosta talissoncosta commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • 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 #7949

Loading the organisation fetched environments for every project, only so project cards could link to the first one. Large organisations hit rate limits. Environments now load when a project is opened.

  • N+1 fix: project cards link to /project/:id; ProjectRedirectPage loads that project's environments and redirects to the first by name.
  • Permission dialogs: load the selected project's environments themselves, with an error and Try again if they fail (EmptyState gets status='error' and onRetry).
  • Project pages wait for ProjectStore: the App.js loader used to finish after every environment loaded, which also covered ProjectStore. Without the N+1 it finishes first, so it now waits for both.

Chromatic: EmptyState's default icon colour moves from #9DA4AE to the colorIconSecondary token (a little darker in light mode), so every empty state shows a small change.

How did you test this code?

  • Against staging: the Projects page makes no environment requests; opening a project lands on its first environment; both permission dialogs list the right environments when switching projects, and show Try again on a failed load; with environments/?project= delayed, identity pages and project settings load correctly.
  • E2E: new user-permissions-test.pw.ts. Unit tests for the landing path and environment sort.

View guided diff Turn on auto-fix

@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
flagsmith-frontend-preview Ready Ready Preview Nov 18, 2026 4:49pm UTC
flagsmith-frontend-staging Ready Ready Preview Nov 18, 2026 4:49pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
docs Ignored Ignored Preview Nov 18, 2026 4:49pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

The organisation store now loads sorted projects without fetching environments for each project. Components retrieve environments through queries or ProjectStore where needed. Permissions components handle environment loading and error states. Project links open the project route, where a redirect selects a landing path from sorted environments. The changes also add sorting and landing-path utilities with tests, and update the end-to-end helper to wait for an environment URL.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Severity of issue fixed: Medium

Merge Risk: Moderate · previous review 140f3

The Create Environment page can offer a clone source from the previously viewed project after switching projects. Choosing one creates the environment in the wrong project. Failed environment loads also leave the clone selector and the feature-toggle confirmation without an error or retry. Fix the stale clone-source handling before merging; the failure-state gaps are smaller follow-ups.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-8957 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-8957 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-8957 Finished ✅ Results ✅
ghcr.io/flagsmith/flagsmith:pr-8957 Finished ✅ Results ✅
ghcr.io/flagsmith/flagsmith-frontend:pr-8957 Finished ✅ Results ✅
ghcr.io/flagsmith/flagsmith-frontend:pr-8957 Finished ✅ Results ✅
ghcr.io/flagsmith/flagsmith-frontend:pr-8957 Finished ✅ Results ✅
ghcr.io/flagsmith/flagsmith-e2e:pr-8957 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-8957 Finished ✅ Results ✅
ghcr.io/flagsmith/flagsmith-api:pr-8957 Finished ✅ Results ✅
ghcr.io/flagsmith/flagsmith:pr-8957 Finished ✅ Results ✅
ghcr.io/flagsmith/flagsmith-private-cloud:pr-8957 Finished ✅ Results ✅
ghcr.io/flagsmith/flagsmith-frontend:pr-8957 Finished ✅ Results ✅
ghcr.io/flagsmith/flagsmith-private-cloud:pr-8957 Finished ✅ Results ✅

@github-actions github-actions Bot added the fix label Nov 13, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 15 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: ff7b7848-3a7c-49b7-9735-211810ad6631
Commits

Reviewing files that changed from the base of the PR and between 450eb5d and 1aa88f0.

Files selected for processing: 15

  • frontend/common/hooks/__tests__/useEnvironmentsByName.test.ts
  • frontend/common/hooks/useEnvironmentsByName.ts
  • frontend/common/stores/organisation-store.js
  • frontend/common/types/responses.ts
  • frontend/common/utils/__tests__/environmentFixture.ts
  • frontend/common/utils/__tests__/projectLandingPath.test.ts
  • frontend/common/utils/projectLandingPath.ts
  • frontend/e2e/helpers/e2e-helpers.playwright.ts
  • frontend/web/components/EnvironmentsLoadState.tsx
  • frontend/web/components/PermissionsTabs.tsx
  • frontend/web/components/ProjectManageWidget.tsx
  • frontend/web/components/inspect-permissions/EnvironmentPermissions.tsx
  • frontend/web/components/inspect-permissions/InspectPermissions.tsx
  • frontend/web/components/pages/CreateEnvironmentPage.tsx
  • frontend/web/components/pages/ProjectRedirectPage.tsx

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #23426 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  1 minute, 11 seconds
commit  fd004cf
info  🔄 Run: #23426 (attempt 1)

🗂️ Previous results
✅ private-cloud · depot-ubuntu-latest-16 — run #23427 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  5 passed

Details

stats  5 tests across 4 suites
duration  35.3 seconds
commit  4f85618
info  🔄 Run: #23427 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-arm-16 — run #23427 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  6 passed

Details

stats  6 tests across 4 suites
duration  3.8 seconds
commit  4f85618
info  🔄 Run: #23427 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-16 — run #23426 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  4 passed

Details

stats  4 tests across 4 suites
duration  51.8 seconds
commit  fd004cf
info  🔄 Run: #23426 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #23427 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  36.7 seconds
commit  4f85618
info  🔄 Run: #23427 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #23427 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  32.2 seconds
commit  4f85618
info  🔄 Run: #23427 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #23426 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  35.2 seconds
commit  fd004cf
info  🔄 Run: #23426 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #23426 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  31.2 seconds
commit  fd004cf
info  🔄 Run: #23426 (attempt 1)

❌ private-cloud · depot-ubuntu-latest-arm-16 — run #23425 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

failed  2 failed

Details

stats  2 tests across 1 suite
duration  22.9 seconds
commit  78a944e
info  📦 Artifacts: View test results and HTML report
🔄 Run: #23425 (attempt 1)

Failed tests

firefox › tests/user-permissions-test.pw.ts › User permissions dialogs › Manage user lists only the picked project's environments @enterprise
firefox › tests/user-permissions-test.pw.ts › User permissions dialogs › Inspect permissions lists only the picked project's environments @enterprise

❌ private-cloud · depot-ubuntu-latest-arm-16 — run #23423 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

failed  2 failed

Details

stats  2 tests across 1 suite
duration  23.3 seconds
commit  e2663b3
info  📦 Artifacts: View test results and HTML report
🔄 Run: #23423 (attempt 1)

Failed tests

firefox › tests/user-permissions-test.pw.ts › User permissions dialogs › Manage user lists only the picked project's environments @enterprise
firefox › tests/user-permissions-test.pw.ts › User permissions dialogs › Inspect permissions lists only the picked project's environments @enterprise

❌ private-cloud · depot-ubuntu-latest-arm-16 — run #23424 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

failed  2 failed

Details

stats  2 tests across 1 suite
duration  23.2 seconds
commit  27fda93
info  📦 Artifacts: View test results and HTML report
🔄 Run: #23424 (attempt 1)

Failed tests

firefox › tests/user-permissions-test.pw.ts › User permissions dialogs › Manage user lists only the picked project's environments @enterprise
firefox › tests/user-permissions-test.pw.ts › User permissions dialogs › Inspect permissions lists only the picked project's environments @enterprise

✅ oss · depot-ubuntu-latest-arm-16 — run #23425 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  36.9 seconds
commit  78a944e
info  🔄 Run: #23425 (attempt 1)

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Visual Regression

25 screenshots compared. See report for details.
View full report

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 10 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 11 files (changes from recent commits).

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.

View guided diff | Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 6 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 3 unresolved issues from previous reviews.

View guided diff | Turn on auto-fix | Re-trigger cubic

@Zaimwa9 Zaimwa9 left a comment

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.

Ok honestly not a lot to comment given the piece of work. Just 2 improvements to add maybe in Nav and we should be good to go

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 5 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Removes the per-project environments N+1 by loading environments on project open, but an acknowledged duplicate environments request per project open remains deferred; the request-cost tradeoff needs human sign-off.

Turn on auto-fix | Re-trigger cubic

@Zaimwa9 Zaimwa9 left a comment

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.

One small regression that could be annoying when it triggers (coming straight to the identity page), after this one we should be good

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 6 files (changes from recent commits).

Confidence score: 3/5

  • In useEdgeIdentities.ts, Compare can briefly offer the wrong identities while the project is unresolved. Gate the identity selectors on isReady so they wait for the project to load.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="frontend/common/hooks/useEdgeIdentities.ts">

<violation number="1" location="frontend/common/hooks/useEdgeIdentities.ts:11">
P2: An unresolved project is treated as Core, so Compare can briefly load and offer the wrong identities before switching to Edge. Gate the identity selectors on `isReady` instead of using this value while the project is still loading.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

talissoncosta and others added 4 commits November 18, 2026 13:27
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Project cards link to /project/:id, which redirects to the first
environment by name, and the permission dialogs load the selected
project's environments themselves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… dialogs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The loader used to finish after every project's environments loaded, which
also covered ProjectStore. Without the N+1 it finishes first, so pages
reading Edge from ProjectStore saw false on a direct load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@talissoncosta

talissoncosta commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@Zaimwa9 I've cut this PR down to the N+1 fix, as it had grown well past the issue.

The RTK Query moves, modal changes and other clean-ups are dropped, and I'll bring back what's worth it as separate PRs. Identities E2E coverage is in #9011.

talissoncosta and others added 2 commits November 18, 2026 13:40
…them

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 7 files (changes from recent commits).

Requires human review: Auto-approval skipped because cubic reviewed only this push, not the earlier force-push. Comment @cubic review to review the whole pull request.

Turn on auto-fix | Re-trigger cubic

talissoncosta and others added 2 commits November 18, 2026 13:46
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hook

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files (changes from recent commits).

Requires human review: Auto-approval skipped because cubic reviewed only this push, not the earlier force-push. Comment @cubic review to review the whole pull request.

Turn on auto-fix | Re-trigger cubic

@Zaimwa9 Zaimwa9 left a comment

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.

Thanks for going through the comments

This branch was successfully deployed

2 active deployments
Preview – flagsmith-frontend-staging — 4f856186 Deployed Nov 18, 2026 by vercel[bot]
Preview – flagsmith-frontend-preview — 4f856186 Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimise FE to remove N+1 calls to get project environments

3 participants