-
Notifications
You must be signed in to change notification settings - Fork 143
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: initializing surveys twice and calling survey shown/dismissed more than once per survey #1747
Conversation
…re than once per survey
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here: app.greptile.com/review/github.
1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile
Size Change: +6.41 kB (+0.19%) Total Size: 3.32 MB
ℹ️ View Unchanged
|
`/api/surveys/?token=${this.instance.config.token}` | ||
), | ||
method: 'GET', | ||
callback: (response) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there's no connection, is the callback
still called so we can reset the _isFetchingSurveys
?
or is it gonna throw and the catch
will reset it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be tested, but I believe callback
will still be called even if there's no connection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, and this test actually calls the callback in the test, so its not really testing what it would happen in case of a timeout/no connection
posthog-js/src/posthog-surveys.ts Lines 257 to 259 in 8a82b35
i think this should be removed and let be init only by loadIfEnabled
|
posthog-js/src/posthog-surveys.ts Lines 224 to 226 in 8a82b35
i think this should only be init if the _surveyManager was also properly inited, _surveyManager might fail because of eg 'Could not load surveys script' but the _surveyEventReceiver is now in a limbo state
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropping a couple of very cheap 2 Brazilian cents
`/api/surveys/?token=${this.instance.config.token}` | ||
), | ||
method: 'GET', | ||
callback: (response) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be tested, but I believe callback
will still be called even if there's no connection
@marandaneto edit: actually, nevermind, as we need to make sure If surveys is disabled, we still return early so no code is executed. |
if
IMO the test should be wrong then unless I miss something |
@marandaneto agree - I changed the test to first call Also, couple of other changes:
|
Fix race conditions in survey initialization
Problem
Two intermittent race conditions causing duplicate survey displays:
/surveys
endpointSurveyManager
instances being created during PostHog's remote config loading processThese issues don't occur consistently because they depend on:
Solution
Added synchronization mechanisms:
_isFetchingSurveys
flag to prevent concurrent API calls_isInitializingSurveys
flag with proper cleanup to ensure only oneSurveyManager
instance is createdNote: Multiple "Already initializing surveys" logs are expected due to PostHog's config loading retry mechanism, but only one initialization actually occurs.
Testing
Verify:
/surveys
Checklist