alibaba / alibaba/rax

[BUG] useEffect 调用 setState 堆栈溢出

Open
#2,377 0 comments 0 reactions 1 assignee Claimed by @wssgcg1213 View on GitHub
Bug
Dominant language
JavaScript
Stars
8k
Forks
611
PR merge metrics
No merged PRs in 30d

Description

### ⌨️

- [ ] Would you like to work on a fix?

### Where is the bug from?

Rax Core

### Minimal code and steps to reproduce the bug

```js
import { createElement, useEffect, useState } from 'rax';

function Comp(props) {
const [, setA] = useState(props.width);
useEffect(() => { setA(50); }, []);
return

test
;
}
const array = new Array(2000); array.fill(1);
const Demo = () => {
return array.map((n) => );
};

export default Demo;
```

### Current and expected behavior

「Flush all effects first before update state 」 这个机制存在循环调用的问题,setState 里会调 useEffect ,如果在 useEffect 内有 setState 调用,这个调用栈就是嵌套的,通过上述代码,会导致调用栈溢出,而 react 不会

![image](https://user-images.githubusercontent.com/4219965/186562073-5e1a5bf2-ffda-40b0-a647-6fd1946f32c9.png)

### Environment

- OS : mac

### build.json

_No response_

### Possible solution

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.