Skip to content
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

fix issue with chrome freezing on android #4

Closed
jeznag opened this issue Mar 5, 2021 · 9 comments
Closed

fix issue with chrome freezing on android #4

jeznag opened this issue Mar 5, 2021 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@jeznag
Copy link
Contributor

jeznag commented Mar 5, 2021

Fix for JodusNodus/react-qr-reader#185

Here is the diff that solved my problem:

diff --git a/node_modules/modern-react-qr-reader/lib/index.js b/node_modules/modern-react-qr-reader/lib/index.js
index 27330bc..f02698a 100644
--- a/node_modules/modern-react-qr-reader/lib/index.js
+++ b/node_modules/modern-react-qr-reader/lib/index.js
@@ -235,7 +235,11 @@ module.exports = (_temp = _class = function (_Component) {
 
       var streamTrack = stream.getTracks()[0];
       // Assign `stopCamera` so the track can be stopped once component is cleared
-      this.stopCamera = streamTrack.stop.bind(streamTrack);
+      this.stopCamera = () => {
+        setTimeout(() => {
+          streamTrack.stop();
+        }, 2000);
+      }
 
       preview.addEventListener('loadstart', this.handleLoadStart);
 
diff --git a/node_modules/modern-react-qr-reader/src/index.js b/node_modules/modern-react-qr-reader/src/index.js
index 879993e..3e5f13c 100644
--- a/node_modules/modern-react-qr-reader/src/index.js
+++ b/node_modules/modern-react-qr-reader/src/index.js
@@ -195,7 +195,11 @@ module.exports = class Reader extends Component {
 
     const streamTrack = stream.getTracks()[0]
     // Assign `stopCamera` so the track can be stopped once component is cleared
-    this.stopCamera = streamTrack.stop.bind(streamTrack)
+    this.stopCamera = () => {
+      setTimeout(() => {
+        streamTrack.stop();
+      }, 2000);
+    }
 
     preview.addEventListener('loadstart', this.handleLoadStart)
 

This issue body was partially generated by patch-package.

@KhaosArbiter
Copy link
Owner

Thank you for the input. Can you please submit a pull request for the changes and I will be happy to test and implement this. Is this in regard to the browser freezing due to OOM issues if it's been running for a bit without a successful scan or some separate issue?

@DaemonAlchemist
Copy link

I'm getting this issue as well: If I close the reader by removing the QRReader component once I get a successful scan, the browser freezes. It happens even if the reader has only been open a few seconds.

@KhaosArbiter
Copy link
Owner

Merged your pull request and tested, it works great. NPM Package has been updated as well. Thank you @jeznag

@KhaosArbiter
Copy link
Owner

This actually still seems to be an issue. Reopening this to take a closer look.

@KhaosArbiter KhaosArbiter self-assigned this Mar 16, 2021
@DaemonAlchemist
Copy link

Well, the original fix seems to work for my use case.

@KhaosArbiter KhaosArbiter added the bug Something isn't working label Mar 16, 2021
@KhaosArbiter
Copy link
Owner

Can I ask what version of Chrome you are running and on what device? I just want to compare and rule out it being a local issue.

@KhaosArbiter
Copy link
Owner

The issue comes and goes on a LG V60 running Chrome 89.0.4389.90

@KhaosArbiter
Copy link
Owner

I actually think this might be a separate issue. I am going to close this again, that is my mistake. It seems to work, but if I refresh the page for some reason it will no longer scan. It doesn't freeze though. I have to switch to a different page with an instance of the component and it works fine, but trying to scan different codes after it's been removed from the page seems to not work.

@DaemonAlchemist
Copy link

My test device is a Pixel 2 running Chrome 89 on Android 11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants