@@ -436,6 +436,17 @@ export class PostHog implements PostHogInterface {
436436 this . requestRouter = new RequestRouter ( this )
437437 this . consent = new ConsentManager ( this )
438438 this . externalIntegrations = new ExternalIntegrations ( this )
439+
440+ // Eagerly construct extensions from default classes so they're available before init().
441+ // For the slim bundle, these remain undefined until _initExtensions sets them from config.
442+ const ext = PostHog . __defaultExtensionClasses ?? { }
443+ this . toolbar = ext . toolbar && new ext . toolbar ( this )
444+ this . surveys = ext . surveys && new ext . surveys ( this )
445+ this . conversations = ext . conversations && new ext . conversations ( this )
446+ this . logs = ext . logs && new ext . logs ( this )
447+ this . experiments = ext . experiments && new ext . experiments ( this )
448+ this . exceptions = ext . exceptions && new ext . exceptions ( this )
449+
439450 // NOTE: See the property definition for deprecation notice
440451 this . people = {
441452 set : ( prop : string | Properties , to ?: string , callback ?: RequestCallback ) => {
@@ -713,7 +724,7 @@ export class PostHog implements PostHogInterface {
713724 // Due to name mangling, we can't easily iterate and assign these extensions
714725 // The assignment needs to also be mangled. Thus, the loop is unrolled.
715726 if ( ext . exceptions ) {
716- this . _extensions . push ( ( this . exceptions = new ext . exceptions ( this ) ) )
727+ this . _extensions . push ( ( this . exceptions = this . exceptions ?? new ext . exceptions ( this ) ) )
717728 }
718729 if ( ext . historyAutocapture ) {
719730 this . _extensions . push ( ( this . historyAutocapture = new ext . historyAutocapture ( this ) ) )
@@ -736,13 +747,13 @@ export class PostHog implements PostHogInterface {
736747 this . _extensions . push ( ( this . autocapture = new ext . autocapture ( this ) ) )
737748 }
738749 if ( ext . surveys ) {
739- this . _extensions . push ( ( this . surveys = new ext . surveys ( this ) ) )
750+ this . _extensions . push ( ( this . surveys = this . surveys ?? new ext . surveys ( this ) ) )
740751 }
741752 if ( ext . logs ) {
742- this . _extensions . push ( ( this . logs = new ext . logs ( this ) ) )
753+ this . _extensions . push ( ( this . logs = this . logs ?? new ext . logs ( this ) ) )
743754 }
744755 if ( ext . conversations ) {
745- this . _extensions . push ( ( this . conversations = new ext . conversations ( this ) ) )
756+ this . _extensions . push ( ( this . conversations = this . conversations ?? new ext . conversations ( this ) ) )
746757 }
747758 if ( ext . productTours ) {
748759 this . _extensions . push ( ( this . productTours = new ext . productTours ( this ) ) )
@@ -762,10 +773,10 @@ export class PostHog implements PostHogInterface {
762773 )
763774 }
764775 if ( ext . toolbar ) {
765- this . _extensions . push ( ( this . toolbar = new ext . toolbar ( this ) ) )
776+ this . _extensions . push ( ( this . toolbar = this . toolbar ?? new ext . toolbar ( this ) ) )
766777 }
767778 if ( ext . experiments ) {
768- this . _extensions . push ( ( this . experiments = new ext . experiments ( this ) ) )
779+ this . _extensions . push ( ( this . experiments = this . experiments ?? new ext . experiments ( this ) ) )
769780 }
770781
771782 this . _extensions . forEach ( ( extension ) => {
0 commit comments