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)

Most upvoted comments

This is what worked for me:

// Remove the resizeObserver error
useEffect(() => {
  const errorHandler = (e: any) => {
    if (
      e.message.includes(
        "ResizeObserver loop completed with undelivered notifications" ||
          "ResizeObserver loop limit exceeded"
      )
    ) {
      const resizeObserverErr = document.getElementById(
        "webpack-dev-server-client-overlay"
      );
      if (resizeObserverErr) {
        resizeObserverErr.style.display = "none";
      }
    }
  };
  window.addEventListener("error", errorHandler);

  return () => {
    window.removeEventListener("error", errorHandler);
  };
}, []);

Hope it helps

This is what worked for me:

// Remove the resizeObserver error
useEffect(() => {
  const errorHandler = (e: any) => {
    if (
      e.message.includes(
        "ResizeObserver loop completed with undelivered notifications" ||
          "ResizeObserver loop limit exceeded"
      )
    ) {
      const resizeObserverErr = document.getElementById(
        "webpack-dev-server-client-overlay"
      );
      if (resizeObserverErr) {
        resizeObserverErr.style.display = "none";
      }
    }
  };
  window.addEventListener("error", errorHandler);

  return () => {
    window.removeEventListener("error", errorHandler);
  };
}, []);

Hope it helps

Thanks

this finally worked for me

appreciate the help

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 onNodesChange triggers.

A temporary (and not ideal) workaround is to wrap the dispatch in a setTimeout:

onNodesChange={(changes) => {
  setTimeout(() => dispatch(onNodesChange(changes)));
}}

as this seems to prevent the ResizeObserver loop.

Hopefully this is helpful to others.

I can confirm this fixed it for me 😸

<NodeDataFlow
        nodes={nodes}
        edges={edges}
        onNodeClick={handleNodeClick}
        onNodesChange={(changes) => setTimeout(() => onNodesChange(changes))} // Timeout is needed to fix this error: "ResizeObserver loop completed with undelivered notifications."
        onEdgesChange={(changes) => setTimeout(() => onEdgesChange(changes))} // Timeout is needed to fix this error: "ResizeObserver loop completed with undelivered notifications."
      />

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 onNodesChange triggers.

A temporary (and not ideal) workaround is to wrap the dispatch in a setTimeout:

onNodesChange={(changes) => {
  setTimeout(() => dispatch(onNodesChange(changes)));
}}

as this seems to prevent the ResizeObserver loop.

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 ResizeObserver being 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:

useEffect(() => {
    async function setupNode() {
      const journalId = props.data.journalId;
      const res = await getJournal({
        where: {
          id: journalId,
        },
      });

      if (!res.id) return console.log("failed to fetch", res); // ! todo err handling

      return setJournal(res);
    }

    setupNode();
  }, []);

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.

const BuilderFlow = () => {
  const nodes = [
    {
      id: NodeTypes.Text,
      label: "Text Message",
      type: NodeTypes.Text,
    },
    {
      id: NodeTypes.Image,
      label: "Image Message",
      type: NodeTypes.Image,
    },
  ];

  return (
    <>
      <div
        style={{
          height: "100%",
          width: "100%",
          display: "flex",
          flexDirection: "column",
        }}
      >
        <Header />
        <DndProvider backend={HTML5Backend}>
          <ReactFlowProvider>
            <div
              style={{
                display: "grid",
                gridTemplateColumns: "3fr 1fr",
                gridAutoRows: "1fr",
                flex: 1,
              }}
            >
              <FlowZone />
              <Sidebar nodes={nodes} />
            </div>
          </ReactFlowProvider>
        </DndProvider>
      </div>
    </>
  );
};

export default BuilderFlow;

I was getting the ResizeObserver loop limit error. I added 2 seconds delay to loading the ReactFlow component and the error disappeared.


const BuilderFlow = () => {
  const nodes = [
    {
      id: NodeTypes.Text,
      label: "Text Message",
      type: NodeTypes.Text,
    },
    {
      id: NodeTypes.Image,
      label: "Image Message",
      type: NodeTypes.Image,
    },
  ];

  return (
    <div
      style={{
        height: "100%",
        width: "100%",
        display: "flex",
        flexDirection: "column",
      }}
    >
      <Header />
      <DndProvider backend={HTML5Backend}>
        <ReactFlowProvider>
          <div
            style={{
              display: "grid",
              gridTemplateColumns: "3fr 1fr",
              gridAutoRows: "1fr",
              flex: 1,
            }}
          >
            <FlowZone />
            <Sidebar nodes={nodes} />
          </div>
        </ReactFlowProvider>
      </DndProvider>
    </div>
  );
};

const DelayedBuilderFlow = () => {
  const [isLoading, setIsLoading] = useState(true);

  useEffect(() => {
    setTimeout(() => {
      setIsLoading(false);
    }, 2000);
  }, []);

  return (
    <div
      style={{
        height: "100vh",
        display: "flex",
        alignItems: "center",
        justifyContent: "center",
      }}
    >
      {isLoading ? (
        <div className="builder-dual-ring"></div>
      ) : (
        <BuilderFlow />
      )}
    </div>
  );
};

export default DelayedBuilderFlow;

Hope this helps

The same issue for me in version 12.3.5

+1, this indeed a bug