Skip to content
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(): prevent person processing if /decide fails to fetch remote config #1658

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

Conversation

havenbarnes
Copy link
Contributor

@havenbarnes havenbarnes commented Jan 17, 2025

Changes

Context:

In digging through the code it appears that there are two cases where this could potentially happen:

  1. An event is emitted in between _init setting this.config = {} (here) and it getting re-set to the proper value (this seems like an extremely unlikely race condition but we may as well protect against it in _hasPersonProcessing, and while writing unit tests for a potential fix here I discovered that all events would fail to send if posthog.config was an empty object anyway)
  2. /decide fails to return the config values, leaving the SDK to fall back to person_profiles: 'always' (here)

To protect against the second edge case we make the following change: Remove the dependency on the defaultIdentifiedOnly field from /decide. This is the new default, so we should not need this conditional moving forward anyway.

Checklist

  • Tests for new code (see advice on the tests we use)
  • Accounted for the impact of any changes across different browsers
  • Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

Copy link

vercel bot commented Jan 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Jan 18, 2025 0:55am

Copy link

github-actions bot commented Jan 17, 2025

Size Change: -330 B (-0.01%)

Total Size: 3.25 MB

Filename Size Change
dist/array.full.es5.js 265 kB -33 B (-0.01%)
dist/array.full.js 369 kB -33 B (-0.01%)
dist/array.full.no-external.js 367 kB -33 B (-0.01%)
dist/array.js 181 kB -33 B (-0.02%)
dist/array.no-external.js 180 kB -33 B (-0.02%)
dist/main.js 182 kB -33 B (-0.02%)
dist/module.full.js 369 kB -33 B (-0.01%)
dist/module.full.no-external.js 367 kB -33 B (-0.01%)
dist/module.js 181 kB -33 B (-0.02%)
dist/module.no-external.js 180 kB -33 B (-0.02%)
ℹ️ View Unchanged
Filename Size
dist/all-external-dependencies.js 208 kB
dist/customizations.full.js 13.8 kB
dist/dead-clicks-autocapture.js 14.4 kB
dist/exception-autocapture.js 9.48 kB
dist/external-scripts-loader.js 2.64 kB
dist/recorder-v2.js 116 kB
dist/recorder.js 116 kB
dist/surveys-preview.js 58.1 kB
dist/surveys.js 63.8 kB
dist/tracing-headers.js 1.76 kB
dist/web-vitals.js 10.4 kB

compressed-size-action

@@ -35,7 +35,7 @@ export const isObject = (x: unknown): x is Record<string, any> => {
// eslint-disable-next-line posthog-js/no-direct-object-check
return x === Object(x) && !isArray(x)
}
export const isEmptyObject = (x: unknown): x is Record<string, any> => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit of an inaccurate use of the is keyword; my new usage of it in posthog-core.ts gets mad because a false return from isEmptyObject tells TS that this.config is "not an object" when it could instead just be "not an empty object"

@havenbarnes havenbarnes changed the title fix(): prevent person processing if capture is called before SDK config is set fix(): prevent person processing if /decide fails to fetch remote config Jan 18, 2025
@havenbarnes havenbarnes marked this pull request as ready for review January 18, 2025 00:52
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.

1 participant