Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled Runtime Error TypeError: Cannot read properties of undefined (reading 'ensure') #3962

Closed
kemisstep opened this issue Oct 9, 2023 · 3 comments
Labels
resolution: needs demos 需要复现 Issues that need minimal demos to reproduce any problems

Comments

@kemisstep
Copy link

问题描述

image

在nextjs使用x6保错

重现链接

暂无

重现步骤

import React, { useEffect, useState } from 'react'
import ReactDOM from "react-dom";
import { Graph, Node } from '@antv/x6'
import { register } from '@antv/x6-react-shape'
import { Dropdown } from 'antd'
import styles from "./index.module.scss"
import { Stencil } from '@antv/x6-plugin-stencil'
import { Snapline } from "@antv/x6-plugin-snapline";
// import useSnapline from "../plugin/useSnapline";
const CustomComponent = ({ node }) => {
    const label = node.prop('label')
    return (
        <Dropdown
            menu={{
                items: [
                    {
                        key: 'copy',
                        label: '复制',
                    },
                    {
                        key: 'paste',
                        label: '粘贴',
                    },
                    {
                        key: 'delete',
                        label: '删除',
                    },
                ],
            }}
            trigger={['contextMenu']}
        >
            <div className="custom-react-node">{label}</div>
        </Dropdown>
    )
}
// 注册
register({
    shape: 'custom-react-node',
    width: 100,
    height: 40,
    component: CustomComponent,
})

const data = {
    nodes: [
        {
            id: 'node1',
            shape: 'rect',
            x: 40,
            y: 40,
            width: 100,
            height: 40,
            label: 'hello',
            attrs: {
                body: {
                    stroke: '#8f8f8f',
                    strokeWidth: 1,
                    fill: '#fff',
                    rx: 6,
                    ry: 6,
                },
            },
        },
        {
            id: 'node2',
            shape: 'rect',
            x: 160,
            y: 180,
            width: 100,
            height: 40,
            label: 'world',
            attrs: {
                body: {
                    stroke: '#8f8f8f',
                    strokeWidth: 1,
                    fill: '#fff',
                    rx: 6,
                    ry: 6,
                },
            },
        },
    ],
    edges: [
        {
            shape: 'edge',
            source: 'node1',
            target: 'node2',
            label: 'x6',
            attrs: {
                line: {
                    stroke: '#8f8f8f',
                    strokeWidth: 1,
                },
            },
        },
    ],
}


const X6Demo3 = () => {
    const refcontainer = React.useRef();
    const refdndContainer = React.useRef();
    const [graph, setGraph] = React.useState(null);
    const [dnd, setDnd] = React.useState(null);
    useEffect(() => {
        if (typeof window !== undefined &&
            refcontainer.current &&
            refdndContainer.current
        ) {
            // if (
            //     refcontainer.current
            // ) {
            const graph = new Graph({
                container: refcontainer.current,
                // autoResize: true,
                background: {
                    color: '#F2F7FA',
                },
                mousewheel: {
                    enabled: true,
                    modifiers: ['ctrl', 'meta'],
                },
            })
            // 
            graph.use(
                new Snapline({
                    enabled: true,
                    sharp: true
                })
            );
            // useSnapline(graph)
            graph.fromJSON(data) // 渲染元素
            graph.centerContent() // 居中显示

        }
    }, [])
    return (
        <div className={styles.root}>
            <div className="react-shape-app" >
                <div className="dnd-wrap" ref={refdndContainer} />
                <div className="app-content" ref={refcontainer} />
            </div>
        </div>

    )
};

export default X6Demo3;

预期行为

正常展示

平台

nextjs

x6 最新版本

屏幕截图或视频(可选)

No response

补充说明(可选)

No response

@NewByVector NewByVector added the resolution: needs demos 需要复现 Issues that need minimal demos to reproduce any problems label Oct 11, 2023
@NewByVector
Copy link
Contributor

用 codesanbox 复现一下?

@lily97
Copy link

lily97 commented Jan 8, 2024

我也遇到了同样的问题,我的是vue2,antv是1.34.14版本

@x6-bot
Copy link
Contributor

x6-bot bot commented Jan 8, 2025

This thread has been automatically locked because it has not had recent activity.

Please open a new issue for related bugs and link to relevant comments in this thread.

@x6-bot x6-bot bot locked as resolved and limited conversation to collaborators Jan 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolution: needs demos 需要复现 Issues that need minimal demos to reproduce any problems
Projects
None yet
Development

No branches or pull requests

3 participants