[WC-3537]: Fix resizing issue with Signature pad - #2375
Open
r0b1n wants to merge 8 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug fixes
Strokes stop registering after widget resize
When the widget container was resized mid-stroke (e.g., opening browser DevTools),
signature_padleft its internal_drawingStrokeflag astruepermanently. Thepointeruplistener had been removed from the window, sostrokeEndnever fired and every subsequentpointerdownwas silently dropped. Fixed by callingpad.off()before resizing the canvas andpad.on()after — this resets_drawingStrokeand re-registers the pointer listeners.Canvas initializes at wrong size
The canvas was initialized at the HTML default size (300×150) when the
ResizeObserverfired beforeimageSourcebecame available. On init, the pad now reads the container's actual dimensions directly before instantiatingSignaturePad.Code quality improvements
useSignaturePadowns theResizeObserver— the hook now callsuseResizeObserverinternally and returns acontainerRefalongsidecanvasRef.SizeContainerno longer manages the observer or exposes anonResizecallback; it is a plainforwardRefcomponent. This removes the prop-threading indirection, and theparentElementlookup.pad.redraw()replaces manualtoData()/clear()/fromData()— the library's own method handles the snapshot internally.useMemowithif/elsechains with aRecord<PenTypeEnum, Options>constant and agetPenOptionshelper; type safety is enforced at the call site.isSignatureInitializedref removed — redundant alongside the existingsignaturePadRef === nullguard.ifblocks into a single expression.