Fix/canvas overlay layer for performance - #877
Closed
ivanruizcode wants to merge 1 commit into
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change splits the canvas content into two Konva layers. Until now, all shapes, the Transformer, the snap guide lines, and the rubber-band selection rectangle lived on a single . Since Konva's batchDraw re-rasterizes the entire layer whenever any node changes, every per-frame update of the selection rectangle or the snap guides forced a redraw of every shape on the canvas. With many elements on screen this caused noticeable stutters, especially during rubber-band selection.
The fix moves the snap lines and the selection rectangle onto a new overlay layer with listening={false}, so their per-frame updates only re-rasterize that layer (a couple of purely visual nodes) instead of the shapes layer. The listening={false} flag also prevents Konva from maintaining a hit canvas for those nodes and stops them from intercepting pointer events meant for the Stage. The Transformer is deliberately kept on the main layer, because dragging it moves the shape nodes along with it (they redraw together anyway, so relocating it would bring no benefit) and because the e2e helpers locate it there. The change is additive and low-risk (typecheck and canvas unit tests pass); it targets Konva's rasterization cost, not React's reconciliation, which remains the next optimization step.