@unhead/react 2.1.4 → 2.1.6
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/index.mjs +29 -8
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -22,20 +22,41 @@ function useUnhead() {
|
|
|
22
22
|
function withSideEffects(input, options, fn) {
|
|
23
23
|
const unhead = options.head || useUnhead();
|
|
24
24
|
const entryRef = useRef(null);
|
|
25
|
-
|
|
25
|
+
const inputRef = useRef(input);
|
|
26
|
+
inputRef.current = input;
|
|
27
|
+
if (unhead.ssr && !entryRef.current) {
|
|
26
28
|
entryRef.current = fn(unhead, input, options);
|
|
27
29
|
}
|
|
28
|
-
const entry = entryRef.current;
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
entry?.patch(input);
|
|
31
|
-
}, [input, entry]);
|
|
32
30
|
useEffect(() => {
|
|
31
|
+
const entry = fn(unhead, inputRef.current, options);
|
|
32
|
+
entryRef.current = entry;
|
|
33
33
|
return () => {
|
|
34
|
-
entry
|
|
34
|
+
entry.dispose();
|
|
35
35
|
entryRef.current = null;
|
|
36
36
|
};
|
|
37
|
-
}, [
|
|
38
|
-
|
|
37
|
+
}, [unhead]);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
entryRef.current?.patch(input);
|
|
40
|
+
}, [input]);
|
|
41
|
+
if (unhead.ssr) {
|
|
42
|
+
return entryRef.current;
|
|
43
|
+
}
|
|
44
|
+
const proxyRef = useRef(null);
|
|
45
|
+
if (!proxyRef.current) {
|
|
46
|
+
proxyRef.current = {
|
|
47
|
+
patch: (newInput) => {
|
|
48
|
+
entryRef.current?.patch(newInput);
|
|
49
|
+
},
|
|
50
|
+
dispose: () => {
|
|
51
|
+
entryRef.current?.dispose();
|
|
52
|
+
entryRef.current = null;
|
|
53
|
+
},
|
|
54
|
+
_poll: (rm) => {
|
|
55
|
+
entryRef.current?._poll(rm);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return proxyRef.current;
|
|
39
60
|
}
|
|
40
61
|
function useHead(input = {}, options = {}) {
|
|
41
62
|
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.
|
|
4
|
+
"version": "2.1.6",
|
|
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.
|
|
73
|
+
"unhead": "2.1.6"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@testing-library/react": "^16.3.1",
|