Skip to content

Fix null environments access in getEnvironmentIdFromKey - #7513

Merged
kyle-ssg merged 4 commits into
Flagsmith:mainfrom
Manoj-M19:fix/null-environment-guard
Jul 29, 2026
Merged

Fix null environments access in getEnvironmentIdFromKey#7513
kyle-ssg merged 4 commits into
Flagsmith:mainfrom
Manoj-M19:fix/null-environment-guard

Conversation

@Manoj-M19

Copy link
Copy Markdown
Contributor

Fixes a runtime error caused by store.model.environments being accessed before project data is fully loaded.

Adds a guard in getEnvironmentIdFromKey to safely handle cases where store.model or environments are temporarily null during async loading flows.

Issue

Sentry Issue: FLAGSMITH-FRONTEND-4N3

Testing
Ran the application locally
Refreshed and navigated between routes to verify no runtime crash occurs
Confirmed the application still loads correctly

@Manoj-M19
Manoj-M19 requested a review from a team as a code owner May 13, 2026 20:38
@Manoj-M19
Manoj-M19 requested review from Zaimwa9 and removed request for a team May 13, 2026 20:38

@claude claude 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@vercel

vercel Bot commented May 13, 2026

Copy link
Copy Markdown

@Manoj-M19 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 May 13, 2026
kyle-ssg added 2 commits July 29, 2026 12:47
Addresses review feedback: collapse the `!store.model || !store.model.environments`
checks to `!store.model?.environments`, and fix the indentation and trailing
whitespace in the guarded blocks.
Resolves the overlap with Flagsmith#7778, which added a `store.model` guard to
getEnvironmentIdFromKey on main. Keeps this branch's version, which also
guards `environments` and uses optional chaining.
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The project store now defensively handles missing environment collections in getEnvironmentIdFromKey and getIsVersioned. Both methods return null when store.model?.environments is unavailable; otherwise, their existing environment lookup behaviour is retained.

Estimated code review effort: 1 (Trivial) | ~3 minutes

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks

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

Comment @coderabbitai help to get the list of available commands.

@kyle-ssg
kyle-ssg requested a review from talissoncosta July 29, 2026 11:57
Applies the same style to the `env && env.x` returns in getEnvironmentIdFromKey
and getIsVersioned. lodash `find` returns undefined when there is no match, so
the behaviour is unchanged.
Comment thread frontend/common/stores/project-store.js Outdated
Comment thread frontend/common/stores/project-store.js Outdated

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
frontend/common/stores/project-store.js (1)

179-183: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Do not propagate null into environment requests.

When environments is temporarily unavailable, this returns null, despite getEnvironmentIdFromKey being typed as number | undefined. Consumers interpolate the result into URLs, producing environment=null and potentially fetching incorrectly or triggering a 404. Preserve the existing return contract and ensure callers defer the request or omit the filter until the environment ID is available.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2b1657b9-8e1a-49dd-8217-d52ac2b4787c

📥 Commits

Reviewing files that changed from the base of the PR and between 08f54d6 and 7d00cd6.

📒 Files selected for processing (1)
  • frontend/common/stores/project-store.js

@kyle-ssg
kyle-ssg merged commit 6b0a54a into Flagsmith:main Jul 29, 2026
3 of 6 checks passed
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.

4 participants