question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dynamic import with `suspense:true, ssr:false` causes `The server could not finish this Suspense boundary` error

See original GitHub issue

Verify canary release

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

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:41 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T6000
Binaries:
  Node: 16.14.2
  npm: 8.1.4
  Yarn: 1.22.1
  pnpm: 6.32.4
Relevant packages:
  next: 12.1.6-canary.16
  react: 18.1.0
  react-dom: 18.1.0

Describe the Bug

Using dynamic component import with {suspense: true, ssr:false} cause this error:

Error: The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.

image

Important Note: functionally this works correctly, the issue is just that an error is being generated and so it appears broken

Expected Behavior

Should work without any error popup or error in browser console

To Reproduce

Runable reproduction: https://codesandbox.io/s/dank-sound-pkxopr?file=/pages/index.js

import { Suspense } from "react";
import dynamic from "next/dynamic";

const Thing = dynamic(() => import("../thing"), { ssr: false, suspense: true });

export default function IndexPage() {
  return (
    <div>
      <p>Next.js Example</p>
      <Suspense fallback="Loading...">
        <Thing />
      </Suspense>
    </div>
  );
}
//thing.js
export default function Thing() {
  return "Thing";
}

Other

You can also cause this same behavior with this next.js page:

import { Suspense } from "react";

export default function Thing() {
  if (typeof window === 'undefined') {
    const e = new error()
    e.name = "rendering suspense fallback..."
    delete e.stack
    throw e
  } 
  return "Thing"
}

export default function IndexPage() {
  return (
    <div>
      <p>Next.js Example</p>
      <Suspense fallback="Loading...">
        <Thing />
      </Suspense>
    </div>
  );
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
graupcommented, Jun 24, 2022

Is there any workaround for this? How to fix code that throws on server? We have a page component with a hook that needs to be run on the client. It throws on pre-rendering with ssr: false and suspense: true.

1reaction
bkyervcommented, May 30, 2022

I use @canary but about a week ago version of canary. I will try @canary one more time tonight and report back if I succeeded.

Read more comments on GitHub >

github_iconTop Results From Across the Web

invalid-dynamic-suspense - Next.js
React 18 or newer will always try to resolve the Suspense boundary on the server. This behavior can not be disabled, thus the...
Read more >
"This Suspense boundary received an update before it ...
Error : This Suspense boundary received an update before it finished hydrating. This caused the boundary to switch to client rendering. The usual ......
Read more >
nextjs hydration error | The AI Search Engine You Control
Error : This Suspense boundary received an update before it finished hydrating. This caused the boundary to switch to client rendering. The usual...
Read more >
import() - JavaScript - MDN Web Docs - Mozilla
The import() syntax, commonly called dynamic import, is a function-like expression that allows loading an ECMAScript module asynchronously ...
Read more >
Dynamic imports and code splitting with Next.js
Note that next/dynamic does not allow template literals or variables to be used in the import() argument. Also, react/suspense has a specified ...
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