Skip to content
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] Multiple Injected Providers for same wallet #1842

Closed
1 task done
sbauch opened this issue Mar 9, 2024 · 12 comments
Closed
1 task done

[bug] Multiple Injected Providers for same wallet #1842

sbauch opened this issue Mar 9, 2024 · 12 comments

Comments

@sbauch
Copy link

sbauch commented Mar 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

RainbowKit Version

2.0.1

wagmi Version

2.5.7

Current Behavior

I'm working on doing some performance refactors in my NextJS app, moving from pages router to app router and rendering a lot more on the server.

When I click between routes in my app without my wallet connected, each navigation adds another duplicate row for injected wallet.

Screenshot 2024-03-09 at 11 50 51 AM

Entirely possible this is on my end, I'm not very familiar with Next SSR. But it also happens with Rainbow extension (different chrome profile)

Screenshot 2024-03-09 at 1 46 21 PM

Expected Behavior

The discovered wallets should be deduped. Although maybe it's an indication I'm doing something odd?

Steps To Reproduce

My getDefaultConfig uses ssr: true

I'm happy to try put together an reproducible example but if there's a simpler explanation here that would be ideal! lmk, i can fork the rainbowkit example and switch it over to app router and see what's what

Link to Minimal Reproducible Example (CodeSandbox, StackBlitz, etc.)

No response

Anything else?

No response

@magiziz
Copy link
Contributor

magiziz commented Mar 9, 2024

@sbauch Thanks for raising this issue. This is a bug that comes from the wagmi package when rendering in server-side. I've raised a PR in their repo here: wevm/wagmi#3683.

For now can you try to not render a lot on the server and try to use RainbowKit and Wagmi only in client side ?

Check out some of our examples using next-js (SSR) and RainbowKit:

I know this is a bit crucial, but please bear with us 🙏

@sbauch
Copy link
Author

sbauch commented Mar 10, 2024

thanks for the quick reply!! i love Set() lol often forget about it. but awesome ok, glad I didn't do the whole repro.

I do think I'm only rendering wagmi and RainbowKit on the client? I've got an EthereumProviders component that's got the "use client"; directive, but admittedly am still wrapping my head around it all. Feels very similar to the second example above. I don't have a wallets key in my config seems like the only difference.

"use client";

export const config = getDefaultConfig({
appName: "Speedtracer",
  projectId: "my id",
  chains: [base],
  ssr: true,
  transports: { 
   // ...
  
  },
});

// ...

export const EthereumProviders = ({ children }: Props) => (
  <WagmiProvider config={config}>
    <QueryClientProvider client={queryClient}>
      <RainbowKitProvider>{children}</RainbowKitProvider>
    </QueryClientProvider>
  </WagmiProvider>
);

but no worries, i still have a few more things to switch over before i can deploy this anyhow. ill keep an eye on the wagmi PR if you wanna close this

@magiziz
Copy link
Contributor

magiziz commented Mar 10, 2024

@sbauch Gotcha. Where do you wrap your <EthereumProviders /> ?

@sbauch
Copy link
Author

sbauch commented Mar 10, 2024

Not sure what you mean by wrap, but I import and render the component in what is essentially the root of my client components. so it should be at the top of the suspense boundary?

@magiziz
Copy link
Contributor

magiziz commented Mar 10, 2024

@sbauch Yeah i meant more like this, but can you share a small portion of your code here so i can see what other approach you can take ?

@sbauch
Copy link
Author

sbauch commented Mar 11, 2024

I push it a little further down. im under the impression that this would cause the page.tsx component to render client side, as it's parent Providers component include the "use client" directive?

so im still moving some things around with this all to try to address some hydration errors, but something like this:

// layout.tsx
export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body className={cn("font-Bebas antialiased", bebasNeue.variable)}>
        {children}
      </body>
    </html>
  );
}
// page.tsx
const PlayPage = async ({ params: { s } }: { params: { s: string } }) => {
 
  // a bunch of server-side contract calls with viem and redis caching

  return (
    <div
      className="w-[100vw] h=[100vh]"
      style={{ backgroundColor: theme.background }}
    >
      <PageComponent
        seed={BigInt(s)}
        updatedAtBlock={BigInt(updatedAtBlock)}
        currentId={BigInt(today)}
        d={d}
        theme={theme}
        ads={ads}
        leaders={leaders}
      />
    </div>
  );
};
// PageComponent.tsx
"use client";

// ...

const PlayPage = (props: Props) => {
  return (
    <Providers>
      <div className="max-h-[100dvh] flex flex-col items-center overflow-hidden">
      // ...
      </div>
    </Providers>
    );
}

@magiziz
Copy link
Contributor

magiziz commented Mar 11, 2024

@sbauch Gotcha. The best thing for now is to move your <Providers> in layout.tsx since that's where your provider will exist on top of your app instead of providing it in page.tsx + other pages. Are you able to do that ?

@sbauch
Copy link
Author

sbauch commented Mar 11, 2024

I dont think thats right tbh. imo placing the providers component in the layout would make the page render client side. and i only have one page in this route tree, which i want to render server side, so my providers component is only added on this page

@magiziz
Copy link
Contributor

magiziz commented Mar 11, 2024

I dont think thats right tbh. imo placing the providers component in the layout would make the page render client side. and i only have one page in this route tree, which i want to render server side, so my providers component is only added on this page

Sounds good. Yeah if you don't want to wrap it to your whole app that's fine. We'll keep this issue open and ping you once it's resolved on wagmi's side 🙏

@magiziz
Copy link
Contributor

magiziz commented Apr 7, 2024

@sbauch Sorry for the delay here. Can you upgrade your wagmi version to the latest one and see if the issue still persists ?

@magiziz
Copy link
Contributor

magiziz commented Apr 10, 2024

@sbauch Any updates ?

@magiziz
Copy link
Contributor

magiziz commented Apr 23, 2024

Closing this issue since it's wagmi has fixed this issue 👍

@magiziz magiziz closed this as completed Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants