Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
next-ssr-fallback
Advanced tools
This library helps you to fallback to CSR more easily when using SSR to avoid Next.js app rendering failure.
We usually use getServerSideProps
in Next.js to fetch the initial properties of SSR. If the acquisition fails due to server-side network problems, Next.js will return a status code of 500, which causes our app to fail to render normally.
In order to solve this problem, we need to add the fallback logic by CSR, and obtain properties on the client again when SSR acquisition fails, so as to improve the success rate of rendering.
This library is to help you do this, it only takes a few lines of code to complete.
next-ssr-fallback
is tested with:
^12.0.0
and aboveFirst, install next-ssr-fallback
:
$ npm install next-ssr-fallback
# OR
$ yarn add next-ssr-fallback
# OR
$ pnpm install next-ssr-fallback
You need to make the following changes to the page components:
getServerSideProps
function to getServerSidePropsOrigin
next-ssr-fallback
and create a new SSRFallback
instanceimport FallbackSSR from 'next-ssr-fallback';
const fallbackSSR = new FallbackSSR({
getServerSideProps: getServerSidePropsOrigin,
});
getServerSideProps
by using createGetServerSidePropsFunction
export const getServerSideProps = fallbackSSR.createGetServerSidePropsFunction();
withCSR
for page componentsexport default fallbackSSR.withCSR(PageComponent);
That's all there is to it, your page will support fallback to CSR.
Here is a example recruit-pc using this library. You can refer to how to use.
FAQs
Make it easier for Next.js app to support SSR fallback to CSR
The npm package next-ssr-fallback receives a total of 1 weekly downloads. As such, next-ssr-fallback popularity was classified as not popular.
We found that next-ssr-fallback demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.