mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Repro for false positive gating mode hoisting check
ghstack-source-id: c4f5777b85751e9d5f0323384160adfba55d883f Pull Request resolved: https://github.com/facebook/react-forget/pull/2875
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @flow @gating
|
||||
import { memo } from "react";
|
||||
|
||||
// TODO: this appears as a hoisted reference to Component, but it's a type not runtime reference!
|
||||
type Props = React.ElementConfig<typeof Component>;
|
||||
|
||||
component Component(value: string) {
|
||||
return <div>{value}</div>;
|
||||
}
|
||||
|
||||
export default memo<Props>(Component);
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
5 | type Props = React.ElementConfig<typeof Component>;
|
||||
6 |
|
||||
> 7 | component Component(value: string) {
|
||||
| ^^^^^^^^^ Invariant: Encountered a function used before its declaration, which breaks Forget's gating codegen due to hoisting. Rewrite the reference to Component to not rely on hoisting to fix this issue (7:7)
|
||||
8 | return <div>{value}</div>;
|
||||
9 | }
|
||||
10 |
|
||||
```
|
||||
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// @flow @gating
|
||||
import { memo } from "react";
|
||||
|
||||
// TODO: this appears as a hoisted reference to Component, but it's a type not runtime reference!
|
||||
type Props = React.ElementConfig<typeof Component>;
|
||||
|
||||
component Component(value: string) {
|
||||
return <div>{value}</div>;
|
||||
}
|
||||
|
||||
export default memo<Props>(Component);
|
||||
Reference in New Issue
Block a user