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

Stops working after Polyfill component unmounts #15

Closed
kowalski opened this issue Oct 1, 2020 · 3 comments
Closed

Stops working after Polyfill component unmounts #15

kowalski opened this issue Oct 1, 2020 · 3 comments

Comments

@kowalski
Copy link

kowalski commented Oct 1, 2020

This happens on Android when app is closed and opened again.
The new React component is created but the global module context holds old reference to worker.

@sirpy
Copy link
Collaborator

sirpy commented Oct 1, 2020

I dont have much time to investigate this, but maybe you can suggest a quick fix.
do you have a suggestion for a fix?
can you point me to the code you think is the source of the issue?
@kowalski

@kowalski
Copy link
Author

kowalski commented Oct 1, 2020

@sirpy I was going to ask a colleage to do a PR @Ofadiman

I think the fix is like

class PolyfillCrypto extends React.Component {
  constructor(props) {
    super(props);
    this.props = props;
    this.webViewRef = React.createRef();
  }

  shouldComponentUpdate() {
    return false;
  }

  componentWillUnmount() {
    resolveWorker = undefined;
+    workerPromise = new Promise((resolve) => {
+      resolveWorker = resolve;
+    });
  }

So basically reset the promise that holds the reference when component is unmounting so that the next one can set the correct reference.

@kowalski
Copy link
Author

kowalski commented Oct 2, 2020

@sirpy @Ofadiman added the pull request with the changes that fix it for us

@sirpy sirpy closed this as completed May 20, 2021
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

No branches or pull requests

2 participants