Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/app/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,30 @@ function DrawCanvas({
const finishedRef = useRef(false);
const streamActiveRef = useRef(false);

const safelySetPointerCapture = useCallback(
(target: HTMLCanvasElement, pointerId: number) => {
if (!('setPointerCapture' in target)) return;
try {
target.setPointerCapture(pointerId);
} catch {
// iOS Safari can throw for touch pointers when capture isn't available.
}
},
[],
);

const safelyReleasePointerCapture = useCallback(
(target: HTMLCanvasElement, pointerId: number) => {
if (!('releasePointerCapture' in target)) return;
try {
target.releasePointerCapture(pointerId);
} catch {
// Ignore missing/stale capture state.
}
},
[],
);

// Drawing hook
const drawing = useDrawingCanvas({
userId,
Expand Down Expand Up @@ -536,12 +560,12 @@ function DrawCanvas({
className="w-full cursor-crosshair"
style={{ touchAction: 'none', backgroundColor: drawing.bgColor }}
onPointerDown={(e) => {
e.currentTarget.setPointerCapture(e.pointerId);
safelySetPointerCapture(e.currentTarget, e.pointerId);
drawing.handlePointerDown(e);
}}
onPointerMove={drawing.handlePointerMove}
onPointerUp={(e) => {
e.currentTarget.releasePointerCapture(e.pointerId);
safelyReleasePointerCapture(e.currentTarget, e.pointerId);
drawing.handlePointerUp(e);
}}
/>
Expand Down