rax icon indicating copy to clipboard operation
rax copied to clipboard

[BUG] useEffect 调用 setState 堆栈溢出

Open ClarkXia opened this issue 3 years ago • 0 comments

⌨️

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

Where is the bug from?

Rax Core

Minimal code and steps to reproduce the bug

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

function Comp(props) {
  const [, setA] = useState(props.width);
  useEffect(() => { setA(50); }, []);
  return <div>test</div>;
}
const array = new Array(2000); array.fill(1);
const Demo = () => {
  return array.map((n) => <Comp width={n} />);
};

export default Demo;

Current and expected behavior

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

image

Environment

  • OS : mac

build.json

No response

Possible solution

No response

Additional context

No response

ClarkXia avatar Aug 25 '22 02:08 ClarkXia