-
Notifications
You must be signed in to change notification settings - Fork 431
feat(shared): Remove SWR #7455
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
Merged
Merged
feat(shared): Remove SWR #7455
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
eb0bae1
feat(shared): Remove SWR
jacekradko 6ee75be
changeset
jacekradko b55dc0e
upgrade RQ to latest
jacekradko ca51690
Merge branch 'main' into feat/remove-swr
jacekradko 6e885b6
Merge branch 'main' into feat/remove-swr
jacekradko 1ab5bae
Merge branch 'main' into feat/remove-swr
jacekradko f333710
fix(shared): Move useSubscription telemetry call to useEffect
jacekradko 6baf6ce
latest RQ
jacekradko 88ac0c5
Merge branch 'main' into feat/remove-swr
jacekradko acdecff
fix test and bundlewatch config bump
jacekradko 1a351ae
any -> unknown
jacekradko 6b2cae1
completely remove all SWR
jacekradko 9fa9cda
Merge branch 'main' into feat/remove-swr
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
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/shared': major | ||
| --- | ||
|
|
||
| Remove SWR hooks and env-based switchovers in favor of the React Query implementations; promote @tanstack/query-core to a runtime dependency. |
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
76 changes: 0 additions & 76 deletions
76
packages/shared/src/react/billing/useInitializePaymentMethod.rq.tsx
This file was deleted.
Oops, something went wrong.
60 changes: 0 additions & 60 deletions
60
packages/shared/src/react/billing/useInitializePaymentMethod.swr.tsx
This file was deleted.
Oops, something went wrong.
78 changes: 76 additions & 2 deletions
78
packages/shared/src/react/billing/useInitializePaymentMethod.tsx
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 |
|---|---|---|
| @@ -1,2 +1,76 @@ | ||
| export type { UseInitializePaymentMethodResult } from 'virtual:data-hooks/useInitializePaymentMethod'; | ||
| export { __internal_useInitializePaymentMethod } from 'virtual:data-hooks/useInitializePaymentMethod'; | ||
| import { useCallback, useMemo } from 'react'; | ||
|
|
||
| import type { BillingInitializedPaymentMethodResource, ForPayerType } from '../../types'; | ||
| import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data'; | ||
| import { useClerkQueryClient } from '../clerk-rq/use-clerk-query-client'; | ||
| import { useClerkQuery } from '../clerk-rq/useQuery'; | ||
| import { useOrganizationContext, useUserContext } from '../contexts'; | ||
| import { useBillingHookEnabled } from '../hooks/useBillingHookEnabled'; | ||
|
|
||
| type InitializePaymentMethodOptions = { | ||
| for?: ForPayerType; | ||
| }; | ||
|
|
||
| export type UseInitializePaymentMethodResult = { | ||
| initializedPaymentMethod: BillingInitializedPaymentMethodResource | undefined; | ||
| initializePaymentMethod: () => Promise<BillingInitializedPaymentMethodResource | undefined>; | ||
| }; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| function useInitializePaymentMethod(options?: InitializePaymentMethodOptions): UseInitializePaymentMethodResult { | ||
| const { for: forType } = options ?? {}; | ||
| const { organization } = useOrganizationContext(); | ||
| const user = useUserContext(); | ||
|
|
||
| const resource = forType === 'organization' ? organization : user; | ||
|
|
||
| const billingEnabled = useBillingHookEnabled(options); | ||
|
|
||
| const queryKey = useMemo(() => { | ||
| return ['billing-payment-method-initialize', { resourceId: resource?.id }] as const; | ||
| }, [resource?.id]); | ||
|
|
||
| const isEnabled = Boolean(resource?.id) && billingEnabled; | ||
|
|
||
| const query = useClerkQuery({ | ||
| queryKey, | ||
| queryFn: async () => { | ||
| if (!resource) { | ||
| return undefined; | ||
| } | ||
|
|
||
| return resource.initializePaymentMethod({ | ||
| gateway: 'stripe', | ||
| }); | ||
| }, | ||
| enabled: isEnabled, | ||
| staleTime: 1_000 * 60, | ||
| refetchOnWindowFocus: false, | ||
| placeholderData: defineKeepPreviousDataFn(true), | ||
| }); | ||
|
|
||
| const [queryClient] = useClerkQueryClient(); | ||
|
|
||
| const initializePaymentMethod = useCallback(async () => { | ||
| if (!resource) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const result = await resource.initializePaymentMethod({ | ||
| gateway: 'stripe', | ||
| }); | ||
|
|
||
| queryClient.setQueryData(queryKey, result); | ||
|
|
||
| return result; | ||
| }, [queryClient, queryKey, resource]); | ||
|
|
||
| return { | ||
| initializedPaymentMethod: query.data ?? undefined, | ||
| initializePaymentMethod, | ||
| }; | ||
| } | ||
|
|
||
| export { useInitializePaymentMethod as __internal_useInitializePaymentMethod }; |
37 changes: 0 additions & 37 deletions
37
packages/shared/src/react/billing/useStripeClerkLibs.rq.tsx
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
packages/shared/src/react/billing/useStripeClerkLibs.swr.tsx
This file was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,2 +1,39 @@ | ||
| export type { UseStripeClerkLibsResult } from 'virtual:data-hooks/useStripeClerkLibs'; | ||
| export { __internal_useStripeClerkLibs } from 'virtual:data-hooks/useStripeClerkLibs'; | ||
| import type { loadStripe } from '@stripe/stripe-js'; | ||
|
|
||
| import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data'; | ||
| import { useClerkQuery } from '../clerk-rq/useQuery'; | ||
| import { useBillingHookEnabled } from '../hooks/useBillingHookEnabled'; | ||
| import { useClerk } from '../hooks/useClerk'; | ||
|
|
||
| type LoadStripeFn = typeof loadStripe; | ||
|
|
||
| type StripeClerkLibs = { | ||
| loadStripe: LoadStripeFn; | ||
| }; | ||
|
|
||
| export type UseStripeClerkLibsResult = StripeClerkLibs | null; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| function useStripeClerkLibs(): UseStripeClerkLibsResult { | ||
| const clerk = useClerk(); | ||
|
|
||
| const billingEnabled = useBillingHookEnabled(); | ||
|
|
||
| const query = useClerkQuery({ | ||
| queryKey: ['clerk-stripe-sdk'], | ||
| queryFn: async () => { | ||
| const loadStripe = (await clerk.__internal_loadStripeJs()) as LoadStripeFn; | ||
| return { loadStripe }; | ||
| }, | ||
| enabled: billingEnabled, | ||
| staleTime: Infinity, | ||
| refetchOnWindowFocus: false, | ||
| placeholderData: defineKeepPreviousDataFn(true), | ||
| }); | ||
|
|
||
| return query.data ?? null; | ||
| } | ||
|
|
||
| export { useStripeClerkLibs as __internal_useStripeClerkLibs }; |
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.
Uh oh!
There was an error while loading. Please reload this page.