Hey @eesheng, could you share if youâre using server-side rendering or not? I suspect that its trying to access context on the server side and as Context is not available on the server side, its throwing an error.
In NextJS 13 onwards, if the first line of code isnât using âuse clientâ, it will use server side rendering. I tried using it on Root Layout, albeit it affect processing and shouldnât be used at all because developers unable to benefit from NextJS 13. Hence, to answer your question, yes, it uses server side rendering. Pretty sure itâs because of using the app router standard of NextJS 13 onwards hence causing the issue. Do clarify if Iâm wrong.
Just to test it out, I changed the wrapper into app/page.tsx. It instead pop out. What Iâm trying to accomplish is creating a NextJS14 of swayswap. Most files are adapted from there, but I still think that itâs because the wallet require client side, but canât add âuse clientâ into app/layout.tsx.
I manage to solve the issue with adding âuse clientâ on top of app/layout.tsx. I think it is suboptimal since all rendering will be client side. Are all DEX build this way?
I created a wrap provider using the client side rendering, I then wrap it in my layout.tsx to solve the issue without forfeiting the Nextjs v14 server-side rendering features:
// src/app/WrapProvider.tsx
'use client'
import { FuelProvider } from '@fuels/react';
import {
FuelWalletConnector,
FuelWalletDevelopmentConnector,
FueletWalletConnector,
} from '@fuels/connectors';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
const queryClient = new QueryClient();
export default function WrapProvider({
children,
}: {
children: React.ReactNode
}) {
return (
<>
<QueryClientProvider client={queryClient}>
<FuelProvider
fuelConfig={{
connectors: [
new FuelWalletConnector(),
new FuelWalletDevelopmentConnector(),
new FueletWalletConnector(),
],
}}
>
{children}
</FuelProvider>
</QueryClientProvider>
</>
)
}
This is my src/app/layout.tsx. You will notice that metadata works instead of my previous solution.
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import NavBar from "./components/organisms/NavBar";
import WrapProvider from "./WrapProvider";
import { ThemeContextProvider } from "@src/libs/state";
import { FuelProvider } from '@fuels/react';
import {
FuelWalletConnector,
FuelWalletDevelopmentConnector,
FueletWalletConnector,
} from '@fuels/connectors';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
const inter = Inter({ subsets: ["latin"] });
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={inter.className}>
<WrapProvider>
{children}
</WrapProvider>
</body>
</html>
);
}