-
Notifications
You must be signed in to change notification settings - Fork 314
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(clerk-js): Fix captcha layout shift on invisible and custom flows #5049
Conversation
🦋 Changeset detectedLatest commit: e285189 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
!snapshot |
Hey @anagstef - the snapshot version command generated the following package versions:
Tip: Use the snippet copy button below to quickly install the required packages. npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact |
!snapshot |
Hey @anagstef - the snapshot version command generated the following package versions:
Tip: Use the snippet copy button below to quickly install the required packages. npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
|
||
return ( | ||
<Box | ||
ref={elementRef} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use a useCallback instead of useEffect + elementRef, but i think this comes down to personal preference, so feel free to ignore.
Description
The initial issue:
The Turnstile script causes a minor layout shift when it starts executing. Until now we use to force the Div element rendering the challenge to have
max-height
set to0
. And then, right before the script becomes interactive we override the styles of it to let it show the challenge. The issue here is that the turnstile script lives outside of the react ecosystem/lifecycles, so if a re-render is triggered on our div element, then it resets tomax-height: 0
.Proposed solution:
In order to be able to persist the state that is altered from the outside of this component, we use a
MutationObserver
and keep the state in a ref, so the latest state is always applied on re-renders, instead of resetting to 0.In this PR:
This PR is fixing an issue with a layout shift we have on transfer flow, where we could not force the max-height to 0 until now because it was being re-applied on a re-render and the captcha challenge was getting hidden.
Also, we initialize the container element to
max-height: 0
for either smart or invisible beforecaptcha.render
is called.Transfer flow with invisible/non-interactive widget:
https://github.com/user-attachments/assets/7d003e65-2ba0-4306-b5c1-6ff6926cc91c
Custom flow invisible/non-interactive widget:
custom-flow-invisible.mp4
Custom flow interactive widget:
custom-flow-interactive.mp4
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change