Skip to content

feat: Add method to wait for feature flag definitions for local evaluation to be loaded. #447

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

haacked
Copy link
Contributor

@haacked haacked commented Apr 9, 2025

This PR provides a way for users to determine if feature flag definitions for local evaluation are loaded.

Problem

Fixes #445

Changes

This adds a new waitForLocalEvaluationReady method that waits up to 30 seconds (configurable) for local evaluation feature flags to be loaded.

  • It returns true immediately if flags are already loaded.
  • It returns false immediately if local evaluation is not enabled.

This new method waits for the new localEvaluationFlagsLoaded event which is emitted when we retrieve feature flag definitions from the local evaluation endpoint.

This PR also adds a synchronous isLocalEvaluationReady() method that checks the feature flag poller to see if any flags are loaded.

Release info Sub-libraries affected

Bump level

  • Major
  • Minor
  • Patch

Libraries affected

  • All of them
  • posthog-web
  • posthog-node
  • posthog-ai
  • posthog-react-native

Changelog notes

  • Added new waitForLocalEvaluationReady() method used to wait for local evaluation flags to be loaded.
  • Added new localEvaluationFlagsLoaded event which is emitted every time local evaluation flags are loaded.
  • Added new isLocalEvaluationReady() method to quickly check if feature flags are loaded.

haacked added 2 commits April 9, 2025 14:05
This adds a method to wait for local evaluation flags to be loaded.
@haacked haacked requested a review from dmarticus April 9, 2025 21:24
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR adds asynchronous and synchronous methods for checking local evaluation readiness in the PostHog Node.js client.

  • Updated /posthog-node/src/feature-flags.ts to emit a localEvaluationFlagsLoaded event and implement isLocalEvaluationReady.
  • Added waitForLocalEvaluationReady with a configurable timeout in /posthog-node/src/posthog-node.ts.
  • Enhanced /posthog-node/test/feature-flags.spec.ts with tests for flag loading behaviors and edge cases.

3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

Copy link

github-actions bot commented Apr 9, 2025

Size Change: +685 B (+0.41%)

Total Size: 168 kB

Filename Size Change
posthog-node/lib/index.cjs.js 35.2 kB +345 B (+0.99%)
posthog-node/lib/index.esm.js 34.9 kB +340 B (+0.98%)
ℹ️ View Unchanged
Filename Size
posthog-react-native/lib/posthog-core/src/eventemitter.js 1.08 kB
posthog-react-native/lib/posthog-core/src/featureFlagUtils.js 1.51 kB
posthog-react-native/lib/posthog-core/src/index.js 12.6 kB
posthog-react-native/lib/posthog-core/src/lz-string.js 1.42 kB
posthog-react-native/lib/posthog-core/src/surveys-types.js 702 B
posthog-react-native/lib/posthog-core/src/types.js 492 B
posthog-react-native/lib/posthog-core/src/utils.js 956 B
posthog-react-native/lib/posthog-core/src/vendor/uuidv7.js 2.04 kB
posthog-react-native/lib/posthog-react-native/index.js 477 B
posthog-react-native/lib/posthog-react-native/src/autocapture.js 1.8 kB
posthog-react-native/lib/posthog-react-native/src/frameworks/wix-navigation.js 505 B
posthog-react-native/lib/posthog-react-native/src/hooks/useFeatureFlag.js 437 B
posthog-react-native/lib/posthog-react-native/src/hooks/useFeatureFlags.js 362 B
posthog-react-native/lib/posthog-react-native/src/hooks/useNavigationTracker.js 628 B
posthog-react-native/lib/posthog-react-native/src/hooks/usePostHog.js 249 B
posthog-react-native/lib/posthog-react-native/src/legacy.js 810 B
posthog-react-native/lib/posthog-react-native/src/native-deps.js 1.34 kB
posthog-react-native/lib/posthog-react-native/src/optional/OptionalAsyncStorage.js 183 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoApplication.js 215 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoDevice.js 211 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoFileSystem.js 224 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoLocalization.js 216 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeDeviceInfo.js 220 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeLocalize.js 169 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeNavigation.js 218 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeNavigationWix.js 222 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeSafeArea.js 312 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalSessionReplay.js 231 B
posthog-react-native/lib/posthog-react-native/src/posthog-rn.js 4.85 kB
posthog-react-native/lib/posthog-react-native/src/PostHogContext.js 210 B
posthog-react-native/lib/posthog-react-native/src/PostHogProvider.js 1.74 kB
posthog-react-native/lib/posthog-react-native/src/storage.js 1.09 kB
posthog-react-native/lib/posthog-react-native/src/surveys/components/BottomSection.js 630 B
posthog-react-native/lib/posthog-react-native/src/surveys/components/Cancel.js 527 B
posthog-react-native/lib/posthog-react-native/src/surveys/components/ConfirmationMessage.js 742 B
posthog-react-native/lib/posthog-react-native/src/surveys/components/QuestionHeader.js 547 B
posthog-react-native/lib/posthog-react-native/src/surveys/components/QuestionTypes.js 2.81 kB
posthog-react-native/lib/posthog-react-native/src/surveys/components/SurveyModal.js 1.6 kB
posthog-react-native/lib/posthog-react-native/src/surveys/components/Surveys.js 1.82 kB
posthog-react-native/lib/posthog-react-native/src/surveys/getActiveMatchingSurveys.js 907 B
posthog-react-native/lib/posthog-react-native/src/surveys/icons.js 1.86 kB
posthog-react-native/lib/posthog-react-native/src/surveys/index.js 222 B
posthog-react-native/lib/posthog-react-native/src/surveys/PostHogSurveyProvider.js 1.82 kB
posthog-react-native/lib/posthog-react-native/src/surveys/surveys-utils.js 2.35 kB
posthog-react-native/lib/posthog-react-native/src/surveys/useActivatedSurveys.js 1.41 kB
posthog-react-native/lib/posthog-react-native/src/surveys/useSurveyStorage.js 690 B
posthog-react-native/lib/posthog-react-native/src/types.js 90 B
posthog-react-native/lib/posthog-react-native/src/version.js 123 B
posthog-web/lib/index.cjs.js 21.2 kB
posthog-web/lib/index.esm.js 21.2 kB

compressed-size-action

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.

feat(flags): Add a way to determine if local flags are cached
1 participant