Skip to content

Commit

Permalink
Do not suggest adding "use client" if using next/router in app (#48680)
Browse files Browse the repository at this point in the history
Feedback form @MaxLeiter, that we shouldn't tell the user to add "use client" in this case:

![image](https://user-images.githubusercontent.com/3676859/233697824-65e8013b-f292-4f77-bdff-d421269ba750.png)
  • Loading branch information
shuding committed Apr 21, 2023
1 parent a875d5a commit 485955b
Showing 1 changed file with 5 additions and 2 deletions.
Expand Up @@ -40,6 +40,7 @@ function formatRSCErrorMessage(
formattedVerboseMessage =
'\n\nMaybe one of these should be marked as a client entry with "use client":\n'
} else if (NEXT_RSC_ERR_SERVER_IMPORT.test(message)) {
let shouldAddUseClient = true
const matches = message.match(NEXT_RSC_ERR_SERVER_IMPORT)
switch (matches && matches[1]) {
case 'react-dom/server':
Expand All @@ -49,15 +50,17 @@ function formatRSCErrorMessage(
case 'next/router':
// If importing "next/router", we should tell them to use "next/navigation".
formattedMessage = `\n\nYou have a Server Component that imports next/router. Use next/navigation instead.`
shouldAddUseClient = false
break
default:
formattedMessage = message.replace(
NEXT_RSC_ERR_SERVER_IMPORT,
`\n\nYou're importing a component that imports $1. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.\n\n`
)
}
formattedVerboseMessage =
'\n\nMaybe one of these should be marked as a client entry "use client":\n'
formattedVerboseMessage = shouldAddUseClient
? '\n\nMaybe one of these should be marked as a client entry "use client":\n'
: '\n\nImport trace:\n'
} else if (NEXT_RSC_ERR_CLIENT_IMPORT.test(message)) {
if (isPagesDir) {
formattedMessage = message.replace(
Expand Down

0 comments on commit 485955b

Please sign in to comment.