-
Notifications
You must be signed in to change notification settings - Fork 455
feat(ui): spotlight interactive captcha during sign-in/sign-up #8907
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
Draft
alexcarpenter
wants to merge
12
commits into
main
Choose a base branch
from
carp/captcha-inline-spotlight
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
28fbdce
feat(ui): surface interactive captcha signal via onInteractiveChange
alexcarpenter f4498bd
refactor(ui): hoist start-flow captcha to a single slot
alexcarpenter 4337e90
feat(ui): spotlight interactive captcha during sign-in/sign-up
alexcarpenter d289d93
chore(ui): add changeset for inline captcha spotlight
alexcarpenter 1499442
chore(js): add sandbox `?captcha=interactive` override to demo the in…
alexcarpenter b694ad7
fix(ui): lift captcha spotlight on resolve when browser serializes ma…
alexcarpenter fb7c867
fix(ui): collapse spotlighted column with display:none to drop the fl…
alexcarpenter e9df953
refactor(ui): dedup SignUpStart captcha beforeEach and skip redundant…
alexcarpenter 39763d0
handle feedback
alexcarpenter 68ffad8
fix(ui): fall back to maxHeight heuristic for old clerk-js without da…
alexcarpenter 043d920
chore(release): add changeset for clerk-js captcha spotlight compat fix
alexcarpenter ca463ef
Merge branch 'main' into carp/captcha-inline-spotlight
alexcarpenter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/ui': patch | ||
| --- | ||
|
|
||
| When an interactive bot-protection challenge appears during sign-in or sign-up, the card now brings the challenge to the foreground — hiding the other fields and buttons until it's solved — so it's clear the "Verify you are human" check must be completed. Invisible challenges are unaffected. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/clerk-js': patch | ||
| --- | ||
|
|
||
| Fix the inline captcha spotlight to expand correctly when an older clerk-js runtime is paired with a newer UI that expects the `data-cl-interactive` attribute — the challenge now falls back to the `maxHeight` heuristic so the spotlight still fires across version skews. |
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
64 changes: 64 additions & 0 deletions
64
packages/clerk-js/src/utils/captcha/__tests__/turnstile.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { CAPTCHA_ELEMENT_ID, CAPTCHA_INVISIBLE_CLASSNAME } from '@clerk/shared/internal/clerk-js/constants'; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { getTurnstileToken } from '../turnstile'; | ||
|
|
||
| /** | ||
| * Regression guard for the inline "spotlight": the spotlight keys off | ||
| * `#clerk-captcha`'s `style.maxHeight !== '0'`. The common invisible flow (~99% of | ||
| * challenges) must never create or mutate `#clerk-captcha`, so its `maxHeight` stays | ||
| * `'0'` and no spotlight is ever triggered. This pins that existing behavior. | ||
| */ | ||
| describe('getTurnstileToken — invisible flow', () => { | ||
| let renderConfig: Record<string, any> | undefined; | ||
|
|
||
| beforeEach(() => { | ||
| renderConfig = undefined; | ||
| (window as any).turnstile = { | ||
| render: vi.fn((_selector: string, config: Record<string, any>) => { | ||
| renderConfig = config; | ||
| // Real Turnstile returns the widget id, then fires the callback asynchronously. | ||
| // Invisible challenges resolve without ever escalating to interactive, so the | ||
| // `before-interactive-callback` (the only code that expands #clerk-captcha) never fires. | ||
| setTimeout(() => config.callback('mock_token'), 0); | ||
| return 'mock_widget_id'; | ||
| }), | ||
| remove: vi.fn(), | ||
| reset: vi.fn(), | ||
| }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| document.body.innerHTML = ''; | ||
| delete (window as any).turnstile; | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('renders into its own throwaway container, never #clerk-captcha', async () => { | ||
| // An inline #clerk-captcha may coexist on the page (e.g. a Start card is mounted), | ||
| // but an invisible challenge must never touch it. | ||
| const inline = document.createElement('div'); | ||
| inline.id = CAPTCHA_ELEMENT_ID; | ||
| inline.style.maxHeight = '0'; | ||
| document.body.appendChild(inline); | ||
|
|
||
| const result = await getTurnstileToken({ | ||
| captchaProvider: 'turnstile', | ||
| siteKey: 'visible-key', | ||
| invisibleSiteKey: 'invisible-key', | ||
| widgetType: 'invisible', | ||
| }); | ||
|
|
||
| expect(result).toEqual({ captchaToken: 'mock_token', captchaWidgetType: 'invisible' }); | ||
|
|
||
| // The invisible flow targets its own `.clerk-invisible-captcha` div with the invisible key. | ||
| expect((window as any).turnstile.render).toHaveBeenCalledWith(`.${CAPTCHA_INVISIBLE_CLASSNAME}`, expect.anything()); | ||
| expect(renderConfig?.sitekey).toBe('invisible-key'); | ||
|
|
||
| // The spotlight signal on #clerk-captcha is untouched throughout → no spotlight. | ||
| expect(inline.style.maxHeight || '0').toBe('0'); | ||
|
|
||
| // The temporary invisible container is created then cleaned up in `finally`. | ||
| expect(document.querySelector(`.${CAPTCHA_INVISIBLE_CLASSNAME}`)).toBeNull(); | ||
| }); | ||
| }); |
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
This may be breaking customers that have applied layout CSS changes on the Card.Content component, because it adds one more child to it.
The impact may be really small here, but let's make sure first.
Same applies for
SignInStart.tsx