Fix null environments access in getEnvironmentIdFromKey - #7513
Conversation
|
@Manoj-M19 is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
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.
📝 WalkthroughWalkthroughThe project store now defensively handles missing environment collections in Estimated code review effort: 1 (Trivial) | ~3 minutes ✨ Finishing Touches 💡 1🛠️ 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. Comment |
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.
There was a problem hiding this comment.
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 liftDo not propagate
nullinto environment requests.When
environmentsis temporarily unavailable, this returnsnull, despitegetEnvironmentIdFromKeybeing typed asnumber | undefined. Consumers interpolate the result into URLs, producingenvironment=nulland 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
📒 Files selected for processing (1)
frontend/common/stores/project-store.js
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