Skip to content

Commit 02c2f11

Browse files
huozhiijjk
andauthored
Enable missing suspense bailout by default (#60840)
`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 <[email protected]>
1 parent 2096dfa commit 02c2f11

File tree

9 files changed

+58
-13
lines changed

9 files changed

+58
-13
lines changed

errors/missing-suspense-with-csr-bailout.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Certain methods like `useSearchParams()` opt Next.js into client-side rendering.
1010

1111
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.
1212

13+
> 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.
14+
1315
### Useful Links
1416

1517
- [`useSearchParams`](https://nextjs.org/docs/app/api-reference/functions/use-search-params)

packages/next/src/server/config-shared.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ export interface ExperimentalConfig {
387387
*
388388
* 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.
389389
*
390-
* @default false
390+
* @note This flag will be removed in Next.js 15.
391+
* @default true
391392
*/
392393
missingSuspenseWithCSRBailout?: boolean
393394
}
@@ -866,7 +867,7 @@ export const defaultConfig: NextConfig = {
866867
? true
867868
: false,
868869
webpackBuildWorker: undefined,
869-
missingSuspenseWithCSRBailout: false,
870+
missingSuspenseWithCSRBailout: true,
870871
},
871872
}
872873

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
/** @type {import("next").NextConfig} */
2-
const config = {
3-
experimental: {
4-
missingSuspenseWithCSRBailout: true,
5-
},
6-
}
2+
const config = {}
73

84
module.exports = config
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
'use client'
22

3+
import { Suspense } from 'react'
34
import { ParamsComponent } from '../../../shared/params-component'
45

5-
export default ParamsComponent
6+
export default function Page() {
7+
return (
8+
<Suspense>
9+
<ParamsComponent />
10+
</Suspense>
11+
)
12+
}

test/e2e/app-dir/params-hooks-compat/shared/params-component.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import { useParams, useSearchParams } from 'next/navigation'
32

43
export function ParamsComponent() {

test/e2e/app-dir/shallow-routing/app/(shallow)/pushstate-new-searchparams/page.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use client'
2+
3+
import { Suspense } from 'react'
24
import { useSearchParams } from 'next/navigation'
35

4-
export default function Page() {
6+
function InnerPage() {
57
const searchParams = useSearchParams()
68
return (
79
<>
@@ -24,3 +26,11 @@ export default function Page() {
2426
</>
2527
)
2628
}
29+
30+
export default function Page() {
31+
return (
32+
<Suspense>
33+
<InnerPage />
34+
</Suspense>
35+
)
36+
}

test/e2e/app-dir/shallow-routing/app/(shallow)/pushstate-string-url/page.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use client'
2+
3+
import { Suspense } from 'react'
24
import { useSearchParams } from 'next/navigation'
35

4-
export default function Page() {
6+
function InnerPage() {
57
const searchParams = useSearchParams()
68
return (
79
<>
@@ -57,3 +59,11 @@ export default function Page() {
5759
</>
5860
)
5961
}
62+
63+
export default function Page() {
64+
return (
65+
<Suspense>
66+
<InnerPage />
67+
</Suspense>
68+
)
69+
}

test/e2e/app-dir/shallow-routing/app/(shallow)/replacestate-new-searchparams/page.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use client'
2+
3+
import { Suspense } from 'react'
24
import { useSearchParams } from 'next/navigation'
35

4-
export default function Page() {
6+
function InnerPage() {
57
const searchParams = useSearchParams()
68
return (
79
<>
@@ -24,3 +26,11 @@ export default function Page() {
2426
</>
2527
)
2628
}
29+
30+
export default function Page() {
31+
return (
32+
<Suspense>
33+
<InnerPage />
34+
</Suspense>
35+
)
36+
}

test/e2e/app-dir/shallow-routing/app/(shallow)/replacestate-string-url/page.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use client'
2+
3+
import { Suspense } from 'react'
24
import { useSearchParams } from 'next/navigation'
35

4-
export default function Page() {
6+
function InnerPage() {
57
const searchParams = useSearchParams()
68
return (
79
<>
@@ -57,3 +59,11 @@ export default function Page() {
5759
</>
5860
)
5961
}
62+
63+
export default function Page() {
64+
return (
65+
<Suspense>
66+
<InnerPage />
67+
</Suspense>
68+
)
69+
}

0 commit comments

Comments
 (0)