Skip to content

Clone function in core/util should guard against circular reference, otherwise stack overflow may occur in valid usecases #1066

Open
@li6in9muyou

Description

@li6in9muyou

This is issue is repeated in a echarts issue as well.
util 里面里的克隆函数应该防范环形引用,否则一些很合理的场景会抛出栈溢出异常,然后图表就不能显示了,这个 issue 我在 echarts 也提了。

我意见就是添加在 util.ts 里面添加一个全局变量,用 weakset ,只把克隆过程中遇到的对象放进去,递归前检查当前对象是否已经在这个 weakset 里面,如果在的话就不递归下去了。我就是不知道这样随意添加一个全局变量合适不合适,这个是模块私有的变量,应该也没问题。

[Bug] Circular reference in series.data causes stack overflow thus chart fails to show

  1. paste the follow code in to echarts official example editor
  2. open dev tool, read latest exception
const root = {
  name: "root",
  value: 20,
  children: []
};
const a = {
  name: "a",
  value: 10,
  parent: root
};
root.children.push(a);

option = {
  series: {
    type: 'sunburst',
    data: [root]
  }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions