Skip to content

Conversation

@marandaneto
Copy link
Member

@marandaneto marandaneto commented Nov 6, 2025

💡 Motivation and Context

port fixes from PostHog/posthog-android#315

💚 How did you test it?

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

@marandaneto marandaneto requested a review from a team as a code owner November 6, 2025 08:40

/// Internal implementation for resetting group properties.
private func resetGroupPropertiesForFlags(groupType: String?) {
private func internalResetGroupPropertiesForFlags(groupType: String?, reloadFeatureFlags: Bool) {
Copy link
Member Author

@marandaneto marandaneto Nov 6, 2025

Choose a reason for hiding this comment

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

to avoid name clash with the new method

@marandaneto marandaneto requested a review from a team November 6, 2025 08:45
@posthog-project-board-bot posthog-project-board-bot bot moved this to In Review in Feature Flags Nov 6, 2025
/// let flagValue = PostHogSDK.shared.isFeatureEnabled("feature")
/// ```
///
/// - Note: This method does not automatically reload feature flags. Call `reloadFeatureFlags()`
Copy link
Member Author

@marandaneto marandaneto Nov 6, 2025

Choose a reason for hiding this comment

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

people might be calling resetPersonPropertiesForFlags and then reloadFeatureFlags
2 options:
we default reloadFeatureFlags to false to avoid calling reloadFeatureFlags twice
we let it as is since the loadingFeatureFlagsLock and loadingFeatureFlags will do the job and bail out immediatelly on the 2nd call
i chose the later, let me know if thats not ideal.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah the only problem I see is that the reloadFeatureFlags callback will never be called.

Maybe not for this PR but we need a way to save the callback if there's another reload request in-flight and call it once the original request finishes

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure i follow, which callback?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is similar to call identify, we just call reloadFeatureFlags and dont allow the user to pass a callback unless they want to relaod it manually passing a callback

Copy link
Member Author

Choose a reason for hiding this comment

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

if thats the case, they could call the method with reloadFeatureFlags: false and then manually reloadFeatureFlags(...)

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if we should add a bool parameters to reloadFeatureFlags then that will reset person or group parameters

not sure i understand, mind clarifying?

Copy link
Contributor

Choose a reason for hiding this comment

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

What I mean is maybe we can give people a way to do:

PostHog.shared.reloadFeatureFlags(
  resetPersonProperties: true
) {
  // completion handler
}

Instead of them calling resetPersonPropertiesForFlags and then reloadFeatureFlags

Copy link
Member Author

Choose a reason for hiding this comment

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

i dont think thats a good API
there are so many reasons to reload the flags, in this case the reloadFeatureFlags method would have a bunch of things (reset groups, reset all, etc).
its a much more natural API to eg
resetPersonPropertiesForFlags and flags are automatically reloaded unless opt out
or resetPersonPropertiesForFlags never reloads and the user has to reload manually, it seems a much better UX IMO
its the intention and the side effect and not the other way around if that makes sense

Copy link
Member Author

Choose a reason for hiding this comment

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

i will merge to unblock the fix

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeap agreed. I think a future improvement is saving the callbacks from reloadFeatureFlags calls in memory and calling them whenever flags reload (for whatever reason) so that we make sure that the logic that people attach there always gets executed

Copy link
Contributor

@ioannisj ioannisj left a comment

Choose a reason for hiding this comment

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

Lg left a few comments from discussion

/// let flagValue = PostHogSDK.shared.isFeatureEnabled("feature")
/// ```
///
/// - Note: This method does not automatically reload feature flags. Call `reloadFeatureFlags()`
Copy link
Contributor

Choose a reason for hiding this comment

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

people might be calling resetPersonPropertiesForFlags and then reloadFeatureFlags

So if they call reloadFeatureFlags with a callback the code will bail out because there's another call to flags by resetPersonPropertiesForFlags right?

/// let flagValue = PostHogSDK.shared.isFeatureEnabled("feature")
/// ```
///
/// - Note: This method does not automatically reload feature flags. Call `reloadFeatureFlags()`
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should add a bool parameters to reloadFeatureFlags then that will reset person or group parameters

@github-project-automation github-project-automation bot moved this from In Review to Approved in Feature Flags Nov 6, 2025
@posthog-project-board-bot posthog-project-board-bot bot moved this from Approved to In Review in Feature Flags Nov 6, 2025
Copy link

@dustinbyrne dustinbyrne left a comment

Choose a reason for hiding this comment

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

Beat me to it! 😄

The thread lock on reload preventing two /flags calls sounds totally reasonable.

@github-project-automation github-project-automation bot moved this from In Review to Approved in Feature Flags Nov 6, 2025
@marandaneto marandaneto merged commit 05c1a8e into main Nov 7, 2025
11 checks passed
@marandaneto marandaneto deleted the fix/group-and-default-properties-flags branch November 7, 2025 16:20
@github-project-automation github-project-automation bot moved this from Approved to Done in Feature Flags Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants