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(recaptcha): various optimizations #3631

Merged
merged 10 commits into from
Dec 17, 2024
Merged

Conversation

chickenn00dle
Copy link
Contributor

@chickenn00dle chickenn00dle commented Dec 13, 2024

All Submissions:

Changes proposed in this Pull Request:

Closes https://app.asana.com/0/1207817176293825/1208950357031079/f

This PR makes some optimizations to our recaptcha implementation:

  1. Only render recaptcha once a form is focused
  2. Auto retry on recaptcha error/expire
  3. Specify recaptcha container so we don't break form layouts

Screenshot 2024-12-16 at 14 26 17

How to test the changes in this Pull Request:

  1. Enable recaptcha v2
  2. As reader open any page/post that contains a newsletters subscribe block but do not focus the form yet.
  3. In browser dev tools, search for an element with a data-recaptcha-widget-id attribute. There should be none
  4. Now click anywhere in the form
  5. In dev tools again, search for an element with a data-recaptcha-widget-id attribute. The button in the focused form should have this.
  6. Now smoke test all of the following, each time making sure the layout of the forms don't change as you focus:
    • Checkout Button or Donate block
    • Newsletters subscribe block
    • Registration block
    • RAS-ACC auth registration modal
  7. Enable recaptcha v3
  8. Repeat steps 2-6, this time searching for a hidden input with a name of g-recaptcha-response.
  9. Now smoke test all of the following:
    • Checkout Button or Donate block
    • Newsletters subscribe block
    • Registration block
    • RAS-ACC auth registration modal
  10. Disable recaptcha and smoke test the following
    • Checkout Button or Donate block
    • Newsletters subscribe block
    • Registration block
    • RAS-ACC auth registration modal

Testing recaptcha errors:
To test auto-retry on recaptcha error, you can force the error callback by replacing this line with callback: errorCallback:

callback: successCallback,

  1. Re-enable recaptcha v2
  2. As reader, go through any relevant form
  3. After recaptcha is triggered, instead of succeeding the error callback should be triggered, re-prompting the widget (in normal circumstances a render failure would not trigger the widget to appear)
  4. This should happen 3 times before an error is rendered asking for a page reload.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@chickenn00dle chickenn00dle force-pushed the fix/recaptcha-optimizations branch 2 times, most recently from 10072da to 9d3a932 Compare December 16, 2024 18:46
@chickenn00dle chickenn00dle marked this pull request as ready for review December 16, 2024 19:29
@chickenn00dle chickenn00dle requested a review from a team as a code owner December 16, 2024 19:29
@chickenn00dle chickenn00dle force-pushed the fix/recaptcha-optimizations branch from 3036508 to ba6f10f Compare December 16, 2024 19:29
@chickenn00dle chickenn00dle added ras-acc testing [Status] Needs Review The issue or pull request needs to be reviewed labels Dec 16, 2024
Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

@chickenn00dle all is working well, and the rendering of the widgets/hidden fields during field focus is seamless and causes no detectable form layout changes or delays in form submission. 🎉

The only thing I see is that when displaying the v2 widget on the modal checkout second screen, the modal is no longer scrolling up to bring it into the viewport. As a reader, if I don't know to expect a reCAPTCHA v2 widget, it's hard to tell what's happening as the form inside modal simply becomes greyed-out and non-interactive. Could we ensure that if the widget is displayed, we're scrolling the modal viewport so that it's visible?

@dkoo
Copy link
Contributor

dkoo commented Dec 16, 2024

Also, I pushed 80cb850 because I saw an issue in my local environment while testing this in which the site key/secret fields in the admin dashboard were appearing empty even though I knew the data existed in my site DB.

@chickenn00dle
Copy link
Contributor Author

The only thing I see is that when displaying the v2 widget on the modal checkout second screen, the modal is no longer scrolling up to bring it into the viewport. As a reader, if I don't know to expect a reCAPTCHA v2 widget, it's hard to tell what's happening as the form inside modal simply becomes greyed-out and non-interactive. Could we ensure that if the widget is displayed, we're scrolling the modal viewport so that it's visible?

That's odd. On my end it looks to be scrolling:

Screen.Recording.2024-12-16.at.16.52.21.mov

@chickenn00dle chickenn00dle force-pushed the fix/recaptcha-optimizations branch from 80cb850 to c66d116 Compare December 16, 2024 22:49
@chickenn00dle chickenn00dle requested a review from dkoo December 17, 2024 00:01
@dkoo
Copy link
Contributor

dkoo commented Dec 17, 2024

fe03f44 restores a couple of lines from #3283 which trigger a re-render of v2 widgets when Woo checkout fires updated_checkout or checkout_error jQuery events. These events indicate that entire form elements (including our widgets and the submit buttons they're attached to) may have been replaced by new DOM elements, so re-rendering ensures that the reCAPTCHA check will continue to happen afterward.

Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

This is working now on my end, and because it's in response to some time-sensitive publisher requests, I'm going to go ahead and merge without a second PR reviewer. 🤞

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Dec 17, 2024
@dkoo dkoo merged commit 5d816bc into release Dec 17, 2024
8 checks passed
@dkoo dkoo deleted the fix/recaptcha-optimizations branch December 17, 2024 00:24
matticbot pushed a commit that referenced this pull request Dec 17, 2024
## [5.10.2](v5.10.1...v5.10.2) (2024-12-17)

### Bug Fixes

* **recaptcha:** various optimizations ([#3631](#3631)) ([5d816bc](5d816bc)), closes [#3627](#3627)
@matticbot
Copy link
Contributor

🎉 This PR is included in version 5.10.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ras-acc testing released [Status] Approved The pull request has been reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants