-
Notifications
You must be signed in to change notification settings - Fork 422
feat(shared): Remove SWR #7568
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
4
commits into
main
Choose a base branch
from
jacekradko/remove-swr
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.
Open
feat(shared): Remove SWR #7568
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a61d6c9
Reapply "feat(shared): Remove SWR (#7455)" (#7565)
jacekradko fdd148f
fix(shared): Fix useClearQueriesOnSignOut hook defects
jacekradko ec21010
changeset
jacekradko aa68070
fix(shared): Extract pagination utilities and fix double multiplicati…
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': patch | ||
| --- | ||
|
|
||
| Fix `useClearQueriesOnSignOut` hook by removing conditional `useEffect` |
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
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.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: clerk/javascript
Length of output: 2757
🏁 Script executed:
Repository: clerk/javascript
Length of output: 2472
🏁 Script executed:
Repository: clerk/javascript
Length of output: 2884
🏁 Script executed:
Repository: clerk/javascript
Length of output: 2248
🏁 Script executed:
Repository: clerk/javascript
Length of output: 157
🏁 Script executed:
Repository: clerk/javascript
Length of output: 116
🏁 Script executed:
Repository: clerk/javascript
Length of output: 279
🏁 Script executed:
Repository: clerk/javascript
Length of output: 1394
🏁 Script executed:
Repository: clerk/javascript
Length of output: 3261
Add
useClearQueriesOnSignOutto clear cached payment method data on sign-out.The hook caches the payment method initialization result containing
externalClientSecret(a sensitive Stripe client secret) but doesn't clear this cache when the user signs out. This is inconsistent with other billing hooks (usePaymentAttemptQuery,useSubscription) which explicitly calluseClearQueriesOnSignOut({isSignedOut: user === null, authenticated, stableKeys: stableKey})to clear sensitive cached data. Add this call to prevent the client secret from persisting in the query cache after sign-out.🤖 Prompt for AI Agents