lowcode-engine icon indicating copy to clipboard operation
lowcode-engine copied to clipboard

渲染死循环

Open mmmmmmmgo opened this issue 3 years ago • 2 comments

问题描述

这个问题比较边界

复现

// antd物料包的 src/index.tsx
import { Tree as AntdTree } from 'antd';

const MyTree = React.forwardRef((props: any, ref) => {
  const treeRef = React.useRef(null);
  React.useImperativeHandle(ref, () => ({ // 触发问题的关键是这个解构, 如果直接返回treeRef.current不会有问题.
    ...treeRef.current,
  }));
  return (
    <div>
      <AntdTree ref={treeRef} {...props} />
    </div>
  );
});

export { MyTree as Tree };

业务背景是, 公司组件库对antd的tree二次封装, 给ref添加一些东西

mmmmmmmgo avatar Oct 09 '22 14:10 mmmmmmmgo

复现了一下,并没有出现死循环。

但是使用了 useImperativeHandle,会重写 ref,引擎会依赖正确的 ref 进行相关的操作,所以不建议使用这个 api。

liujuping avatar Mar 06 '23 07:03 liujuping

你好 @mmmmmmmgo,由于缺乏必要的信息(如 bug 重现步骤、引擎版本信息 等),无法定位问题,请按照 issue bug 模板 补全信息,也可以通过阅读 引擎的 issue 说明 了解什么类型的 issue 可以获得更好、更快的支持。

github-actions[bot] avatar Mar 06 '23 08:03 github-actions[bot]