Error occured in Server Component render when redirect (next/navigation) is used

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 22.1.0: Sun Oct  9 20:14:54 PDT 2022; root:xnu-8792.41.9~2/RELEASE_X86_64
Binaries:
  Node: 18.12.0
  npm: 8.19.2
  Yarn: 1.22.19
  pnpm: 7.15.0
Relevant packages:
  next: 13.0.3
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

Firefox 106.0.5, macOS Ventura 13.0.1

How are you deploying your application? (if relevant)

Locally with next start

Describe the Bug

When redirect is used in a Server Component, in the production build there is a mysterious error, although the redirection itself works fine:

An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.

Furthermore, when the root has a loading.tsx, the following error will also be shown (well, not that exact error, but a minified error with a URL leading to this decoded text):

This Suspense boundary received an update before it finished hydrating. This caused the boundary to switch to client rendering. The usual way to fix this is to wrap the original update in startTransition.

Expected Behavior

No errors.

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

https://github.com/joulev/debug/tree/nextjs-redirect-error

To Reproduce

  1. Clone the repository
  2. npm install
  3. npm run build (the bug doesn’t appear in dev mode)
  4. npm run start
  5. Navigate to localhost:3000 with the console open
  6. It will automatically redirect to /test (of course), but in the console the above error message appears.

To reproduce the second error

  1. Do steps 1–2 above.

  2. Add a file app/loading.tsx (not available in the repro repo above) with the following content

    export default function Loading() {
      return <div>Loading</div>;
    }
    
  3. Repeat steps 3–6 above.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
balazsorban44commented, Nov 14, 2022

Seems to be a different issue, the link you provided works fine for me. Could you open a separate issue with a linked minimal reproduction of your code? Just remove anything unnecessary so it’s easier to debug/verify. 🙏

For the original report, I did some digging and it is a duplicate of https://github.com/vercel/next.js/issues/42556. Basically, you can ignore the console in this case, we will make sure it’s not shown as an error.

1reaction
kochiecommented, Nov 13, 2022

I’m also getting the same error when used in a client component.

'use client'
import { load, trackPageview } from 'fathom-client'
import { useEffect } from 'react'
import { usePathname, useSearchParams } from 'next/navigation'

export default function Fathom() {
  const pathname = usePathname()
  const searchParams = useSearchParams()
  useEffect(() => {
    load('XXXXXXXX', {
      includedDomains: ['example.com'],
      spa: 'auto',
    })

    // Initialize Fathom when the app loads
    // Example: yourdomain.com
    //  - Do not include https://
    //  - This must be an exact match of your domain.
    //  - If you're using www. for your domain, make sure you include that here.
    trackPageview()

    // Record a pageview when route changes
  }, [pathname, searchParams])

  return null
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to catch server errors in Nuxt.js so it doesn't crash page ...
Important to understand is that rendering failed so you have to redirect or render another page. //nuxt.config.js hooks: { render: ...
Read more >
Handle Load Errors in Nuxt with Alternate Data, Redirect, or ...
In a server-rendered application, if you attempt to load data before the page renders and the data fails to load, your application will...
Read more >
Data Fetching - Nuxt
fetch is a hook called during server-side rendering after the component instance is created, and on the client when navigating. The fetch hook...
Read more >
Error handling in NuxtJS - Damir's Corner
Error handling works differently in SSR (server-side rendering) and SPA (single page application) mode. Since the pages rehydrate as SPAs even ...
Read more >
Creating Server-side Rendered Vue.js Apps Using Nuxt.js
This is a big indication that something is wrong with the application logic. Thankfully, an error will be generated in your browser's console...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found