mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix for destructuring with partial context variables
This commit is contained in:
@@ -3434,7 +3434,12 @@ function lowerAssignment(
|
||||
*/
|
||||
const forceTemporaries =
|
||||
kind === InstructionKind.Reassign &&
|
||||
elements.some((element) => !element.isIdentifier());
|
||||
(elements.some((element) => !element.isIdentifier()) ||
|
||||
elements.some(
|
||||
(element) =>
|
||||
element.isIdentifier() &&
|
||||
getStoreKind(builder, element) !== "StoreLocal"
|
||||
));
|
||||
for (let i = 0; i < elements.length; i++) {
|
||||
const element = elements[i];
|
||||
if (element.node == null) {
|
||||
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import { useMemo } from "react";
|
||||
import { Stringify } from "shared-runtime";
|
||||
|
||||
function Component({}) {
|
||||
let a = "a";
|
||||
let b = "";
|
||||
[a, b] = [null, null];
|
||||
return <Stringify a={a} b={b} onClick={() => a} />;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
5 | let a = "a";
|
||||
6 | let b = "";
|
||||
> 7 | [a, b] = [null, null];
|
||||
| ^ [ReactForget] Invariant: Expected consistent kind for destructuring. Other places were 'Const' but 'store b$36[10:12]' is reassigned (7:7)
|
||||
8 | return <Stringify a={a} b={b} onClick={() => a} />;
|
||||
9 | }
|
||||
10 |
|
||||
```
|
||||
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import { useMemo } from "react";
|
||||
import { Stringify } from "shared-runtime";
|
||||
|
||||
function Component({}) {
|
||||
let a = "a";
|
||||
let b = "";
|
||||
[a, b] = [null, null];
|
||||
// NOTE: reference `a` in a callback to force a context variable
|
||||
return <Stringify a={a} b={b} onClick={() => a} />;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { useMemo, unstable_useMemoCache as useMemoCache } from "react";
|
||||
import { Stringify } from "shared-runtime";
|
||||
|
||||
function Component(t0) {
|
||||
const $ = useMemoCache(4);
|
||||
let t1;
|
||||
let a;
|
||||
let b;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
a = "a";
|
||||
|
||||
const [t2, t3] = [null, null];
|
||||
t1 = t3;
|
||||
a = t2;
|
||||
$[0] = t1;
|
||||
$[1] = a;
|
||||
$[2] = b;
|
||||
} else {
|
||||
t1 = $[0];
|
||||
a = $[1];
|
||||
b = $[2];
|
||||
}
|
||||
b = t1;
|
||||
let t2;
|
||||
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t2 = <Stringify a={a} b={b} onClick={() => a} />;
|
||||
$[3] = t2;
|
||||
} else {
|
||||
t2 = $[3];
|
||||
}
|
||||
return t2;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) <div>{"a":null,"b":"[[ cyclic ref *1 ]]","onClick":"[[ function params=0 ]]"}</div>
|
||||
+1
@@ -5,6 +5,7 @@ function Component({}) {
|
||||
let a = "a";
|
||||
let b = "";
|
||||
[a, b] = [null, null];
|
||||
// NOTE: reference `a` in a callback to force a context variable
|
||||
return <Stringify a={a} b={b} onClick={() => a} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user