Prosopo Procaptcha: guard against wpautop hoisting captcha children out of the custom element - #853
Merged
dannyvankooten merged 1 commit intoAug 13, 2026
Conversation
…ment
Some themes (and any content path that applies `wpautop`) wrap the
`<mc4wp-procaptcha>` custom element in a `<p>`. The HTML parser then
auto-closes that `<p>` before the child `<div class="mc4wp-procaptcha__captcha">`
— block-level content is not allowed inside `<p>` — hoisting the container
out as a sibling. `this.querySelector('.mc4wp-procaptcha__captcha')` returns
null, `window.procaptcha.render(null, …)` throws, and the page's other JS
stops running.
Walk to the enclosing `<form>` when the local query returns null, and skip
rendering with a console warning rather than crashing if the container is
truly absent.
Reported on gilliancooper.co.uk (Flatsome + LiteSpeed). Latent since the
integration shipped; only manifests when the surrounding markup wraps the
custom element in a `<p>`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
<mc4wp-procaptcha>custom element'ssetup()callsthis.querySelector('.mc4wp-procaptcha__captcha')and passes the result straight towindow.procaptcha.render(...). If the custom element ends up wrapped in a<p>(as it does underwpautop, or in many themes that filter form content), the browser's HTML parser auto-closes that<p>before the child<div>— block-level content is not permitted inside<p>— and hoists the captcha container out to become a sibling.Result:
querySelectorreturnsnull,render(null, …)throws aTypeError: Cannot read properties of null (reading 'tagName'), and the page's other JavaScript stops running.Reproduced on gilliancooper.co.uk (Flatsome + LiteSpeed Cache). The problem has been latent since the integration shipped in October 2024; it only surfaces when the surrounding markup wraps the custom element in a
<p>.Fix
In
setup():<form>when the localquerySelectorreturnsnull, for both the captcha container and the validation error element.console.warnrather than crashing if the container is genuinely missing.The plugin's PHP-side markup is already correct — this is purely defensive against downstream markup post-processing.
Test plan
<div>child intact) — widget renders as before.<p>(or run the content throughwpautop) — widget renders using the sibling<div>instead of crashing.