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: feature staying enabled despite its feature flag disabling [LW-12195] #1684

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

szymonmaslowski
Copy link
Contributor

@szymonmaslowski szymonmaslowski commented Jan 30, 2025

Checklist

  • JIRA - <link>
  • Proper tests implemented
  • Screenshots added.

Proposed solution

  • changed from iteration over received FFs from posthog to iterating over all defined feature flags. Posthog does not respond with feature flags that are disabled. Therefore those been switched off didn't change their current value as they were skipped.
  • dead code removal
  • naming improvements
  • removed experiments context (mostly dead code) and implemented a simple useIsPosthogClientInitialized() hook in its place

Testing

  • switch the dapp-explorer (or any other) feature flag off and ensure corresponding feature loads in lace
  • remove your current network from the feature flag payload's allowedNetworks property and ensure the feature does not load for given network
  • ensure payload of given feature flag gets correctly reflected (e.g. dapp explorer hides dapps and categories)

Screenshots

Attach screenshots here if implementation involves some UI changes

@szymonmaslowski szymonmaslowski requested a review from a team as a code owner January 30, 2025 15:49
@szymonmaslowski szymonmaslowski self-assigned this Jan 30, 2025
@@ -60,71 +62,67 @@ export class PostHogClient<Action extends string = string> {
private postHogHost: string = POSTHOG_HOST
) {
if (!this.postHogHost) throw new Error('POSTHOG_HOST url has not been provided');

// eslint-disable-next-line promise/catch-or-return
this.initializePosthogClient().then(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two improvements with initializePosthogClient initializeFromBackgroundStorage:

  • they are not chained - previously posthog initialization was delayed by accessing BG storage
  • extracting to methods improves the readibility of the constructor so it is clear what happens here.

const payload = payloadsByFeature[feature as FeatureFlag];
const allowedNetworks = payload ? payload.allowedNetworks : [];
flags[feature as FeatureFlag] = isFeatureEnabled && allowedNetworks.includes(networkName);
const handleFeatureFlagsUpdate: Parameters<typeof posthog.onFeatureFlags>[0] = async (_, loadedFeatureFlags) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That callback extracted to improve visibility of sending to hasPostHogInitialized$ stream which happens bellow

if (NETWORK_NAME_TO_NETWORK_MAGIC.hasOwnProperty(networkName)) {
const networkMagic = NETWORK_NAME_TO_NETWORK_MAGIC[networkName];

for (const feature in featureFlags) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Iterating over received feature flags seems the reason of the issue.

  • posthog does not send FFs which are disabled
  • recently we introduced initialization of feature flags with a data from BG storage (last known feature flag values)
  • dapp-explorer was set enabled during initialization
  • it was never overridden as we didn;t receive it from posthog

@pczeglik-iohk
Copy link
Contributor

pczeglik-iohk commented Jan 30, 2025

Allure Report

allure-report-publisher generated test report!

processReports: ✅ test report for cb26170b

passed failed skipped flaky total result
Total 33 0 4 0 37

}
}

const backgroundStorage = await this.backgroundServiceUtils.getBackgroundStorage();

if (!PostHogClient.areAllFeatureFlagsEmpty(this.featureFlags)) {
Copy link
Contributor Author

@szymonmaslowski szymonmaslowski Jan 30, 2025

Choose a reason for hiding this comment

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

I don't see a value in checking if flags are empty (the check was looking if there is no single FF key). They cannot be empty as we now iterate over defined list of flags.

If there is any change it is intentional - saving in storage always

// if we were not able to retrieve posthog experiment config, use local config
if (PostHogClient.areAllFeatureFlagsEmpty(this.featureFlags)) {
// override posthog experiment config with local
posthog.featureFlags.override(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to override as we don't access FFs via posthog client directly. We keep them in the this.featureFlagsByNetwork

import { useEffect, useState } from 'react';

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useIsPosthogClientInitialized = () => {
Copy link
Contributor Author

@szymonmaslowski szymonmaslowski Jan 30, 2025

Choose a reason for hiding this comment

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

This hook replaced entire experiments context that was exposing Provider, hook and was providing down the context some unused properties.

@szymonmaslowski szymonmaslowski force-pushed the fix/LW-12195-fix-feature-flags branch 2 times, most recently from ad3171c to 3c9a451 Compare January 31, 2025 09:53
@@ -203,17 +203,17 @@ export const BrowserViewRoutes = ({ routesMap = defaultRoutes }: { routesMap?: R
});

const isLoaded = useMemo(
() => !areExperimentsLoading && !isLoadingWalletInfo && walletInfo && walletState && initialHdDiscoveryCompleted,
[areExperimentsLoading, isLoadingWalletInfo, walletInfo, walletState, initialHdDiscoveryCompleted]
() => posthogClientInitialized && !isLoadingWalletInfo && walletInfo && walletState && initialHdDiscoveryCompleted,
Copy link
Collaborator

Choose a reason for hiding this comment

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

what happens to the application if a request to posthog can't be made?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • if there is last value stored in background storage then client will use it
  • if no value in background storage then every FF disabled.

@szymonmaslowski szymonmaslowski force-pushed the fix/LW-12195-fix-feature-flags branch from 3c9a451 to f5fbcab Compare January 31, 2025 10:47
- removed a check for existance of particular ff in the posthog response from the iteration over all defined feature flags. Posthog does not respond with feature flags that are disabled. Therefore those been switched off didn't change their current value as they were skipped.
- dead code removal
- naming improvements
- removed experiments context (mostly dead code) and implemented a simple useIsPosthogClientInitialized() hook in its place
@szymonmaslowski szymonmaslowski force-pushed the fix/LW-12195-fix-feature-flags branch from f5fbcab to cb26170 Compare January 31, 2025 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants