Flagsmith / Flagsmith/flagsmith

TypeError: Cannot read 'use_v2_feature_versioning' of undefined in feature-list-store

Open
#6,535 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
6.6k
Forks
567
Avg merge
1d 13h
Merged PRs (30d)
121

Description

## Bug Description

Users encounter a TypeError when editing/toggling features that prevents the operation from completing.

**Error**: `TypeError: Cannot read properties of undefined (reading 'use_v2_feature_versioning')`

**Sentry Issue**: https://flagsmith.sentry.io/issues/7188659117/

## Impact

- **5 events / 5 users** in 1 day
- First seen: 2026-01-14
- Blocks feature editing operations

## Steps to Reproduce

1. Open Flagsmith in multiple browser tabs with different projects
2. Navigate between projects in different tabs
3. On the Features page, click the toggle switch on any feature
4. Click "Confirm" in the toggle confirmation modal
5. Error occurs because `ProjectStore` has cached environments from a different project

**Alternative scenario:**
1. Have a browser tab open on the Features page
2. Let the session remain idle for an extended period
3. Try to toggle a feature
4. `ProjectStore` may be stale or out of sync

## Root Cause

In `frontend/common/stores/feature-list-store.ts` lines 276-278:

```typescript
const env = ProjectStore.getEnvironment(environmentId)

if (env.use_v2_feature_versioning) { // env can be undefined
```

`ProjectStore.getEnvironment()` returns `undefined` when the environment isn't found in the cached environments list.

## Suggested Fix

Add null check:

```typescript
const env = ProjectStore.getEnvironment(environmentId)

if (!env) {
console.error(`Environment ${environmentId} not found in ProjectStore`)
store.goneABitWest()
return
}

if (env.use_v2_feature_versioning) {
```

## Files to Modify

- `frontend/common/stores/feature-list-store.ts` (lines 276-278)
- Same pattern may exist in `editFeatureStateChangeRequest` function

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.