mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Add infinite loop test case
Discovered this by accident modifying Joe's playground example. This seemed to be triggered in inferReactiveScopeVariables when iterating over the DisjointSet of scopeIdentifiers. In particular this test case contains a cycle and DisjointSet.find would never terminate.
This commit is contained in:
1 parent
75fc20981a
commit
311e5fdf69
2 files changed
+72
No files matched your search
+64
@@ -0,0 +1,64 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// This causes an infinite loop in the compiler
|
||||
function MyApp(props) {
|
||||
const y = makeObj();
|
||||
const tmp = y.a;
|
||||
const tmp2 = tmp.b;
|
||||
y.push(tmp2);
|
||||
return y;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## HIR
|
||||
|
||||
```
|
||||
bb0:
|
||||
[1] Const mutate y$7_@0[1:5] = Call mutate makeObj$2:TFunction()
|
||||
[2] Const mutate tmp$8_@0[1:5] = read y$7_@0.a
|
||||
[3] Const mutate tmp2$9_@0[1:5] = read tmp$8_@0.b
|
||||
[4] Call mutate y$7_@0.push(mutate tmp2$9_@0)
|
||||
[5] Return freeze y$7_@0
|
||||
```
|
||||
|
||||
## Reactive Scopes
|
||||
|
||||
```
|
||||
function MyApp(
|
||||
props,
|
||||
) {
|
||||
scope @0 [1:5] deps=[] out=[y$7_@0] {
|
||||
[1] Const mutate y$7_@0[1:5] = Call mutate makeObj$2:TFunction()
|
||||
[2] Const mutate tmp$8_@0[1:5] = read y$7_@0.a
|
||||
[3] Const mutate tmp2$9_@0[1:5] = read tmp$8_@0.b
|
||||
[4] Call mutate y$7_@0.push(mutate tmp2$9_@0)
|
||||
}
|
||||
return freeze y$7_@0
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function MyApp$0(props$6) {
|
||||
const $ = React.useMemoCache();
|
||||
let y$7;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
y$7 = makeObj$2();
|
||||
const tmp$8 = y$7.a;
|
||||
const tmp2$9 = tmp$8.b;
|
||||
y$7.push(tmp2$9);
|
||||
$[0] = y$7;
|
||||
} else {
|
||||
y$7 = $[0];
|
||||
}
|
||||
|
||||
return y$7;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// This caused an infinite loop in the compiler
|
||||
function MyApp(props) {
|
||||
const y = makeObj();
|
||||
const tmp = y.a;
|
||||
const tmp2 = tmp.b;
|
||||
y.push(tmp2);
|
||||
return y;
|
||||
}
|
||||
Reference in new issue
Block a user