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

Should not show no index for client rendering bailout #59531

Merged
merged 12 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/next/src/client/on-recoverable-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NEXT_DYNAMIC_NO_SSR_CODE } from '../shared/lib/lazy-dynamic/no-ssr-error'
import { isBailoutCSRError } from '../shared/lib/lazy-dynamic/no-ssr-error'

export default function onRecoverableError(err: any) {
// Using default react onRecoverableError
Expand All @@ -13,7 +13,7 @@ export default function onRecoverableError(err: any) {
}

// Skip certain custom errors which are not expected to be reported on client
if (err.digest === NEXT_DYNAMIC_NO_SSR_CODE) return
if (isBailoutCSRError(err)) return

defaultOnRecoverableError(err)
}
4 changes: 2 additions & 2 deletions packages/next/src/export/helpers/is-dynamic-usage-error.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { DYNAMIC_ERROR_CODE } from '../../client/components/hooks-server-context'
import { isNotFoundError } from '../../client/components/not-found'
import { isRedirectError } from '../../client/components/redirect'
import { NEXT_DYNAMIC_NO_SSR_CODE } from '../../shared/lib/lazy-dynamic/no-ssr-error'
import { isBailoutCSRError } from '../../shared/lib/lazy-dynamic/no-ssr-error'

export const isDynamicUsageError = (err: any) =>
err.digest === DYNAMIC_ERROR_CODE ||
isNotFoundError(err) ||
err.digest === NEXT_DYNAMIC_NO_SSR_CODE ||
isBailoutCSRError(err) ||
isRedirectError(err)
6 changes: 3 additions & 3 deletions packages/next/src/export/routes/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
NEXT_DATA_SUFFIX,
SERVER_PROPS_EXPORT_ERROR,
} from '../../lib/constants'
import { NEXT_DYNAMIC_NO_SSR_CODE } from '../../shared/lib/lazy-dynamic/no-ssr-error'
import { isBailoutCSRError } from '../../shared/lib/lazy-dynamic/no-ssr-error'
import AmpHtmlValidator from 'next/dist/compiled/amphtml-validator'
import { FileType, fileExists } from '../../lib/file-exists'
import { lazyRenderPagesPage } from '../../server/future/route-modules/pages/module.render'
Expand Down Expand Up @@ -106,7 +106,7 @@ export async function exportPages(
renderOpts
)
} catch (err: any) {
if (err.digest !== NEXT_DYNAMIC_NO_SSR_CODE) {
if (!isBailoutCSRError(err)) {
throw err
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ export async function exportPages(
renderOpts
)
} catch (err: any) {
if (err.digest !== NEXT_DYNAMIC_NO_SSR_CODE) {
if (!isBailoutCSRError(err)) {
throw err
}
}
Expand Down
7 changes: 4 additions & 3 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import { parseAndValidateFlightRouterState } from './parse-and-validate-flight-r
import { validateURL } from './validate-url'
import { createFlightRouterStateFromLoaderTree } from './create-flight-router-state-from-loader-tree'
import { handleAction } from './action-handler'
import { NEXT_DYNAMIC_NO_SSR_CODE } from '../../shared/lib/lazy-dynamic/no-ssr-error'
import { isBailoutCSRError } from '../../shared/lib/lazy-dynamic/no-ssr-error'
import { warn, error } from '../../build/output/log'
import { appendMutableCookies } from '../web/spec-extension/adapters/request-cookies'
import { createServerInsertedHTML } from './server-inserted-html'
Expand Down Expand Up @@ -863,7 +863,8 @@ async function renderToHTMLOrFlightImpl(
throw err
}

if (err.digest === NEXT_DYNAMIC_NO_SSR_CODE) {
const isBailoutCSR = isBailoutCSRError(err)
if (isBailoutCSR) {
warn(
`Entire page ${pagePath} deopted into client-side rendering. https://nextjs.org/docs/messages/deopted-into-client-rendering`,
pagePath
Expand Down Expand Up @@ -894,7 +895,7 @@ async function renderToHTMLOrFlightImpl(
}

const is404 = res.statusCode === 404
if (!is404 && !hasRedirectError) {
if (!is404 && !hasRedirectError && !isBailoutCSR) {
res.statusCode = 500
}

Expand Down
4 changes: 4 additions & 0 deletions packages/next/src/shared/lib/lazy-dynamic/no-ssr-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ export function throwWithNoSSR() {
;(error as any).digest = NEXT_DYNAMIC_NO_SSR_CODE
throw error
}

export function isBailoutCSRError(err: any) {
return err?.digest === NEXT_DYNAMIC_NO_SSR_CODE
}
42 changes: 26 additions & 16 deletions test/e2e/app-dir/app-static/app-static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,12 @@ createNextDescribe(
'blog/styfle/second-post.rsc',
'force-static/[slug]/page.js',
'hooks/use-pathname/slug.rsc',
'hooks/use-search-params.rsc',
'route-handler/post/route.js',
'blog/[author]/[slug]/page.js',
'blog/styfle/second-post.html',
'hooks/use-pathname/slug.html',
'hooks/use-search-params.html',
'flight/[slug]/[slug2]/page.js',
'variable-revalidate/cookie.rsc',
'hooks/use-search-params/page.js',
'ssr-auto/cache-no-store/page.js',
'variable-revalidate/cookie.html',
'api/revalidate-tag-edge/route.js',
Expand Down Expand Up @@ -663,7 +660,10 @@ createNextDescribe(
'force-static/[slug]/page_client-reference-manifest.js',
'blog/[author]/[slug]/page_client-reference-manifest.js',
'flight/[slug]/[slug2]/page_client-reference-manifest.js',
'hooks/use-search-params/page_client-reference-manifest.js',
'hooks/use-search-params/static-bailout.html',
'hooks/use-search-params/static-bailout.rsc',
'hooks/use-search-params/static-bailout/page.js',
'hooks/use-search-params/static-bailout/page_client-reference-manifest.js',
'ssr-auto/cache-no-store/page_client-reference-manifest.js',
'gen-params-dynamic/[slug]/page_client-reference-manifest.js',
'hooks/use-pathname/[slug]/page_client-reference-manifest.js',
Expand Down Expand Up @@ -966,8 +966,8 @@ createNextDescribe(
"initialRevalidateSeconds": false,
"srcRoute": "/hooks/use-pathname/[slug]",
},
"/hooks/use-search-params": {
"dataRoute": "/hooks/use-search-params.rsc",
"/hooks/use-search-params/force-static": {
"dataRoute": "/hooks/use-search-params/force-static.rsc",
"experimentalBypassFor": [
{
"key": "Next-Action",
Expand All @@ -980,10 +980,10 @@ createNextDescribe(
},
],
"initialRevalidateSeconds": false,
"srcRoute": "/hooks/use-search-params",
"srcRoute": "/hooks/use-search-params/force-static",
},
"/hooks/use-search-params/force-static": {
"dataRoute": "/hooks/use-search-params/force-static.rsc",
"/hooks/use-search-params/static-bailout": {
"dataRoute": "/hooks/use-search-params/static-bailout.rsc",
"experimentalBypassFor": [
{
"key": "Next-Action",
Expand All @@ -996,7 +996,7 @@ createNextDescribe(
},
],
"initialRevalidateSeconds": false,
"srcRoute": "/hooks/use-search-params/force-static",
"srcRoute": "/hooks/use-search-params/static-bailout",
},
"/hooks/use-search-params/with-suspense": {
"dataRoute": "/hooks/use-search-params/with-suspense.rsc",
Expand Down Expand Up @@ -2838,9 +2838,9 @@ createNextDescribe(
describe('useSearchParams', () => {
describe('client', () => {
it('should bailout to client rendering - without suspense boundary', async () => {
const browser = await next.browser(
'/hooks/use-search-params?first=value&second=other&third'
)
const url =
'/hooks/use-search-params/static-bailout?first=value&second=other&third'
const browser = await next.browser(url)

expect(await browser.elementByCss('#params-first').text()).toBe(
'value'
Expand All @@ -2852,12 +2852,15 @@ createNextDescribe(
expect(await browser.elementByCss('#params-not-real').text()).toBe(
'N/A'
)

const $ = await next.render$(url)
expect($('meta[content=noindex]').length).toBe(0)
})

it('should bailout to client rendering - with suspense boundary', async () => {
const browser = await next.browser(
const url =
'/hooks/use-search-params/with-suspense?first=value&second=other&third'
)
const browser = await next.browser(url)

expect(await browser.elementByCss('#params-first').text()).toBe(
'value'
Expand All @@ -2869,6 +2872,11 @@ createNextDescribe(
expect(await browser.elementByCss('#params-not-real').text()).toBe(
'N/A'
)

const $ = await next.render$(url)
// dynamic page doesn't have bail out
expect($('html#__next_error__').length).toBe(0)
expect($('meta[content=noindex]').length).toBe(0)
})

it.skip('should have empty search params on force-static', async () => {
Expand Down Expand Up @@ -2919,7 +2927,9 @@ createNextDescribe(
if (!isDev) {
describe('server response', () => {
it('should bailout to client rendering - without suspense boundary', async () => {
const res = await next.fetch('/hooks/use-search-params')
const res = await next.fetch(
'/hooks/use-search-params/static-bailout'
)
const html = await res.text()
expect(html).toInclude('<html id="__next_error__">')
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import UseSearchParams from './search-params'
import UseSearchParams from '../search-params'

export default function Page() {
return (
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app-static/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
afterFiles: [
{
source: '/rewritten-use-search-params',
destination: '/hooks/use-search-params',
destination: '/hooks/use-search-params/static-bailout',
},
{
source: '/rewritten-use-pathname',
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion test/e2e/app-dir/hooks/app/layout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

export const revalidate = 0
export const dynamic = 'force-dynamic'

export default function Layout({ children }) {
return (
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/hooks/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ createNextDescribe(
initialRand = $('#rand').text()
})

it('should genenerate rand when draft mode enabled', async () => {
it('should generate rand when draft mode enabled', async () => {
const res = await next.fetch('/enable')
const h = res.headers.get('set-cookie') || ''
const cookie = h
Expand Down