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

Uncaught Error: Already created an embed #62

Open
yuvrajchaudhari03 opened this issue Jan 30, 2023 · 1 comment
Open

Uncaught Error: Already created an embed #62

yuvrajchaudhari03 opened this issue Jan 30, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@yuvrajchaudhari03
Copy link

yuvrajchaudhari03 commented Jan 30, 2023

I'm trying to embed Kleki into the next Js project but getting this error

Uncaught Error: Already created an embed

Screenshot 2023-01-30 at 10 26 16 AM

code:
`
if (typeof window !== "undefined" && typeof window.Klecks !== "undefined") {
const klecks = new Klecks({
onSubmit: (onSuccess, onError) => {
console.log(klecks.getPNG())
klecks.getPSD().then((blob) => {
console.log(blob)
});

            setTimeout(() => {
                onSuccess();
            }, 500);
        }
    });
    if (psdURL) {
        console.log("in psdUrl")
        fetch(new Request(psdURL)).then(response => {
            return response.arrayBuffer();
        }).then(buffer => {
            return klecks.readPSD(buffer); // resolves to Klecks project
        }).then(project => {
            klecks.openProject(project);
        }).catch(e => {
            klecks.initError('failed to read image');
        });

    } else {
        klecks.openProject({
            width: 500,
            height: 500,
            layers: [{
                name: 'Background',
                opacity: 1,
                mixModeStr: 'source-over',
                image: (() => {
                    const canvas = document.createElement('canvas');
                    canvas.width = 500;
                    canvas.height = 500;
                    const ctx = canvas.getContext('2d');
                    ctx.save();
                    ctx.fillStyle = '#fff';
                    ctx.fillRect(0, 0, canvas.width, canvas.height);
                    ctx.restore();
                    return canvas;
                })(),
            }]
        });
    }
}

`

@bitbof
Copy link
Owner

bitbof commented Feb 7, 2023

So far I've made no effort to support React/Next.js. I'd be surprised if it works out of the box. You need to be careful to not execute Kleck's initialization logic twice. Also Klecks has no destructor yet.

At some point I will look into this.

@bitbof bitbof added the enhancement New feature or request label May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants