@shware/analytics 16.1.0 → 16.2.1
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/README.md +14 -4
- package/dist/react/index.cjs +11 -2
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +3 -2
- package/dist/react/index.d.cts.map +1 -1
- package/dist/react/index.d.mts +3 -2
- package/dist/react/index.d.mts.map +1 -1
- package/dist/react/index.mjs +3 -2
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/posthog-error-boundary.cjs +119 -0
- package/dist/react/posthog-error-boundary.cjs.map +1 -0
- package/dist/react/posthog-error-boundary.d.cts +60 -0
- package/dist/react/posthog-error-boundary.d.cts.map +1 -0
- package/dist/react/posthog-error-boundary.d.mts +60 -0
- package/dist/react/posthog-error-boundary.d.mts.map +1 -0
- package/dist/react/posthog-error-boundary.mjs +117 -0
- package/dist/react/posthog-error-boundary.mjs.map +1 -0
- package/dist/react/posthog.cjs +97 -0
- package/dist/react/posthog.cjs.map +1 -0
- package/dist/react/posthog.d.cts +41 -0
- package/dist/react/posthog.d.cts.map +1 -0
- package/dist/react/posthog.d.mts +41 -0
- package/dist/react/posthog.d.mts.map +1 -0
- package/dist/react/posthog.mjs +90 -0
- package/dist/react/posthog.mjs.map +1 -0
- package/dist/third-parties/google-analytics.cjs +1 -1
- package/dist/third-parties/google-analytics.cjs.map +1 -1
- package/dist/third-parties/google-analytics.mjs +1 -1
- package/dist/third-parties/google-analytics.mjs.map +1 -1
- package/dist/third-parties/integration.cjs.map +1 -1
- package/dist/third-parties/integration.d.cts +5 -1
- package/dist/third-parties/integration.d.cts.map +1 -1
- package/dist/third-parties/integration.d.mts +5 -1
- package/dist/third-parties/integration.d.mts.map +1 -1
- package/dist/third-parties/integration.mjs.map +1 -1
- package/dist/third-parties/posthog.cjs +4 -4
- package/dist/third-parties/posthog.cjs.map +1 -1
- package/dist/third-parties/posthog.d.cts +3 -3
- package/dist/third-parties/posthog.d.mts +3 -3
- package/dist/third-parties/posthog.mjs +4 -4
- package/dist/third-parties/posthog.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/react/use-feature-flag.cjs +0 -23
- package/dist/react/use-feature-flag.cjs.map +0 -1
- package/dist/react/use-feature-flag.d.cts +0 -10
- package/dist/react/use-feature-flag.d.cts.map +0 -1
- package/dist/react/use-feature-flag.d.mts +0 -10
- package/dist/react/use-feature-flag.d.mts.map +0 -1
- package/dist/react/use-feature-flag.mjs +0 -22
- package/dist/react/use-feature-flag.mjs.map +0 -1
|
@@ -28,14 +28,14 @@ let flagsReady;
|
|
|
28
28
|
/**
|
|
29
29
|
* Resolves once PostHog has loaded its feature flags — or after `timeoutMs` (3 s by default),
|
|
30
30
|
* since an ad blocker that stops the library would otherwise hold it forever; read the flags
|
|
31
|
-
* after it with `
|
|
32
|
-
* promise per page, so React's `use()` can suspend on it:
|
|
31
|
+
* after it with `useFeatureFlagVariantKey` / `getLoadedPosthog`, which are `undefined` in that
|
|
32
|
+
* case. One promise per page, so React's `use()` can suspend on it:
|
|
33
33
|
*
|
|
34
34
|
* ```tsx
|
|
35
35
|
* function Checkout() {
|
|
36
36
|
* use(browser()); // react-dom: the server renders the <Suspense> fallback instead
|
|
37
37
|
* use(posthogFlagsReady());
|
|
38
|
-
* return
|
|
38
|
+
* return useFeatureFlagVariantKey('new-checkout') === 'test' ? <NewCheckout /> : <OldCheckout />;
|
|
39
39
|
* }
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
@@ -113,7 +113,7 @@ function posthogAnalytics(options) {
|
|
|
113
113
|
setUser: setPosthogUser,
|
|
114
114
|
preconnect: URL.canParse(assets) ? [new URL(assets).origin] : [],
|
|
115
115
|
script: {
|
|
116
|
-
id: "posthog",
|
|
116
|
+
id: "posthog-snippet",
|
|
117
117
|
strategy: "beforeInteractive",
|
|
118
118
|
inline: `
|
|
119
119
|
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],Object.defineProperty(u,"toString",{configurable:!0,enumerable:!0,writable:!0,value:function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e}}),Object.defineProperty(u.people,"toString",{configurable:!0,enumerable:!0,writable:!0,value:function(){return u.toString(1)+".people (stub)"}}),o="init capture register register_once register_for_session unregister unregister_for_session getFeatureFlag getFeatureFlagResult isFeatureEnabled reloadFeatureFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSessionId getSurveys getActiveMatchingSurveys renderSurvey canRenderSurvey getNextSurveyStep identify setPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException loadToolbar get_property getSessionProperty createPersonProfile opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing clear_opt_in_out_capturing debug".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog.mjs","names":[],"sources":["../../src/third-parties/posthog.ts"],"sourcesContent":["import type { PostHog, PostHogConfig } from 'posthog-js';\nimport type { UpdateVisitorDTO } from '../schema/index';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\nimport type { Integration } from './integration';\n\nexport type { PostHog, PostHogConfig } from 'posthog-js';\n\n/**\n * `window.posthog`, for calls that return nothing (`capture`, `identify`, `onFeatureFlags`, …):\n * the snippet's stub until the library loads, which queues them and replays them in order once it\n * has. A method that returns a value returns `undefined` on the stub — use `getLoadedPosthog` for\n * those. `undefined` on the server and before the snippet has run.\n *\n * Read off `window` rather than declared on it, so a host that also has `posthog-js`'s own types\n * does not get two conflicting declarations. Types only: install `posthog-js` (a dev dependency\n * is enough) for them; it is never bundled.\n */\nexport function getPosthog(): PostHog | undefined {\n if (typeof document === 'undefined') return undefined;\n return (window as { posthog?: PostHog }).posthog;\n}\n\n/**\n * The PostHog instance once the library has loaded, for the methods that return a value\n * (`getFeatureFlag`, `isFeatureEnabled`, `get_distinct_id`, …); `undefined` while only the stub is\n * there. To act when flags arrive, subscribe with `getPosthog()?.onFeatureFlags` instead, which\n * the stub queues.\n */\nexport function getLoadedPosthog(): PostHog | undefined {\n const posthog = getPosthog();\n return posthog?.__loaded ? posthog : undefined;\n}\n\nlet flagsReady: Promise<void> | undefined;\n\n/**\n * Resolves once PostHog has loaded its feature flags — or after `timeoutMs` (3 s by default),\n * since an ad blocker that stops the library would otherwise hold it forever; read the flags\n * after it with `
|
|
1
|
+
{"version":3,"file":"posthog.mjs","names":[],"sources":["../../src/third-parties/posthog.ts"],"sourcesContent":["import type { PostHog, PostHogConfig } from 'posthog-js';\nimport type { UpdateVisitorDTO } from '../schema/index';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\nimport type { Integration } from './integration';\n\nexport type { PostHog, PostHogConfig } from 'posthog-js';\n\n/**\n * `window.posthog`, for calls that return nothing (`capture`, `identify`, `onFeatureFlags`, …):\n * the snippet's stub until the library loads, which queues them and replays them in order once it\n * has. A method that returns a value returns `undefined` on the stub — use `getLoadedPosthog` for\n * those. `undefined` on the server and before the snippet has run.\n *\n * Read off `window` rather than declared on it, so a host that also has `posthog-js`'s own types\n * does not get two conflicting declarations. Types only: install `posthog-js` (a dev dependency\n * is enough) for them; it is never bundled.\n */\nexport function getPosthog(): PostHog | undefined {\n if (typeof document === 'undefined') return undefined;\n return (window as { posthog?: PostHog }).posthog;\n}\n\n/**\n * The PostHog instance once the library has loaded, for the methods that return a value\n * (`getFeatureFlag`, `isFeatureEnabled`, `get_distinct_id`, …); `undefined` while only the stub is\n * there. To act when flags arrive, subscribe with `getPosthog()?.onFeatureFlags` instead, which\n * the stub queues.\n */\nexport function getLoadedPosthog(): PostHog | undefined {\n const posthog = getPosthog();\n return posthog?.__loaded ? posthog : undefined;\n}\n\nlet flagsReady: Promise<void> | undefined;\n\n/**\n * Resolves once PostHog has loaded its feature flags — or after `timeoutMs` (3 s by default),\n * since an ad blocker that stops the library would otherwise hold it forever; read the flags\n * after it with `useFeatureFlagVariantKey` / `getLoadedPosthog`, which are `undefined` in that\n * case. One promise per page, so React's `use()` can suspend on it:\n *\n * ```tsx\n * function Checkout() {\n * use(browser()); // react-dom: the server renders the <Suspense> fallback instead\n * use(posthogFlagsReady());\n * return useFeatureFlagVariantKey('new-checkout') === 'test' ? <NewCheckout /> : <OldCheckout />;\n * }\n * ```\n *\n * Waiting shows the fallback until the flags are in, instead of the default then the variant;\n * with server-evaluated flags in `config.bootstrap` it resolves as soon as the library loads.\n * Browser only: it never resolves on the server.\n */\nexport function posthogFlagsReady(timeoutMs = 3000): Promise<void> {\n if (typeof document === 'undefined') return new Promise(() => {});\n flagsReady ??= new Promise<void>((resolve) => {\n setTimeout(resolve, timeoutMs);\n const posthog = getPosthog();\n if (!posthog) return;\n // Queued on the stub; once loaded, called as soon as flags are (or already were) in.\n posthog.onFeatureFlags(() => resolve());\n });\n return flagsReady;\n}\n\nconst metrics = ['CLS', 'FCP', 'FID', 'INP', 'LCP', 'TTFB'];\n\nexport function sendPosthogEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n // `document`, not `window`: React Native defines `window` as an alias of `global`, so a\n // window check would pass there and then throw on `window.location`, which it has no such\n // alias for.\n if (typeof document === 'undefined') return;\n const posthog = getPosthog();\n if (!posthog) {\n console.warn('posthog has not been initialized');\n return false;\n }\n if (metrics.includes(name)) return;\n if (window.location.host.includes('127.0.0.1')) return;\n if (window.location.host.includes('localhost')) return;\n\n posthog.capture(name, properties);\n}\n\n/**\n * Identifies the visitor to PostHog as the signed-in user, by the user's id — the server's\n * `distinct_id` for the visitor once someone has signed in on it. Only a user: identifying an\n * anonymous visitor by its own id would make PostHog treat it as an identified person, and\n * PostHog does not merge one identified person into another when the user later signs in, so the\n * pre-sign-in events would stay split off.\n *\n * Without a user it is sign-out (`reset()`): PostHog's identity is reset, so the next person on\n * this page starts anonymous instead of merging into the one who left.\n */\nexport function setPosthogUser({ user_id, user_data }: Omit<UpdateVisitorDTO, 'tags'>) {\n const posthog = getPosthog();\n if (!posthog) {\n console.warn('posthog has not been initialized');\n return;\n }\n if (!user_id) {\n posthog.reset();\n return;\n }\n posthog.identify(user_id, { email: getFirst(user_data?.email) });\n}\n\n/**\n * PostHog: every event, for behavior analysis. Loaded with PostHog's HTML snippet, which defines\n * a stub `window.posthog` and fetches the library (`array.js`) asynchronously from PostHog's\n * assets host, so it stays out of the app's bundle; calls made before it loads are queued.\n *\n * `config` is serialized into the snippet's `posthog.init` call, so only its JSON survives:\n * `api_host`, `defaults`, `bootstrap` (server-evaluated flags, so an experiment renders its variant\n * without a flicker), and the other plain options — functions such as `loaded` are dropped.\n */\nexport function posthogAnalytics(options: {\n token: `phc_${string}`;\n config: Partial<PostHogConfig> & { api_host: string };\n}): Integration {\n // Where the snippet loads `array.js` from, by its own rule; a relative `api_host` (a reverse\n // proxy on the site's origin) needs no preconnect.\n const assets = options.config.api_host.replace('.i.posthog.com', '-assets.i.posthog.com');\n // `<` escaped: `config` is arbitrary JSON (a `bootstrap` can carry user data), and a `</script>`\n // inside it would end this inline script early. `\\u003c` parses back to the same value.\n const config = JSON.stringify(options.config).replace(/</g, '\\\\u003c');\n return {\n type: 'analytics',\n track: sendPosthogEvent,\n setUser: setPosthogUser,\n preconnect: URL.canParse(assets) ? [new URL(assets).origin] : [],\n script: {\n id: 'posthog-snippet',\n // The stub must exist before hydration, whose effects already track (`page_view`) and\n // identify; it is a few lines, and `array.js` still loads async. PostHog's own Next example\n // does the same.\n strategy: 'beforeInteractive',\n inline: `\n !function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(\".\");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement(\"script\")).type=\"text/javascript\",p.crossOrigin=\"anonymous\",p.async=!0,p.src=s.api_host.replace(\".i.posthog.com\",\"-assets.i.posthog.com\")+\"/static/array.js\",(r=t.getElementsByTagName(\"script\")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a=\"posthog\",u.people=u.people||[],Object.defineProperty(u,\"toString\",{configurable:!0,enumerable:!0,writable:!0,value:function(t){var e=\"posthog\";return\"posthog\"!==a&&(e+=\".\"+a),t||(e+=\" (stub)\"),e}}),Object.defineProperty(u.people,\"toString\",{configurable:!0,enumerable:!0,writable:!0,value:function(){return u.toString(1)+\".people (stub)\"}}),o=\"init capture register register_once register_for_session unregister unregister_for_session getFeatureFlag getFeatureFlagResult isFeatureEnabled reloadFeatureFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSessionId getSurveys getActiveMatchingSurveys renderSurvey canRenderSurvey getNextSurveyStep identify setPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException loadToolbar get_property getSessionProperty createPersonProfile opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing clear_opt_in_out_capturing debug\".split(\" \"),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);\n posthog.init(${JSON.stringify(options.token)}, ${config});\n `,\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,SAAgB,aAAkC;CAChD,IAAI,OAAO,aAAa,aAAa,OAAO,KAAA;CAC5C,OAAQ,OAAiC;AAC3C;;;;;;;AAQA,SAAgB,mBAAwC;CACtD,MAAM,UAAU,WAAW;CAC3B,OAAO,SAAS,WAAW,UAAU,KAAA;AACvC;AAEA,IAAI;;;;;;;;;;;;;;;;;;;AAoBJ,SAAgB,kBAAkB,YAAY,KAAqB;CACjE,IAAI,OAAO,aAAa,aAAa,OAAO,IAAI,cAAc,CAAC,CAAC;CAChE,eAAe,IAAI,SAAe,YAAY;EAC5C,WAAW,SAAS,SAAS;EAC7B,MAAM,UAAU,WAAW;EAC3B,IAAI,CAAC,SAAS;EAEd,QAAQ,qBAAqB,QAAQ,CAAC;CACxC,CAAC;CACD,OAAO;AACT;AAEA,MAAM,UAAU;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;AAAM;AAE1D,SAAgB,iBACd,MACA,YACA;CAIA,IAAI,OAAO,aAAa,aAAa;CACrC,MAAM,UAAU,WAAW;CAC3B,IAAI,CAAC,SAAS;EACZ,QAAQ,KAAK,kCAAkC;EAC/C,OAAO;CACT;CACA,IAAI,QAAQ,SAAS,IAAI,GAAG;CAC5B,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAChD,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAEhD,QAAQ,QAAQ,MAAM,UAAU;AAClC;;;;;;;;;;;AAYA,SAAgB,eAAe,EAAE,SAAS,aAA6C;CACrF,MAAM,UAAU,WAAW;CAC3B,IAAI,CAAC,SAAS;EACZ,QAAQ,KAAK,kCAAkC;EAC/C;CACF;CACA,IAAI,CAAC,SAAS;EACZ,QAAQ,MAAM;EACd;CACF;CACA,QAAQ,SAAS,SAAS,EAAE,OAAO,SAAS,WAAW,KAAK,EAAE,CAAC;AACjE;;;;;;;;;;AAWA,SAAgB,iBAAiB,SAGjB;CAGd,MAAM,SAAS,QAAQ,OAAO,SAAS,QAAQ,kBAAkB,uBAAuB;CAGxF,MAAM,SAAS,KAAK,UAAU,QAAQ,MAAM,CAAC,CAAC,QAAQ,MAAM,SAAS;CACrE,OAAO;EACL,MAAM;EACN,OAAO;EACP,SAAS;EACT,YAAY,IAAI,SAAS,MAAM,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,MAAM,IAAI,CAAC;EAC/D,QAAQ;GACN,IAAI;GAIJ,UAAU;GACV,QAAQ;;uBAES,KAAK,UAAU,QAAQ,KAAK,EAAE,IAAI,OAAO;;EAE5D;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_third_parties_posthog = require("../third-parties/posthog.cjs");
|
|
3
|
-
let react = require("react");
|
|
4
|
-
// src/react/use-feature-flag.ts
|
|
5
|
-
const noop = () => {};
|
|
6
|
-
/** Subscribes to flag (re)loads; on the stub the subscription is queued and has no unsubscribe. */
|
|
7
|
-
function subscribe(onChange) {
|
|
8
|
-
return require_third_parties_posthog.getPosthog()?.onFeatureFlags(onChange) ?? noop;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`
|
|
12
|
-
* until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).
|
|
13
|
-
* `undefined` on the server and through hydration, so the server markup always matches.
|
|
14
|
-
*
|
|
15
|
-
* Renders the default first and the variant once flags arrive. To wait for them instead, call
|
|
16
|
-
* `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.
|
|
17
|
-
*/
|
|
18
|
-
function useFeatureFlag(key) {
|
|
19
|
-
return (0, react.useSyncExternalStore)(subscribe, () => require_third_parties_posthog.getLoadedPosthog()?.getFeatureFlag(key), () => void 0);
|
|
20
|
-
}
|
|
21
|
-
exports.useFeatureFlag = useFeatureFlag;
|
|
22
|
-
|
|
23
|
-
//# sourceMappingURL=use-feature-flag.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-feature-flag.cjs","names":["getPosthog","useSyncExternalStore","getLoadedPosthog"],"sources":["../../src/react/use-feature-flag.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\nimport { getLoadedPosthog, getPosthog } from '../third-parties/posthog';\n\nconst noop = () => {};\n\n/** Subscribes to flag (re)loads; on the stub the subscription is queued and has no unsubscribe. */\nfunction subscribe(onChange: () => void): () => void {\n const unsubscribe: (() => void) | undefined = getPosthog()?.onFeatureFlags(onChange);\n return unsubscribe ?? noop;\n}\n\n/**\n * A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`\n * until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).\n * `undefined` on the server and through hydration, so the server markup always matches.\n *\n * Renders the default first and the variant once flags arrive. To wait for them instead, call\n * `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.\n */\nexport function useFeatureFlag(key: string): string | boolean | undefined {\n return useSyncExternalStore(\n subscribe,\n () => getLoadedPosthog()?.getFeatureFlag(key),\n () => undefined\n );\n}\n"],"mappings":";;;;AAGA,MAAM,aAAa,CAAC;;AAGpB,SAAS,UAAU,UAAkC;CAEnD,OAD8CA,8BAAAA,WAAW,CAAC,EAAE,eAAe,QAAQ,KAC7D;AACxB;;;;;;;;;AAUA,SAAgB,eAAe,KAA2C;CACxE,QAAA,GAAOC,MAAAA,qBAAAA,CACL,iBACMC,8BAAAA,iBAAiB,CAAC,EAAE,eAAe,GAAG,SACtC,KAAA,CACR;AACF"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`
|
|
3
|
-
* until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).
|
|
4
|
-
* `undefined` on the server and through hydration, so the server markup always matches.
|
|
5
|
-
*
|
|
6
|
-
* Renders the default first and the variant once flags arrive. To wait for them instead, call
|
|
7
|
-
* `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.
|
|
8
|
-
*/
|
|
9
|
-
export declare function useFeatureFlag(key: string): string | boolean | undefined;
|
|
10
|
-
//# sourceMappingURL=use-feature-flag.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-feature-flag.d.cts","names":[],"sources":["../../src/react/use-feature-flag.ts"],"mappings":";;;;;;;;wBAmBgB,eAAe"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`
|
|
3
|
-
* until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).
|
|
4
|
-
* `undefined` on the server and through hydration, so the server markup always matches.
|
|
5
|
-
*
|
|
6
|
-
* Renders the default first and the variant once flags arrive. To wait for them instead, call
|
|
7
|
-
* `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.
|
|
8
|
-
*/
|
|
9
|
-
export declare function useFeatureFlag(key: string): string | boolean | undefined;
|
|
10
|
-
//# sourceMappingURL=use-feature-flag.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-feature-flag.d.mts","names":[],"sources":["../../src/react/use-feature-flag.ts"],"mappings":";;;;;;;;wBAmBgB,eAAe"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { getLoadedPosthog, getPosthog } from "../third-parties/posthog.mjs";
|
|
2
|
-
import { useSyncExternalStore } from "react";
|
|
3
|
-
// src/react/use-feature-flag.ts
|
|
4
|
-
const noop = () => {};
|
|
5
|
-
/** Subscribes to flag (re)loads; on the stub the subscription is queued and has no unsubscribe. */
|
|
6
|
-
function subscribe(onChange) {
|
|
7
|
-
return getPosthog()?.onFeatureFlags(onChange) ?? noop;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`
|
|
11
|
-
* until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).
|
|
12
|
-
* `undefined` on the server and through hydration, so the server markup always matches.
|
|
13
|
-
*
|
|
14
|
-
* Renders the default first and the variant once flags arrive. To wait for them instead, call
|
|
15
|
-
* `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.
|
|
16
|
-
*/
|
|
17
|
-
function useFeatureFlag(key) {
|
|
18
|
-
return useSyncExternalStore(subscribe, () => getLoadedPosthog()?.getFeatureFlag(key), () => void 0);
|
|
19
|
-
}
|
|
20
|
-
export { useFeatureFlag };
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=use-feature-flag.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-feature-flag.mjs","names":[],"sources":["../../src/react/use-feature-flag.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\nimport { getLoadedPosthog, getPosthog } from '../third-parties/posthog';\n\nconst noop = () => {};\n\n/** Subscribes to flag (re)loads; on the stub the subscription is queued and has no unsubscribe. */\nfunction subscribe(onChange: () => void): () => void {\n const unsubscribe: (() => void) | undefined = getPosthog()?.onFeatureFlags(onChange);\n return unsubscribe ?? noop;\n}\n\n/**\n * A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`\n * until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).\n * `undefined` on the server and through hydration, so the server markup always matches.\n *\n * Renders the default first and the variant once flags arrive. To wait for them instead, call\n * `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.\n */\nexport function useFeatureFlag(key: string): string | boolean | undefined {\n return useSyncExternalStore(\n subscribe,\n () => getLoadedPosthog()?.getFeatureFlag(key),\n () => undefined\n );\n}\n"],"mappings":";;;AAGA,MAAM,aAAa,CAAC;;AAGpB,SAAS,UAAU,UAAkC;CAEnD,OAD8C,WAAW,CAAC,EAAE,eAAe,QAAQ,KAC7D;AACxB;;;;;;;;;AAUA,SAAgB,eAAe,KAA2C;CACxE,OAAO,qBACL,iBACM,iBAAiB,CAAC,EAAE,eAAe,GAAG,SACtC,KAAA,CACR;AACF"}
|