Skip to content

fix(QRCode): guard against a non-positive size prop - #418

Merged
k-deejah merged 1 commit into
Sorokit:mainfrom
KayProject:fix/qrcode-size-guard
Jul 29, 2026
Merged

fix(QRCode): guard against a non-positive size prop#418
k-deejah merged 1 commit into
Sorokit:mainfrom
KayProject:fix/qrcode-size-guard

Conversation

@KayProject

Copy link
Copy Markdown
Contributor

Resolves #310

Scope note

Two of the three items in the issue have already landed on main since it was filed:

  • Canvas clearing / ghost artifacts — the hand-rolled fillRect grid loop the clearRect fix targeted is gone. QRCode now delegates to QRCodeLib.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 size guard, which this PR implements.

The fix

size defaulted to 160 but 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 size logs [QRCode] size must be > 0 and skips the draw entirely — getContext is never reached.

The check is derived at render rather than stored in state, for two reasons:

  1. Setting state inside the effect trips the repo's react-hooks/set-state-in-effect rule.
  2. Returning early from the effect without settling isLoading would 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.tsx15 passed, including 4 new cases: warn + no draw for size={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 build doesn't pass on main for unrelated reasons — FeeEstimator.tsx and SorobanPanel.tsx each carry an unclosed block from a merge (also the source of 61 pre-existing test failures). Happy to open a separate repair PR.

`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
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@k-deejah
k-deejah merged commit add0b1f into Sorokit:main Jul 29, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(QRCode): canvas not cleared on value change causing ghost artifacts, size<=0 not guarded, wrapper missing figure/figcaption

2 participants