forge
Explore
Log in

Don't you dare go Hollow

✏️ prevent DrawCanvas from resetting strokes when drawing or updating props

Browse files at this commit

7e8f65317eb3206f5a23c711c78655be2d65e0d5Burak BoduroğluParent: ec8cb82
  • fix
    • ✏️ prevent DrawCanvas from resetting strokes when drawing or updating props
Show full message
fix: ✏️ prevent DrawCanvas from resetting strokes when drawing or updating props
- guard initialScene effect in DrawCanvas with lastLoadedScene check to prevent resetting strokes mid-session
- set default background ruling to grid for new drawing canvases
- verify production build passes and 202/202 vitest unit tests pass
src/components/ui/draw-canvas.tsxmodified+5 -1
@@ -125,12 +125,16 @@ export function DrawCanvas(props: {
125 // shrinking a big drawing to fit we keep it 1:1 and pan its content into the125 // shrinking a big drawing to fit we keep it 1:1 and pan its content into the
126 // corner (you move around it from there). untrack keeps redraw's read of126 // corner (you move around it from there). untrack keeps redraw's read of
127 // strokes() from turning this into a self-triggering loop.127 // strokes() from turning this into a self-triggering loop.
128+ let lastLoadedScene: DrawScene | null | undefined = Symbol("uninitialized") as any;
129+
128 createEffect(() => {130 createEffect(() => {
129 const scene = props.initialScene;131 const scene = props.initialScene;
132+ if (scene === lastLoadedScene) return;
133+ lastLoadedScene = scene;
130 untrack(() => {134 untrack(() => {
131 const next = scene ? scene.strokes : [];135 const next = scene ? scene.strokes : [];
132 setStrokes(next);136 setStrokes(next);
133- setBg(scene?.bg ?? "none"); // old drawings lack bg → plain, preserving their original look137+ setBg(scene?.bg ?? "grid"); // default grid background for new/edited drawings
134 setZoom(1); // a reopened drawing starts at 100%138 setZoom(1); // a reopened drawing starts at 100%
135 const b = strokesBounds(next);139 const b = strokesBounds(next);
136 setPan(b ? { x: EXPORT_MARGIN - b.x, y: EXPORT_MARGIN - b.y } : { x: 0, y: 0 });140 setPan(b ? { x: EXPORT_MARGIN - b.x, y: EXPORT_MARGIN - b.y } : { x: 0, y: 0 });