@unhead/react 2.1.3 → 2.1.5

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.
Files changed (2) hide show
  1. package/dist/index.mjs +25 -10
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -22,20 +22,35 @@ function useUnhead() {
22
22
  function withSideEffects(input, options, fn) {
23
23
  const unhead = options.head || useUnhead();
24
24
  const entryRef = useRef(null);
25
- if (!entryRef.current) {
26
- entryRef.current = fn(unhead, input, options);
27
- }
28
- const entry = entryRef.current;
29
- useEffect(() => {
30
- entry?.patch(input);
31
- }, [input, entry]);
25
+ const inputRef = useRef(input);
26
+ inputRef.current = input;
32
27
  useEffect(() => {
28
+ const entry = fn(unhead, inputRef.current, options);
29
+ entryRef.current = entry;
33
30
  return () => {
34
- entry?.dispose();
31
+ entry.dispose();
35
32
  entryRef.current = null;
36
33
  };
37
- }, [entry]);
38
- return entry;
34
+ }, [unhead]);
35
+ useEffect(() => {
36
+ entryRef.current?.patch(input);
37
+ }, [input]);
38
+ const proxyRef = useRef(null);
39
+ if (!proxyRef.current) {
40
+ proxyRef.current = {
41
+ patch: (newInput) => {
42
+ entryRef.current?.patch(newInput);
43
+ },
44
+ dispose: () => {
45
+ entryRef.current?.dispose();
46
+ entryRef.current = null;
47
+ },
48
+ _poll: (rm) => {
49
+ entryRef.current?._poll(rm);
50
+ }
51
+ };
52
+ }
53
+ return proxyRef.current;
39
54
  }
40
55
  function useHead(input = {}, options = {}) {
41
56
  return withSideEffects(input, options, useHead$1);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unhead/react",
3
3
  "type": "module",
4
- "version": "2.1.3",
4
+ "version": "2.1.5",
5
5
  "description": "Full-stack <head> manager built for React.",
6
6
  "author": "Harlan Wilton <harlan@harlanzw.com>",
7
7
  "license": "MIT",
@@ -70,7 +70,7 @@
70
70
  ]
71
71
  },
72
72
  "dependencies": {
73
- "unhead": "2.1.3"
73
+ "unhead": "2.1.5"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@testing-library/react": "^16.3.1",