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: Add warnings if feature flags are read before initialization #21201

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,13 @@ declare global {
}

export function isFeatureEnabled(feature: FeatureFlag) {
return window && window.featureFlags && !!window.featureFlags[feature];
try {
return !!window.featureFlags[feature];
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Failed to query feature flag ${feature} (see error below)`);
// eslint-disable-next-line no-console
console.error(error);
return false;
}
}
10 changes: 9 additions & 1 deletion superset-frontend/src/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ export function initFeatureFlags(featureFlags: FeatureFlagMap) {
}

export function isFeatureEnabled(feature: FeatureFlag) {
return window && window.featureFlags && !!window.featureFlags[feature];
Copy link
Member

Choose a reason for hiding this comment

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

I think this is fine for this PR, but it seems like we should just be importing the above Superset UI module everywhere and avoid having duplicate code in the project. Maybe we can clean that up in some other PR.

try {
return !!window.featureFlags[feature];
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Failed to query feature flag ${feature} (see error below)`);
// eslint-disable-next-line no-console
console.error(error);
return false;
}
}