-
Notifications
You must be signed in to change notification settings - Fork 194
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
[BUG] Not compatible with Wagmi persistence with cookies #407
Comments
I have run into the same issue after attempting to implement the SSR guide on the wagmi docs. I came looking for this after noticing a recurring issue whereby the current wallet seems to persist after calling This is currently observable in your docs too here. You can follow these steps to reproduce: (1) Connect with MM (2) Disconnect (without page refresh) (3) Connect again with MM (4) MM error (5) Refresh page and connect with MM succeeds. See demo below: Screen.Recording.2024-07-07.at.22.34.59.mov |
Confirming I'm having the same issue. |
Hello @0x3dev! After investigating, it appears that this error is related to framer-motion, a dependency of ConnectKit. Even though Interestingly, when I create a local version of Below is the code that is server-side rendered and causing the issue: const initialState = cookieToInitialState(
getConfig(),
headers().get("cookie")
); Some Workarounds
export function getConfig() {
const config = createConfig(
getDefaultConfig({
// Your dApp's chains
chains: [mainnet],
transports: {
// RPC URL for each chain
[mainnet.id]: http(
`https://eth-mainnet.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_ID}`
),
},
// Required API Keys
walletConnectProjectId: "WalletConnect Project Id",
// Required App Info
appName: "Your App Name",
// Optional App Info
appDescription: "Your App Description",
appUrl: "https://family.co", // your app's url
appIcon: "https://family.co/logo.png", // your app's icon, no bigger than 1024x1024px (max. 1MB)
ssr: true,
storage: createStorage({
storage: cookieStorage,
}),
})
);
return config;
}
export function getWagmiConfig() {
return createConfig({
chains: [mainnet],
ssr: true,
storage: createStorage({
storage: cookieStorage,
}),
transports: {
[mainnet.id]: http(),
},
});
}
|
Wow nice discovery @sahilkakwani9! Thanks for investigating this, definitely weird that We've internally discussed removing |
It not depends on the connectKit even on the wagmi, it depends on the framework, how to get rendered, it's not a bug |
Just wanted to flag that I finally got around to implementing @sahilkakwani9's workaround. It works great and removes the exception thrown in the OP, but unfortunately it also prevents users from using the MetaMask Chrome extension -- it always prompts them to use their phone to sign in with Metamask. Setting Presumably there's an issue with extension detection when it's first server-rendered? |
hi, @sahilkakwani9 thanks a lot for workaround with cookies storage, but I'd like to ask something, do you still have an issue to see empty space instead of wallet account when you refresh the page. with only Wagmi it worked well but when I added connectKit and using your workaround now it blinks on refresh |
Describe the bug
When trying to implement the steps outlined in Wagmi SSR page, specifically Persistence using Cookies, NextJS throws this error:
Error: (0 , react__WEBPACK_IMPORTED_MODULE_0__.createContext) is not a function
eval node_modules/.pnpm/framer-motion@6.5.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/framer-motion/dist/es/context/LazyContext.mjs (3:32) (rsc)/./node_modules/.pnpm/framer-motion@6.5.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/framer-motion/dist/es/context/LazyContext.mjs
To reproduce
Create a new project with
npm create wagmi --template next
and addconnectkit
to it. The error will show at first run.Additional context
If we don't pass the initialState like this,
const initialState = cookieToInitialState( getConfig(), headers().get("cookie") );
The error is gone, so it seems the method
getDefaultConfig
from connectkit doesn't support SSR.The text was updated successfully, but these errors were encountered: