Unverified Commit 66478522 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Improve RSC error messages (#90702)

Improve the RSC error messages to be more comprehensive.

x-ref:
https://github.com/vercel/next.js/pull/89688#discussion_r2865847895

---------
Co-authored-by: 's avatarClaude Haiku 4.5 <noreply@anthropic.com>
parent a060fbf9
...@@ -328,9 +328,9 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK ...@@ -328,9 +328,9 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK
.unwrap_or_default(); .unwrap_or_default();
let msg = if !is_app_dir { let msg = if !is_app_dir {
format!("You're importing a component that needs \"{source}\". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components\n\n") format!("You're importing a module that depends on \"{source}\". This API is only available in Server Components in the App Router, but you are using it in the Pages Router.\nLearn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components\n\n")
} else { } else {
format!("You're importing a component that needs \"{source}\". That only works in a Server Component but one of its parents is marked with \"use client\", so it's a Client Component.\nLearn more: https://nextjs.org/docs/app/building-your-application/rendering\n\n") format!("You're importing a module that depends on \"{source}\" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with \"use client\", so this module is also a Client Component.\nLearn more: https://nextjs.org/docs/app/building-your-application/rendering\n\n")
}; };
(msg, vec![span]) (msg, vec![span])
} }
...@@ -338,7 +338,7 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK ...@@ -338,7 +338,7 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK
let msg = if source == "Component" { let msg = if source == "Component" {
"You’re importing a class component. It only works in a Client Component but none of its parents are marked with \"use client\", so they're Server Components by default.\nLearn more: https://nextjs.org/docs/app/building-your-application/rendering/client-components\n\n".to_string() "You’re importing a class component. It only works in a Client Component but none of its parents are marked with \"use client\", so they're Server Components by default.\nLearn more: https://nextjs.org/docs/app/building-your-application/rendering/client-components\n\n".to_string()
} else { } else {
format!("You're importing a component that needs `{source}`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `\"use client\"` directive.\n\n Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client\n\n") format!("You're importing a module that depends on `{source}` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the `\"use client\"` directive.\nLearn more: https://nextjs.org/docs/app/api-reference/directives/use-client\n\n")
}; };
(msg, vec![span]) (msg, vec![span])
......
x You're importing a component that needs "cacheLife". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component. x You're importing a module that depends on "cacheLife" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use client", so
| this module is also a Client Component.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering | Learn more: https://nextjs.org/docs/app/building-your-application/rendering
| |
| |
......
x You're importing a component that needs "cacheTag". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component. x You're importing a module that depends on "cacheTag" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use client", so
| this module is also a Client Component.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering | Learn more: https://nextjs.org/docs/app/building-your-application/rendering
| |
| |
......
x You're importing a component that needs "next/root-params". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component. x You're importing a module that depends on "next/root-params" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use
| client", so this module is also a Client Component.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering | Learn more: https://nextjs.org/docs/app/building-your-application/rendering
| |
| |
......
x You're importing a component that needs "server-only". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component. x You're importing a module that depends on "server-only" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use client",
| so this module is also a Client Component.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering | Learn more: https://nextjs.org/docs/app/building-your-application/rendering
| |
| |
......
x You're importing a component that needs "cacheLife". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your- x You're importing a module that depends on "cacheLife". This API is only available in Server Components in the App Router, but you are using it in the Pages Router.
| application/rendering/server-components | Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
| |
| |
,-[input.js:1:1] ,-[input.js:1:1]
......
x You're importing a component that needs "cacheTag". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your- x You're importing a module that depends on "cacheTag". This API is only available in Server Components in the App Router, but you are using it in the Pages Router.
| application/rendering/server-components | Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
| |
| |
,-[input.js:1:1] ,-[input.js:1:1]
......
x You're importing a component that needs "next/root-params". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building- x You're importing a module that depends on "next/root-params". This API is only available in Server Components in the App Router, but you are using it in the Pages Router.
| your-application/rendering/server-components | Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
| |
| |
,-[input.js:9:1] ,-[input.js:9:1]
......
x You're importing a component that needs "server-only". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your- x You're importing a module that depends on "server-only". This API is only available in Server Components in the App Router, but you are using it in the Pages Router.
| application/rendering/server-components | Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
| |
| |
,-[input.js:9:1] ,-[input.js:9:1]
......
x You're importing a component that needs `useState`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `useState` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the `"use
| | client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
1 | import { useState } from 'react' 1 | import { useState } from 'react'
: ^^^^^^^^ : ^^^^^^^^
`---- `----
x You're importing a component that needs `createContext`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `createContext` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the
| | `"use client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
3 | import { createContext } from 'react' 3 | import { createContext } from 'react'
: ^^^^^^^^^^^^^ : ^^^^^^^^^^^^^
`---- `----
x You're importing a component that needs `useEffect`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `useEffect` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the `"use
| | client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
5 | import { useEffect, useImperativeHandle } from 'react' 5 | import { useEffect, useImperativeHandle } from 'react'
: ^^^^^^^^^ : ^^^^^^^^^
`---- `----
x You're importing a component that needs `useImperativeHandle`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `useImperativeHandle` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with
| | the `"use client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -47,8 +47,8 @@ ...@@ -47,8 +47,8 @@
: ^^^^^^^^^ : ^^^^^^^^^
9 | createFactory, 9 | createFactory,
`---- `----
x You're importing a component that needs `createFactory`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `createFactory` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the
| | `"use client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -58,8 +58,8 @@ ...@@ -58,8 +58,8 @@
: ^^^^^^^^^^^^^ : ^^^^^^^^^^^^^
10 | PureComponent, 10 | PureComponent,
`---- `----
x You're importing a component that needs `PureComponent`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `PureComponent` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the
| | `"use client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -69,8 +69,8 @@ ...@@ -69,8 +69,8 @@
: ^^^^^^^^^^^^^ : ^^^^^^^^^^^^^
11 | useDeferredValue, 11 | useDeferredValue,
`---- `----
x You're importing a component that needs `useDeferredValue`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `useDeferredValue` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the
| | `"use client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -80,8 +80,8 @@ ...@@ -80,8 +80,8 @@
: ^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^
12 | useInsertionEffect, 12 | useInsertionEffect,
`---- `----
x You're importing a component that needs `useInsertionEffect`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `useInsertionEffect` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with
| | the `"use client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -91,8 +91,8 @@ ...@@ -91,8 +91,8 @@
: ^^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^^^
13 | useLayoutEffect, 13 | useLayoutEffect,
`---- `----
x You're importing a component that needs `useLayoutEffect`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `useLayoutEffect` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the
| | `"use client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -102,8 +102,8 @@ ...@@ -102,8 +102,8 @@
: ^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^
14 | useReducer, 14 | useReducer,
`---- `----
x You're importing a component that needs `useReducer`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `useReducer` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the `"use
| | client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -113,8 +113,8 @@ ...@@ -113,8 +113,8 @@
: ^^^^^^^^^^ : ^^^^^^^^^^
15 | useRef, 15 | useRef,
`---- `----
x You're importing a component that needs `useRef`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `useRef` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the `"use
| | client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -124,8 +124,8 @@ ...@@ -124,8 +124,8 @@
: ^^^^^^ : ^^^^^^
16 | useSyncExternalStore, 16 | useSyncExternalStore,
`---- `----
x You're importing a component that needs `useSyncExternalStore`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `useSyncExternalStore` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with
| | the `"use client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -135,8 +135,8 @@ ...@@ -135,8 +135,8 @@
: ^^^^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^^^^^
17 | } from 'react' 17 | } from 'react'
`---- `----
x You're importing a component that needs `experimental_useOptimistic`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `experimental_useOptimistic` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its
| | parent) with the `"use client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
......
x You're importing a component that needs `flushSync`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `flushSync` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the `"use
| | client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
1 | import { flushSync, unstable_batchedUpdates } from 'react-dom' 1 | import { flushSync, unstable_batchedUpdates } from 'react-dom'
: ^^^^^^^^^ : ^^^^^^^^^
`---- `----
x You're importing a component that needs `unstable_batchedUpdates`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `unstable_batchedUpdates` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent)
| | with the `"use client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
1 | import { flushSync, unstable_batchedUpdates } from 'react-dom' 1 | import { flushSync, unstable_batchedUpdates } from 'react-dom'
: ^^^^^^^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^^^^^^^^
`---- `----
x You're importing a component that needs `useActionState`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `useActionState` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the
| | `"use client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
3 | import { useActionState } from 'react' 3 | import { useActionState } from 'react'
: ^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^
`---- `----
x You're importing a component that needs `useFormStatus`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `useFormStatus` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the
| | `"use client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
...@@ -36,8 +36,8 @@ ...@@ -36,8 +36,8 @@
5 | import { useFormStatus, useFormState } from 'react-dom' 5 | import { useFormStatus, useFormState } from 'react-dom'
: ^^^^^^^^^^^^^ : ^^^^^^^^^^^^^
`---- `----
x You're importing a component that needs `useFormState`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive. x You're importing a module that depends on `useFormState` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the
| | `"use client"` directive.
| Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client | Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
| |
| |
......
...@@ -230,7 +230,7 @@ describe('Error overlay - RSC build errors', () => { ...@@ -230,7 +230,7 @@ describe('Error overlay - RSC build errors', () => {
// `Component` has a custom error message // `Component` has a custom error message
api === 'Component' api === 'Component'
? `You’re importing a class component. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.` ? `You’re importing a class component. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.`
: `You're importing a component that needs \`${api}\`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the \`"use client"\` directive.` : `You're importing a module that depends on \`${api}\` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the \`"use client"\` directive.`
) )
}) })
} }
...@@ -251,7 +251,7 @@ describe('Error overlay - RSC build errors', () => { ...@@ -251,7 +251,7 @@ describe('Error overlay - RSC build errors', () => {
const { session } = sandbox const { session } = sandbox
await session.waitForRedbox() await session.waitForRedbox()
expect(await session.getRedboxSource()).toInclude( expect(await session.getRedboxSource()).toInclude(
`You're importing a component that needs \`${api}\`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the \`"use client"\` directive.` `You're importing a module that depends on \`${api}\` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the \`"use client"\` directive.`
) )
}) })
} }
...@@ -276,7 +276,7 @@ describe('Error overlay - RSC build errors', () => { ...@@ -276,7 +276,7 @@ describe('Error overlay - RSC build errors', () => {
const { session } = sandbox const { session } = sandbox
await session.waitForRedbox() await session.waitForRedbox()
expect(await session.getRedboxSource()).toInclude( expect(await session.getRedboxSource()).toInclude(
'You\'re importing a component that needs `unstable_catchError`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive.' 'You\'re importing a module that depends on `unstable_catchError` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the `"use client"` directive.'
) )
}) })
...@@ -311,7 +311,7 @@ describe('Error overlay - RSC build errors', () => { ...@@ -311,7 +311,7 @@ describe('Error overlay - RSC build errors', () => {
const { session } = sandbox const { session } = sandbox
await session.waitForRedbox() await session.waitForRedbox()
expect(await session.getRedboxSource()).toInclude( expect(await session.getRedboxSource()).toInclude(
'You\'re importing a component that needs `unstable_catchError`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive.' 'You\'re importing a module that depends on `unstable_catchError` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the `"use client"` directive.'
) )
} }
) )
...@@ -335,7 +335,7 @@ describe('Error overlay - RSC build errors', () => { ...@@ -335,7 +335,7 @@ describe('Error overlay - RSC build errors', () => {
await session.waitForRedbox() await session.waitForRedbox()
expect(await session.getRedboxSource()).toInclude( expect(await session.getRedboxSource()).toInclude(
`You're importing a component that needs "server-only". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.` `You're importing a module that depends on "server-only" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use client", so this module is also a Client Component.`
) )
}) })
...@@ -351,7 +351,7 @@ describe('Error overlay - RSC build errors', () => { ...@@ -351,7 +351,7 @@ describe('Error overlay - RSC build errors', () => {
const { session } = sandbox const { session } = sandbox
await session.waitForRedbox() await session.waitForRedbox()
expect(await session.getRedboxSource()).toInclude( expect(await session.getRedboxSource()).toInclude(
`You're importing a component that needs "${api}". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.` `You're importing a module that depends on "${api}" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use client", so this module is also a Client Component.`
) )
} }
) )
...@@ -414,7 +414,7 @@ describe('Error overlay - RSC build errors', () => { ...@@ -414,7 +414,7 @@ describe('Error overlay - RSC build errors', () => {
const { session } = sandbox const { session } = sandbox
await session.waitForRedbox() await session.waitForRedbox()
expect(await session.getRedboxSource()).toInclude( expect(await session.getRedboxSource()).toInclude(
`You're importing a component that needs "next/root-params". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.` `You're importing a module that depends on "next/root-params" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use client", so this module is also a Client Component.`
) )
}) })
......
...@@ -525,7 +525,7 @@ describe('Error Overlay for server components', () => { ...@@ -525,7 +525,7 @@ describe('Error Overlay for server components', () => {
// So we need to check for the first part of the message. // So we need to check for the first part of the message.
const normalizedSource = await session.getRedboxSource() const normalizedSource = await session.getRedboxSource()
expect(normalizedSource).toContain( expect(normalizedSource).toContain(
`You're importing a component that needs \`${hook}\`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the \`"use client"\` directive.` `You're importing a module that depends on \`${hook}\` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the \`"use client"\` directive.`
) )
expect(normalizedSource).toContain( expect(normalizedSource).toContain(
`import { ${hook} } from 'next/navigation'` `import { ${hook} } from 'next/navigation'`
...@@ -557,7 +557,7 @@ describe('Error Overlay for server components', () => { ...@@ -557,7 +557,7 @@ describe('Error Overlay for server components', () => {
// So we need to check for the first part of the message. // So we need to check for the first part of the message.
const normalizedSource = await session.getRedboxSource() const normalizedSource = await session.getRedboxSource()
expect(normalizedSource).toContain( expect(normalizedSource).toContain(
`You're importing a component that needs \`${hook}\`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the \`"use client"\` directive.` `You're importing a module that depends on \`${hook}\` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the \`"use client"\` directive.`
) )
expect(normalizedSource).toContain( expect(normalizedSource).toContain(
`import { ${hook} } from 'next/link'` `import { ${hook} } from 'next/link'`
......
...@@ -27,7 +27,7 @@ describe('after() - invalid usages', () => { ...@@ -27,7 +27,7 @@ describe('after() - invalid usages', () => {
await waitForRedbox(session) await waitForRedbox(session)
expect(await getRedboxSource(session)).toMatch( expect(await getRedboxSource(session)).toMatch(
/You're importing a component that needs "?after"?\. That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component\./ /You're importing a module that depends on "?after"? into a React Client Component module\. This API is only available in Server Components but one of its parents is marked with "use client", so this module is also a Client Component\./
) )
expect(getAfterLogs()).toHaveLength(0) expect(getAfterLogs()).toHaveLength(0)
}) })
......
...@@ -62,7 +62,7 @@ _describe('after() - pages', () => { ...@@ -62,7 +62,7 @@ _describe('after() - pages', () => {
await waitForRedbox(browser) await waitForRedbox(browser)
expect(await getRedboxSource(browser)).toMatch( expect(await getRedboxSource(browser)).toMatch(
/You're importing a component that needs "?after"?\. That only works in a Server Component which is not supported in the pages\/ directory\./ /You're importing a module that depends on "?after"?\. This API is only available in Server Components in the App Router, but you are using it in the Pages Router\./
) )
expect(getLogs()).toHaveLength(0) expect(getLogs()).toHaveLength(0)
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment