Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) O3-4371: useFeatureFlag hook should not log an error if a feature flag does not exist #1273

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/framework/esm-react-utils/src/useFeatureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ export function useFeatureFlag(flagName: string) {
const { flags } = useStore(featureFlagsStore);

useEffect(() => {
if (!flags[flagName]) {
console.error(
`useFeatureFlag: Attempted to get value of non-existent flag "${flagName}". Did you forget to call registerFeatureFlag?`,
);
if (flags[flagName] === undefined) {
console.warn(`useFeatureFlag: Flag "${flagName}" does not exist. Returning false.`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a warning is really any better. We don't need to log anything. It's fine.

}
}, [flags[flagName]]);

return flags[flagName]?.enabled;
// Return false if flag does not exist or if it's off
return flags[flagName]?.enabled ?? false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
Loading