Skip to content

Commit 517b0e4

Browse files
committed
fix canvas not repainting when props change
The repaint callback only depended on [imageState, border] but not on scale, rotate, borderRadius, showGrid, color, etc. When those props changed, the core config was updated but repaint never re-ran because its dependency array was unchanged. Add all visual props to the repaint dependency array.
1 parent 7d658ee commit 517b0e4

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

packages/lib/src/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,27 @@ const AvatarEditor = forwardRef<AvatarEditorRef, Props>((props, ref) => {
195195
context.clearRect(0, 0, canvasEl.width, canvasEl.height)
196196
coreRef.current.paint(context)
197197
coreRef.current.paintImage(context, imageState, border)
198-
}, [getContext, getCanvas, imageState, border])
198+
// eslint-disable-next-line -- all visual props must trigger repaint
199+
}, [
200+
getContext,
201+
getCanvas,
202+
imageState,
203+
border,
204+
width,
205+
height,
206+
borderRadius,
207+
scale,
208+
rotate,
209+
color,
210+
backgroundColor,
211+
borderColor,
212+
showGrid,
213+
gridColor,
214+
disableBoundaryChecks,
215+
disableHiDPIScaling,
216+
disableCanvasRotation,
217+
crossOrigin,
218+
])
199219

200220
const handleMouseDown: MouseEventHandler<HTMLCanvasElement> = useCallback(
201221
(e) => {

0 commit comments

Comments
 (0)