Skip to content

Commit f3449a9

Browse files
committed
fix: Eager instantiation of featureFlags
This closes a behavioral gap where `.featureFlags` would return a stub before `init()` is called
1 parent 7668e60 commit f3449a9

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

packages/browser/src/__tests__/extension-classes.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe('__extensionClasses enrollment', () => {
8888

8989
const posthog = new PostHog()
9090

91+
expect(posthog._featureFlags).toBeDefined()
9192
expect(posthog.toolbar).toBeDefined()
9293
expect(posthog.surveys).toBeDefined()
9394
expect(posthog.conversations).toBeDefined()
@@ -101,6 +102,7 @@ describe('__extensionClasses enrollment', () => {
101102

102103
const posthog = new PostHog()
103104

105+
expect(posthog._featureFlags).toBeUndefined()
104106
expect(posthog.toolbar).toBeUndefined()
105107
expect(posthog.surveys).toBeUndefined()
106108
expect(posthog.conversations).toBeUndefined()

packages/browser/src/posthog-core.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ export class PostHog implements PostHogInterface {
442442
// Eagerly construct extensions from default classes so they're available before init().
443443
// For the slim bundle, these remain undefined until _initExtensions sets them from config.
444444
const ext = PostHog.__defaultExtensionClasses ?? {}
445+
this._featureFlags = ext.featureFlags && new ext.featureFlags(this)
445446
this.toolbar = ext.toolbar && new ext.toolbar(this)
446447
this.surveys = ext.surveys && new ext.surveys(this)
447448
this.conversations = ext.conversations && new ext.conversations(this)
@@ -707,7 +708,7 @@ export class PostHog implements PostHogInterface {
707708
// Due to name mangling, we can't easily iterate and assign these extensions
708709
// The assignment needs to also be mangled. Thus, the loop is unrolled.
709710
if (ext.featureFlags) {
710-
this._extensions.push((this._featureFlags = new ext.featureFlags(this)))
711+
this._extensions.push((this._featureFlags = this.featureFlags ?? new ext.featureFlags(this)))
711712
}
712713
if (ext.exceptions) {
713714
this._extensions.push((this.exceptions = this.exceptions ?? new ext.exceptions(this)))

0 commit comments

Comments
 (0)