@posthog/browser-common 0.9.6 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.js CHANGED
@@ -27,7 +27,7 @@ var __webpack_require__ = {};
27
27
  })();
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
- const packageVersion = "0.9.6";
30
+ const packageVersion = "0.9.7";
31
31
  const Config = {
32
32
  DEBUG: false,
33
33
  LIB_VERSION: packageVersion,
package/dist/config.mjs CHANGED
@@ -1,4 +1,4 @@
1
- const packageVersion = "0.9.6";
1
+ const packageVersion = "0.9.7";
2
2
  const Config = {
3
3
  DEBUG: false,
4
4
  LIB_VERSION: packageVersion,
@@ -75,6 +75,7 @@ export declare class PostHogFeatureFlags implements Extension {
75
75
  private _reloadingDisabled;
76
76
  private _additionalReloadRequested;
77
77
  private _reloadDebouncer;
78
+ private _firingFeatureFlagsCallbacks;
78
79
  private _flagsLoadedFromRemote;
79
80
  private _staleCacheRefreshTriggered;
80
81
  private _consecutiveStatusZeroFailures;
@@ -206,6 +206,7 @@ class PostHogFeatureFlags {
206
206
  this._requestGeneration = 0;
207
207
  this._reloadingDisabled = false;
208
208
  this._additionalReloadRequested = false;
209
+ this._firingFeatureFlagsCallbacks = false;
209
210
  this._flagsLoadedFromRemote = false;
210
211
  this._staleCacheRefreshTriggered = false;
211
212
  this._consecutiveStatusZeroFailures = 0;
@@ -598,6 +599,7 @@ class PostHogFeatureFlags {
598
599
  reloadFeatureFlags() {
599
600
  if (this._reloadingDisabled || this._config.featureFlagsDisabled) return;
600
601
  if (this._hasStatusZeroCircuitBreakerTripped()) return;
602
+ if (this._firingFeatureFlagsCallbacks) this._logger.warn("reloadFeatureFlags() was called inside an onFeatureFlags callback. This callback also runs when flags change in other tabs, so this can cause a request loop.");
601
603
  if (this._requestInFlight) this._additionalReloadRequested = true;
602
604
  if (this._reloadDebouncer) return;
603
605
  this._reloadingHandlers.slice().forEach((handler)=>{
@@ -1114,6 +1116,8 @@ class PostHogFeatureFlags {
1114
1116
  _fireFeatureFlagsCallbacks(errorsLoading) {
1115
1117
  this._rebuildEventProperties();
1116
1118
  const { flags, flagVariants } = this._prepareFeatureFlagsForCallbacks();
1119
+ const wasFiring = this._firingFeatureFlagsCallbacks;
1120
+ this._firingFeatureFlagsCallbacks = true;
1117
1121
  this.featureFlagEventHandlers.forEach((handler)=>{
1118
1122
  try {
1119
1123
  handler(flags, flagVariants, {
@@ -1123,6 +1127,7 @@ class PostHogFeatureFlags {
1123
1127
  this._logger.error('Error while running feature flags callback', error);
1124
1128
  }
1125
1129
  });
1130
+ this._firingFeatureFlagsCallbacks = wasFiring;
1126
1131
  }
1127
1132
  setPersonPropertiesForFlags(properties, reloadFeatureFlags = true) {
1128
1133
  this._setPersonPropertiesForFlags(properties, reloadFeatureFlags);
@@ -170,6 +170,7 @@ class PostHogFeatureFlags {
170
170
  this._requestGeneration = 0;
171
171
  this._reloadingDisabled = false;
172
172
  this._additionalReloadRequested = false;
173
+ this._firingFeatureFlagsCallbacks = false;
173
174
  this._flagsLoadedFromRemote = false;
174
175
  this._staleCacheRefreshTriggered = false;
175
176
  this._consecutiveStatusZeroFailures = 0;
@@ -562,6 +563,7 @@ class PostHogFeatureFlags {
562
563
  reloadFeatureFlags() {
563
564
  if (this._reloadingDisabled || this._config.featureFlagsDisabled) return;
564
565
  if (this._hasStatusZeroCircuitBreakerTripped()) return;
566
+ if (this._firingFeatureFlagsCallbacks) this._logger.warn("reloadFeatureFlags() was called inside an onFeatureFlags callback. This callback also runs when flags change in other tabs, so this can cause a request loop.");
565
567
  if (this._requestInFlight) this._additionalReloadRequested = true;
566
568
  if (this._reloadDebouncer) return;
567
569
  this._reloadingHandlers.slice().forEach((handler)=>{
@@ -1078,6 +1080,8 @@ class PostHogFeatureFlags {
1078
1080
  _fireFeatureFlagsCallbacks(errorsLoading) {
1079
1081
  this._rebuildEventProperties();
1080
1082
  const { flags, flagVariants } = this._prepareFeatureFlagsForCallbacks();
1083
+ const wasFiring = this._firingFeatureFlagsCallbacks;
1084
+ this._firingFeatureFlagsCallbacks = true;
1081
1085
  this.featureFlagEventHandlers.forEach((handler)=>{
1082
1086
  try {
1083
1087
  handler(flags, flagVariants, {
@@ -1087,6 +1091,7 @@ class PostHogFeatureFlags {
1087
1091
  this._logger.error('Error while running feature flags callback', error);
1088
1092
  }
1089
1093
  });
1094
+ this._firingFeatureFlagsCallbacks = wasFiring;
1090
1095
  }
1091
1096
  setPersonPropertiesForFlags(properties, reloadFeatureFlags = true) {
1092
1097
  this._setPersonPropertiesForFlags(properties, reloadFeatureFlags);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/browser-common",
3
- "version": "0.9.6",
3
+ "version": "0.9.7",
4
4
  "description": "Internal shared browser utilities and extension primitives for PostHog Browser SDKs",
5
5
  "license": "MIT",
6
6
  "repository": {