Fix blank QR in ShareProfileDialog — import qrcode lazily

Top-level `import QRCode from 'qrcode'` crashes on its canvas dependency at
module load, leaving the QR blank. Switch to the shared generateQRCode helper
which imports qrcode lazily (dynamic import), matching every other working QR
in the app. Also reset the QR while regenerating and log failures.

Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
shakespeare.diy 2026-09-02 22:12:45 +07:00
parent deb8fe1995
commit 1b57f79cba

View file

@ -1,9 +1,9 @@
import { useEffect, useState } from 'react';
import QRCode from 'qrcode';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Check, Copy, Share2, Loader2 } from 'lucide-react';
import { useToast } from '@/hooks/useToast';
import { generateQRCode } from '@/lib/wallet/qrCodeGenerator';
interface ShareProfileDialogProps {
open: boolean;
@ -33,14 +33,15 @@ export function ShareProfileDialog({ open, onOpenChange, npub, displayName }: Sh
useEffect(() => {
if (!open) return;
let active = true;
QRCode.toDataURL(shareUrl, {
width: 320,
margin: 1,
color: { dark: '#000000', light: '#ffffff' },
errorCorrectionLevel: 'M',
})
setQr(null);
// qrcode must be imported lazily (see generateQRCode) — a top-level import
// crashes on its canvas dependency at module load.
generateQRCode(shareUrl)
.then((url) => { if (active) setQr(url); })
.catch(() => { if (active) setQr(null); });
.catch((err) => {
console.error('[ShareProfileDialog] QR generation failed:', err);
if (active) setQr(null);
});
return () => { active = false; };
}, [open, shareUrl]);