2

I've a NextJS project and I'm using getStaticPaths() and getStaticProps() on It.

On SEO side, I got a feedback that; "this site is not working SSR, Its all client-side. because when we disable javascript, it returns empty page".

I couldnt understand why, but thats right, when I disable javascript, site returns empty result. (There's a json result for my getstaticprops and thats all)

Whats wrong with It? What should I make to make SSR?

edit:

Here's my _app.js

    <Provider store={store}>
      <PersistGate persistor={persistor}>
      <NextNprogress
          color="#29D"
          startPosition={0.3}
          stopDelayMs={200}
          height={3}
          showOnShallow={true}
        />
        <Component {...pageProps}  />
      </PersistGate>
    </Provider>

When I remove PersistGate, It begins to work.

juliomalves
  • 42,130
  • 20
  • 150
  • 146
TCS
  • 629
  • 3
  • 11
  • 32
  • Does this answer your question? [SSR does not work when javascript is disabled](https://stackoverflow.com/questions/54313108/ssr-does-not-work-when-javascript-is-disabled) – OMi Shah Mar 15 '22 at 08:51

1 Answers1

1

Out of the box, persistgate delays rendering children until the storage has been hydrated - This obviously would not work on SSR as these are client strategies (localstorage etc.) as a result, SSR rendering is prevented - Others have tried rendering children if its rendered server side

import {PersistGate as PersistGateClient} from 'redux-persist/integration/react';
class PersistGateServer extends React.Component {
    render() {
        return this.props.children
    }
}

class App extends React.Component {
    render() {
        let runtime = process.env.RUNTIME;
        let PersistGate = PersistGateServer;
        if (runtime === 'browser') {
             PersistGate = PersistGateClient
        }
        return (
                <PersistGate loading={null} persistor={persistor}>
                       <WhateverYouWant />
                </PersistGate>
        )
    }

with credit to https://github.com/rt2zz/redux-persist/issues/576#issuecomment-889439120

Ramakay
  • 2,919
  • 1
  • 5
  • 21