Skip to content

fix(frontend): Allow new QR code library in the CSP#12167

Merged
AntonioVentilii merged 1 commit intomainfrom
fix-frontend/Allow-new-QR-code-library-in-the-CSP
Mar 25, 2026
Merged

fix(frontend): Allow new QR code library in the CSP#12167
AntonioVentilii merged 1 commit intomainfrom
fix-frontend/Allow-new-QR-code-library-in-the-CSP

Conversation

@AntonioVentilii
Copy link
Copy Markdown
Collaborator

Motivation

To use the new library from QrCodeReader component (PR #12162) we need to allow it in the CSP.

@AntonioVentilii AntonioVentilii requested a review from a team as a code owner March 25, 2026 15:46
Copilot AI review requested due to automatic review settings March 25, 2026 15:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the frontend build configuration and CSP to support the new WASM-based QR scanning stack (barcode-detector) introduced for the QrCodeReader component.

Changes:

  • Switches Vite “lazy” chunking from html5-qrcode to barcode-detector.
  • Updates QrCodeScanner to handle a new nnsQRCodeError event from QrCodeReader.
  • Relaxes CSP script-src to include wasm-unsafe-eval to allow WebAssembly compilation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
vite.config.ts Updates Rollup manual chunking to treat barcode-detector as a lazily-loaded dependency.
src/frontend/src/lib/components/qr/QrCodeScanner.svelte Adds handling for QR reader error events during scanning.
scripts/build.csp.mjs Adjusts CSP script-src to permit WASM compilation required by the new scanner library.
Comments suppressed due to low confidence (1)

vite.config.ts:37

  • barcode-detector pulls in zxing-wasm (via dependency), but only barcode-detector was added to the lazy chunk allowlist. With the current manualChunks logic, zxing-wasm modules will likely land in the vendor chunk and be downloaded eagerly, which defeats the purpose of lazy-loading the QR scanning stack. Consider adding zxing-wasm (and any other large transitive deps used exclusively for scanning) to the lazy list so they remain in the lazy chunk.
					const lazy = ['@dfinity/nns', '@dfinity/nns-proto', 'barcode-detector', 'qr-creator'];

					if (
						['@sveltejs', 'svelte', '@dfinity/gix-components', ...lazy].find((lib) =>
							folder.includes(lib)

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

@AntonioVentilii AntonioVentilii added this pull request to the merge queue Mar 25, 2026
Merged via the queue into main with commit c2e1cfb Mar 25, 2026
85 checks passed
@AntonioVentilii AntonioVentilii deleted the fix-frontend/Allow-new-QR-code-library-in-the-CSP branch March 25, 2026 16:04
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.

3 participants