diff --git a/packages/plugins/free-container-plugin/src/container-node-render/components/container/index.tsx b/packages/plugins/free-container-plugin/src/container-node-render/components/container/index.tsx index 2d29dc93..e8399329 100644 --- a/packages/plugins/free-container-plugin/src/container-node-render/components/container/index.tsx +++ b/packages/plugins/free-container-plugin/src/container-node-render/components/container/index.tsx @@ -21,35 +21,34 @@ export const ContainerNodeContainer: FC = ({ children } const [height, setHeight] = useState(size.height); const updatePorts = () => { - requestAnimationFrame(() => { - const portsData = node.getData(WorkflowNodePortsData); - portsData.updateDynamicPorts(); - }); + const portsData = node.getData(WorkflowNodePortsData); + portsData.updateDynamicPorts(); + }; + + const updateSize = () => { + // 无子节点时 + if (node.blocks.length === 0) { + setWidth(size.width); + setHeight(size.height); + return; + } + // 存在子节点时,只监听宽高变化 + setWidth(transform.bounds.width); + setHeight(transform.bounds.height); }; useEffect(() => { - const updateSize = () => { - // 无子节点时 - if (node.blocks.length === 0) { - setWidth(size.width); - setHeight(size.height); - return; - } - // 存在子节点时,只监听宽高变化 - if (width !== transform.bounds.width) { - setWidth(transform.bounds.width); - } - if (height !== transform.bounds.height) { - setHeight(transform.bounds.height); - } - }; - updateSize(); const dispose = transform.onDataChange(() => { updateSize(); updatePorts(); }); return () => dispose.dispose(); - }, [transform]); + }, [transform, width, height]); + + useEffect(() => { + // 初始化触发一次 + updateSize(); + }, []); return (