mirror of
https://github.com/jhbruhn/respira.git
synced 2026-01-27 02:13:41 +00:00
feature: Enhance Konva rendering with React.memo optimization
Wrap PatternCanvas and PatternLayer components with React.memo to prevent unnecessary re-renders when props haven't changed. This builds on the existing useMemo optimizations and provides better performance with large patterns and frequent UI updates. Benefits: - Prevents re-renders when parent components update - Improves render performance during active sewing - Smoother user experience with complex patterns Fixes #43 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
957a3f07b8
commit
512eb732de
2 changed files with 6 additions and 6 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { useRef, useMemo } from "react";
|
import { useRef, useMemo, memo } from "react";
|
||||||
import { useShallow } from "zustand/react/shallow";
|
import { useShallow } from "zustand/react/shallow";
|
||||||
import {
|
import {
|
||||||
useMachineStore,
|
useMachineStore,
|
||||||
|
|
@ -23,7 +23,7 @@ import { ZoomControls } from "./ZoomControls";
|
||||||
import { PatternLayer } from "./PatternLayer";
|
import { PatternLayer } from "./PatternLayer";
|
||||||
import { useCanvasViewport, usePatternTransform } from "@/hooks";
|
import { useCanvasViewport, usePatternTransform } from "@/hooks";
|
||||||
|
|
||||||
export function PatternCanvas() {
|
export const PatternCanvas = memo(function PatternCanvas() {
|
||||||
// Machine store
|
// Machine store
|
||||||
const { sewingProgress, machineInfo } = useMachineStore(
|
const { sewingProgress, machineInfo } = useMachineStore(
|
||||||
useShallow((state) => ({
|
useShallow((state) => ({
|
||||||
|
|
@ -277,4 +277,4 @@ export function PatternCanvas() {
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
* Handles both interactive (draggable/rotatable) and locked states
|
* Handles both interactive (draggable/rotatable) and locked states
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useMemo, type RefObject } from "react";
|
import { useMemo, memo, type RefObject } from "react";
|
||||||
import { Group, Transformer } from "react-konva";
|
import { Group, Transformer } from "react-konva";
|
||||||
import type Konva from "konva";
|
import type Konva from "konva";
|
||||||
import type { KonvaEventObject } from "konva/lib/Node";
|
import type { KonvaEventObject } from "konva/lib/Node";
|
||||||
|
|
@ -30,7 +30,7 @@ interface PatternLayerProps {
|
||||||
attachTransformer?: () => void;
|
attachTransformer?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PatternLayer({
|
export const PatternLayer = memo(function PatternLayer({
|
||||||
pesData,
|
pesData,
|
||||||
offset,
|
offset,
|
||||||
rotation = 0,
|
rotation = 0,
|
||||||
|
|
@ -143,4 +143,4 @@ export function PatternLayer({
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue