Skip to content

feat: re-export setZXingModuleOverrides #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2023

Conversation

gruhn
Copy link
Owner

@gruhn gruhn commented Aug 7, 2023

The BarcodeDetector polyfill fetches a WASM file at runtime from a CDN. That's a problem for offline applications or applications that run in a network with strict CSP policy. As a workaround the polyfill exports a function to configure the WASM file URL. So we re-export the function here.

Also, by default the BarcodeDetector polyfill installs itself by setting globalThis.BarcodeDetector but only if there is no native support. This is likely not SSR compatible. Also, native support BarcodeDetector is inconsistent. For example, Chrome on MacOS does support BarcodeDetector but does not support Blob inputs, violating the specification. To have a more consistent support we simply always use the polyfill on all platforms. That likely comes as at a performance cost in raw scanning speed on supporting platforms but the download penalty is paid either way.

TODO

  • testing ✔️
  • documentation ✔️
  • maybe create dedicated demo

See #354 #353

@netlify
Copy link

netlify bot commented Aug 7, 2023

Deploy Preview for vue-qrcode-reader ready!

Name Link
🔨 Latest commit 099a8d9
🔍 Latest deploy log https://app.netlify.com/sites/vue-qrcode-reader/deploys/64d2af7ca18fed00088d159b
😎 Deploy Preview https://deploy-preview-355--vue-qrcode-reader.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

src/index.ts Outdated
@@ -4,6 +4,8 @@ import QrcodeStream from './components/QrcodeStream.vue'
import QrcodeCapture from './components/QrcodeCapture.vue'
import QrcodeDropZone from './components/QrcodeDropZone.vue'

import { setZXingModuleOverrides } from '@sec-ant/barcode-detector'
Copy link
Contributor

Choose a reason for hiding this comment

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

This import is a combination of pure and side-effects, so it can potentially pollute globalThis unintendedly. If only pure module is needed, as shown in the changes of scanner.ts, I suggest changing the import path here to @sec-ant/barcode-detector/pure, too :)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ah yes, thanks. I don't know, here I did it right

@gruhn gruhn force-pushed the reexport-zxing-module-overrides branch from 32f429b to 12e544c Compare August 7, 2023 18:20
The BarcodeDetector polyfill fetches a WASM file at runtime from a
CDN. That's a problem for offline applications or applications that
run in a network with strict CSP policy. As a workaround the polyfill
exports a function to configure the WASM file URL. So we re-export
the function here.

Also, by default the BarcodeDetector polyfill installs itself by setting
`globalThis.BarcodeDetector` but only if there is no native support.
This is likely not SSR compatible. Also, native support `BarcodeDetector`
is inconsistent. For example, Chrome on MacOS does support `BarcodeDetector`
but does not support `Blob` inputs, violating the specification. To have
a more consistent support we simply always use the polyfill on all
platforms. That likely comes as at a performance cost in raw scanning speed
on supporting platforms but the download penalty is paid either way.

See #354 #353
@gruhn gruhn force-pushed the reexport-zxing-module-overrides branch from 12e544c to 099a8d9 Compare August 8, 2023 21:11
@gruhn gruhn marked this pull request as ready for review August 8, 2023 21:13
@gruhn gruhn merged commit e16cdb1 into master Aug 8, 2023
@github-actions
Copy link

github-actions bot commented Aug 8, 2023

🎉 This PR is included in version 5.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants