xyflow: ResizeObserver loop limit exceeded
Describe the Bug
import React, { useState } from ‘react’; import { Handle } from ‘reactflow’; import { Select } from ‘antd’; import ‘./index.css’; import { shallow } from ‘zustand/shallow’; import useStore from ‘…/…/store’;
const selector = (state) => ({ nodes: state.nodes, edges: state.edges, onNodesChange: state.onNodesChange, onEdgesChange: state.onEdgesChange, onConnect: state.onConnect, onAddNodes: state.onAddNodes });
export default function Formation (props) {
const { id, isConnectable = true } = props;
const { nodes, onAddNodes } = useStore(selector, shallow);
const [Topoffset, setTopoffset] = useState([]);
const handleChange = (value) => {
let lengths = nodes.map(item => item.id == id);
// nodes嵌套对象
const AddNode = {
id: ${new Date().getTime()},
data: {
label: value
},
type: ‘input’,
position: {
x: 15,
y: lengths.length * 50
},
draggable: false,
parentNode: id,
extent: ‘parent’,
targetPosition: ‘top’
}
// 为reactflow添加嵌套子节点
onAddNodes([…nodes, AddNode]);
// 更新该父节点下的所有子节点,从而根据length属性更新dom的marginTop间距
setTopoffset(lengths);
}
return ( <div className='FormationNode'>
xxx
<div className=‘FormationNodeContent’ style={{ marginTop: Topoffset.length * 100 }}> <Select defaultValue=“lucy” style={{ width: 120 }} onChange={handleChange} options={[ { value: ‘jack’, label: ‘Jack’ }, { value: ‘lucy’, label: ‘Lucy’ }, { value: ‘Yiminghe’, label: ‘yiminghe’ }, { value: ‘disabled’, label: ‘Disabled’, disabled: true } ]} className=“nodrag” /> <button onClick={() => { handleChange(‘sss’) }}>asd</button> </div>
<Handle type="target" position="top" isConnectable={isConnectable} />
<Handle type="source" position="bottom" isConnectable={isConnectable} />
</div>
) }
这个文件是一个自定义节点,我希望在选择选项时添加新的嵌套节点,通过zustand新增node,这成功了,然后通过nodes的长度改变div的外边距头部,但是就在这里动态改变margintop时报错了。我已经被折磨一天了。
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
在一个自定义节点中添加另一个子节点时,改变其父节点的高度/间距时报错
Expected behavior
因为子节点是脱离文档流的,所以我希望能够通过改变css间距来改变父节点高度
Screenshots or Videos
No response
Platform
- OS: [e.g. macOS, Windows, Linux]
- Browser: [e.g. Chrome, Safari, Firefox]
- Version: [e.g. 91.1]
Additional context
No response
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 40 (10 by maintainers)
This is what worked for me:
Hope it helps
Thanks
this finally worked for me
appreciate the help
I can confirm this fixed it for me 😸
We started running into this issue on v12.3.5 and v12.3.6.
We use redux for state management (configured as provided in the example here: https://github.com/xyflow/xyflow/tree/main/examples/react/src/examples/Redux). The above issue occrus when the
onNodesChangetriggers.A temporary (and not ideal) workaround is to wrap the dispatch in a
setTimeout:as this seems to prevent the
ResizeObserverloop.Hopefully this is helpful to others.
same problem. work with lib a week. Have custome node with NodeResizer. If resize using mouse - ResizeObserver loop limit exceeded
+1 this is happening for us too. Adding the listener on the window to handle the error gracefully is a good enough workaround for now, but I would not be surprised if there is some underlying issue with the
ResizeObserverbeing used in React Flow.Notably, I have found that this only happens on Chrome, and it only happens in a development environment.
There is a related issue for another popular library here, in case that possibly helps.
+1, i encounter the error while setting a state for some reason:
removing setJournal() seems to work. any updates on this?
Here is a temporary fix that I found, if you can add a slight delay to loading the ReactFlow component, the error seems to disappear.
I was getting the ResizeObserver loop limit error. I added 2 seconds delay to loading the ReactFlow component and the error disappeared.
Hope this helps
The same issue for me in version 12.3.5
+1, this indeed a bug