Skip to content

fix: improve null safety in QrCodeOverlay - #2434

Open
synakr wants to merge 3 commits into
inji:masterfrom
synakr:fix/qrcodeoverlay-null-safety
Open

fix: improve null safety in QrCodeOverlay#2434
synakr wants to merge 3 commits into
inji:masterfrom
synakr:fix/qrcodeoverlay-null-safety

Conversation

@synakr

@synakr synakr commented May 3, 2026

Copy link
Copy Markdown

Summary

Improved null safety and edge-case handling in QrCodeOverlay to prevent potential runtime errors.

Changes

  • Added safe checks before accessing keyData[1] from secure storage
  • Handled empty object case when extracting QR data from claim169
  • Added null check before calling toDataURL on qrRef

Impact

Prevents crashes caused by:

  • undefined or incomplete async data
  • empty object key access
  • uninitialized component refs

Notes

  • No functional changes
  • Minimal, safe improvements to robustness and stability

Summary by CodeRabbit

Bug Fixes

  • Improved QR code generation reliability with enhanced data validation and safer data access patterns.
  • Strengthened QR code sharing functionality with additional null-safety checks and error handling to prevent crashes during normal operation.

Signed-off-by: Chandra Keshav Mishra <chandrakeshavmishra@gmail.com>
Copilot AI review requested due to automatic review settings May 3, 2026 19:37
@coderabbitai

coderabbitai Bot commented May 3, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@synakr has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 40 minutes and 25 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 104c250e-f3e8-4a6b-9ac8-a93982fb688b

📥 Commits

Reviewing files that changed from the base of the PR and between 41fe57c and 9da55bf.

📒 Files selected for processing (1)
  • components/QrCodeOverlay.tsx

Walkthrough

Three functions in QrCodeOverlay.tsx receive defensive null and undefined checks: getQRData uses optional chaining to safely validate keystore data before indexing, getClaim169Qr refactors claim extraction to check key existence, and handleShareQRCodePress guards ref access before invoking method calls.

Changes

Defensive Safety Improvements

Layer / File(s) Summary
Data Access Safety
components/QrCodeOverlay.tsx
getQRData now requires keyData?.length > 1 and safely accesses keyData?.[1] with optional chaining. getClaim169Qr extracts keys array first and checks existence before indexing, replacing direct [0] access on Object.keys(...) result.
Ref Invocation Safety
components/QrCodeOverlay.tsx
handleShareQRCodePress guards against missing ref by checking qrRef.current?.toDataURL exists before invoking it, replacing unconditional method call.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • KiruthikaJeyashankar
  • swatigoel

Poem

🐰 A rabbit hops through QR code lands,
Where keyData checks now firmly stand,
Optional chains keep crashes at bay,
Safe refs and keys in every way! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: improving null safety checks in the QrCodeOverlay component.
Description check ✅ Passed The description is well-structured with summary, changes, and impact sections, but lacks the required issue ticket number and screenshots fields from the repository template.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 40 minutes and 25 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves runtime robustness of QrCodeOverlay by adding defensive checks around async secure-storage reads, claim169 QR extraction, and QR ref usage to prevent crashes from null/undefined data.

Changes:

  • Guarded access to secure storage tuple data (keyData[1]) with optional chaining and length checks.
  • Handled empty-object claim169 payloads safely when selecting the first QR entry.
  • Added a null-safe guard before calling toDataURL on the QR code ref during sharing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +58 to +60
claim169Qrs && typeof claim169Qrs === 'object'
? Object.keys(claim169Qrs)
: [];
Comment on lines 72 to +77
function handleShareQRCodePress() {
qrRef.current.toDataURL(dataURL => {
shareImage(`${base64ImageType}${dataURL}`);
});
if (qrRef.current?.toDataURL) {
qrRef.current.toDataURL(dataURL => {
shareImage(`${base64ImageType}${dataURL}`);
});
}
@synakr
synakr force-pushed the fix/qrcodeoverlay-null-safety branch 2 times, most recently from 02dcf44 to 2c596e5 Compare May 3, 2026 19:49
synakr added 2 commits May 4, 2026 01:26
Signed-off-by: Md Sayan Akram <mdsayanakram@gmail.com>
Signed-off-by: Md Sayan Akram <mdsayanakram@gmail.com>
@synakr
synakr force-pushed the fix/qrcodeoverlay-null-safety branch from 2c596e5 to 9da55bf Compare May 3, 2026 19:57
@swatigoel

Copy link
Copy Markdown
Contributor

@synakr please check coderabbit comment and raise PR for develop

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.

4 participants