Async loading of connectors / Bundle size #2402
Unanswered
Julien-R44
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
So, on my dApp I have quite a few different connectors: Ledger/Web3Auth/Torus/Metamask/CoinbaseWallet and WalletConnect.
The issue I'm currently facing is my bundle size. Therefore, I've made sure that the various connectors were correctly lazy loaded.
Theoretically, this is the case. In the various connectors, we indeed have dynamic imports of the different provider SDKs.
However, in practice, it seems this is not the case due to this piece of code:
https://github.com/wagmi-dev/wagmi/blob/main/packages/core/src/config.ts#L244
We end up calling isAuthorized on all the registered connectors.
isAuthorized
usually callsgetAccount
, which requires loading the provider SDK. Therefore, what happens on my end is that all the SDKs are loaded at the application's launch.I am probably missing something here, but I'm having trouble understanding why this is done. Shouldn't the logic of autoConnect simply be to test the connection on a single connector - the one in local storage - and ignore the others? This way, we wouldn't be loading all the SDKs unnecessarily
I came across different discussions that talked a bit about the same problem, and one of the alternatives would be to dynamically set the connectors, but that seems a bit cumbersome to do
I ended up patching wagmi with what I proposed just above: so just test the connection on the localStorage connector and it seems to work, but as I said I may be missing something about the value of testing all the connectors.
Beta Was this translation helpful? Give feedback.
All reactions