I shifted my project from CRA to nextjs because of SEO. On Sever side rendering, the client gets a complete HTML page as a response but in my case when i view page source of my landing page then i just see <div id="__next"><div></div></div>
. On every pages, the page source shows the same.
Here is my code
pages/index.js
const IndexPage = () => {
return (
<Layout title="Home">
<Home />
</Layout>
);
};
export default IndexPage;
_app.js
class MyApp extends App {
render() {
const { Component, pageProps, apolloClient } = this.props;
return (
<ApolloProvider client={apolloClient}>
<UserProvider>
<RoleBasedComponent comp={Component} {...pageProps} />
</UserProvider>
</ApolloProvider>
);
}
}
export default withApollo(MyApp, {
ssr: false,
});
Is there something i did to violate the concept of server side rendering? Can anyone help me to understand why the HTML response is not viewable when looking at the view page source? I am totally confused and I afraid if google bot cannot index the page for SEO.
UPDATE
UserContext.js
const UserContext = createContext();
// Use this wherever current user data is required eg const {currentUser, loading} = useContext(UserContext)
const UserProvider = ({ children }) => {
const token = cookies.getSession();
return (
<Query
query={GET_CURRENT_USER}
variables={{
input: {
token,
},
}}
>
{({ data, refetch, loading }) => {
const currentUser = get(data, 'currentUser.data');
if (loading) return <div />;
return (
<UserContext.Provider
value={{ currentUser, loading, refetchUser: refetch }}
>
{children}
</UserContext.Provider>
);
}}
</Query>
);
};
2
Answers
When rendering the component “MyApp` you’re passing:
I would give a read to this page – https://www.apollographql.com/docs/react/performance/server-side-rendering/
It can probably help.
u can use this from documentation … https://nextjs.org/docs/advanced-features/custom-document (Customizing renderPage)
and try to include strategy=’beforeInteractive’ inside Scripts.
In my case i receive some props from each article (or each page) That is why i used extra tags. Be careful about your layout .Try to make layout which will dynamically receive meta tags or link tags which u will include inside metagas
Here is code example