How to enable SSR in nextjs14 + redux/toolkit + redux-persist?

I am trying to enable SSR in in Next.JS 14 + redux/toolkit + redux-persist but the whole page is not appearing inside the page source.

CODE: (layout.js)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>"use client";
import './globals.css';
import { usePathname } from 'next/navigation';
import { Suspense, useState, useEffect } from 'react';
import classes from './App.module.css';
import { CSRReduxProviders, SSRReduxProviders } from './_store/reduxProvider'
import Navbar from './_Layouts/navbar'
import Footer from './_Layouts/footer/Footer'
import { LoaderSkeleton } from './_components'
import { ToastContainer } from 'react-toastify'
import { AppProgressBar as ProgressBar } from 'next-nprogress-bar';
import Script from 'next/script';
import { HomePage, OffCanvasPopup } from './_components';
import Head from 'next/head';
export default function RootLayout({ children }) {
const pathname = usePathname();
const [title, setTitle] = useState('Sustainable Products | Ecowiser');
useEffect(() => {
if (pathname.includes('/search')) {
setTitle(`${pathname.split('/').pop().replaceAll('%20', ' ').replaceAll('_', ' ').replaceAll('-', ' ')} | Ecowiser`);
} else if (pathname.includes('/category')) {
setTitle(`${pathname.split('/').pop().replaceAll('-', ' ')} | Ecowiser`);
} else if (pathname.includes('/lux')) {
setTitle(`Luxury Products | Ecowiser`);
} else if (pathname.includes('/how-we-rate')) {
setTitle("How We Rate | Ecowiser")
} else if (pathname.split('/')[1].includes('-')) {
setTitle(`${pathname.split('/').pop().split('-').slice(1).join(" ")} | Ecowiser`);
}
}, [pathname]);
return (
<html>
<Head>
<meta charSet="utf-8" />
<meta name="description" content={'EcoWiser Products is a directory of sustainable products, helping consumers find eco-friendly items made from renewable resources and biodegradable materials.'} />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href={`${process.env.NEXT_PUBLIC_BASE_PATH}/icon.ico`} />
<link rel="shortcut icon" href={`${process.env.NEXT_PUBLIC_BASE_PATH}/icon.ico`} />
<link rel="apple-touch-icon" href={`${process.env.NEXT_PUBLIC_BASE_PATH}/apple-icon.png`} />
<title>{title}</title>
</Head>
<body suppressHydrationWarning={true}>
<Script
id={"Skimlinks"}
strategy="beforeInteractive"
src={`https://s.skimresources.com/js/263708X1748630.skimlinks.js`}
/>
<Script
id={"GoogleTagManager"}
strategy="beforeInteractive"
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}`}
/>
<Script
id={"GoogleAnalytics"}
strategy="beforeInteractive"
>
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}', {
page_path: window.location.pathname,
});
`}
</Script>
<Script
id={"commento.io"}
strategy="beforeInteractive"
defer
src="https://ec2-44-219-132-22.compute-1.amazonaws.com/js/commento.js"
data-auto-init="true"
/>
<Script
id={"kissmetrics-cdn"}
strategy="beforeInteractive"
dangerouslySetInnerHTML={{
__html: `
var _kmq = _kmq || [];
var _kmk = _kmk || '8291a27d7270981e8c87dda4d684803f873c00e1';
function _kms(u){
setTimeout(function(){
var d = document, f = d.getElementsByTagName('script')[0],
s = d.createElement('script');
s.type = 'text/javascript'; s.async = true; s.src = u;
f.parentNode.insertBefore(s, f);
}, 1);
}
_kms('//i.kissmetrics.io/i.js');
_kms('//scripts.kissmetrics.io/' + _kmk + '.2.js');
`,
}}
/>
<ProgressBar
height="4px"
color="#025951"
options={{
showSpinner: false,
}}
shallowRouting
/>
<Navbar />
<Suspense fallback={<LoaderSkeleton />}>
{typeof window !== 'undefined' ? (
<CSRReduxProviders>
{children}
</CSRReduxProviders>
) : (
<SSRReduxProviders>
{children}
</SSRReduxProviders>
)}
</Suspense>
<Footer />
<ToastContainer />
</body>
</html>
)
}
"use client";
import { store, persistor } from './store.js';
import { PersistGate } from 'redux-persist/integration/react';
import { Provider } from "react-redux";
export function CSRReduxProviders({ children }) {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
{children}
</PersistGate>
</Provider>
);
}
export function SSRReduxProviders({ children }) {
return (
<Provider store={store}>
{children}
</Provider>
);
}
</code>
<code>"use client"; import './globals.css'; import { usePathname } from 'next/navigation'; import { Suspense, useState, useEffect } from 'react'; import classes from './App.module.css'; import { CSRReduxProviders, SSRReduxProviders } from './_store/reduxProvider' import Navbar from './_Layouts/navbar' import Footer from './_Layouts/footer/Footer' import { LoaderSkeleton } from './_components' import { ToastContainer } from 'react-toastify' import { AppProgressBar as ProgressBar } from 'next-nprogress-bar'; import Script from 'next/script'; import { HomePage, OffCanvasPopup } from './_components'; import Head from 'next/head'; export default function RootLayout({ children }) { const pathname = usePathname(); const [title, setTitle] = useState('Sustainable Products | Ecowiser'); useEffect(() => { if (pathname.includes('/search')) { setTitle(`${pathname.split('/').pop().replaceAll('%20', ' ').replaceAll('_', ' ').replaceAll('-', ' ')} | Ecowiser`); } else if (pathname.includes('/category')) { setTitle(`${pathname.split('/').pop().replaceAll('-', ' ')} | Ecowiser`); } else if (pathname.includes('/lux')) { setTitle(`Luxury Products | Ecowiser`); } else if (pathname.includes('/how-we-rate')) { setTitle("How We Rate | Ecowiser") } else if (pathname.split('/')[1].includes('-')) { setTitle(`${pathname.split('/').pop().split('-').slice(1).join(" ")} | Ecowiser`); } }, [pathname]); return ( <html> <Head> <meta charSet="utf-8" /> <meta name="description" content={'EcoWiser Products is a directory of sustainable products, helping consumers find eco-friendly items made from renewable resources and biodegradable materials.'} /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link rel="icon" href={`${process.env.NEXT_PUBLIC_BASE_PATH}/icon.ico`} /> <link rel="shortcut icon" href={`${process.env.NEXT_PUBLIC_BASE_PATH}/icon.ico`} /> <link rel="apple-touch-icon" href={`${process.env.NEXT_PUBLIC_BASE_PATH}/apple-icon.png`} /> <title>{title}</title> </Head> <body suppressHydrationWarning={true}> <Script id={"Skimlinks"} strategy="beforeInteractive" src={`https://s.skimresources.com/js/263708X1748630.skimlinks.js`} /> <Script id={"GoogleTagManager"} strategy="beforeInteractive" src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}`} /> <Script id={"GoogleAnalytics"} strategy="beforeInteractive" > {` window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', '${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}', { page_path: window.location.pathname, }); `} </Script> <Script id={"commento.io"} strategy="beforeInteractive" defer src="https://ec2-44-219-132-22.compute-1.amazonaws.com/js/commento.js" data-auto-init="true" /> <Script id={"kissmetrics-cdn"} strategy="beforeInteractive" dangerouslySetInnerHTML={{ __html: ` var _kmq = _kmq || []; var _kmk = _kmk || '8291a27d7270981e8c87dda4d684803f873c00e1'; function _kms(u){ setTimeout(function(){ var d = document, f = d.getElementsByTagName('script')[0], s = d.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = u; f.parentNode.insertBefore(s, f); }, 1); } _kms('//i.kissmetrics.io/i.js'); _kms('//scripts.kissmetrics.io/' + _kmk + '.2.js'); `, }} /> <ProgressBar height="4px" color="#025951" options={{ showSpinner: false, }} shallowRouting /> <Navbar /> <Suspense fallback={<LoaderSkeleton />}> {typeof window !== 'undefined' ? ( <CSRReduxProviders> {children} </CSRReduxProviders> ) : ( <SSRReduxProviders> {children} </SSRReduxProviders> )} </Suspense> <Footer /> <ToastContainer /> </body> </html> ) } "use client"; import { store, persistor } from './store.js'; import { PersistGate } from 'redux-persist/integration/react'; import { Provider } from "react-redux"; export function CSRReduxProviders({ children }) { return ( <Provider store={store}> <PersistGate loading={null} persistor={persistor}> {children} </PersistGate> </Provider> ); } export function SSRReduxProviders({ children }) { return ( <Provider store={store}> {children} </Provider> ); } </code>
"use client";

import './globals.css';
import { usePathname } from 'next/navigation';
import { Suspense, useState, useEffect } from 'react';
import classes from './App.module.css';
import { CSRReduxProviders, SSRReduxProviders } from './_store/reduxProvider'
import Navbar from './_Layouts/navbar'
import Footer from './_Layouts/footer/Footer'
import { LoaderSkeleton } from './_components'
import { ToastContainer } from 'react-toastify'
import { AppProgressBar as ProgressBar } from 'next-nprogress-bar';
import Script from 'next/script';
import { HomePage, OffCanvasPopup } from './_components';
import Head from 'next/head';

export default function RootLayout({ children }) {
  const pathname = usePathname();
  const [title, setTitle] = useState('Sustainable Products | Ecowiser');


  useEffect(() => {
    if (pathname.includes('/search')) {
      setTitle(`${pathname.split('/').pop().replaceAll('%20', ' ').replaceAll('_', ' ').replaceAll('-', ' ')} | Ecowiser`);
    } else if (pathname.includes('/category')) {
      setTitle(`${pathname.split('/').pop().replaceAll('-', ' ')} | Ecowiser`);
    } else if (pathname.includes('/lux')) {
      setTitle(`Luxury Products | Ecowiser`);
    } else if (pathname.includes('/how-we-rate')) {
      setTitle("How We Rate | Ecowiser")
    } else if (pathname.split('/')[1].includes('-')) {
      setTitle(`${pathname.split('/').pop().split('-').slice(1).join(" ")} | Ecowiser`);
    }
  }, [pathname]);


  return (
    <html>
      <Head>
        <meta charSet="utf-8" />
        <meta name="description" content={'EcoWiser Products is a directory of sustainable products, helping consumers find eco-friendly items made from renewable resources and biodegradable materials.'} />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <link rel="icon" href={`${process.env.NEXT_PUBLIC_BASE_PATH}/icon.ico`} />
        <link rel="shortcut icon" href={`${process.env.NEXT_PUBLIC_BASE_PATH}/icon.ico`} />
        <link rel="apple-touch-icon" href={`${process.env.NEXT_PUBLIC_BASE_PATH}/apple-icon.png`} />
        <title>{title}</title>
      </Head>
      <body suppressHydrationWarning={true}>
        <Script
          id={"Skimlinks"}
          strategy="beforeInteractive"
          src={`https://s.skimresources.com/js/263708X1748630.skimlinks.js`}
        />
        <Script
          id={"GoogleTagManager"}
          strategy="beforeInteractive"
          src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}`}
        />
        <Script
          id={"GoogleAnalytics"}
          strategy="beforeInteractive"
        >
          {`
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
            gtag('config', '${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}', {
            page_path: window.location.pathname,
            });
          `}
        </Script>
        <Script
          id={"commento.io"}
          strategy="beforeInteractive"
          defer
          src="https://ec2-44-219-132-22.compute-1.amazonaws.com/js/commento.js"
          data-auto-init="true"
        />
        <Script
          id={"kissmetrics-cdn"}
          strategy="beforeInteractive"
          dangerouslySetInnerHTML={{
            __html: `
            var _kmq = _kmq || [];
            var _kmk = _kmk || '8291a27d7270981e8c87dda4d684803f873c00e1';
            function _kms(u){
            setTimeout(function(){
                var d = document, f = d.getElementsByTagName('script')[0],
                s = d.createElement('script');
                s.type = 'text/javascript'; s.async = true; s.src = u;
                f.parentNode.insertBefore(s, f);
            }, 1);
            }
            _kms('//i.kissmetrics.io/i.js');
            _kms('//scripts.kissmetrics.io/' + _kmk + '.2.js');
            `,
          }}
        />
        <ProgressBar
          height="4px"
          color="#025951"
          options={{
            showSpinner: false,
          }}
          shallowRouting
        />
        <Navbar />
        <Suspense fallback={<LoaderSkeleton />}>
          {typeof window !== 'undefined' ? (
            <CSRReduxProviders>
              {children}
            </CSRReduxProviders>
          ) : (
            <SSRReduxProviders>
              {children}
            </SSRReduxProviders>
          )}
        </Suspense>
        <Footer />
        <ToastContainer />
      </body>
    </html>
  )
}

"use client";

import { store, persistor } from './store.js';
import { PersistGate } from 'redux-persist/integration/react';
import { Provider } from "react-redux";

export function CSRReduxProviders({ children }) {
    return (
        <Provider store={store}>
            <PersistGate loading={null} persistor={persistor}>
                {children}
            </PersistGate>
        </Provider>
    );
}

export function SSRReduxProviders({ children }) {
    return (
        <Provider store={store}>
            {children}
        </Provider>
    );
}

All elements inside {children} do not appear inside the page source.
Is there any way to make the whole page visible inside the page source?

I have tried conditionally rendering the {children} based on the typeof window, but it is not working, apart from the navbar and footer nothing else appears on the page source, not even the page heading

New contributor

Anurag Goswami is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật