[M2] IgviewerCanvas mutates the DOM canvas during render + bogus effect dependency #23

Open
opened 2026-06-27 03:54:47 +00:00 by sessamekesh · 0 comments
Owner

File: packages/viewer-react/src/IgviewerCanvas.tsx

Two issues:

  1. Side effect during render (lines 21-33): the component resizes canvas.width / canvas.height and reads the devicePixelRatio global during the render phase. This is an impure render side effect that React 18+ concurrent rendering / StrictMode may double-invoke. Move it into the rAF tick or a layout effect.

  2. Bogus effect dependency (line 62): useEffect(..., [runtime, canvasId, canvasRef.current]) lists canvasRef.current as a dependency. Refs don't trigger re-renders, so this dependency is dead/misleading, and react-hooks/exhaustive-deps would flag it.


Filed by an automated AI code review (manual proof-of-concept run). Code locations reference the various-cleanup branch.

**File:** `packages/viewer-react/src/IgviewerCanvas.tsx` Two issues: 1. **Side effect during render (lines 21-33):** the component resizes `canvas.width` / `canvas.height` and reads the `devicePixelRatio` global *during the render phase*. This is an impure render side effect that React 18+ concurrent rendering / StrictMode may double-invoke. Move it into the rAF tick or a layout effect. 2. **Bogus effect dependency (line 62):** `useEffect(..., [runtime, canvasId, canvasRef.current])` lists `canvasRef.current` as a dependency. Refs don't trigger re-renders, so this dependency is dead/misleading, and `react-hooks/exhaustive-deps` would flag it. --- _Filed by an automated AI code review (manual proof-of-concept run). Code locations reference the `various-cleanup` branch._
Sign in to join this conversation.
No description provided.