Skip to content

Commit 6672405

Browse files
author
Joe Savona
committed
[compiler] Fix SSR fixture pragma to use correct outputMode
SSR test fixtures used `@enableOptimizeForSSR` which is not a valid config key and was silently ignored. Changed to `@outputMode:"ssr"` so the fixtures actually compile in SSR mode and exercise the optimizeForSSR pass.
1 parent 9581133 commit 6672405

10 files changed

+33
-182
lines changed

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssr/optimize-ssr.expect.md

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Input
33

44
```javascript
5-
// @enableOptimizeForSSR
5+
// @outputMode:"ssr"
66
function Component() {
77
const [state, setState] = useState(0);
88
const ref = useRef(null);
@@ -20,40 +20,11 @@ function Component() {
2020
## Code
2121

2222
```javascript
23-
import { c as _c } from "react/compiler-runtime"; // @enableOptimizeForSSR
23+
// @outputMode:"ssr"
2424
function Component() {
25-
const $ = _c(4);
26-
const [state, setState] = useState(0);
27-
const ref = useRef(null);
28-
let t0;
29-
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
30-
t0 = (e) => {
31-
setState(e.target.value);
32-
};
33-
$[0] = t0;
34-
} else {
35-
t0 = $[0];
36-
}
37-
const onChange = t0;
38-
let t1;
39-
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
40-
t1 = () => {
41-
log(ref.current.value);
42-
};
43-
$[1] = t1;
44-
} else {
45-
t1 = $[1];
46-
}
47-
useEffect(t1);
48-
let t2;
49-
if ($[2] !== state) {
50-
t2 = <input value={state} onChange={onChange} ref={ref} />;
51-
$[2] = state;
52-
$[3] = t2;
53-
} else {
54-
t2 = $[3];
55-
}
56-
return t2;
25+
const state = 0;
26+
27+
return <input value={state} />;
5728
}
5829

5930
```

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssr/optimize-ssr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @enableOptimizeForSSR
1+
// @outputMode:"ssr"
22
function Component() {
33
const [state, setState] = useState(0);
44
const ref = useRef(null);

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssr/ssr-infer-event-handlers-from-setState.expect.md

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Input
33

44
```javascript
5-
// @enableOptimizeForSSR
5+
// @outputMode:"ssr"
66
function Component() {
77
const [state, setState] = useState(0);
88
const ref = useRef(null);
@@ -22,40 +22,13 @@ function Component() {
2222
## Code
2323

2424
```javascript
25-
import { c as _c } from "react/compiler-runtime"; // @enableOptimizeForSSR
25+
// @outputMode:"ssr"
2626
function Component() {
27-
const $ = _c(4);
28-
const [state, setState] = useState(0);
27+
const state = 0;
2928
const ref = useRef(null);
30-
let t0;
31-
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
32-
t0 = (e) => {
33-
setState(e.target.value);
34-
};
35-
$[0] = t0;
36-
} else {
37-
t0 = $[0];
38-
}
39-
const onChange = t0;
40-
let t1;
41-
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
42-
t1 = () => {
43-
log(ref.current.value);
44-
};
45-
$[1] = t1;
46-
} else {
47-
t1 = $[1];
48-
}
49-
useEffect(t1);
50-
let t2;
51-
if ($[2] !== state) {
52-
t2 = <CustomInput value={state} onChange={onChange} ref={ref} />;
53-
$[2] = state;
54-
$[3] = t2;
55-
} else {
56-
t2 = $[3];
57-
}
58-
return t2;
29+
const onChange = undefined;
30+
31+
return <CustomInput value={state} onChange={onChange} ref={ref} />;
5932
}
6033

6134
```

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssr/ssr-infer-event-handlers-from-setState.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @enableOptimizeForSSR
1+
// @outputMode:"ssr"
22
function Component() {
33
const [state, setState] = useState(0);
44
const ref = useRef(null);

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssr/ssr-infer-event-handlers-from-startTransition.expect.md

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Input
33

44
```javascript
5-
// @enableOptimizeForSSR
5+
// @outputMode:"ssr"
66
function Component() {
77
const [, startTransition] = useTransition();
88
const [state, setState] = useState(0);
@@ -25,43 +25,14 @@ function Component() {
2525
## Code
2626

2727
```javascript
28-
import { c as _c } from "react/compiler-runtime"; // @enableOptimizeForSSR
28+
// @outputMode:"ssr"
2929
function Component() {
30-
const $ = _c(4);
31-
const [, startTransition] = useTransition();
32-
const [state, setState] = useState(0);
30+
useTransition();
31+
const state = 0;
3332
const ref = useRef(null);
34-
let t0;
35-
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
36-
t0 = (e) => {
37-
startTransition(() => {
38-
setState.call(null, e.target.value);
39-
});
40-
};
41-
$[0] = t0;
42-
} else {
43-
t0 = $[0];
44-
}
45-
const onChange = t0;
46-
let t1;
47-
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
48-
t1 = () => {
49-
log(ref.current.value);
50-
};
51-
$[1] = t1;
52-
} else {
53-
t1 = $[1];
54-
}
55-
useEffect(t1);
56-
let t2;
57-
if ($[2] !== state) {
58-
t2 = <CustomInput value={state} onChange={onChange} ref={ref} />;
59-
$[2] = state;
60-
$[3] = t2;
61-
} else {
62-
t2 = $[3];
63-
}
64-
return t2;
33+
const onChange = undefined;
34+
35+
return <CustomInput value={state} onChange={onChange} ref={ref} />;
6536
}
6637

6738
```

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssr/ssr-infer-event-handlers-from-startTransition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @enableOptimizeForSSR
1+
// @outputMode:"ssr"
22
function Component() {
33
const [, startTransition] = useTransition();
44
const [state, setState] = useState(0);

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssr/ssr-use-reducer-initializer.expect.md

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Input
33

44
```javascript
5-
// @enableOptimizeForSSR
5+
// @outputMode:"ssr"
66

77
import {useReducer} from 'react';
88

@@ -25,7 +25,7 @@ function Component() {
2525
## Code
2626

2727
```javascript
28-
import { c as _c } from "react/compiler-runtime"; // @enableOptimizeForSSR
28+
// @outputMode:"ssr"
2929

3030
import { useReducer } from "react";
3131

@@ -34,41 +34,9 @@ const initializer = (x) => {
3434
};
3535

3636
function Component() {
37-
const $ = _c(4);
38-
const [state, dispatch] = useReducer(_temp, 0, initializer);
39-
const ref = useRef(null);
40-
let t0;
41-
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
42-
t0 = (e) => {
43-
dispatch(e.target.value);
44-
};
45-
$[0] = t0;
46-
} else {
47-
t0 = $[0];
48-
}
49-
const onChange = t0;
50-
let t1;
51-
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
52-
t1 = () => {
53-
log(ref.current.value);
54-
};
55-
$[1] = t1;
56-
} else {
57-
t1 = $[1];
58-
}
59-
useEffect(t1);
60-
let t2;
61-
if ($[2] !== state) {
62-
t2 = <input value={state} onChange={onChange} ref={ref} />;
63-
$[2] = state;
64-
$[3] = t2;
65-
} else {
66-
t2 = $[3];
67-
}
68-
return t2;
69-
}
70-
function _temp(_, next) {
71-
return next;
37+
const state = initializer(0);
38+
39+
return <input value={state} />;
7240
}
7341

7442
```

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssr/ssr-use-reducer-initializer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @enableOptimizeForSSR
1+
// @outputMode:"ssr"
22

33
import {useReducer} from 'react';
44

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssr/ssr-use-reducer.expect.md

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Input
33

44
```javascript
5-
// @enableOptimizeForSSR
5+
// @outputMode:"ssr"
66

77
import {useReducer} from 'react';
88

@@ -23,46 +23,14 @@ function Component() {
2323
## Code
2424

2525
```javascript
26-
import { c as _c } from "react/compiler-runtime"; // @enableOptimizeForSSR
26+
// @outputMode:"ssr"
2727

2828
import { useReducer } from "react";
2929

3030
function Component() {
31-
const $ = _c(4);
32-
const [state, dispatch] = useReducer(_temp, 0);
33-
const ref = useRef(null);
34-
let t0;
35-
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
36-
t0 = (e) => {
37-
dispatch(e.target.value);
38-
};
39-
$[0] = t0;
40-
} else {
41-
t0 = $[0];
42-
}
43-
const onChange = t0;
44-
let t1;
45-
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
46-
t1 = () => {
47-
log(ref.current.value);
48-
};
49-
$[1] = t1;
50-
} else {
51-
t1 = $[1];
52-
}
53-
useEffect(t1);
54-
let t2;
55-
if ($[2] !== state) {
56-
t2 = <input value={state} onChange={onChange} ref={ref} />;
57-
$[2] = state;
58-
$[3] = t2;
59-
} else {
60-
t2 = $[3];
61-
}
62-
return t2;
63-
}
64-
function _temp(_, next) {
65-
return next;
31+
const state = 0;
32+
33+
return <input value={state} />;
6634
}
6735

6836
```

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssr/ssr-use-reducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @enableOptimizeForSSR
1+
// @outputMode:"ssr"
22

33
import {useReducer} from 'react';
44

0 commit comments

Comments
 (0)