question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable force update of properties of Konva nodes

See original GitHub issue

Currently, react-konva works VERY strictly in terms of how it updates props of nodes.

When a component is updated react-konva will change all attributes of a node exactly how it is defined in render() function. In many cases, it gives unexpected behavior for new users and it requires additional work to sync state of the app with the props of nodes.

The most common issue is drag&drop:

<Circle
   draggable
   x={10}
   y={10}
   radius={50}
   fill={this.state.fill}
   onDragEnd={() => {
      this.setState({  fill: getRandomColor() })
   }}
/>

At first, the component looks good. But it will not work, as expected. Because on dragend the position will be reseted back to {10,10} (as defined in render). I think most of the users expect no to see that reset.

My proposal is to add useStrictMode function. By default react-konva will NOT use strict mode. I think it will work better for the most of the apps. If strict updates are still required a user can do this:

import { useStrictMode } from 'react-konva';

useStrictMode(true);

In non-strict-mode react-konva wil update properties of the node only if they changed in render() function. That is similar how react-dom updates DOM nodes.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lyleunderwoodcommented, Jan 24, 2019

Also struggling with a regression for the last few hours, eventually did a bisect to track it down to a react-konva upgrade and led me here.

1reaction
lavrtoncommented, Jan 14, 2019

@bmoquist sorry for that situation. Will be more careful next time. Also soon I will add more info about strict mode into the documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML5 Canvas Force Update Tutorial - Konva
Konva.Transformer automatically track properties of attached nodes.So it will adopt its own properties automatically. But in some cases Konva.
Read more >
Class: Node - Konva
Node constructor. Nodes are entities that can be transformed, layered, and have bound events. The stage, layers, groups, and shapes all extend Node....
Read more >
Class: Layer - Konva
clearBeforeDraw(); // disable clear before draw layer. ... the node properties with an object literal, enabling you to use an existing node as...
Read more >
Class: Transformer - Konva
Transforming tool is not changing width and height properties of nodes when you resize them. Instead it changes scaleX and scaleY properties.
Read more >
Class: Group - Konva
remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy(). If the node is a container...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found