Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip client-side data-fetching after ssr error #51377

Merged
merged 11 commits into from
Feb 8, 2024
8 changes: 7 additions & 1 deletion packages/next/src/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ __webpack_require__.miniCssF = addChunkSuffix(getMiniCssFilename)
type RenderRouteInfo = PrivateRouteInfo & {
App: AppComponent
scroll?: { x: number; y: number } | null
isHydratePass?: boolean
}
type RenderErrorProps = Omit<RenderRouteInfo, 'Component' | 'styleSheets'>
type RegisterFn = (input: [string, () => void]) => void
Expand Down Expand Up @@ -761,7 +762,11 @@ function doRender(input: RenderRouteInfo): Promise<any> {
}

async function render(renderingProps: RenderRouteInfo): Promise<void> {
if (renderingProps.err) {
// if an error occurs in a server-side page (e.g. in getInitialProps),
// skip re-rendering the error page client-side as data-fetching operations
// will already have been done on the server and NEXT_DATA contains the correct
// data for straight-forward hydration of the error page
if (renderingProps.err && !renderingProps.isHydratePass) {
await renderError(renderingProps)
return
}
Expand Down Expand Up @@ -930,6 +935,7 @@ export async function hydrate(opts?: { beforeRender?: () => Promise<void> }) {
Component: CachedComponent,
props: initialData.props,
err: initialErr,
isHydratePass: true,
}

if (opts?.beforeRender) {
Expand Down