Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

NextJS SSR bug #3722

Closed
t0mpl opened this issue Jan 10, 2025 · 2 comments
Closed

NextJS SSR bug #3722

t0mpl opened this issue Jan 10, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@t0mpl
Copy link

t0mpl commented Jan 10, 2025

Hi everyone,

Following this tutorial: https://solana.com/developers/guides/wallets/add-solana-wallet-adapter-to-nextjs#3-setting-up-wallet-adapter-in-your-nextjs-app

I get this error:

TypeError: (0 , {imported module [project]/nodemodules/next/dist/server/route-modules/app-page/vendored/rsc/react.js [app-rsc] (ecmascript)}.createContext) is not a function


import React, { FC, ReactNode, useMemo } from "react";
import {
    ConnectionProvider,
    WalletProvider,
} from "@solana/wallet-adapter-react";
import { WalletAdapterNetwork } from "@solana/wallet-adapter-base";
import { clusterApiUrl, } from "@solana/web3.js";

interface SolanaProviderProps {
    children: ReactNode;
}

export const SolanaProvider: FC<SolanaProviderProps> = ({ children }) => {
    const network = WalletAdapterNetwork.Devnet;
    const endpoint = useMemo(() => clusterApiUrl(network), [network]);
    const wallets = useMemo(
      () => [
        // manually add any legacy wallet adapters here
        // new UnsafeBurnerWalletAdapter(),
      ],
      [network],
    );

    return (
        <>
         <ConnectionProvider endpoint={endpoint}>
            <WalletProvider wallets={wallets}>
                {children}
            </WalletProvider>
         </ConnectionProvider>
        </>
    );
};

It only works when i "use client";

any idea if it's possible to wrap the whole app and not break the SSR ?

@t0mpl t0mpl added the bug Something isn't working label Jan 10, 2025
@nickfrosty
Copy link

This is generally the wrong place for this issue, but here is why it is happening:
nextjs uses server components by default, and react's createContext is client side only functionality (same with other types of react state). wallet adapter is only meant to be used client side only, hence the error

the only way to resolve this is to add the use client; directive at the top of the file. you could wrap the whole app and make it client only, but is a nextjs anti pattern (since it removes all server side functionality for pages) and should not be done

@t0mpl
Copy link
Author

t0mpl commented Jan 13, 2025

Thanks for explanation but as you had a dedicated NextJS part on the doc, I thought it was supporting SSR. Wagmi does so it is somehow possible to wrap the whole app.

Thanks for clarifying, i'll find another solution.

@t0mpl t0mpl closed this as completed Jan 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants