-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(clerk-react): Fix race condition on updating ClerkProvider props (#…
…3655) Fixes issues with updating `ClerkProvider` props before ClerkJS has loaded. Sometimes, `clerk.__unstable__updateProps` was called before clerkjs had a value, so the props update did not happen. With this change the `__unstable__updateProps` waits for ClerkJS to load and then calls the `clerk.__unstable__updateProps` function to update the props. This change also implements `buildAfterMultiSessionSingleSignOutUrl` in `isomorphicClerk` to resolve typing issues.
- Loading branch information
Showing
4 changed files
with
75 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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-react": patch | ||
--- | ||
|
||
Fix race condition on updating ClerkProvider props before ClerkJS has loaded |
This file contains 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,52 @@ | ||
import { IsomorphicClerk } from '../isomorphicClerk'; | ||
|
||
describe('isomorphicClerk', () => { | ||
beforeAll(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('instantiates a IsomorphicClerk instance', () => { | ||
expect(() => { | ||
new IsomorphicClerk({ publishableKey: 'pk_test_XXX' }); | ||
}).not.toThrow(); | ||
}); | ||
|
||
it('updates props asynchronously after clerkjs has loaded', async () => { | ||
const propsHistory: any[] = []; | ||
const dummyClerkJS = { | ||
__unstable__updateProps: (props: any) => propsHistory.push(props), | ||
}; | ||
|
||
const isomorphicClerk = new IsomorphicClerk({ publishableKey: 'pk_test_XXX' }); | ||
(isomorphicClerk as any).clerkjs = dummyClerkJS as any; | ||
|
||
void isomorphicClerk.__unstable__updateProps({ appearance: { baseTheme: 'dark' } }); | ||
void isomorphicClerk.__unstable__updateProps({ appearance: { baseTheme: 'light' } }); | ||
void isomorphicClerk.__unstable__updateProps({ appearance: { baseTheme: 'purple' } }); | ||
void isomorphicClerk.__unstable__updateProps({ appearance: { baseTheme: 'yellow' } }); | ||
void isomorphicClerk.__unstable__updateProps({ appearance: { baseTheme: 'red' } }); | ||
void isomorphicClerk.__unstable__updateProps({ appearance: { baseTheme: 'blue' } }); | ||
void isomorphicClerk.__unstable__updateProps({ appearance: { baseTheme: 'green' } }); | ||
expect(propsHistory).toEqual([]); | ||
|
||
jest.spyOn(isomorphicClerk, 'loaded', 'get').mockReturnValue(true); | ||
isomorphicClerk.emitLoaded(); | ||
void isomorphicClerk.__unstable__updateProps({ appearance: { baseTheme: 'white' } }); | ||
await jest.runAllTimersAsync(); | ||
|
||
expect(propsHistory).toEqual([ | ||
{ appearance: { baseTheme: 'dark' } }, | ||
{ appearance: { baseTheme: 'light' } }, | ||
{ appearance: { baseTheme: 'purple' } }, | ||
{ appearance: { baseTheme: 'yellow' } }, | ||
{ appearance: { baseTheme: 'red' } }, | ||
{ appearance: { baseTheme: 'blue' } }, | ||
{ appearance: { baseTheme: 'green' } }, | ||
{ appearance: { baseTheme: 'white' } }, | ||
]); | ||
}); | ||
}); |
This file contains 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 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