Code Monkey home page Code Monkey logo

Comments (5)

danesto avatar danesto commented on June 9, 2024 1

from react-konva.

dev-fredericfox avatar dev-fredericfox commented on June 9, 2024 1

Not working on 14.1.3 (tested with static export).
(With 'use client', dynamic import, and webpack config).

Edit: My mistake was thinking I could import elements from react-konva directly like this
import { Circle } from "react-konva" however this is not the case. Same as with the cavas element explained in the guide, you need to create your own component and then dynamically import it wherever you want to use it.

import dynamic from "next/dynamic";
const Canvas = dynamic(() => import("../../../components/Canvas"), { ssr: false });
// Do not: import { Circle } from "react-konva"; this will also lead to the same bug.
const MyCircle = dynamic(() => import("../../../components/MyCircle"), { ssr: false });
export default function NestedCanvas() {
	return (
		<Canvas>
			<MyCircle x={200} y={100} radius={50} fill="red" />
		</Canvas>
	);
}

and then MyCircle can be something as simple as

import Konva from "konva";
import { Circle } from "react-konva";

type Props = Konva.CircleConfig;
export default function MyCircle({ ...props }: Props) {
	return <Circle {...props} />;
}

See my demo:
https://github.com/dev-fredericfox/konva-nested-dynamic-import-nextjs/blob/main/app/nested/_components/NestedCanvas.tsx

from react-konva.

myassir avatar myassir commented on June 9, 2024

Using 'use client'; on the lazy loaded component solved the issue for me.

from react-konva.

kev-bee avatar kev-bee commented on June 9, 2024

I had the issue last year when I began my project on Next 13, but the guide here https://github.com/konvajs/react-konva#usage-with-nextjs fixed he issue.

Now I'm facing the same issue since the Next 14.1 update, but only on local (for now at least...).
Already tried the lazy loading, 'use client' and webpack config update, but none of them worked 😕

@danesto how did you manage to build it locally?

Also, is there some investigation on the subject?

from react-konva.

lavrton avatar lavrton commented on June 9, 2024

Just tried with the last next 14, all works good for me with the approach described in the readme.

@kev-bee please make a little repository to reproduce.

from react-konva.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.