mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[test] Add failing test for component syntax with refs
The desugaring of Component syntax with refs is not compatible with our gating lowering.
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @flow @gating
|
||||
component Foo(ref: React.RefSetter<Controls>) {
|
||||
return <Bar ref={ref}/>;
|
||||
}
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag";
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
const Foo = React.forwardRef(Foo_withRef);
|
||||
const Foo_withRef = isForgetEnabled_Fixtures()
|
||||
? function Foo_withRef(_$$empty_props_placeholder$$, ref) {
|
||||
const $ = useMemoCache(2);
|
||||
let t0;
|
||||
if ($[0] !== ref) {
|
||||
t0 = <Bar ref={ref} />;
|
||||
$[0] = ref;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
: function Foo_withRef(
|
||||
_$$empty_props_placeholder$$: $ReadOnly<{ ... }>,
|
||||
ref: React.RefSetter<Controls>
|
||||
) {
|
||||
return <Bar ref={ref} />;
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// @flow @gating
|
||||
component Foo(ref: React.RefSetter<Controls>) {
|
||||
return <Bar ref={ref}/>;
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @gating
|
||||
const Foo = React.forwardRef(Foo_withRef);
|
||||
function Foo_withRef(props, ref) {
|
||||
return <Bar ref={ref} {...props}></Bar>;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
[ReactForget] Invariant: Encountered Foo_withRef used before declaration which breaks Forget's gating codegen due to hoisting. Rewrite the reference to not use hoisting to fix this issue (3:3)
|
||||
```
|
||||
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// @gating
|
||||
const Foo = React.forwardRef(Foo_withRef);
|
||||
function Foo_withRef(props, ref) {
|
||||
return <Bar ref={ref} {...props}></Bar>;
|
||||
}
|
||||
@@ -514,6 +514,7 @@ const skipFilter = new Set([
|
||||
// bug
|
||||
"bug-jsx-memberexpr-tag-in-lambda",
|
||||
"bug-invalid-code-when-bailout",
|
||||
"component-syntax-ref-gating.flow",
|
||||
]);
|
||||
|
||||
export default skipFilter;
|
||||
|
||||
Reference in New Issue
Block a user