Skip to content

Commit df73f8f

Browse files
dstaleykduprey
authored andcommitted
fix(clerk-js): Dynamically load Web3WalletButtons
1 parent 7a9a22a commit df73f8f

File tree

4 files changed

+72
-38
lines changed

4 files changed

+72
-38
lines changed

packages/clerk-js/bundlewatch.config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"files": [
3-
{ "path": "./dist/clerk.js", "maxSize": "840KB" },
3+
{ "path": "./dist/clerk.js", "maxSize": "918KB" },
44
{ "path": "./dist/clerk.browser.js", "maxSize": "81KB" },
55
{ "path": "./dist/clerk.channel.browser.js", "maxSize": "81KB" },
66
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "123KB" },
77
{ "path": "./dist/clerk.headless*.js", "maxSize": "65KB" },
8-
{ "path": "./dist/ui-common*.js", "maxSize": "117.1KB" },
8+
{ "path": "./dist/ui-common*.js", "maxSize": "119KB" },
99
{ "path": "./dist/ui-common*.legacy.*.js", "maxSize": "122KB" },
1010
{ "path": "./dist/vendors*.js", "maxSize": "47KB" },
1111
{ "path": "./dist/coinbase*.js", "maxSize": "38KB" },
@@ -16,11 +16,11 @@
1616
{ "path": "./dist/organizationswitcher*.js", "maxSize": "5KB" },
1717
{ "path": "./dist/organizationlist*.js", "maxSize": "5.5KB" },
1818
{ "path": "./dist/signin*.js", "maxSize": "18KB" },
19-
{ "path": "./dist/signup*.js", "maxSize": "9.5KB" },
19+
{ "path": "./dist/signup*.js", "maxSize": "11KB" },
2020
{ "path": "./dist/userbutton*.js", "maxSize": "5KB" },
2121
{ "path": "./dist/userprofile*.js", "maxSize": "16KB" },
2222
{ "path": "./dist/userverification*.js", "maxSize": "5KB" },
23-
{ "path": "./dist/onetap*.js", "maxSize": "1KB" },
23+
{ "path": "./dist/onetap*.js", "maxSize": "3KB" },
2424
{ "path": "./dist/waitlist*.js", "maxSize": "1.5KB" },
2525
{ "path": "./dist/keylessPrompt*.js", "maxSize": "6.5KB" },
2626
{ "path": "./dist/pricingTable*.js", "maxSize": "4.02KB" },

packages/clerk-js/rspack.config.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,40 @@ const common = ({ mode, variant, disableRHC = false }) => {
129129
signUp: {
130130
minChunks: 1,
131131
name: 'signup',
132-
test: module => !!(module.resource && module.resource.includes('/ui/components/SignUp')),
132+
test: module =>
133+
!!(
134+
module instanceof rspack.NormalModule &&
135+
module.resource &&
136+
module.resource.includes('/ui/components/SignUp')
137+
),
133138
},
134139
common: {
135140
minChunks: 1,
136141
name: 'ui-common',
137142
priority: -20,
138-
test: module => !!(module.resource && !module.resource.includes('/ui/components')),
143+
test: module =>
144+
!!(
145+
module instanceof rspack.NormalModule &&
146+
module.resource &&
147+
!module.resource.includes('/ui/components') &&
148+
!module.resource.includes('node_modules')
149+
),
139150
},
140151
defaultVendors: {
141152
minChunks: 1,
142153
test: /[\\/]node_modules[\\/]/,
143154
name: 'vendors',
144155
priority: -10,
156+
/**
157+
* Only apply to initial chunks. Dependencies used exclusively by async chunks
158+
* (like Solana packages and their transitive deps) will be bundled with those
159+
* async chunks instead of being forced into the shared vendors bundle.
160+
*
161+
* This ensures that lazy-loaded features (like Web3 wallet support) don't
162+
* bloat the initial bundle, and their dependencies are automatically
163+
* code-split without needing explicit configuration.
164+
*/
165+
chunks: 'initial',
145166
},
146167
react: {
147168
chunks: 'all',

packages/clerk-js/src/ui/components/SignIn/SignInFactorOneSolanaWalletsCard.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { useClerk } from '@clerk/shared/react';
2+
import { lazy, Suspense } from 'react';
23

34
import { withRedirectToAfterSignIn, withRedirectToSignInTask } from '@/ui/common/withRedirect';
45
import { descriptors, Flex, Flow, localizationKeys } from '@/ui/customizables';
56
import { BackLink } from '@/ui/elements/BackLink';
67
import { Card } from '@/ui/elements/Card';
78
import { useCardState, withCardStateProvider } from '@/ui/elements/contexts';
89
import { Header } from '@/ui/elements/Header';
9-
import { Web3WalletButtons } from '@/ui/elements/Web3WalletButtons';
1010
import { web3CallbackErrorHandler } from '@/ui/utils/web3CallbackErrorHandler';
1111

12+
const Web3WalletButtons = lazy(() =>
13+
import('@/ui/elements/Web3WalletButtons').then(m => ({ default: m.Web3WalletButtons })),
14+
);
15+
1216
import { useSignInContext } from '../../contexts';
1317
import { useRouter } from '../../router';
1418

@@ -35,20 +39,23 @@ const SignInFactorOneSolanaWalletsCardInner = () => {
3539
direction='col'
3640
gap={4}
3741
>
38-
<Web3WalletButtons
39-
web3AuthCallback={({ walletName }) => {
40-
return clerk
41-
.authenticateWithWeb3({
42-
customNavigate: router.navigate,
43-
redirectUrl: ctx.afterSignInUrl || '/',
44-
secondFactorUrl: 'factor-two',
45-
signUpContinueUrl: ctx.isCombinedFlow ? '../create/continue' : ctx.signUpContinueUrl,
46-
strategy: 'web3_solana_signature',
47-
walletName,
48-
})
49-
.catch(err => web3CallbackErrorHandler(err, card.setError));
50-
}}
51-
/>
42+
<Suspense fallback={null}>
43+
<Web3WalletButtons
44+
web3AuthCallback={({ walletName }) => {
45+
return clerk
46+
.authenticateWithWeb3({
47+
customNavigate: router.navigate,
48+
redirectUrl: ctx.afterSignInUrl || '/',
49+
secondFactorUrl: 'factor-two',
50+
signUpContinueUrl: ctx.isCombinedFlow ? '../create/continue' : ctx.signUpContinueUrl,
51+
strategy: 'web3_solana_signature',
52+
walletName,
53+
})
54+
.catch(err => web3CallbackErrorHandler(err, card.setError));
55+
}}
56+
/>
57+
</Suspense>
58+
5259
<BackLink
5360
boxElementDescriptor={descriptors.backRow}
5461
linkElementDescriptor={descriptors.backLink}

packages/clerk-js/src/ui/components/SignUp/SignUpStartSolanaWalletsCard.tsx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { useClerk } from '@clerk/shared/react';
2+
import { lazy, Suspense } from 'react';
23

34
import { withRedirectToAfterSignUp, withRedirectToSignUpTask } from '@/ui/common/withRedirect';
45
import { descriptors, Flex, Flow, localizationKeys } from '@/ui/customizables';
56
import { BackLink } from '@/ui/elements/BackLink';
67
import { Card } from '@/ui/elements/Card';
78
import { useCardState, withCardStateProvider } from '@/ui/elements/contexts';
89
import { Header } from '@/ui/elements/Header';
9-
import { Web3WalletButtons } from '@/ui/elements/Web3WalletButtons';
1010
import { web3CallbackErrorHandler } from '@/ui/utils/web3CallbackErrorHandler';
1111

12+
const Web3WalletButtons = lazy(() =>
13+
import('@/ui/elements/Web3WalletButtons').then(m => ({ default: m.Web3WalletButtons })),
14+
);
15+
1216
import { useSignUpContext } from '../../contexts';
1317
import { useRouter } from '../../router';
1418

@@ -35,22 +39,24 @@ const SignUpStartSolanaWalletsCardInner = () => {
3539
direction='col'
3640
gap={4}
3741
>
38-
<Web3WalletButtons
39-
web3AuthCallback={({ walletName }) => {
40-
return clerk
41-
.authenticateWithWeb3({
42-
customNavigate: router.navigate,
43-
redirectUrl: ctx.afterSignUpUrl || '/',
44-
signUpContinueUrl: '../continue',
45-
strategy: 'web3_solana_signature',
46-
unsafeMetadata: ctx.unsafeMetadata,
47-
// TODO: Add support to pass legalAccepted status
48-
// legalAccepted: ,
49-
walletName,
50-
})
51-
.catch(err => web3CallbackErrorHandler(err, card.setError));
52-
}}
53-
/>
42+
<Suspense fallback={null}>
43+
<Web3WalletButtons
44+
web3AuthCallback={({ walletName }) => {
45+
return clerk
46+
.authenticateWithWeb3({
47+
customNavigate: router.navigate,
48+
redirectUrl: ctx.afterSignUpUrl || '/',
49+
signUpContinueUrl: '../continue',
50+
strategy: 'web3_solana_signature',
51+
unsafeMetadata: ctx.unsafeMetadata,
52+
// TODO: Add support to pass legalAccepted status
53+
// legalAccepted: ,
54+
walletName,
55+
})
56+
.catch(err => web3CallbackErrorHandler(err, card.setError));
57+
}}
58+
/>
59+
</Suspense>
5460
<BackLink
5561
boxElementDescriptor={descriptors.backRow}
5662
linkElementDescriptor={descriptors.backLink}

0 commit comments

Comments
 (0)