Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSRProvider is not working in my NextJs app [duplicate]

My app is built using NextJs with Typescript and using the react-bootstrap library for components. I keep getting an error that says When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.

I tried to include the SSRProvider that comes with react-bootstrap, but it doesn't seem to be working no matter where I put it in my _app.tsx file. Anyone know how to resolve this? My UI keeps breaking when reloading the page.

import type { NextComponentType } from 'next';
import { AppContext, AppInitialProps, AppLayoutProps } from 'next/app';
import { ReactNode } from 'react';
import { ThemeProvider } from 'styled-components';
import theme from '../styles/theme';
import { SSRProvider } from 'react-bootstrap';

const MyApp: NextComponentType<AppContext, AppInitialProps, AppLayoutProps> = ({
  Component,
  pageProps,
}: AppLayoutProps) => {
    const getLayout = Component.getLayout || ((page: ReactNode) => page);

  return (
      getLayout(
      <SSRProvider>
        <ThemeProvider theme={theme}>
          <Component {...pageProps} />
        </ThemeProvider>
      </SSRProvider>
      )
    )
}

export default MyApp;
like image 954
Sako Avatar asked Sep 16 '25 04:09

Sako


1 Answers

Fixed this by wrapping the entire return statement in the <SSRProvider> tag. Last time I tried that, I forgot to wrap the getLayout() statement in curly braces. Here is the code for anyone running into the same issue.

return (
      <SSRProvider>
      {getLayout(
        <ThemeProvider theme={theme}>
          <Component {...pageProps} />
        </ThemeProvider>
      )}
      </SSRProvider>
    )
like image 62
Sako Avatar answered Sep 17 '25 20:09

Sako