-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reapply "feat(app-router): introduce `experimental.missingSuspenseWit…
- Loading branch information
Showing
30 changed files
with
471 additions
and
387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: Missing Suspense with CSR Bailout | ||
--- | ||
|
||
#### Why This Error Occurred | ||
|
||
Certain methods like `useSearchParams()` opt Next.js into client-side rendering. Without a suspense boundary, this will opt the entire page into client-side rendering, which is likely not intended. | ||
|
||
#### Possible Ways to Fix It | ||
|
||
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. | ||
|
||
### Useful Links | ||
|
||
- [`useSearchParams`](https://nextjs.org/docs/app/api-reference/functions/use-search-params) |
13 changes: 5 additions & 8 deletions
13
packages/next/src/client/components/bailout-to-client-rendering.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
import { throwWithNoSSR } from '../../shared/lib/lazy-dynamic/no-ssr-error' | ||
import { BailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr' | ||
import { staticGenerationAsyncStorage } from './static-generation-async-storage.external' | ||
|
||
export function bailoutToClientRendering(): void | never { | ||
export function bailoutToClientRendering(reason: string): void | never { | ||
const staticGenerationStore = staticGenerationAsyncStorage.getStore() | ||
|
||
if (staticGenerationStore?.forceStatic) { | ||
return | ||
} | ||
if (staticGenerationStore?.forceStatic) return | ||
|
||
if (staticGenerationStore?.isStaticGeneration) { | ||
throwWithNoSSR() | ||
} | ||
if (staticGenerationStore?.isStaticGeneration) | ||
throw new BailoutToCSRError(reason) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import { DYNAMIC_ERROR_CODE } from '../../client/components/hooks-server-context' | ||
import { isNotFoundError } from '../../client/components/not-found' | ||
import { isRedirectError } from '../../client/components/redirect' | ||
import { isBailoutCSRError } from '../../shared/lib/lazy-dynamic/no-ssr-error' | ||
|
||
export const isDynamicUsageError = (err: any) => | ||
err.digest === DYNAMIC_ERROR_CODE || | ||
isNotFoundError(err) || | ||
isBailoutCSRError(err) || | ||
isRedirectError(err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/next/src/shared/lib/lazy-dynamic/bailout-to-csr.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// This has to be a shared module which is shared between client component error boundary and dynamic component | ||
|
||
const BAILOUT_TO_CSR = 'BAILOUT_TO_CLIENT_SIDE_RENDERING' | ||
|
||
/** An error that should be thrown when we want to bail out to client-side rendering. */ | ||
export class BailoutToCSRError extends Error { | ||
digest: typeof BAILOUT_TO_CSR = BAILOUT_TO_CSR | ||
} | ||
|
||
/** Checks if a passed argument is an error that is thrown if we want to bail out to client-side rendering. */ | ||
export function isBailoutToCSRError(err: unknown): err is BailoutToCSRError { | ||
if (typeof err !== 'object' || err === null) return false | ||
return 'digest' in err && err.digest === BAILOUT_TO_CSR | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/next/src/shared/lib/lazy-dynamic/dynamic-bailout-to-csr.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use client' | ||
|
||
import type { ReactElement } from 'react' | ||
import { BailoutToCSRError } from './bailout-to-csr' | ||
|
||
interface BailoutToCSRProps { | ||
reason: string | ||
children: ReactElement | ||
} | ||
|
||
/** | ||
* If rendered on the server, this component throws an error | ||
* to signal Next.js that it should bail out to client-side rendering instead. | ||
*/ | ||
export function BailoutToCSR({ reason, children }: BailoutToCSRProps) { | ||
if (typeof window === 'undefined') { | ||
throw new BailoutToCSRError(reason) | ||
} | ||
|
||
return children | ||
} |
14 changes: 0 additions & 14 deletions
14
packages/next/src/shared/lib/lazy-dynamic/dynamic-no-ssr.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.