1
+
2
+## Input
3
+
4
+```javascript
5
+// @flow
6
+component Example() {
7
+ const fooRef = useRef();
8
+
9
+ function updateStyles() {
10
+ const foo = fooRef.current;
11
+ // The access of `barRef` here before its declaration causes it be hoisted...
12
+ if (barRef.current == null || foo == null) {
13
+ return;
14
+ }
15
+ foo.style.height = '100px';
16
+ }
17
+
18
+ // ...which previously meant that we didn't infer a type...
19
+ const barRef = useRef(null);
20
+
21
+ const resizeRef = useResizeObserver(
22
+ rect => {
23
+ const {width} = rect;
24
+ // ...which meant that we failed to ignore the mutation here...
25
+ barRef.current = width;
26
+ } // ...which caused this to fail with "can't freeze a mutable function"
27
+ );
28
+
29
+ useLayoutEffect(() => {
30
+ const observer = new ResizeObserver(_ => {
31
+ updateStyles();
32
+ });
33
+
34
+ return () => {
35
+ observer.disconnect();
36
+ };
37
+ }, []);
38
+
39
+ return <div ref={resizeRef} />;
40
+}
41
+
42
+```
43
+
44
+## Code
45
+
46
+```javascript
47
+import { c as _c } from "react/compiler-runtime";
48
+function Example() {
49
+ const $ = _c(6);
50
+ const fooRef = useRef();
51
+ let t0;
52
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
53
+ t0 = function updateStyles() {
54
+ const foo = fooRef.current;
55
+ if (barRef.current == null || foo == null) {
56
+ return;
57
+ }
58
+
59
+ foo.style.height = "100px";
60
+ };
61
+ $[0] = t0;
62
+ } else {
63
+ t0 = $[0];
64
+ }
65
+ const updateStyles = t0;
66
+
67
+ const barRef = useRef(null);
68
+ let t1;
69
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
70
+ t1 = (rect) => {
71
+ const { width } = rect;
72
+
73
+ barRef.current = width;
74
+ };
75
+ $[1] = t1;
76
+ } else {
77
+ t1 = $[1];
78
+ }
79
+ const resizeRef = useResizeObserver(t1);
80
+ let t2;
81
+ let t3;
82
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
83
+ t2 = () => {
84
+ const observer = new ResizeObserver((_) => {
85
+ updateStyles();
86
+ });
87
+ return () => {
88
+ observer.disconnect();
89
+ };
90
+ };
91
+
92
+ t3 = [];
93
+ $[2] = t2;
94
+ $[3] = t3;
95
+ } else {
96
+ t2 = $[2];
97
+ t3 = $[3];
98
+ }
99
+ useLayoutEffect(t2, t3);
100
+ let t4;
101
+ if ($[4] !== resizeRef) {
102
+ t4 = <div ref={resizeRef} />;
103
+ $[4] = resizeRef;
104
+ $[5] = t4;
105
+ } else {
106
+ t4 = $[5];
107
+ }
108
+ return t4;
109
+}
110
+
111
+```
112
+
113
+### Eval output
114
+(kind: exception) Fixture not implemented
\ No newline at end of file