@knocklabs/react-core 0.6.3 → 0.6.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 96d70bc: fixes memory leak when unmounting the useNotifications hook
8
+
3
9
  ## 0.6.3
4
10
 
5
11
  ### Patch Changes
@@ -1,2 +1,2 @@
1
- "use strict";const i=require("react");require("../../core/context/KnockProvider.js");require("@knocklabs/client");const o=require("../../core/hooks/useStableOptions.js");require("date-fns");function a(r,t,n={}){const e=i.useRef(),s=o(n);return i.useMemo(()=>(e.current&&e.current.dispose(),e.current=r.feeds.initialize(t,s),e.current.store.subscribe(c=>{var u;return(u=e==null?void 0:e.current)==null?void 0:u.store.setState(c)}),e.current.listenForUpdates(),e.current),[r,t,s])}module.exports=a;
1
+ "use strict";const r=require("react");require("../../core/context/KnockProvider.js");require("@knocklabs/client");const o=require("../../core/hooks/useStableOptions.js");require("date-fns");function a(t,s,n={}){const e=r.useRef(),u=o(n);return r.useEffect(()=>()=>{e.current&&e.current.dispose()},[]),r.useMemo(()=>(e.current&&e.current.dispose(),e.current=t.feeds.initialize(s,u),e.current.store.subscribe(c=>{var i;return(i=e==null?void 0:e.current)==null?void 0:i.store.setState(c)}),e.current.listenForUpdates(),e.current),[t,s,u])}module.exports=a;
2
2
  //# sourceMappingURL=useNotifications.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useNotifications.js","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"sourcesContent":["import Knock, { Feed, FeedClientOptions } from \"@knocklabs/client\";\nimport { useMemo, useRef } from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction useNotifications(\n knock: Knock,\n feedChannelId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed>();\n const stableOptions = useStableOptions(options);\n\n return useMemo(() => {\n if (feedClientRef.current) {\n feedClientRef.current.dispose();\n }\n\n feedClientRef.current = knock.feeds.initialize(\n feedChannelId,\n stableOptions,\n );\n\n // In development, we need to introduce this extra set state to force a render\n // for Zustand as otherwise the state doesn't get reflected correctly\n feedClientRef.current.store.subscribe((t) =>\n feedClientRef?.current?.store.setState(t),\n );\n\n feedClientRef.current.listenForUpdates();\n\n return feedClientRef.current;\n }, [knock, feedChannelId, stableOptions]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedChannelId","options","feedClientRef","useRef","stableOptions","useStableOptions","useMemo","current","dispose","feeds","initialize","store","subscribe","t","setState","listenForUpdates"],"mappings":"8LAKA,SAASA,EACPC,EACAC,EACAC,EAA6B,CAAA,EAC7B,CACA,MAAMC,EAAgBC,EAAAA,OAAa,EAC7BC,EAAgBC,EAAiBJ,CAAO,EAE9C,OAAOK,UAAQ,KACTJ,EAAcK,SAChBL,EAAcK,QAAQC,QAAQ,EAGhCN,EAAcK,QAAUR,EAAMU,MAAMC,WAClCV,EACAI,CACF,EAIcG,EAAAA,QAAQI,MAAMC,UAAWC,UACrCX,OAAAA,EAAAA,GAAAA,YAAAA,EAAeK,UAAfL,YAAAA,EAAwBS,MAAMG,SAASD,GACzC,EAEAX,EAAcK,QAAQQ,iBAAiB,EAEhCb,EAAcK,SACpB,CAACR,EAAOC,EAAeI,CAAa,CAAC,CAC1C"}
1
+ {"version":3,"file":"useNotifications.js","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"sourcesContent":["import Knock, { Feed, FeedClientOptions } from \"@knocklabs/client\";\nimport { useEffect, useMemo, useRef } from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction useNotifications(\n knock: Knock,\n feedChannelId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed>();\n const stableOptions = useStableOptions(options);\n\n useEffect(() => {\n return () => {\n if (feedClientRef.current) {\n feedClientRef.current.dispose();\n }\n };\n }, []);\n\n return useMemo(() => {\n if (feedClientRef.current) {\n feedClientRef.current.dispose();\n }\n\n feedClientRef.current = knock.feeds.initialize(\n feedChannelId,\n stableOptions,\n );\n\n // In development, we need to introduce this extra set state to force a render\n // for Zustand as otherwise the state doesn't get reflected correctly\n feedClientRef.current.store.subscribe((t) =>\n feedClientRef?.current?.store.setState(t),\n );\n\n feedClientRef.current.listenForUpdates();\n\n return feedClientRef.current;\n }, [knock, feedChannelId, stableOptions]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedChannelId","options","feedClientRef","useRef","stableOptions","useStableOptions","useEffect","current","dispose","useMemo","feeds","initialize","store","subscribe","t","setState","listenForUpdates"],"mappings":"8LAKA,SAASA,EACPC,EACAC,EACAC,EAA6B,CAAA,EAC7B,CACA,MAAMC,EAAgBC,EAAAA,OAAa,EAC7BC,EAAgBC,EAAiBJ,CAAO,EAE9CK,OAAAA,EAAAA,UAAU,IACD,IAAM,CACPJ,EAAcK,SAChBL,EAAcK,QAAQC,QAAQ,CAElC,EACC,EAAE,EAEEC,UAAQ,KACTP,EAAcK,SAChBL,EAAcK,QAAQC,QAAQ,EAGhCN,EAAcK,QAAUR,EAAMW,MAAMC,WAClCX,EACAI,CACF,EAIcG,EAAAA,QAAQK,MAAMC,UAAWC,UACrCZ,OAAAA,EAAAA,GAAAA,YAAAA,EAAeK,UAAfL,YAAAA,EAAwBU,MAAMG,SAASD,GACzC,EAEAZ,EAAcK,QAAQS,iBAAiB,EAEhCd,EAAcK,SACpB,CAACR,EAAOC,EAAeI,CAAa,CAAC,CAC1C"}
@@ -1,14 +1,16 @@
1
- import { useRef as n, useMemo as c } from "react";
1
+ import { useRef as n, useEffect as c, useMemo as p } from "react";
2
2
  import "../../core/context/KnockProvider.mjs";
3
3
  import "@knocklabs/client";
4
- import p from "../../core/hooks/useStableOptions.mjs";
4
+ import f from "../../core/hooks/useStableOptions.mjs";
5
5
  import "date-fns";
6
- function O(r, e, i = {}) {
7
- const t = n(), s = p(i);
8
- return c(() => (t.current && t.current.dispose(), t.current = r.feeds.initialize(e, s), t.current.store.subscribe((u) => {
9
- var o;
10
- return (o = t == null ? void 0 : t.current) == null ? void 0 : o.store.setState(u);
11
- }), t.current.listenForUpdates(), t.current), [r, e, s]);
6
+ function O(t, e, o = {}) {
7
+ const r = n(), s = f(o);
8
+ return c(() => () => {
9
+ r.current && r.current.dispose();
10
+ }, []), p(() => (r.current && r.current.dispose(), r.current = t.feeds.initialize(e, s), r.current.store.subscribe((u) => {
11
+ var i;
12
+ return (i = r == null ? void 0 : r.current) == null ? void 0 : i.store.setState(u);
13
+ }), r.current.listenForUpdates(), r.current), [t, e, s]);
12
14
  }
13
15
  export {
14
16
  O as default
@@ -1 +1 @@
1
- {"version":3,"file":"useNotifications.mjs","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"sourcesContent":["import Knock, { Feed, FeedClientOptions } from \"@knocklabs/client\";\nimport { useMemo, useRef } from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction useNotifications(\n knock: Knock,\n feedChannelId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed>();\n const stableOptions = useStableOptions(options);\n\n return useMemo(() => {\n if (feedClientRef.current) {\n feedClientRef.current.dispose();\n }\n\n feedClientRef.current = knock.feeds.initialize(\n feedChannelId,\n stableOptions,\n );\n\n // In development, we need to introduce this extra set state to force a render\n // for Zustand as otherwise the state doesn't get reflected correctly\n feedClientRef.current.store.subscribe((t) =>\n feedClientRef?.current?.store.setState(t),\n );\n\n feedClientRef.current.listenForUpdates();\n\n return feedClientRef.current;\n }, [knock, feedChannelId, stableOptions]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedChannelId","options","feedClientRef","useRef","stableOptions","useStableOptions","useMemo","current","dispose","feeds","initialize","store","subscribe","t","setState","listenForUpdates"],"mappings":";;;;;AAKA,SAASA,EACPC,GACAC,GACAC,IAA6B,CAAA,GAC7B;AACA,QAAMC,IAAgBC,EAAa,GAC7BC,IAAgBC,EAAiBJ,CAAO;AAE9C,SAAOK,EAAQ,OACTJ,EAAcK,WAChBL,EAAcK,QAAQC,QAAQ,GAGhCN,EAAcK,UAAUR,EAAMU,MAAMC,WAClCV,GACAI,CACF,GAIcG,EAAAA,QAAQI,MAAMC,UAAWC,CAAAA;;AACrCX,YAAAA,IAAAA,KAAAA,gBAAAA,EAAeK,YAAfL,gBAAAA,EAAwBS,MAAMG,SAASD;AAAAA,GACzC,GAEAX,EAAcK,QAAQQ,iBAAiB,GAEhCb,EAAcK,UACpB,CAACR,GAAOC,GAAeI,CAAa,CAAC;AAC1C;"}
1
+ {"version":3,"file":"useNotifications.mjs","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"sourcesContent":["import Knock, { Feed, FeedClientOptions } from \"@knocklabs/client\";\nimport { useEffect, useMemo, useRef } from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction useNotifications(\n knock: Knock,\n feedChannelId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed>();\n const stableOptions = useStableOptions(options);\n\n useEffect(() => {\n return () => {\n if (feedClientRef.current) {\n feedClientRef.current.dispose();\n }\n };\n }, []);\n\n return useMemo(() => {\n if (feedClientRef.current) {\n feedClientRef.current.dispose();\n }\n\n feedClientRef.current = knock.feeds.initialize(\n feedChannelId,\n stableOptions,\n );\n\n // In development, we need to introduce this extra set state to force a render\n // for Zustand as otherwise the state doesn't get reflected correctly\n feedClientRef.current.store.subscribe((t) =>\n feedClientRef?.current?.store.setState(t),\n );\n\n feedClientRef.current.listenForUpdates();\n\n return feedClientRef.current;\n }, [knock, feedChannelId, stableOptions]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedChannelId","options","feedClientRef","useRef","stableOptions","useStableOptions","useEffect","current","dispose","useMemo","feeds","initialize","store","subscribe","t","setState","listenForUpdates"],"mappings":";;;;;AAKA,SAASA,EACPC,GACAC,GACAC,IAA6B,CAAA,GAC7B;AACA,QAAMC,IAAgBC,EAAa,GAC7BC,IAAgBC,EAAiBJ,CAAO;AAE9CK,SAAAA,EAAU,MACD,MAAM;AACX,IAAIJ,EAAcK,WAChBL,EAAcK,QAAQC,QAAQ;AAAA,EAElC,GACC,EAAE,GAEEC,EAAQ,OACTP,EAAcK,WAChBL,EAAcK,QAAQC,QAAQ,GAGhCN,EAAcK,UAAUR,EAAMW,MAAMC,WAClCX,GACAI,CACF,GAIcG,EAAAA,QAAQK,MAAMC,UAAWC,CAAAA;;AACrCZ,YAAAA,IAAAA,KAAAA,gBAAAA,EAAeK,YAAfL,gBAAAA,EAAwBU,MAAMG,SAASD;AAAAA,GACzC,GAEAZ,EAAcK,QAAQS,iBAAiB,GAEhCd,EAAcK,UACpB,CAACR,GAAOC,GAAeI,CAAa,CAAC;AAC1C;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useNotifications.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAKnE,iBAAS,gBAAgB,CACvB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,iBAAsB,QAyBhC;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"useNotifications.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAKnE,iBAAS,gBAAgB,CACvB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,iBAAsB,QAiChC;AAED,eAAe,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@knocklabs/react-core",
3
3
  "description": "A set of React components to build notification experiences powered by Knock",
4
4
  "author": "@knocklabs",
5
- "version": "0.6.3",
5
+ "version": "0.6.4",
6
6
  "license": "MIT",
7
7
  "main": "dist/cjs/index.js",
8
8
  "module": "dist/esm/index.mjs",
@@ -11,10 +11,10 @@
11
11
  "react-native": "./src/index.ts",
12
12
  "exports": {
13
13
  ".": {
14
- "require": "./dist/cjs/index.js",
15
- "import": "./dist/esm/index.mjs",
16
14
  "types": "./dist/types/index.d.ts",
17
15
  "react-native": "./src/index.ts",
16
+ "require": "./dist/cjs/index.js",
17
+ "import": "./dist/esm/index.mjs",
18
18
  "default": "./dist/cjs/index.js"
19
19
  }
20
20
  },
@@ -67,15 +67,15 @@
67
67
  "eslint": "^8.56.0",
68
68
  "eslint-plugin-react-hooks": "^5.2.0",
69
69
  "eslint-plugin-react-refresh": "^0.4.14",
70
- "jsdom": "^25.0.1",
70
+ "jsdom": "^26.1.0",
71
71
  "react": "^18.2.0",
72
72
  "react-dom": "^18.2.0",
73
73
  "rimraf": "^6.0.1",
74
74
  "rollup-plugin-execute": "^1.1.1",
75
75
  "typescript": "^5.8.3",
76
- "vite": "^5.0.0",
76
+ "vite": "^5.4.18",
77
77
  "vite-plugin-dts": "^4.5.0",
78
78
  "vite-plugin-no-bundle": "^4.0.0",
79
- "vitest": "^2.1.8"
79
+ "vitest": "^3.1.1"
80
80
  }
81
81
  }
@@ -1,5 +1,5 @@
1
1
  import Knock, { Feed, FeedClientOptions } from "@knocklabs/client";
2
- import { useMemo, useRef } from "react";
2
+ import { useEffect, useMemo, useRef } from "react";
3
3
 
4
4
  import { useStableOptions } from "../../core";
5
5
 
@@ -11,6 +11,14 @@ function useNotifications(
11
11
  const feedClientRef = useRef<Feed>();
12
12
  const stableOptions = useStableOptions(options);
13
13
 
14
+ useEffect(() => {
15
+ return () => {
16
+ if (feedClientRef.current) {
17
+ feedClientRef.current.dispose();
18
+ }
19
+ };
20
+ }, []);
21
+
14
22
  return useMemo(() => {
15
23
  if (feedClientRef.current) {
16
24
  feedClientRef.current.dispose();