-
Notifications
You must be signed in to change notification settings - Fork 431
feat(react,vue,astro): Replace clerkUiCtor prop with ui prop #7664
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
Open
jacekradko
wants to merge
22
commits into
main
Choose a base branch
from
jrad/ui-prop-cleanup
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.
+568
−140
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c5ff0d1
feat(react,vue,astro): Add ui prop for version metadata
jacekradko d8370e0
chore: add changeset for ui prop
jacekradko 67fdc89
refactor: use ui prop instead of clerkUiCtor in chrome-extension
jacekradko 2399eff
refactor: remove clerkUiCtor from public API, add __internal_forceBun…
jacekradko 89bb1ff
chore: update changeset description
jacekradko ccac639
refactor: rename clerkUiCtor to ClerkUI and ClerkUiConstructor to Cle…
jacekradko cf2a354
refactor: rename __internal_ClerkUiCtor to __internal_ClerkUICtor
jacekradko 1d2c8cf
chore: simplify changeset
jacekradko 8f705a8
refactor: rename ui.ctor to ui.ClerkUI
jacekradko 478a0b3
Merge branch 'main' into jrad/ui-prop-cleanup
jacekradko 9517d40
refactor: move ClerkUI inside ui object in ClerkOptions
jacekradko 890cd43
fix: rename ctor to ClerkUI in ui export
jacekradko 7f7665f
chore: fix formatting
jacekradko a3014de
chore: fix es-ES.ts formatting
jacekradko 9774008
fix(astro): Remove unnecessary eslint-disable directive
jacekradko e81f20a
test(vue): add unit tests for CDN UI loading with version pinning
jacekradko d3c96f3
fix(astro): honor bundled UI constructor in getClerkUiEntryChunk
jacekradko aa0c84b
fix(astro): preserve clerkUiUrl fallback in loadClerkUiScript call
jacekradko 64ff3dc
fix: standardize casing for clerkUIUrl and clerkUIVersion properties
jacekradko 76d7c96
fix(vue): preserve clerkUIUrl fallback when ui.url is not set
jacekradko c0d3b6f
fix(vue): use type cast for clerkUIUrl/clerkUIVersion fallback
jacekradko 61655b1
fix: update integration templates to use clerkUIUrl casing
jacekradko 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
Some comments aren't visible on the classic Files Changed page.
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,19 @@ | ||
| --- | ||
| '@clerk/ui': minor | ||
| '@clerk/react': minor | ||
| '@clerk/vue': minor | ||
| '@clerk/astro': minor | ||
| '@clerk/chrome-extension': minor | ||
| '@clerk/shared': minor | ||
| --- | ||
|
|
||
| Add `ui` prop to ClerkProvider for passing `@clerk/ui` | ||
|
|
||
| Usage: | ||
| ```tsx | ||
| import { ui } from '@clerk/ui'; | ||
|
|
||
| <ClerkProvider ui={ui}> | ||
| ... | ||
| </ClerkProvider> | ||
| ``` |
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
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
127 changes: 127 additions & 0 deletions
127
packages/astro/src/internal/__tests__/create-clerk-instance.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,127 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| const mockLoadClerkUiScript = vi.fn(); | ||
| const mockLoadClerkJsScript = vi.fn(); | ||
|
|
||
| vi.mock('@clerk/shared/loadClerkJsScript', () => ({ | ||
| loadClerkJsScript: (...args: unknown[]) => mockLoadClerkJsScript(...args), | ||
| loadClerkUiScript: (...args: unknown[]) => mockLoadClerkUiScript(...args), | ||
| setClerkJsLoadingErrorPackageName: vi.fn(), | ||
| })); | ||
|
|
||
| // Mock nanostores | ||
| vi.mock('../../stores/external', () => ({ | ||
| $clerkStore: { notify: vi.fn() }, | ||
| })); | ||
|
|
||
| vi.mock('../../stores/internal', () => ({ | ||
| $clerk: { get: vi.fn(), set: vi.fn() }, | ||
| $csrState: { setKey: vi.fn() }, | ||
| })); | ||
|
|
||
| vi.mock('../invoke-clerk-astro-js-functions', () => ({ | ||
| invokeClerkAstroJSFunctions: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock('../mount-clerk-astro-js-components', () => ({ | ||
| mountAllClerkAstroJSComponents: vi.fn(), | ||
| })); | ||
|
|
||
| const mockClerkUICtor = vi.fn(); | ||
|
|
||
| describe('getClerkUiEntryChunk', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| vi.resetModules(); | ||
| (window as any).__internal_ClerkUICtor = undefined; | ||
| (window as any).Clerk = undefined; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| (window as any).__internal_ClerkUICtor = undefined; | ||
| (window as any).Clerk = undefined; | ||
| }); | ||
|
|
||
| it('preserves clerkUIUrl from options when options.ui.url is not provided', async () => { | ||
| mockLoadClerkUiScript.mockImplementation(async () => { | ||
| (window as any).__internal_ClerkUICtor = mockClerkUICtor; | ||
| return null; | ||
| }); | ||
|
|
||
| mockLoadClerkJsScript.mockImplementation(async () => { | ||
| (window as any).Clerk = { | ||
| load: vi.fn().mockResolvedValue(undefined), | ||
| addListener: vi.fn(), | ||
| }; | ||
| return null; | ||
| }); | ||
|
|
||
| // Dynamically import to get fresh module with mocks | ||
| const { createClerkInstance } = await import('../create-clerk-instance'); | ||
|
|
||
| // Call createClerkInstance with clerkUIUrl but without ui.url | ||
| await createClerkInstance({ | ||
| publishableKey: 'pk_test_xxx', | ||
| clerkUIUrl: 'https://custom.selfhosted.example.com/ui.js', | ||
| }); | ||
|
|
||
| expect(mockLoadClerkUiScript).toHaveBeenCalled(); | ||
| const loadClerkUiScriptCall = mockLoadClerkUiScript.mock.calls[0]?.[0] as Record<string, unknown>; | ||
| expect(loadClerkUiScriptCall?.clerkUIUrl).toBe('https://custom.selfhosted.example.com/ui.js'); | ||
| }); | ||
|
|
||
| it('prefers options.ui.url over options.clerkUIUrl when both are provided', async () => { | ||
| mockLoadClerkUiScript.mockImplementation(async () => { | ||
| (window as any).__internal_ClerkUICtor = mockClerkUICtor; | ||
| return null; | ||
| }); | ||
|
|
||
| mockLoadClerkJsScript.mockImplementation(async () => { | ||
| (window as any).Clerk = { | ||
| load: vi.fn().mockResolvedValue(undefined), | ||
| addListener: vi.fn(), | ||
| }; | ||
| return null; | ||
| }); | ||
|
|
||
| const { createClerkInstance } = await import('../create-clerk-instance'); | ||
|
|
||
| await createClerkInstance({ | ||
| publishableKey: 'pk_test_xxx', | ||
| clerkUIUrl: 'https://fallback.example.com/ui.js', | ||
| ui: { | ||
| version: '1.0.0', | ||
| url: 'https://preferred.example.com/ui.js', | ||
| } as any, | ||
| }); | ||
|
|
||
| expect(mockLoadClerkUiScript).toHaveBeenCalled(); | ||
| const loadClerkUiScriptCall = mockLoadClerkUiScript.mock.calls[0]?.[0] as Record<string, unknown>; | ||
| expect(loadClerkUiScriptCall?.clerkUIUrl).toBe('https://preferred.example.com/ui.js'); | ||
| }); | ||
|
|
||
| it('does not set clerkUIUrl when neither options.ui.url nor options.clerkUIUrl is provided', async () => { | ||
| mockLoadClerkUiScript.mockImplementation(async () => { | ||
| (window as any).__internal_ClerkUICtor = mockClerkUICtor; | ||
| return null; | ||
| }); | ||
|
|
||
| mockLoadClerkJsScript.mockImplementation(async () => { | ||
| (window as any).Clerk = { | ||
| load: vi.fn().mockResolvedValue(undefined), | ||
| addListener: vi.fn(), | ||
| }; | ||
| return null; | ||
| }); | ||
|
|
||
| const { createClerkInstance } = await import('../create-clerk-instance'); | ||
|
|
||
| await createClerkInstance({ | ||
| publishableKey: 'pk_test_xxx', | ||
| }); | ||
|
|
||
| expect(mockLoadClerkUiScript).toHaveBeenCalled(); | ||
| const loadClerkUiScriptCall = mockLoadClerkUiScript.mock.calls[0]?.[0] as Record<string, unknown>; | ||
| expect(loadClerkUiScriptCall?.clerkUIUrl).toBeUndefined(); | ||
| }); | ||
| }); |
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.
Add coverage for the renamed
clerkUIUrlprop.This is a public API change in the template; please add or update tests (or an integration/template validation) to ensure the new prop name is exercised and prevents regressions.
🤖 Prompt for AI Agents