Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: useFlag to update initial check of flag store (#41209)

Ali Waseem6d10a4ddade3
diff --git a/packages/common/feature-flags.tsx b/packages/common/feature-flags.tsx
index f9ea005889d..f16d7394634 100644
--- a/packages/common/feature-flags.tsx
+++ b/packages/common/feature-flags.tsx
@@ -164,12 +164,17 @@ const isObjectEmpty = (obj: Object) => {
export function useFlag<T = boolean>(name: string) {
const flagStore = useFeatureFlags()
-
const store = flagStore.configcat
- if (!isObjectEmpty(store) && store[name] === undefined) {
+ // Flag store is empty means config cat is not loaded yet, return false
+ if (isObjectEmpty(store)) {
+ return false
+ }
+
+ if (store[name] === undefined) {
console.error(`Flag key "${name}" does not exist in ConfigCat flag store`)
return false
}
+
return store[name] as T
}