dynamic import with `suspense:true, ssr:false` causes `The server could not finish this Suspense boundary` error
See original GitHub issueVerify 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.
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:
- Created a year ago
- Comments:13 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
andsuspense: true
.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.