fix(QRCode): guard against a non-positive size prop - #418
Merged
Conversation
`size` defaulted to 160 but was never validated, so `size={0}` or a negative
value gave the canvas invalid dimensions and rendered as a broken box with no
indication of why. Warn and skip the draw instead. The invalid-size check is
derived rather than stored so the spinner isn't left running while waiting on
a draw that will never be attempted.
Resolves Sorokit#310
|
@KayProject Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Resolves #310
Scope note
Two of the three items in the issue have already landed on
mainsince it was filed:fillRectgrid loop theclearRectfix targeted is gone.QRCodenow delegates toQRCodeLib.toCanvas, which sets the canvas dimensions and repaints the full area on each draw, so there's no partial-overdraw window left to fix.figure/figcaption— already in place; the wrapper is a<figure>and the label renders in a<figcaption>.That leaves the
sizeguard, which this PR implements.The fix
sizedefaulted to160but was never validated.size={0}or a negative value gave the canvas invalid dimensions and rendered as a broken box with no indication of why.Now a non-positive
sizelogs[QRCode] size must be > 0and skips the draw entirely —getContextis never reached.The check is derived at render rather than stored in state, for two reasons:
react-hooks/set-state-in-effectrule.isLoadingwould leave the spinner running forever, waiting on a draw that is never attempted. Deriving it lets the render skip the spinner directly.Verification
npx vitest run src/components/QRCode.test.tsx— 15 passed, including 4 new cases: warn + no draw forsize={0}, same for a negative size, no spinner left running for an invalid size, and no false warning for a valid size.ESLint clean on both changed files.
Heads-up on the build AC
npm run builddoesn't pass onmainfor unrelated reasons —FeeEstimator.tsxandSorobanPanel.tsxeach carry an unclosed block from a merge (also the source of 61 pre-existing test failures). Happy to open a separate repair PR.