Bin
2025-12-17 2b99d77d73ba568beff0a549534017caaad8a6de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { FF_NEW_STORAGES, FF_THEME_TOGGLE } from "./flags";
 
const FEATURE_FLAGS = window.APP_SETTINGS?.feature_flags || {};
 
// TODO: remove the override + if statement once LSE and LSO start building
// react the same way and `fflag_fix_front_lsdv_4620_memory_leaks_100723_short` is removed
const FLAGS_OVERRIDE: Record<string, boolean> = {
  // While it's safe to have overrides living here forever,
  // they could disrupt others' work if left. Keep it clean
  // and remove overrides before merging.
  //
  // Add your flags overrides as following:
  // [FF_FLAG_NAME]: boolean
  [FF_NEW_STORAGES]: true,
  [FF_THEME_TOGGLE]: true,
};
 
/**
 * Checks if the Feature Flag is active or not.
 */
export const isActive = (id: string) => {
  const defaultValue = window.APP_SETTINGS?.feature_flags_default_value === true;
  const isSentryOSS =
    window?.APP_SETTINGS?.sentry_environment === "opensource" || process.env.NODE_ENV === "development";
 
  if (isSentryOSS && id in FLAGS_OVERRIDE) return FLAGS_OVERRIDE[id];
  if (id in FEATURE_FLAGS) return FEATURE_FLAGS[id] ?? defaultValue;
 
  return defaultValue;
};
 
/**
 * @deprecated
 */
export const isFlagEnabled = (id: string, flagList: Record<string, boolean>, defaultValue = false) => {
  if (id in flagList) {
    return flagList[id] ?? defaultValue;
  }
  return defaultValue;
};
 
/**
 * Checks if the Feature Flag is active or not.
 *
 * @deprecated Use `isActive` instead
 */
export function isFF(id: string) {
  // TODO: remove the override + if statement once LSE and LSO start building react the same way and fflag_fix_front_lsdv_4620_memory_leaks_100723_short is removed
  const override: Record<string, boolean> = FLAGS_OVERRIDE;
  if (window?.APP_SETTINGS?.sentry_environment === "opensource" && id in override) {
    return override[id];
  }
  return isFlagEnabled(id, FEATURE_FLAGS, window.APP_SETTINGS?.feature_flags_default_value === true);
}
 
export * from "./flags";