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: Refactor decide loading #1596

Merged
merged 14 commits into from
Dec 13, 2024
Merged

fix: Refactor decide loading #1596

merged 14 commits into from
Dec 13, 2024

Conversation

benjackwhite
Copy link
Collaborator

@benjackwhite benjackwhite commented Dec 11, 2024

Changes

This is a beafy refactor that came out of me having issues around how the RemoteConfig was working.

I basically found our code is super buggy around choosing when to load flags because there were two different things calling decide with a lot of bool properties that weren't really accurate to what they were doing

The main improvements here are:

  • Move all the decide logic into feature flags
  • Make it more deterministic so that the load is always called unless it is actively disabled.
  • Fixes some weirdness I think that existed where in certain cases the flags would actually not be loaded correctly (you can sort of see this that the anon-id wasn't included in one test when it totally should have been!)

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 Dec 11, 2024

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

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Dec 13, 2024 1:15pm

@posthog-bot
Copy link
Collaborator

Hey @benjackwhite! 👋
This pull request seems to contain no description. Please add useful context, rationale, and/or any other information that will help make sense of this change now and in the distant Mars-based future.

Copy link

github-actions bot commented Dec 11, 2024

Size Change: -8.4 kB (-0.26%)

Total Size: 3.2 MB

Filename Size Change
dist/array.full.es5.js 260 kB -838 B (-0.32%)
dist/array.full.js 363 kB -842 B (-0.23%)
dist/array.full.no-external.js 362 kB -842 B (-0.23%)
dist/array.js 177 kB -833 B (-0.47%)
dist/array.no-external.js 176 kB -840 B (-0.47%)
dist/main.js 178 kB -851 B (-0.48%)
dist/module.full.js 363 kB -842 B (-0.23%)
dist/module.full.no-external.js 362 kB -842 B (-0.23%)
dist/module.js 178 kB -833 B (-0.47%)
dist/module.no-external.js 176 kB -840 B (-0.47%)
ℹ️ View Unchanged
Filename Size
dist/all-external-dependencies.js 206 kB
dist/customizations.full.js 12.6 kB
dist/dead-clicks-autocapture.js 14.4 kB
dist/exception-autocapture.js 9.48 kB
dist/external-scripts-loader.js 2.48 kB
dist/recorder-v2.js 115 kB
dist/recorder.js 115 kB
dist/surveys-preview.js 57.6 kB
dist/surveys.js 63.3 kB
dist/tracing-headers.js 1.75 kB
dist/web-vitals.js 10.4 kB

compressed-size-action

@benjackwhite benjackwhite marked this pull request as ready for review December 12, 2024 12:09
@benjackwhite benjackwhite requested a review from a team December 12, 2024 12:09
@@ -33,7 +33,9 @@ export default function App({ Component, pageProps }: AppProps) {
}
}, [])

const localhostDomain = process.env.NEXT_PUBLIC_CROSSDOMAIN ? 'https://localhost:8000' : 'http://localhost:8000'
const localhostDomain = process.env.NEXT_PUBLIC_CROSSDOMAIN
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Helper if runnning on localhost:8010

import '../entrypoints/external-scripts-loader'
import { assignableWindow } from '../utils/globals'

describe('RemoteConfigLoader', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was Decide but now it only handles config loading

@@ -545,6 +548,14 @@ export class PostHog {
}

_onRemoteConfig(config: RemoteConfig) {
if (!(document && document.body)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was in decide before but should actually be here as this is the lower level call.

Copy link
Contributor

@dmarticus dmarticus left a comment

Choose a reason for hiding this comment

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

seems good by my judgement, thanks for taking the time to dive in and pull things apart!

functional_tests/feature-flags.test.ts Show resolved Hide resolved
src/posthog-featureflags.ts Show resolved Hide resolved
src/posthog-featureflags.ts Outdated Show resolved Hide resolved
@benjackwhite benjackwhite added the bump minor Bump minor version when this PR gets merged label Dec 13, 2024
# Conflicts:
#	src/__tests__/featureflags.test.ts
#	src/decide.ts
#	src/posthog-core.ts
#	src/posthog-featureflags.ts
@benjackwhite benjackwhite merged commit 065c911 into main Dec 13, 2024
13 checks passed
@benjackwhite benjackwhite deleted the fix/decide-loading branch December 13, 2024 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump minor Bump minor version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants