PostHog / posthog-js-lite

Reimplementation of posthog-js to be as light and modular as possible.
https://posthog.com/docs/libraries
MIT License
70 stars 36 forks source link

fix: bootstrap flags do not overwrite the current values #259

Closed marandaneto closed 1 month ago

marandaneto commented 2 months ago

Problem

https://posthoghelp.zendesk.com/agent/tickets/17685

Changes

bootstrap values are always overwriting everything even if there are new values cached

Release info Sub-libraries affected

Bump level

Libraries affected

Changelog notes

github-actions[bot] commented 2 months ago

Size Change: +363 B (+0.35%)

Total Size: 105 kB

Filename Size Change
posthog-react-native/lib/posthog-core/src/index.js 9.68 kB +43 B (+0.45%)
posthog-web/lib/index.cjs.js 17.1 kB +160 B (+0.94%)
posthog-web/lib/index.esm.js 17 kB +160 B (+0.95%)
ℹ️ View Unchanged | Filename | Size | | :--- | :---: | | `posthog-node/lib/index.cjs.js` | 20 kB | | `posthog-node/lib/index.esm.js` | 19.9 kB | | `posthog-react-native/lib/posthog-core/src/eventemitter.js` | 1.08 kB | | `posthog-react-native/lib/posthog-core/src/lz-string.js` | 1.42 kB | | `posthog-react-native/lib/posthog-core/src/types.js` | 365 B | | `posthog-react-native/lib/posthog-core/src/utils.js` | 822 B | | `posthog-react-native/lib/posthog-core/src/vendor/uuidv7.js` | 2.04 kB | | `posthog-react-native/lib/posthog-react-native/index.js` | 485 B | | `posthog-react-native/lib/posthog-react-native/src/autocapture.js` | 1.78 kB | | `posthog-react-native/lib/posthog-react-native/src/frameworks/wix-navigation.js` | 651 B | | `posthog-react-native/lib/posthog-react-native/src/hooks/useFeatureFlag.js` | 437 B | | `posthog-react-native/lib/posthog-react-native/src/hooks/useFeatureFlags.js` | 362 B | | `posthog-react-native/lib/posthog-react-native/src/hooks/useLifecycleTracker.js` | 416 B | | `posthog-react-native/lib/posthog-react-native/src/hooks/useNavigationTracker.js` | 628 B | | `posthog-react-native/lib/posthog-react-native/src/hooks/usePostHog.js` | 249 B | | `posthog-react-native/lib/posthog-react-native/src/legacy.js` | 810 B | | `posthog-react-native/lib/posthog-react-native/src/native-deps.js` | 1.17 kB | | `posthog-react-native/lib/posthog-react-native/src/optional/OptionalAsyncStorage.js` | 183 B | | `posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoApplication.js` | 215 B | | `posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoDevice.js` | 211 B | | `posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoFileSystem.js` | 224 B | | `posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoLocalization.js` | 216 B | | `posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeDeviceInfo.js` | 220 B | | `posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeNavigation.js` | 218 B | | `posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeNavigationWix.js` | 222 B | | `posthog-react-native/lib/posthog-react-native/src/optional/OptionalSessionReplay.js` | 231 B | | `posthog-react-native/lib/posthog-react-native/src/posthog-rn.js` | 3.77 kB | | `posthog-react-native/lib/posthog-react-native/src/PostHogContext.js` | 210 B | | `posthog-react-native/lib/posthog-react-native/src/PostHogProvider.js` | 1.49 kB | | `posthog-react-native/lib/posthog-react-native/src/storage.js` | 1.09 kB | | `posthog-react-native/lib/posthog-react-native/src/types.js` | 90 B | | `posthog-react-native/lib/posthog-react-native/src/version.js` | 122 B |

compressed-size-action

marandaneto commented 2 months ago

logic looks correct for the goal... just the open "product" question for me. once we know the canonical answer we should update posthog.com/docs/feature-flags/bootstrapping (which assumes i'm not the only person that would make the same assumption 🙈)

I think its correct already:

To have your feature flags available immediately, you can initialize PostHog with precomputed values until it has had a chance to fetch them. This is called bootstrapping.

that means, after having the chance to fetch them, use the fetched values and not the bootstraped values anymore, which is what this fix does.

marandaneto commented 1 month ago

259 (files)

Special only to these 2, those are unique identifiers per installation or until the user identify or reset. eg bootstrap with distinctId A, then the user calls identify with distinctId B, the app restarts, and the distinctId should still be B and not the bootstrapped A anymore because the user already identified.