Skip to content

Commit

Permalink
update docs, restore deps
Browse files Browse the repository at this point in the history
  • Loading branch information
lavrton committed Dec 6, 2024
1 parent 056cf6a commit dfde469
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,27 @@ import 'konva/lib/shapes/Rect';

Demo: [https://codesandbox.io/s/6l97wny44z](https://codesandbox.io/s/6l97wny44z)

### Usage with Next.js
## Usage with Next.js

Note: `react-konva` is designed to work in the client-side. On the server side, it will render just empty div. So it doesn't make much sense to use react-konva for server-side rendering. In Next.js you may have issue like

> Module not found: Can't resolve 'canvas'
Why do we see this error? `canvas` module is used for canvas rendering in Node.JS environment. `konva` library will use it there, but it doesn't have this dependency explicitly.

#### Use dynamic loading
How to solver this issue? There are two approaches:

### Approach 1: manually install canvas module

You can install `canvas` module manually.

```bash
npm install canvas@next
```

The solution will solve the issue, but it will have unnecessary dependency on `canvas` module which may increase build time a little bit.

### Approach 2: Use dynamic import

Next.js docs: https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"dependencies": {
"@types/react-reconciler": "^0.28.8",
"its-fine": "^1.2.5",
"scheduler": "0.25.0"
"scheduler": "0.25.0",
"react-reconciler": "0.31.0"
},
"targets": {
"none": {}
Expand All @@ -39,7 +40,6 @@
}
],
"peerDependencies": {
"react-reconciler": "~0.29.0 || ~0.31.0",
"konva": "^8.0.1 || ^7.2.5 || ^9.0.0",
"react": "^18.3.1 || ^19.0.0",
"react-dom": "^18.3.1 || ^19.0.0"
Expand Down

0 comments on commit dfde469

Please sign in to comment.