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

ReCaptcha V2 is not rendered if provider and comsumer is not rendered at the same time #27

Closed
denke8 opened this issue May 7, 2020 · 3 comments · Fixed by #28
Closed
Assignees
Labels
bug Something isn't working

Comments

@denke8
Copy link

denke8 commented May 7, 2020

Describe the bug
If you use the widget like the example show, it works correctly, but if you want to use it in a more complex app, which uses somekind of router, put the provider around the router and later navigate to a route which renders the recaptcha, is not rendered.

To Reproduce
-Run create react app
-replace the content of app.js with the following:

import React, { useState, useEffect } from "react";
import { ReCaptchaProvider, ReCaptchaV2 } from "react-recaptcha-x";

const delay = 500;

function App() {
  const [show, setShow] = useState(false);

  useEffect(() => {
    setTimeout(() => setShow(true), delay);
  }, []);

  return (
    <div>
      <ReCaptchaProvider siteKeyV2="KEY">
        {show && (
          <>
            rendered
            <ReCaptchaV2 callback={() => {}} />
          </>
        )}
      </ReCaptchaProvider>
    </div>
  );
}

export default App;

Expected behavior
the recaptcha whould render

Actual
If you set delay to ~50 it works, if tou set it to ~500 it does not. I guess it depends on when the google recaptcha script (added by this lib) loads

Desktop

  • OS: Ubuntu 20.04
  • Browser Firefox 75.0 (64bit)
  • React 16.13.1
  • Rreact-dom 16.13.1
  • React-recaptcha-x 1.1.3
  • React-scripts 3.4.1
@denke8 denke8 added the bug Something isn't working label May 7, 2020
@antokara
Copy link
Owner

antokara commented May 7, 2020

thank you @denesstreambright for the report, I'll try to fix it quickly.

antokara added a commit that referenced this issue May 8, 2020
* modify index of dev and examples, to test and demo delayed render of v2 widget
* fix comment in v2 component IState
* rename checkComponentDidUpdate method of v2 component, to shouldRenderWidget and change comparison logic to check if previously rendered instead of change in providerContext.loaded
* add componentDidMount lifecycle event method in v2 component to invoke shouldRenderWidget
* refactor v2 component tests to smaller files
* add v2 component tests for test with initial providerContext.loaded:true

fix #27
antokara added a commit that referenced this issue May 8, 2020
* modify index of dev and examples, to test and demo delayed render of v2 widget
* fix comment in v2 component IState
* rename checkComponentDidUpdate method of v2 component, to shouldRenderWidget and change comparison logic to check if previously rendered instead of change in providerContext.loaded
* add componentDidMount lifecycle event method in v2 component to invoke shouldRenderWidget
* refactor v2 component tests to smaller files
* add v2 component tests for test with initial providerContext.loaded:true

fix #27
antokara added a commit that referenced this issue May 8, 2020
## [1.1.4](v1.1.3...v1.1.4) (2020-05-08)

### Bug Fixes

* **packages:** update npm packages ([ce9eea4](ce9eea4))
* **recaptcha v2 component:** delayed render ([bab3d2d](bab3d2d)), closes [#27](#27)
@antokara
Copy link
Owner

antokara commented May 8, 2020

@denesstreambright I just released v1.1.4 with the fix
https://www.npmjs.com/package/react-recaptcha-x/v/1.1.4

please let me know if the issue persists.
Thanks again and if you like this package, consider starring it, to support it and help others find it.

@denke8
Copy link
Author

denke8 commented May 8, 2020

Thanks for the quick fix, it works now!

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

Successfully merging a pull request may close this issue.

2 participants