-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler): Consider dispatch fn from useActionState and useFormS…
…tate to be non-reactive
- Loading branch information
1 parent
63d673c
commit 9f817ae
Showing
9 changed files
with
256 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
.../fixtures/compiler/useActionState-dispatch-considered-as-non-reactive.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import { useActionState } from "react"; | ||
|
||
function Component() { | ||
const [actionState, dispatchAction] = useActionState(); | ||
const onSubmitAction = () => { | ||
dispatchAction(); | ||
}; | ||
return <Foo onSubmitAction={onSubmitAction} />; | ||
} | ||
|
||
function Foo() {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import { useActionState } from "react"; | ||
|
||
function Component() { | ||
const $ = _c(2); | ||
const [actionState, dispatchAction] = useActionState(); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = () => { | ||
dispatchAction(); | ||
}; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
const onSubmitAction = t0; | ||
let t1; | ||
if ($[1] === Symbol.for("react.memo_cache_sentinel")) { | ||
t1 = <Foo onSubmitAction={onSubmitAction} />; | ||
$[1] = t1; | ||
} else { | ||
t1 = $[1]; | ||
} | ||
return t1; | ||
} | ||
|
||
function Foo() {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) |
16 changes: 16 additions & 0 deletions
16
...ler/src/__tests__/fixtures/compiler/useActionState-dispatch-considered-as-non-reactive.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useActionState } from "react"; | ||
|
||
function Component() { | ||
const [actionState, dispatchAction] = useActionState(); | ||
const onSubmitAction = () => { | ||
dispatchAction(); | ||
}; | ||
return <Foo onSubmitAction={onSubmitAction} />; | ||
} | ||
|
||
function Foo() {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; |
63 changes: 63 additions & 0 deletions
63
...__/fixtures/compiler/useFormState-dispatch-considered-as-non-reactive.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import { useFormState } from "react-dom"; | ||
|
||
function Component() { | ||
const [formState, dispatchForm] = useFormState(); | ||
const onSubmitForm = () => { | ||
dispatchForm(); | ||
}; | ||
return <Foo onSubmitForm={onSubmitForm} />; | ||
} | ||
|
||
function Foo() {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import { useFormState } from "react-dom"; | ||
|
||
function Component() { | ||
const $ = _c(2); | ||
const [formState, dispatchForm] = useFormState(); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = () => { | ||
dispatchForm(); | ||
}; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
const onSubmitForm = t0; | ||
let t1; | ||
if ($[1] === Symbol.for("react.memo_cache_sentinel")) { | ||
t1 = <Foo onSubmitForm={onSubmitForm} />; | ||
$[1] = t1; | ||
} else { | ||
t1 = $[1]; | ||
} | ||
return t1; | ||
} | ||
|
||
function Foo() {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) |
16 changes: 16 additions & 0 deletions
16
...piler/src/__tests__/fixtures/compiler/useFormState-dispatch-considered-as-non-reactive.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useFormState } from "react-dom"; | ||
|
||
function Component() { | ||
const [formState, dispatchForm] = useFormState(); | ||
const onSubmitForm = () => { | ||
dispatchForm(); | ||
}; | ||
return <Foo onSubmitForm={onSubmitForm} />; | ||
} | ||
|
||
function Foo() {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; |