I am attempting to use PostHog feature flags within a WebWorker. However, when I try to access a feature flag (e.g., ab-checklist
), the PostHog JavaScript API returns an incorrect value.
Additionally, when I use the posthog.onFeatureFlags()
method, it triggers an endless loop, continuously returning the wrong value for the feature flag.
This issue only occurs when a Release Condition is specified (as shown in the screenshot below). If I remove the Release Condition, the correct value is returned, but the loop still persists.
-
Install the required dependencies by running the following command:
npm install
-
Add your
PostHog key
andUserID
in theenv.ts
file. -
Start the application with:
npm start
If you open the console, you should notice that the logs in worker.ts
(line 27) are being called repeatedly.
This issue does not occur in the main thread (index.ts
); it only appears in the WebWorker thread. Additionally, the values logged are incorrect. They are correct the first time the onFeatureFlags
callback is triggered but then get overwritten with incorrect values.
I expect to receive the value test
from PostHog, but instead, I am getting either control
or false
.