@dif.sh/react 0.5.0 → 0.5.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/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +11 -4
- package/dist/provider.js.map +1 -1
- package/package.json +6 -2
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE7D,UAAU,YAAY;IACpB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;CAC1E;AAED,MAAM,WAAW,eAAe;IAC9B,0FAA0F;IAC1F,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IACnD,8EAA8E;IAC9E,QAAQ,EAAE,YAAY,CAAC;CACxB;AAID,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,SAAS,CAAC;IACpB,4FAA4F;IAC5F,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,qEAAqE;IACrE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE,gBAAgB,2CA8B1F;AAED,mFAAmF;AACnF,wBAAgB,MAAM,IAAI,eAAe,CAMxC"}
|
package/dist/provider.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext, useRef, useEffect } from "react";
|
|
3
|
+
import { createContext, useContext, useRef, useEffect, useMemo, } from "react";
|
|
4
4
|
import { dif, syncOverrides, mountDifPreview } from "@dif.sh/sdk";
|
|
5
5
|
const DifContext = createContext(null);
|
|
6
6
|
/**
|
|
@@ -12,7 +12,12 @@ const DifContext = createContext(null);
|
|
|
12
12
|
*/
|
|
13
13
|
export function DifProvider({ config, children, allowOverrides, preview }) {
|
|
14
14
|
const initialized = useRef(false);
|
|
15
|
-
|
|
15
|
+
// Client-only: the SDK's state is a module-level singleton, so initializing
|
|
16
|
+
// during an SSR render would share one request's userId/attributes closures
|
|
17
|
+
// across every concurrent request on that server. Server renders fall
|
|
18
|
+
// through to the SDK's uninitialized first-branch behavior; use the pure
|
|
19
|
+
// `assign` API for server rendering that needs real assignments.
|
|
20
|
+
if (!initialized.current && typeof window !== "undefined") {
|
|
16
21
|
dif.init(config);
|
|
17
22
|
initialized.current = true;
|
|
18
23
|
}
|
|
@@ -23,10 +28,12 @@ export function DifProvider({ config, children, allowOverrides, preview }) {
|
|
|
23
28
|
if (preview !== false)
|
|
24
29
|
mountDifPreview();
|
|
25
30
|
}, [allowOverrides, preview]);
|
|
26
|
-
|
|
31
|
+
// Stable identity: both functions close over module-level state, so consumers
|
|
32
|
+
// of useDif() must not re-render just because the provider did.
|
|
33
|
+
const value = useMemo(() => ({
|
|
27
34
|
track: (metric, opts) => dif.track(metric, opts),
|
|
28
35
|
exposure: ((id, branches) => dif(id, branches)),
|
|
29
|
-
};
|
|
36
|
+
}), []);
|
|
30
37
|
return _jsx(DifContext.Provider, { value: value, children: children });
|
|
31
38
|
}
|
|
32
39
|
/** Hook returning `{ track, exposure }`. Must be called inside `<DifProvider>`. */
|
package/dist/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,aAAa,EACb,UAAU,EACV,MAAM,EACN,SAAS,EACT,OAAO,GAER,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAclE,MAAM,UAAU,GAAG,aAAa,CAAyB,IAAI,CAAC,CAAC;AAW/D;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAoB;IACzF,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAClC,4EAA4E;IAC5E,4EAA4E;IAC5E,sEAAsE;IACtE,yEAAyE;IACzE,iEAAiE;IACjE,IAAI,CAAC,WAAW,CAAC,OAAO,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAC1D,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjB,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC;IAC7B,CAAC;IAED,+EAA+E;IAC/E,gFAAgF;IAChF,SAAS,CAAC,GAAG,EAAE;QACb,aAAa,CAAC,EAAE,KAAK,EAAE,cAAc,KAAK,KAAK,EAAE,CAAC,CAAC;QACnD,IAAI,OAAO,KAAK,KAAK;YAAE,eAAe,EAAE,CAAC;IAC3C,CAAC,EAAE,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;IAE9B,8EAA8E;IAC9E,gEAAgE;IAChE,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,KAAK,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC;QAChD,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAiB;KAChE,CAAC,EACF,EAAE,CACH,CAAC;IAEF,OAAO,KAAC,UAAU,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAuB,CAAC;AAC7E,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,MAAM;IACpB,MAAM,GAAG,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dif.sh/react",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "React adapter for @dif.sh/sdk — provider + useDif hook.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "tsc -p tsconfig.json",
|
|
22
22
|
"lint": "tsc --noEmit",
|
|
23
|
-
"
|
|
23
|
+
"test": "node --test --import tsx src/*.test.tsx",
|
|
24
|
+
"prepublishOnly": "npm run lint && npm test && npm run build"
|
|
24
25
|
},
|
|
25
26
|
"engines": {
|
|
26
27
|
"node": ">=20.6"
|
|
@@ -48,7 +49,10 @@
|
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@dif.sh/sdk": "file:../sdk",
|
|
50
51
|
"@types/react": "^19.0.0",
|
|
52
|
+
"@types/react-dom": "^19.0.0",
|
|
51
53
|
"react": "^19.0.0",
|
|
54
|
+
"react-dom": "^19.0.0",
|
|
55
|
+
"tsx": "^4.7.0",
|
|
52
56
|
"typescript": "^5.4.0"
|
|
53
57
|
}
|
|
54
58
|
}
|