Skip to content

Commit

Permalink
Enable missing suspense bailout by default (#60840)
Browse files Browse the repository at this point in the history
`experimental.missingSuspenseWithCSRBailout` should be enabled by
default to help users to disciver unwrapped suspense boundaries.

Add more notes in the error doc about deprecation and temporary
workaround to disable it.

Closes NEXT-2157

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
huozhi and ijjk committed Jan 18, 2024
1 parent 2096dfa commit 02c2f11
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 13 deletions.
2 changes: 2 additions & 0 deletions errors/missing-suspense-with-csr-bailout.mdx
Expand Up @@ -10,6 +10,8 @@ Certain methods like `useSearchParams()` opt Next.js into client-side rendering.

Make sure that the method is wrapped in a suspense boundary. This way Next.js will only opt the component into client-side rendering up to the suspense boundary.

> Note: There's an option `experimental.missingSuspenseWithCSRBailout` to disable the bailout behavior while you are investigating the missing suspense boundary. But it will be removed in next major version as this is a performance de-opt.
### Useful Links

- [`useSearchParams`](https://nextjs.org/docs/app/api-reference/functions/use-search-params)
5 changes: 3 additions & 2 deletions packages/next/src/server/config-shared.ts
Expand Up @@ -387,7 +387,8 @@ export interface ExperimentalConfig {
*
* When this flag is set to `true`, Next.js will break the build instead of warning, to force the developer to add a suspense boundary above the method call.
*
* @default false
* @note This flag will be removed in Next.js 15.
* @default true
*/
missingSuspenseWithCSRBailout?: boolean
}
Expand Down Expand Up @@ -866,7 +867,7 @@ export const defaultConfig: NextConfig = {
? true
: false,
webpackBuildWorker: undefined,
missingSuspenseWithCSRBailout: false,
missingSuspenseWithCSRBailout: true,
},
}

Expand Down
@@ -1,8 +1,4 @@
/** @type {import("next").NextConfig} */
const config = {
experimental: {
missingSuspenseWithCSRBailout: true,
},
}
const config = {}

module.exports = config
9 changes: 8 additions & 1 deletion test/e2e/app-dir/params-hooks-compat/app/app/[slug]/page.js
@@ -1,5 +1,12 @@
'use client'

import { Suspense } from 'react'
import { ParamsComponent } from '../../../shared/params-component'

export default ParamsComponent
export default function Page() {
return (
<Suspense>
<ParamsComponent />
</Suspense>
)
}
@@ -1,4 +1,3 @@
import React from 'react'
import { useParams, useSearchParams } from 'next/navigation'

export function ParamsComponent() {
Expand Down
@@ -1,7 +1,9 @@
'use client'

import { Suspense } from 'react'
import { useSearchParams } from 'next/navigation'

export default function Page() {
function InnerPage() {
const searchParams = useSearchParams()
return (
<>
Expand All @@ -24,3 +26,11 @@ export default function Page() {
</>
)
}

export default function Page() {
return (
<Suspense>
<InnerPage />
</Suspense>
)
}
@@ -1,7 +1,9 @@
'use client'

import { Suspense } from 'react'
import { useSearchParams } from 'next/navigation'

export default function Page() {
function InnerPage() {
const searchParams = useSearchParams()
return (
<>
Expand Down Expand Up @@ -57,3 +59,11 @@ export default function Page() {
</>
)
}

export default function Page() {
return (
<Suspense>
<InnerPage />
</Suspense>
)
}
@@ -1,7 +1,9 @@
'use client'

import { Suspense } from 'react'
import { useSearchParams } from 'next/navigation'

export default function Page() {
function InnerPage() {
const searchParams = useSearchParams()
return (
<>
Expand All @@ -24,3 +26,11 @@ export default function Page() {
</>
)
}

export default function Page() {
return (
<Suspense>
<InnerPage />
</Suspense>
)
}
@@ -1,7 +1,9 @@
'use client'

import { Suspense } from 'react'
import { useSearchParams } from 'next/navigation'

export default function Page() {
function InnerPage() {
const searchParams = useSearchParams()
return (
<>
Expand Down Expand Up @@ -57,3 +59,11 @@ export default function Page() {
</>
)
}

export default function Page() {
return (
<Suspense>
<InnerPage />
</Suspense>
)
}

0 comments on commit 02c2f11

Please sign in to comment.