From 106e8f51fc0cf220398cd728a9a3d7ddf08dec41 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Fri, 23 Oct 2026 18:00:40 -0400 Subject: [PATCH] fix(frontend): show a message when the QR renderer fails to load A rejected dynamic import left the pairing dialog blank forever. The renderer now loads through async/await with a catch and renders an error instead of nothing when the chunk cannot be fetched. --- .../settings/PairingQrCode.test.tsx | 22 ++++++++++++++++++- .../src/components/settings/PairingQrCode.tsx | 21 +++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/settings/PairingQrCode.test.tsx b/frontend/src/components/settings/PairingQrCode.test.tsx index d8839e97..0eca2543 100644 --- a/frontend/src/components/settings/PairingQrCode.test.tsx +++ b/frontend/src/components/settings/PairingQrCode.test.tsx @@ -1,8 +1,28 @@ -import { describe, expect, it } from 'vitest' +import { afterEach, describe, expect, it, vi } from 'vitest' import { render, screen } from '@testing-library/react' import { PairingQrCode } from './PairingQrCode' describe('PairingQrCode', () => { + afterEach(() => { + vi.doUnmock('uqr') + vi.resetModules() + }) + + it('reports a renderer that fails to load', async () => { + vi.resetModules() + vi.doMock('uqr', () => { + throw new Error('chunk failed') + }) + const { PairingQrCode: FreshPairingQrCode } = await import('./PairingQrCode') + + render() + + expect( + await screen.findByText('The QR code could not be loaded. Reload the page and try again.'), + ).toBeInTheDocument() + expect(screen.queryByAltText('Pairing QR code')).not.toBeInTheDocument() + }) + it('renders the QR code once uqr has loaded', async () => { render() diff --git a/frontend/src/components/settings/PairingQrCode.tsx b/frontend/src/components/settings/PairingQrCode.tsx index f4cf6f23..d7ce3b7c 100644 --- a/frontend/src/components/settings/PairingQrCode.tsx +++ b/frontend/src/components/settings/PairingQrCode.tsx @@ -11,12 +11,19 @@ interface PairingQrCodeProps { export function PairingQrCode({ value, label, blurred = false }: PairingQrCodeProps) { const [renderSvg, setRenderSvg] = useState(null) + const [loadFailed, setLoadFailed] = useState(false) useEffect(() => { let active = true - void import('uqr').then((module) => { - if (active) setRenderSvg(() => module.renderSVG) - }) + const loadRenderer = async () => { + try { + const module = await import('uqr') + if (active) setRenderSvg(() => module.renderSVG) + } catch { + if (active) setLoadFailed(true) + } + } + void loadRenderer() return () => { active = false } @@ -31,6 +38,14 @@ export function PairingQrCode({ value, label, blurred = false }: PairingQrCodePr } }, [renderSvg, value]) + if (loadFailed) { + return ( +

+ The QR code could not be loaded. Reload the page and try again. +

+ ) + } + if (!renderSvg) return null if (!source) {