-
Notifications
You must be signed in to change notification settings - Fork 213
fix: use ph persistence instead of localStorage on surveys #2635
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
base: main
Are you sure you want to change the base?
fix: use ph persistence instead of localStorage on surveys #2635
Conversation
|
@alexedwardjones is attempting to deploy a commit to the PostHog Team on Vercel. A member of the Team first needs to authorize 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.
12 files reviewed, 1 comment
| surveyKeys.push(key) | ||
| } | ||
| clearFromPersistenceWithLocalStorageFallback(LAST_SEEN_SURVEY_DATE_KEY, this._instance) | ||
| if (!this._instance.persistence?.props || this._instance.persistence?.props.length === 0) { |
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.
logic: props is an object (Record<string, Property>), not an array. Checking .length === 0 will always evaluate to undefined === 0 (false), so this early return never works when props is empty. Use Object.keys(this._instance.persistence.props).length === 0 instead.
| if (!this._instance.persistence?.props || this._instance.persistence?.props.length === 0) { | |
| if (!this._instance.persistence?.props || Object.keys(this._instance.persistence.props).length === 0) { |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/browser/src/posthog-surveys.ts
Line: 64:64
Comment:
**logic:** `props` is an object (Record<string, Property>), not an array. Checking `.length === 0` will always evaluate to `undefined === 0` (false), so this early return never works when props is empty. Use `Object.keys(this._instance.persistence.props).length === 0` instead.
```suggestion
if (!this._instance.persistence?.props || Object.keys(this._instance.persistence.props).length === 0) {
```
How can I resolve this? If you propose a fix, please make it concise.
lucasheriques
left a comment
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.
hey Alex! thanks for getting this back on. I'll review and test today and get back to you ASAP
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the |
Problem
A fix went in for local storage usage in surveys but it was reverted due to a bug.
My understanding is that the bug was related to
persistence.isDisabled is not a function. This PR reapplies the fix with a few extra checks around the isDisabled function and falls back to_disabledif necessary.Changes
Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes