Skip to content

[WC-3537]: Fix resizing issue with Signature pad - #2375

Open
r0b1n wants to merge 8 commits into
mainfrom
fix/signature
Open

[WC-3537]: Fix resizing issue with Signature pad#2375
r0b1n wants to merge 8 commits into
mainfrom
fix/signature

Conversation

@r0b1n

@r0b1n r0b1n commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Bug fixes

Strokes stop registering after widget resize

When the widget container was resized mid-stroke (e.g., opening browser DevTools), signature_pad left its internal _drawingStroke flag as true permanently. The pointerup listener had been removed from the window, so strokeEnd never fired and every subsequent pointerdown was silently dropped. Fixed by calling pad.off() before resizing the canvas and pad.on() after — this resets _drawingStroke and re-registers the pointer listeners.

Canvas initializes at wrong size

The canvas was initialized at the HTML default size (300×150) when the ResizeObserver fired before imageSource became available. On init, the pad now reads the container's actual dimensions directly before instantiating SignaturePad.

Code quality improvements

  • useSignaturePad owns the ResizeObserver — the hook now calls useResizeObserver internally and returns a containerRef alongside canvasRef. SizeContainer no longer manages the observer or exposes an onResize callback; it is a plain forwardRef component. This removes the prop-threading indirection, and the parentElement lookup.
  • pad.redraw() replaces manual toData()/clear()/fromData() — the library's own method handles the snapshot internally.
  • Pen options moved to a lookup table — replaced a useMemo with if/else chains with a Record<PenTypeEnum, Options> constant and a getPenOptions helper; type safety is enforced at the call site.
  • isSignatureInitialized ref removed — redundant alongside the existing signaturePadRef === null guard.
  • Clear-on-reset condition simplified — collapsed three nested if blocks into a single expression.

@r0b1n
r0b1n requested a review from a team as a code owner August 7, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant