Skip to content

Try to render captcha a second time on a timeout#2058

Merged
Crabcyborg merged 4 commits into
masterfrom
try_to_render_captcha_on_a_timeout
Oct 17, 2024
Merged

Try to render captcha a second time on a timeout#2058
Crabcyborg merged 4 commits into
masterfrom
try_to_render_captcha_on_a_timeout

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Oct 16, 2024

Related Slack conversation https://strategy11.slack.com/archives/C799A2R61/p1729107464507059

Now if the form immediately becomes visible (within the next second), the captcha will still render.

@Crabcyborg Crabcyborg added this to the 6.16 milestone Oct 16, 2024
@Crabcyborg Crabcyborg changed the title Try to render captcha on a timeout Try to render captcha a second time on a timeout Oct 16, 2024
@Crabcyborg Crabcyborg marked this pull request as ready for review October 16, 2024 20:25
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 16, 2024

Walkthrough

The changes in this pull request focus on enhancing the captcha rendering logic within the frmCaptcha function in js/formidable.js. A new timeout mechanism is introduced to re-attempt rendering captchas every 400 milliseconds if the associated form is not visible. Additionally, minor refactorings improve code clarity by explicitly defining and using the variable captcha. Several function signatures have been updated to reflect these changes, ensuring that the captcha rendering process operates correctly even when forms are initially hidden.

Changes

File Change Summary
js/formidable.js - Updated frmCaptcha to include a timeout for rendering captchas if forms are hidden.
- Refactored frmCaptcha for improved variable clarity.
- Updated signatures for frmRecaptcha and frmAfterRecaptcha to align with new logic.

Possibly related PRs

  • Skip rendering captcha only if closest form is hidden #1987: This PR modifies the logic for rendering captchas based on the visibility of the closest form, which is directly related to the changes made in the frmCaptcha function regarding captcha rendering when forms are hidden.
  • Fix pro issue 1961 #2003: This PR addresses issues with invisible captchas and improves the validation process, which is relevant to the changes in the frmCaptcha function that enhance captcha rendering logic.

Suggested reviewers

  • AbdiTolesa
  • garretlaxton
  • truongwp

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
js/formidable.js (1)

1864-1878: Approve changes with a minor suggestion.

The changes to the frmCaptcha function look good. They address the issue of captcha not rendering correctly when the form is initially hidden. The added timeout mechanism is a smart solution to handle forms that fade into view.

A minor suggestion for improvement:

Consider extracting the timeout logic into a separate function for better readability and potential reuse. For example:

function renderCaptchaWithDelay(captcha, captchaSelector, closestForm) {
    setTimeout(
        function() {
            if (closestForm && closestForm.offsetParent !== null) {
                frmFrontForm.renderCaptcha(captcha, captchaSelector);
            }
        },
        1000
    );
}

Then you can call this function instead of having the setTimeout directly in the loop.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 19df972 and f619f6d.

📒 Files selected for processing (1)
  • js/formidable.js (1 hunks)
🧰 Additional context used

@engahmeds3ed
Copy link
Copy Markdown
Contributor

formidable-6.15.1-beta.zip

Zip file from that change.

@Crabcyborg just to confirm, we are sure that one second is enough time, correct?

@Crabcyborg
Copy link
Copy Markdown
Contributor Author

@engahmeds3ed I'm not totally confident it's perfect, no.

It might be nice to actually use an interval so we can solve the modal issue as well.

@Crabcyborg
Copy link
Copy Markdown
Contributor Author

@engahmeds3ed I just updated this to try an interval instead. I shortened it to 400ms now as well so it should be more instant when the visibility change happens.

It should solve the modal issue as well.

Could you help test it out?

Thank you!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
js/formidable.js (1)

1864-1880: Improved captcha rendering logic for hidden forms

The changes to the frmCaptcha function introduce a more robust handling of captcha rendering, especially for forms that may not be immediately visible. This is a good improvement that addresses potential issues with forms in modals or those that fade in on page load.

Key improvements:

  1. Checks if the closest form is visible before rendering the captcha.
  2. If the form is not visible, it sets up an interval to check visibility every 400ms.
  3. Once the form becomes visible, it renders the captcha and clears the interval.

These changes should help prevent issues where captchas fail to render properly in dynamically displayed forms.

Consider adding a maximum number of retry attempts or a timeout for the interval to prevent potential infinite loops in edge cases where the form never becomes visible.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f619f6d and 9d903ae.

📒 Files selected for processing (1)
  • js/formidable.js (1 hunks)
🧰 Additional context used

@engahmeds3ed
Copy link
Copy Markdown
Contributor

I tested this change for that case and it works perfectly.

Let me validate with the modal issue.

@engahmeds3ed
Copy link
Copy Markdown
Contributor

It works perfectly also with the modal issue, u r awesome @Crabcyborg

The only risk here is that the interval will keep working forever till the modal trigger button is clicked, once it's clicked and the form appears, we will clear that interval.
I think this is acceptable risk as we only do a small check each time.

@Crabcyborg
Copy link
Copy Markdown
Contributor Author

Thanks @engahmeds3ed!

Yeah, I think it should be fine. It only happens if it's hidden as well and helps to fix the whole class of new tickets that have been coming up because of this visibility check.

@Crabcyborg Crabcyborg merged commit 2d82d41 into master Oct 17, 2024
@Crabcyborg Crabcyborg deleted the try_to_render_captcha_on_a_timeout branch October 17, 2024 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants