Repository navigation
feat: add an onFeatureFlags listener you can unsubscribe - #670
turnipdabeets wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
PostHog Review · Standard · reviewed 34d79f4: 2 Should fix.
See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.
posthog-flutter Compliance ReportDate: 2026-10-30 16:30:49 UTC ✅ All Tests Passed!45/45 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 16/16 tests passed View Details
|
5a85f1b to
2f7955e
Compare
de3a190 to
0a7ab2a
Compare
2f7955e to
a194366
Compare
dustinbyrne
left a comment
There was a problem hiding this comment.
The subscription API and ordinary delivery/replay paths look sound. Two dispatch-boundary cases remain: a config callback can restore an invalidated snapshot after reset/close, and a synchronous config-callback exception prevents runtime subscribers from receiving the load. Both reproduce through the public Dart API and IO channel harness.
AI-assisted review.
dustinbyrne
left a comment
There was a problem hiding this comment.
The previous web-loader, stale-native-notification and synchronous-replay findings are resolved in the focused regressions. Two runtime subscription routes remain incomplete: native auto-init does not activate the bridge when subscription is the first Dart operation, and Android manual reloads update neither subscribers nor their replay snapshot. Both reproduce independently; native 4.0 build availability remains a separate prerequisite.
AI-assisted review.
fd88c7e to
7eebbca
Compare
…FeatureFlags, update API snapshot
… callback A config callback that threw kept listeners from getting the load, and a reset() or close() it started was undone when the load was cached after it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oader A registration whose unsubscribe isn't stored yet (close() during the synchronous replay) or never arrives (the loader snippet's stub) now goes inert once setup() or close() runs again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dart bumps a generation when reset() or close() clears the listener registry and sends it with setup, reset and close. Android and iOS tag each onFeatureFlags notification with the generation they had when it fired, and Dart drops ones from an earlier generation, so the previous user's flags can't repopulate the replay cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With native auto-init, Posthog().onFeatureFlags() can be the app's only Dart SDK call, and nothing created the platform that installs the channel handler, so native loads never reached the listener. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…teners posthog-android passes a manual reload only to its completion, so no onFeatureFlagsCallback arrives and listeners missed the load while new ones replayed the older snapshot. A reload that finishes after a reset or close is still dropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26f2755 to
4d81d9e
Compare
💡 Motivation and Context
Brings Flutter to parity with posthog-ios 4.0 (
PostHogSDK.shared.onFeatureFlags(_:)) and posthog-android 4.0 (PostHog.onFeatureFlags(callback), PostHog/posthog-android#878). Until now Flutter only hadPostHogConfig.onFeatureFlags, which is fixed atsetup()and can't be removed.Same semantics as iOS and Android:
reloadFeatureFlags(),identify()/group()/reset()), witherrorsLoadingand the last known flags on failure.setup()and survivesclose()/setup().reset()andclose()drop the cached load, so a new listener never gets the previous user's flags.Implementation: a Dart-side registry (
FeatureFlagsListeners,@internal). Each platform delivers to it next to the existing config callback: method channel (iOS/Android/macOS), desktop client (Windows/Linux), and posthog-js on web. No native changes, since native already forwards every load.Web now registers its posthog-js
onFeatureFlagslistener even withoutconfig.onFeatureFlags, and unsubscribes it onclose()and before re-registering on repeatedsetup(). Before, everysetup()added another JS listener, so the config callback ran once persetup()call.A throwing listener is logged and doesn't stop the others. Web skips registration when the page's
posthogobject has noonFeatureFlags(test stubs), instead of throwing duringsetup().Stacked on #664 (needs
PostHogFeatureFlagsLoaded).💚 How did you test it?
test/feature_flags_listeners_test.dart: delivery until unsubscribe, one replay, replay skipped when a newer load wins, no replay after clear, unsubscribe during delivery, a throwing listener.posthog_flutter_io_test), desktop (posthog_flutter_desktop_test), web (posthog_flutter_web_setup_test, also covers repeated setup delivering once).posthog_test: no replay of flags loaded beforereset()/close().flutter analyzeclean,flutter testandflutter test --platform chrome test/posthog_flutter_web_setup_test.dartpass.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code wrote this while aligning the flags API across iOS 4, Android 4 and Flutter 6. Kept the listener in Dart instead of adding a native subscribe/unsubscribe channel method: native already pushes every load to Dart, so a Dart registry covers all five platforms with one implementation.
🤖 Generated with Claude Code