Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude,codex): lazy palette read + canvas-derived DPR

Adam Eivyaf08565a55f8
diff --git a/client/src/components/songs/MidiPianoRoll.jsx b/client/src/components/songs/MidiPianoRoll.jsx
index 3e4aa4d94b..c38f72e583 100644
--- a/client/src/components/songs/MidiPianoRoll.jsx
+++ b/client/src/components/songs/MidiPianoRoll.jsx
@@ -55,7 +55,8 @@ const sceneSigEqual = (a, b) => !!a && !!b
&& a.width === b.width && a.height === b.height && a.zoom === b.zoom
&& a.scroll === b.scroll && a.chordLaneH === b.chordLaneH
&& a.lowMidi === b.lowMidi && a.highMidi === b.highMidi
- && a.multiTrack === b.multiTrack && a.dpr === b.dpr
+ && a.multiTrack === b.multiTrack
+ && a.backingW === b.backingW && a.backingH === b.backingH
&& a.data === b.data && a.chords === b.chords
&& a.bg === b.bg && a.accent === b.accent && a.accentRgb === b.accentRgb;
@@ -336,11 +337,18 @@ export default function MidiPianoRoll({ data, chords, showChords, zoom, onZoomCh
};
// Rebuild the offscreen scene only when its signature changed; otherwise
- // reuse the cached bitmap.
- const dpr = (typeof window !== 'undefined' && window.devicePixelRatio) || 1;
+ // reuse the cached bitmap. DPR is derived from the visible canvas's actual
+ // backing store (set by useCanvasDprSize) rather than reading
+ // window.devicePixelRatio directly — so the offscreen always matches the
+ // visible canvas's resolution even if the DPR changes before the sizing hook
+ // re-runs (a fresh-DPR scene composited into a stale-DPR canvas would blur).
+ const fallbackDpr = (typeof window !== 'undefined' && window.devicePixelRatio) || 1;
+ const backingW = canvas.width || Math.round(width * fallbackDpr);
+ const backingH = canvas.height || Math.round(height * fallbackDpr);
+ const dpr = backingW / width;
const sig = {
width, height, zoom: zoomRef.current, scroll, chordLaneH,
- lowMidi, highMidi, multiTrack, dpr,
+ lowMidi, highMidi, multiTrack, backingW, backingH,
data, chords: chordLaneH ? chords : null, bg, accent, accentRgb,
};
const cached = sceneRef.current;
@@ -351,9 +359,7 @@ export default function MidiPianoRoll({ data, chords, showChords, zoom, onZoomCh
// Only re-allocate (which clears + resets the transform) when the pixel
// size actually changes; a pan/theme rebuild keeps the same buffer and
// repaints over it (paintScene clears its own frame first).
- const pxW = Math.round(width * dpr);
- const pxH = Math.round(height * dpr);
- if (off.width !== pxW || off.height !== pxH) { off.width = pxW; off.height = pxH; }
+ if (off.width !== backingW || off.height !== backingH) { off.width = backingW; off.height = backingH; }
const octx = off.getContext('2d');
if (octx) {
octx.setTransform(dpr, 0, 0, dpr, 0, 0);
diff --git a/client/src/hooks/useCanvasRollPalette.js b/client/src/hooks/useCanvasRollPalette.js
index cd06340533..b8f4680ed1 100644
--- a/client/src/hooks/useCanvasRollPalette.js
+++ b/client/src/hooks/useCanvasRollPalette.js
@@ -9,7 +9,11 @@ import { rollPalette } from '../lib/canvasRoll.js';
// (set by `useTheme` on <html>), but hands back a ref — not React state — so a
// theme switch repaints the canvas without forcing a component re-render.
export default function useCanvasRollPalette(drawRef) {
- const paletteRef = useRef(rollPalette());
+ // Lazy one-time init — `useRef(rollPalette())` would re-run the getComputedStyle
+ // read on every render (hover repaints re-render this component), defeating the
+ // point of caching the palette.
+ const paletteRef = useRef(null);
+ if (paletteRef.current === null) paletteRef.current = rollPalette();
useEffect(() => {
const apply = () => { paletteRef.current = rollPalette(); drawRef.current?.(); };
apply();