Skip to content

Instantly share code, notes, and snippets.

@ianldgs
Created July 19, 2021 02:26
Show Gist options
  • Save ianldgs/0d7a41655feac214a1211061da010338 to your computer and use it in GitHub Desktop.
Save ianldgs/0d7a41655feac214a1211061da010338 to your computer and use it in GitHub Desktop.
import type { GetServerSideProps, GetServerSidePropsContext } from 'next';
/**
* Do not SSR the page when navigating.
* Has to be added right before the final getServerSideProps function
*
* On NextJS, navigation will trigger SSR, but it doesn't
* have any good way of giving feedback to the user that
* something is happening (loading).
* Also, traditional SSR only happens on first page visit.
* Perhaps future versions with React 18 and suspense
* won't need this workaround.
*
* More information can be found on this issue:
* https://github.com/vercel/next.js/issues/13910
*/
export const hasNavigationCSR =
(next?: GetServerSideProps) => async (ctx: GetServerSidePropsContext) => {
if (ctx.req.url?.startsWith('/_next')) {
return {
props: {},
};
}
return next?.(ctx) || { props: {} };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment